diff --git a/imgin/__init__.py b/imgin/__init__.py index b38d032..eb714d5 100644 --- a/imgin/__init__.py +++ b/imgin/__init__.py @@ -21,7 +21,7 @@ def get_timestamp_of_file(file): def album(id): req = IMAGE_CACHE - get("a/" + id, req) + title = get("a/" + id, req) found_list_file = IMAGE_CACHE + ("a/" + id).replace('/', '_') with open(found_list_file, 'r') as f: @@ -40,7 +40,7 @@ def album(id): with open(f'{template_dir}gallery.html', 'r') as img_view: tpl = SimpleTemplate(img_view) - return tpl.render(imgs=imgs) + return tpl.render(imgs=imgs, title=title) @route('/') @route('') diff --git a/imgin/get.py b/imgin/get.py index 1c7ad7f..b7ad1c3 100644 --- a/imgin/get.py +++ b/imgin/get.py @@ -41,12 +41,20 @@ def get(url: str, write_dir: str, delete=True): img.write(requests.get(url).content) if delete: Thread(target=delete_file, args=[f"{write_dir}/{url[-11:]}"]).start() + return None else: found_url = '' found_urls = [] found_list_file = '' print('Detecting album/gallery images (contentUrl)', url) soup = bs4.BeautifulSoup(requests.get(url).text, 'html.parser') + title = '' + try: + title = soup.select('meta[property="og:title"]')[0]['content'] + if title == "Imgur": + title = '' + except (KeyError, IndexError): + title = '' for count, el in enumerate(soup.select('.post-image-container'), start=1): if el is None: continue @@ -78,3 +86,4 @@ def get(url: str, write_dir: str, delete=True): with open(found_list_file, 'w') as f: f.write(','.join(found_urls)) Thread(target=delete_file, args=[found_list_file]).start() + return title diff --git a/imgin/web/gallery.html b/imgin/web/gallery.html index 8d7b4ce..a233a75 100644 --- a/imgin/web/gallery.html +++ b/imgin/web/gallery.html @@ -4,11 +4,14 @@ - imgin - minimal & private imgur proxy + {{title + " - imgin" if title else "imgin - minimal & private imgur proxy"}} + % if title != '': +

{{title}}

+ % end % for img in imgs: