support Fakku works using first page as thumbnail for now

This commit is contained in:
xenofem 2024-01-29 21:25:21 -05:00
parent a76e3eec83
commit 3efee8fe05
6 changed files with 41 additions and 16 deletions

View file

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

View file

@ -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%;
}

View file

@ -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');

View file

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

View file

@ -7,7 +7,7 @@
{% for work in works %}
<div class="card">
<a href="{{ root() }}/works/{{ work['id'] }}/{{ index() }}">
<img src="{{ root() }}/thumbnails/{{ work['id'] }}.jpg">
<img src="{{ root() }}/thumbnails/{{ work['thumbnail_filename'] }}">
<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 %}]
</div>

View file

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