Skip to content

Commit 8a3eb53

Browse files
authored
1 parent 7aec741 commit 8a3eb53

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

comiclib/scanner/24-ehentai_bot.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pathlib import Path
2+
from zipfile import ZipFile
3+
import re, json
4+
from datetime import date
5+
6+
import logging
7+
logger = logging.getLogger(__name__)
8+
9+
class Scanner:
10+
'''For https://github.com/z-mio/ehentai_bot, with <gid>.json put into the zip archive.'''
11+
12+
def scan(self, path: Path, id: str, metadata: dict, prev_scanners: list[str]) -> bool:
13+
if not '10-zip' in prev_scanners or '20-ccloli' in prev_scanners:
14+
return False
15+
with ZipFile(path) as z:
16+
for filename in z.namelist():
17+
if (m := re.fullmatch(r'(\d+)\.json', filename, flags=re.ASCII)):
18+
with z.open(filename) as f:
19+
json_content = json.load(f)
20+
if not isinstance(json_content, dict):
21+
break
22+
gmetadata = json_content.get('gmetadata')
23+
if not (isinstance(gmetadata, list) and len(gmetadata) == 1 and isinstance(gmetadata[0], dict)):
24+
break
25+
logger.info(f' <- {path}')
26+
gmetadata = gmetadata[0]
27+
if gmetadata.get('gid') != int(m[1]):
28+
break
29+
metadata["id"] = f"EH{gmetadata['gid']:>018}{gmetadata['token']}{id[-10:]}"
30+
metadata["title"] = gmetadata['title']
31+
metadata["subtitle"] = gmetadata['title_jpn']
32+
metadata["categories"] = set((gmetadata['category'],))
33+
metadata["thumb"] = gmetadata['thumb']
34+
metadata["pagecount"] = gmetadata['filecount']
35+
metadata["tags"] = gmetadata['tags'] + [
36+
f"date_posted:{date.fromtimestamp(int(gmetadata['posted']))}",
37+
]
38+
metadata["source"] = f"https://exhentai.org/g/{gmetadata['gid']}/{gmetadata['token']}/"
39+
return True
40+
return False

0 commit comments

Comments
 (0)