render descriptions and small titles

This commit is contained in:
Austin Huang 2022-01-09 15:26:35 -05:00
parent 7eef48e341
commit 500cbab146
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 23 additions and 6 deletions

View File

@ -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])

View File

@ -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

View File

@ -13,8 +13,11 @@
<h1>{{title}}</h1>
% end
% for img in imgs:
<a href="{{img}}"><img src="{{img}}" loading="lazy"></a>
<br>
% if img[1] != '':
<h2>{{img[1]}}</h2>
% end
<p>{{img[2]}}</p>
<a href="{{img[0]}}"><img src="{{img[0]}}" loading="lazy"></a>
% end
<footer>
<small>