complain during fetch if a dlsite work isn't a manga or CG

This commit is contained in:
xenofem 2024-04-01 22:47:07 -04:00
parent 21ad04f478
commit 3b1e212055

View file

@ -18,7 +18,7 @@ import unicodedata
from urllib.parse import urlparse from urllib.parse import urlparse
import zipfile import zipfile
from dlsite_async import DlsiteAPI import dlsite_async
import fitz import fitz
from libsixel import * from libsixel import *
from PIL import Image from PIL import Image
@ -207,6 +207,8 @@ def manual_input_metadata(work_id):
} }
async def fetch_async(args): async def fetch_async(args):
any_warnings = False
con = sqlite3.connect(args.destdir / 'meta.db') con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor() cur = con.cursor()
@ -217,7 +219,7 @@ async def fetch_async(args):
thumbnails_dir = args.destdir / 'site' / 'thumbnails' thumbnails_dir = args.destdir / 'site' / 'thumbnails'
thumbnails_dir.mkdir(parents=True, exist_ok=True) thumbnails_dir.mkdir(parents=True, exist_ok=True)
async with DlsiteAPI(locale=args.locale) as api: async with dlsite_async.DlsiteAPI(locale=args.locale) as api:
for work_path in (args.destdir / 'extract').iterdir(): for work_path in (args.destdir / 'extract').iterdir():
work_id = work_path.name work_id = work_path.name
@ -228,6 +230,10 @@ async def fetch_async(args):
if DLSITE_ID_REGEX.fullmatch(work_id): if DLSITE_ID_REGEX.fullmatch(work_id):
print(f'Fetching DLSite metadata for {work_id}') print(f'Fetching DLSite metadata for {work_id}')
dlsite_metadata = await api.get_work(work_id) dlsite_metadata = await api.get_work(work_id)
if dlsite_metadata.work_type not in [dlsite_async.WorkType.MANGA, dlsite_async.WorkType.CG_ILLUSTRATIONS]:
print(f'Work {work_id} is not a manga or CG set, skipping')
any_warnings = True
continue
db_row = { db_row = {
"id": work_id, "id": work_id,
"title": dlsite_metadata.work_name, "title": dlsite_metadata.work_name,
@ -287,12 +293,14 @@ async def fetch_async(args):
con.close() con.close()
return any_warnings
def url_file_ext(url): def url_file_ext(url):
return splitext(urlparse(url).path)[1] return splitext(urlparse(url).path)[1]
def fetch(args): def fetch(args):
asyncio.run(fetch_async(args)) any_warnings = asyncio.run(fetch_async(args))
if args.auto: if args.auto and not any_warnings:
parser_collate.parse_args(args=[], namespace=args) parser_collate.parse_args(args=[], namespace=args)
collate(args) collate(args)