render album title
This commit is contained in:
parent
d07e7caab2
commit
7eef48e341
@ -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('')
|
||||
|
@ -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
|
||||
|
@ -4,11 +4,14 @@
|
||||
<head>
|
||||
<meta charself="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>imgin - minimal & private imgur proxy</title>
|
||||
<title>{{title + " - imgin" if title else "imgin - minimal & private imgur proxy"}}</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📷</text></svg>">
|
||||
<link rel="stylesheet" href="/static/theme.css">
|
||||
</head>
|
||||
<body>
|
||||
% if title != '':
|
||||
<h1>{{title}}</h1>
|
||||
% end
|
||||
% for img in imgs:
|
||||
<a href="{{img}}"><img src="{{img}}" loading="lazy"></a>
|
||||
<br>
|
||||
|
Loading…
Reference in New Issue
Block a user