From 3efee8fe0561680b692598c05d1430b8e9c1163f Mon Sep 17 00:00:00 2001 From: xenofem Date: Mon, 29 Jan 2024 21:25:21 -0500 Subject: [PATCH] support Fakku works using first page as thumbnail for now --- dlibrary/dlibrary.py | 43 +++++++++++++++++++------- dlibrary/static/dlibrary.css | 6 ++++ dlibrary/static/index.js | 2 +- dlibrary/templates/categorization.html | 2 +- dlibrary/templates/list.html | 2 +- dlibrary/templates/work.html | 2 +- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index b2ecc06..cb48a20 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -22,6 +22,7 @@ NUMBER_REGEX = re.compile('[0-9]+') DLSITE_ID_REGEX = re.compile('^[BR]J[0-9]+$') FANZA_ID_REGEX = re.compile('^d_[0-9]+$') +FAKKU_ID_REGEX = re.compile('.*_FAKKU$') IMAGE_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.tiff'] @@ -108,17 +109,26 @@ async def fetch_async(args): } authors = dlsite_metadata.author or [] tags = dlsite_metadata.genre or [] + thumbnail_local = False thumbnail_url = dlsite_metadata.work_image if thumbnail_url.startswith('//'): thumbnail_url = 'https:' + thumbnail_url - elif FANZA_ID_REGEX.fullmatch(work_id): + else: db_row = manual_input_metadata(work_id) authors = db_row.pop('authors') tags = db_row.pop('tags') - thumbnail_url = f'https://doujin-assets.dmm.co.jp/digital/comic/{work_id}/{work_id}pl.jpg' - else: - print(f"Don't know how to fetch metadata for {work_id}, skipping") - continue + 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' + elif FAKKU_ID_REGEX.fullmatch(work_id): + thumbnail_local = True + 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: + thumbnail_local = False + thumbnail_url = input('Thumbnail image URL: ') cur.execute( "INSERT INTO works(id, title, circle, date, description, series) VALUES(:id, :title, :circle, :date, :description, :series)", @@ -133,13 +143,18 @@ async def fetch_async(args): [{ "tag": tag, "work": work_id } for tag in tags], ) - ext = url_file_ext(thumbnail_url) - dest_file = thumbnails_dir / (work_id + ext) - print(f'Downloading thumbnail for {work_id} from {thumbnail_url}') - with open(dest_file, 'wb') as fd: - with requests.get(thumbnail_url, stream=True) as r: - for chunk in r.iter_content(chunk_size=16384): - fd.write(chunk) + if thumbnail_local: + 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) + dest_file = thumbnails_dir / (work_id + ext) + print(f'Downloading thumbnail for {work_id} from {thumbnail_url}') + with open(dest_file, 'wb') as fd: + with requests.get(thumbnail_url, stream=True) as r: + for chunk in r.iter_content(chunk_size=16384): + fd.write(chunk) con.commit() @@ -368,6 +383,9 @@ def generate(args): continue 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,))] + thumbnail_filename = next( + f for f in (args.destdir / 'site' / 'thumbnails').iterdir() if f.stem == work_id + ).name work = { 'id': work_id, 'title': title, @@ -377,6 +395,7 @@ def generate(args): 'series': series, 'authors': authors, 'tags': tags, + 'thumbnail_filename': thumbnail_filename, } works.append(work) diff --git a/dlibrary/static/dlibrary.css b/dlibrary/static/dlibrary.css index c7a17b0..5a7e0bf 100644 --- a/dlibrary/static/dlibrary.css +++ b/dlibrary/static/dlibrary.css @@ -104,6 +104,12 @@ body { gap: 30px; } +.work-preview { + flex-basis: 40%; + flex-grow: 1; + min-width: min(300px, 100%); +} + .work-preview img { max-width: 100%; } diff --git a/dlibrary/static/index.js b/dlibrary/static/index.js index 8d48595..328476d 100644 --- a/dlibrary/static/index.js +++ b/dlibrary/static/index.js @@ -48,7 +48,7 @@ document.addEventListener('DOMContentLoaded', () => { card.appendChild(link); const thumb = document.createElement('img'); - thumb.src = `${ROOT}/thumbnails/${work.id}.jpg`; + thumb.src = `${ROOT}/thumbnails/${work.thumbnail_filename}`; link.appendChild(thumb); const creators = document.createElement('div'); diff --git a/dlibrary/templates/categorization.html b/dlibrary/templates/categorization.html index f903b2f..7849819 100644 --- a/dlibrary/templates/categorization.html +++ b/dlibrary/templates/categorization.html @@ -12,7 +12,7 @@ {{ cat }} {% if samples[cat] %} - + {% endif %} diff --git a/dlibrary/templates/list.html b/dlibrary/templates/list.html index ec7165d..0e28cc5 100644 --- a/dlibrary/templates/list.html +++ b/dlibrary/templates/list.html @@ -7,7 +7,7 @@ {% for work in works %}
- +
[{% if work['circle'] %}{{ work['circle'] }}{% endif %}{% if work['circle'] and work['authors'] %} ({% endif %}{{ ', '.join(work['authors']) }}{% if work['circle'] and work['authors'] %}){% endif %}]
diff --git a/dlibrary/templates/work.html b/dlibrary/templates/work.html index 3f75309..cf0f6bc 100644 --- a/dlibrary/templates/work.html +++ b/dlibrary/templates/work.html @@ -5,7 +5,7 @@