Skip to content

Commit 7cb39a9

Browse files
committed
implement EH ID for ccloli.py
1 parent 4b3b228 commit 7cb39a9

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

comiclib/scan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def scan(paths):
8484
db.add(c)
8585
a.categories.append(c)
8686
if old_a is None:
87+
assert len(metadata["id"]) == 40, f'The length of ID {metadata["id"]} is incorrect.'
8788
a.id = metadata["id"]
8889
db.add(a)
8990
db.commit()

comiclib/scanner/20-ccloli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
from zipfile import ZipFile
3+
import re
34

45
import logging
56
logger = logging.getLogger(__name__)
@@ -31,6 +32,11 @@ def scan(self, path: Path, id: str, metadata: dict, prev_scanners: list[str]) ->
3132
metadata["title"] = info[0]
3233
metadata["subtitle"] = info[1]
3334
metadata["source"] = info[2]
35+
m = re.match(r"https?://e[x-]hentai\.org/g/(\d+)/(\w+)", metadata["source"])
36+
if m is None:
37+
logger.error(metadata["source"])
38+
raise NotImplementedError('Unknow source format.')
39+
metadata["id"] = f"EH{m[1]:>018}{m[2]}{id[-10:]}"
3440
line_tags = False
3541
for line in info:
3642
if line.startswith("Category: "): metadata["categories"].add(line.removeprefix("Category: "))

docs/en/docs/scanner.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ Parameters of `Scanner.scan`:
111111
!!! example "custom ID (Experimental)"
112112
ComicLib first pre-generates a unique ID based on the path, starting with `00` as the value of the parameter `id`. Initially this ID is the same as `metadata[id]`.
113113
The scanner can generate a new ID based on `id`, `metadata[id]` modified by the previous scanning script and other information, and write it into `metadata[id]`.
114-
It is generally agreed that the first two characters of the ID represent the meaning of the ID. For example, the built-in scanner 30-importEHdb.py uses `EH` to represent its designed ID with ehentai gid information.
114+
It is generally agreed that the first several characters of the ID represent the meaning of the ID. For example, the built-in scanner uses `EH` to represent its designed ID with ehentai gid information.
115115
The final `metadata[id]` is written to the database as a unique identifier for the comic.
116116
ID must be unique, and be 40 characters. Custom IDs will not work for updating metadata during rescanning

docs/zh/docs/scanner.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ class Scanner:
110110
!!! example "自定义ID(试验性)"
111111
ComicLib 先根据路径预生成一个唯一 ID,以 `00` 开头,作为参数 `id` 的值。最初这一 ID 与 `metadata[id]` 相同。
112112
扫描脚本可以根据 `id` 、前面扫描脚本修改的 `metadata[id]` 和其他信息生成一个新的 ID,写入 `metadata[id]`
113-
一般约定 ID 的前两个字符表示 ID 的含义,如内置脚本 30-importEHdb.py 用 `EH` 表示其设计的带有 ehentai gid 信息的 ID。
113+
一般约定 ID 的前几个字符表示 ID 的含义,如内置脚本用 `EH` 表示其设计的带有 ehentai gid 信息的 ID。
114114
最终的 `metadata[id]` 作为漫画的唯一标识符写入数据库。
115115
ID 必须保证唯一,且为 40 个字符。自定义 ID 对重新扫描更新元数据无效。

0 commit comments

Comments
 (0)