Added version number to index
This commit is contained in:
Kevin F 2021-10-05 18:40:48 +00:00
parent c652308979
commit 15c199f610
4 changed files with 24 additions and 6 deletions

View File

@ -1,6 +1,8 @@
# Changelog
This project uses Semantic Versioning
## 0.0.1
Switched from glob to a list file which fixes albums overwriting each other (Reported by SeerLite)
## 0.0.0

View File

@ -4,7 +4,6 @@ monkey.patch_all()
from threading import Thread
from os import remove, mkdir, path, stat
from shutil import rmtree
from glob import glob
from uuid import uuid4
@ -20,12 +19,16 @@ def get_timestamp_of_file(file):
return stat(file).st_ctime
def album(id):
req_id = str(uuid4())
req = IMAGE_CACHE
get("/a/" + id, req)
found_list_file = IMAGE_CACHE + ("/a/" + id).replace('/', '_')
imgs = glob(req + "*")
with open(found_list_file, 'r') as f:
imgs = f.read().split(',')
for c, img in enumerate(imgs):
imgs[c] = IMAGE_CACHE + imgs[c]
# sort image order (file creation time)
imgs = sorted(imgs, key=get_timestamp_of_file)
@ -62,6 +65,7 @@ def gallery(id=''):
def img(img=''):
if not img.endswith("jpeg") and not img.endswith("jpg") and not img.endswith("png"):
img = img + ".jpg"
img = img.replace('jpeg', 'jpg')
if not path.exists(IMAGE_CACHE + img):
get(img, IMAGE_CACHE)
return static_file(img, root=IMAGE_CACHE)

View File

@ -6,7 +6,7 @@ import requests
import bs4
from gevent import sleep
from .config import SINGLE_IMAGE_DELETE_AFTER_SECS
from .config import IMAGE_CACHE, SINGLE_IMAGE_DELETE_AFTER_SECS
def delete_file(path):
sleep(SINGLE_IMAGE_DELETE_AFTER_SECS)
@ -22,9 +22,12 @@ def error(msg):
sys.stderr.flush()
def get(url: str, write_dir: str, delete=True):
orig_url = url
if not url.startswith('https://imgur.com/'):
url = 'https://imgur.com/' + url
found_url = ''
found_urls = []
found_list_file = ''
album = False
if "gallery" in url:
@ -37,7 +40,7 @@ def get(url: str, write_dir: str, delete=True):
if not album:
print('Getting img', url)
url = 'https://i.imgur.com/' + url.rsplit('/', 1)[-1].replace('jpeg', 'jpg')
url = 'https://i.imgur.com/' + url.rsplit('/', 1)[-1]
with open(f'{write_dir}/{url[-11:]}', 'wb') as img:
img.write(requests.get(url).content)
if delete:
@ -53,11 +56,19 @@ def get(url: str, write_dir: str, delete=True):
continue
if found_url.endswith('ico.jpg'):
continue
found_urls.append(found_url[-11:])
print(f"Downloading image {count}: {found_url}")
print("Writing image", f"{write_dir}{found_url[-11:]}")
with open(f"{write_dir}{found_url[-11:]}", "wb") as f:
f.write(requests.get(found_url).content)
if delete:
Thread(target=delete_file, args=[f"{write_dir}{found_url[-11:]}"]).start()
# Write the found urls to a file with the name of the album so the viewer endpoint can get them
found_list_file = IMAGE_CACHE + orig_url.replace('/', '_')
with open(found_list_file, 'w') as f:
f.write(','.join(found_urls))
Thread(target=delete_file, args=[found_list_file]).start()

View File

@ -39,6 +39,7 @@
<p>Or, run it with python by installing the requirements.txt and ./run.py. Or use the Dockerfile. Contact me if you want help or find a bug.</p>
<footer>
<small>
<p>Imgin Version 0.0.1</p>
Powered by <a href="https://voidnet.tech/">VoidNetwork LLC</a><br>
This website does not claim ownership of any media.
<br>This service simply acts as a proxy to Imgur.com and does not store images aside from a brief cache.