diff --git a/imgin/__init__.py b/imgin/__init__.py index eb714d5..3abc465 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 - title = get("a/" + id, req) + title, metas = get("a/" + id, req) found_list_file = IMAGE_CACHE + ("a/" + id).replace('/', '_') with open(found_list_file, 'r') as f: @@ -34,7 +34,7 @@ def album(id): imgs = sorted(imgs, key=get_timestamp_of_file) for c, img in enumerate(imgs): - imgs[c] = img.replace(IMAGE_CACHE, '/') + imgs[c] = (img.replace(IMAGE_CACHE, '/'), metas[c][0], metas[c][1]) diff --git a/imgin/get.py b/imgin/get.py index b7ad1c3..bff6209 100644 --- a/imgin/get.py +++ b/imgin/get.py @@ -46,9 +46,10 @@ def get(url: str, write_dir: str, delete=True): found_url = '' found_urls = [] found_list_file = '' + title = '' + metas = [] 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": @@ -81,9 +82,22 @@ def get(url: str, write_dir: str, delete=True): if delete: Thread(target=delete_file, args=[f"{write_dir}{found_url[-11:]}"]).start() + + subtitle = '' + try: + subtitle = minisoup.select('.post-image-title')[0].string + except IndexError: + subtitle = '' + desc = '' + try: + desc = minisoup.select('.post-image-description')[0].string + except IndexError: + desc = '' + date = '' + metas.append((subtitle, desc)) # Write the found urls to a file with the name of the album so the viewer endpoint can get them found_list_file = write_dir + 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() - return title + return title, metas diff --git a/imgin/web/gallery.html b/imgin/web/gallery.html index a233a75..694b136 100644 --- a/imgin/web/gallery.html +++ b/imgin/web/gallery.html @@ -13,8 +13,11 @@

{{title}}

% end % for img in imgs: - -
+ % if img[1] != '': +

{{img[1]}}

+ % end +

{{img[2]}}

+ % end