default to using first page as thumbnail

This commit is contained in:
xenofem 2024-02-06 08:29:52 -05:00
parent 9ebab7d5bb
commit 25374a5ba3
5 changed files with 25 additions and 30 deletions

View file

@ -111,7 +111,6 @@ async def fetch_async(args):
} }
authors = dlsite_metadata.author or [] authors = dlsite_metadata.author or []
tags = dlsite_metadata.genre or [] tags = dlsite_metadata.genre or []
thumbnail_local = False
thumbnail_url = dlsite_metadata.work_image thumbnail_url = dlsite_metadata.work_image
if thumbnail_url.startswith('//'): if thumbnail_url.startswith('//'):
thumbnail_url = 'https:' + thumbnail_url thumbnail_url = 'https:' + thumbnail_url
@ -120,17 +119,11 @@ async def fetch_async(args):
authors = db_row.pop('authors') authors = db_row.pop('authors')
tags = db_row.pop('tags') tags = db_row.pop('tags')
if FANZA_ID_REGEX.fullmatch(work_id): if FANZA_ID_REGEX.fullmatch(work_id):
thumbnail_local = False
thumbnail_url = f'https://doujin-assets.dmm.co.jp/digital/comic/{work_id}/{work_id}pl.jpg' thumbnail_url = f'https://doujin-assets.dmm.co.jp/digital/comic/{work_id}/{work_id}pl.jpg'
elif FAKKU_ID_REGEX.fullmatch(work_id): elif FAKKU_ID_REGEX.fullmatch(work_id):
thumbnail_local = True thumbnail_url = None
thumbnail_path = min(work_path.iterdir())
if not thumbnail_path.is_file():
print(f'Fakku thumbnail path {thumbnail_path} is not a file! Skipping {work_id}')
continue
else: else:
thumbnail_local = False thumbnail_url = input('Thumbnail image URL [default: first page]: ')
thumbnail_url = input('Thumbnail image URL: ')
cur.execute( cur.execute(
"INSERT INTO works(id, title, circle, date, description, series) VALUES(:id, :title, :circle, :date, :description, :series)", "INSERT INTO works(id, title, circle, date, description, series) VALUES(:id, :title, :circle, :date, :description, :series)",
@ -145,11 +138,7 @@ async def fetch_async(args):
[{ "tag": tag, "work": work_id } for tag in tags], [{ "tag": tag, "work": work_id } for tag in tags],
) )
if thumbnail_local: if thumbnail_url:
ext = thumbnail_path.suffix
dest_path = thumbnails_dir / (work_id + ext)
dest_path.symlink_to(relpath(thumbnail_path, thumbnails_dir))
else:
ext = url_file_ext(thumbnail_url) ext = url_file_ext(thumbnail_url)
dest_file = thumbnails_dir / (work_id + ext) dest_file = thumbnails_dir / (work_id + ext)
print(f'Downloading thumbnail for {work_id} from {thumbnail_url}') print(f'Downloading thumbnail for {work_id} from {thumbnail_url}')
@ -375,7 +364,9 @@ def generate(args):
con = sqlite3.connect(args.destdir / 'meta.db') con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor() cur = con.cursor()
collated_work_ids = {p.name for p in (args.destdir / 'site' / 'images').iterdir()} site_dir = args.destdir / 'site'
collated_work_ids = {p.name for p in (site_dir / 'images').iterdir()}
actual_series = {series for (series,) in cur.execute('SELECT series FROM works GROUP BY series HAVING count(series) > 1')} actual_series = {series for (series,) in cur.execute('SELECT series FROM works GROUP BY series HAVING count(series) > 1')}
@ -385,9 +376,16 @@ def generate(args):
continue continue
authors = [author for (author,) in cur.execute('SELECT author FROM authors WHERE work = ?', (work_id,))] authors = [author for (author,) in cur.execute('SELECT author FROM authors WHERE work = ?', (work_id,))]
tags = [tag for (tag,) in cur.execute('SELECT tag FROM tags WHERE work = ?', (work_id,))] tags = [tag for (tag,) in cur.execute('SELECT tag FROM tags WHERE work = ?', (work_id,))]
thumbnail_filename = next(
f for f in (args.destdir / 'site' / 'thumbnails').iterdir() if f.stem == work_id images = [path.name for path in (site_dir / 'images' / work_id).iterdir()]
).name images.sort()
try:
thumbnail_path = relpath(next(
f for f in (site_dir / 'thumbnails').iterdir() if f.stem == work_id
), site_dir)
except StopIteration:
thumbnail_path = f'images/{work_id}/{images[0]}'
work = { work = {
'id': work_id, 'id': work_id,
'title': title, 'title': title,
@ -397,14 +395,11 @@ def generate(args):
'series': series, 'series': series,
'authors': authors, 'authors': authors,
'tags': tags, 'tags': tags,
'thumbnail_filename': thumbnail_filename, 'thumbnail_path': thumbnail_path,
} }
works.append(work) works.append(work)
images = [path.name for path in (args.destdir / 'site' / 'images' / work_id).iterdir()] work_dir = site_dir / 'works' / work_id
images.sort()
work_dir = args.destdir / 'site' / 'works' / work_id
viewer_dir = work_dir / 'view' viewer_dir = work_dir / 'view'
viewer_dir.mkdir(parents=True, exist_ok=True) viewer_dir.mkdir(parents=True, exist_ok=True)
with open(work_dir / 'index.html', 'w') as f: with open(work_dir / 'index.html', 'w') as f:
@ -413,7 +408,7 @@ def generate(args):
f.write(viewer_template.render(depth=3, work=work, title=title, images=images)) f.write(viewer_template.render(depth=3, work=work, title=title, images=images))
def make_categorization(categorization, query, work_filter, work_style_cards=False): def make_categorization(categorization, query, work_filter, work_style_cards=False):
categorization_dir = args.destdir / 'site' / categorization categorization_dir = site_dir / categorization
cats = [cat for (cat,) in cur.execute(query)] cats = [cat for (cat,) in cur.execute(query)]
cat_samples = {} cat_samples = {}
@ -465,9 +460,9 @@ def generate(args):
) )
with resources.as_file(resources.files("dlibrary")) as r: with resources.as_file(resources.files("dlibrary")) as r:
copy_recursive(r / 'static', args.destdir / 'site' / 'static') copy_recursive(r / 'static', site_dir / 'static')
with open(args.destdir / 'site' / 'index.html', 'w') as f: with open(site_dir / 'index.html', 'w') as f:
f.write(index_template.render(depth=0, works=works)) f.write(index_template.render(depth=0, works=works))
con.close() con.close()

View file

@ -48,7 +48,7 @@ document.addEventListener('DOMContentLoaded', () => {
card.appendChild(link); card.appendChild(link);
const thumb = document.createElement('img'); const thumb = document.createElement('img');
thumb.src = `${ROOT}/thumbnails/${work.thumbnail_filename}`; thumb.src = `${ROOT}/${work.thumbnail_path}`;
link.appendChild(thumb); link.appendChild(thumb);
const creators = document.createElement('div'); const creators = document.createElement('div');

View file

@ -12,7 +12,7 @@
{{ cat }} {{ cat }}
</div> </div>
{% if samples[cat] %} {% if samples[cat] %}
<img src="{{ root() }}/thumbnails/{{ samples[cat]['thumbnail_filename'] }}"> <img src="{{ root() }}/{{ samples[cat]['thumbnail_path'] }}">
{% endif %} {% endif %}
</a> </a>
</div> </div>

View file

@ -7,7 +7,7 @@
{% for work in works %} {% for work in works %}
<div class="card"> <div class="card">
<a href="{{ root() }}/works/{{ work['id'] }}/{{ index() }}"> <a href="{{ root() }}/works/{{ work['id'] }}/{{ index() }}">
<img src="{{ root() }}/thumbnails/{{ work['thumbnail_filename'] }}"> <img src="{{ root() }}/{{ work['thumbnail_path'] }}">
<div class="card-creators"> <div class="card-creators">
[{% if work['circle'] %}{{ work['circle'] }}{% endif %}{% if work['circle'] and work['authors'] %} ({% endif %}{{ ', '.join(work['authors']) }}{% if work['circle'] and work['authors'] %}){% endif %}] [{% if work['circle'] %}{{ work['circle'] }}{% endif %}{% if work['circle'] and work['authors'] %} ({% endif %}{{ ', '.join(work['authors']) }}{% if work['circle'] and work['authors'] %}){% endif %}]
</div> </div>

View file

@ -5,7 +5,7 @@
<div class="work-container"> <div class="work-container">
<div class="work-preview"> <div class="work-preview">
<a href="view/{{ index() }}"> <a href="view/{{ index() }}">
<img src="{{ root() }}/thumbnails/{{ work['thumbnail_filename'] }}"> <img src="{{ root() }}/{{ work['thumbnail_path'] }}">
<div class="start-link">Start Reading</div> <div class="start-link">Start Reading</div>
</a> </a>
</div> </div>