bookget 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bookget-0.3.2 → bookget-0.3.3}/PKG-INFO +1 -1
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/base.py +9 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/base_iiif.py +125 -4
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/kyoto.py +5 -5
- {bookget-0.3.2 → bookget-0.3.3}/bookget/main.py +14 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget.egg-info/PKG-INFO +1 -1
- {bookget-0.3.2 → bookget-0.3.3}/pyproject.toml +1 -1
- {bookget-0.3.2 → bookget-0.3.3}/README.md +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/__main__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/harvard.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/ndl.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/princeton.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/iiif/stanford.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/archive_org.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/ctext.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/european.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/hanchi.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/nlc_guji.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/shidianguji.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/taiwan.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/wikimedia_commons.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/other/wikisource.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/adapters/registry.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/config.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/core/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/core/resource_manager.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/downloaders/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/downloaders/base.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/downloaders/iiif.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/exceptions.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/logger.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/models/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/models/book.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/models/manifest.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/models/search.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/scripts/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/scripts/images_to_pdf.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/scripts/siku_catalog_parser.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/scripts/strip_tu_marker.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/server/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/server/app.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/server/routes.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/server/sse.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/server/static.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/server/tasks.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/storage/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/storage/file_storage.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_converters/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_converters/markdown_converter.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_converters/plaintext_converter.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_parsers/__init__.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_parsers/base.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_parsers/ctext_parser.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_parsers/hanchi_parser.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_parsers/shidianguji_parser.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/text_parsers/wikisource_parser.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget/utils.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget.egg-info/SOURCES.txt +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget.egg-info/dependency_links.txt +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget.egg-info/entry_points.txt +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget.egg-info/requires.txt +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/bookget.egg-info/top_level.txt +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/setup.cfg +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_adapters.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_config.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_downloaders.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_exceptions.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_file_storage.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_hanchi.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_manifest.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_models.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_resource_manager.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_text_parsers.py +0 -0
- {bookget-0.3.2 → bookget-0.3.3}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bookget
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Download and parse ancient Chinese book resources from digital libraries
|
|
5
5
|
Keywords: ancient-books,digital-library,downloader,classical-chinese
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -306,6 +306,15 @@ class BaseSiteAdapter(ABC):
|
|
|
306
306
|
total_items=len(vol_images),
|
|
307
307
|
source_data={
|
|
308
308
|
"image_urls": [img.url for img in vol_images],
|
|
309
|
+
"images": [
|
|
310
|
+
{
|
|
311
|
+
"url": img.url,
|
|
312
|
+
"filename": img.get_filename(),
|
|
313
|
+
"page": img.page,
|
|
314
|
+
"volume": img.volume,
|
|
315
|
+
}
|
|
316
|
+
for img in vol_images
|
|
317
|
+
],
|
|
309
318
|
},
|
|
310
319
|
)
|
|
311
320
|
root.children.append(vol_node)
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Base IIIF Adapter - Handles IIIF-compatible digital libraries
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
4
|
+
import os
|
|
3
5
|
import re
|
|
6
|
+
from pathlib import Path
|
|
4
7
|
from typing import List, Optional, Dict, Any
|
|
5
8
|
from urllib.parse import urlparse, urljoin
|
|
6
9
|
import aiohttp
|
|
@@ -8,6 +11,7 @@ import aiohttp
|
|
|
8
11
|
from ..base import BaseSiteAdapter
|
|
9
12
|
from ..registry import AdapterRegistry
|
|
10
13
|
from ...models.book import BookMetadata, Resource, ResourceType, Creator
|
|
14
|
+
from ...models.manifest import ManifestNode, NodeStatus
|
|
11
15
|
from ...logger import logger
|
|
12
16
|
from ...exceptions import MetadataExtractionError
|
|
13
17
|
|
|
@@ -29,10 +33,32 @@ class BaseIIIFAdapter(BaseSiteAdapter):
|
|
|
29
33
|
|
|
30
34
|
# Subclasses should override these
|
|
31
35
|
manifest_url_template: str = "" # e.g., "https://example.com/iiif/{book_id}/manifest.json"
|
|
32
|
-
|
|
36
|
+
|
|
37
|
+
# IIIF Image API "size" parameter used when constructing download URLs.
|
|
38
|
+
# Defaults to "full" (IIIF 2.x); IIIF 3 sites may override to "max".
|
|
39
|
+
# Common values: "full" / "max" / "1600," / "2400," / ",1600".
|
|
40
|
+
DEFAULT_IIIF_SIZE: str = "full"
|
|
41
|
+
|
|
33
42
|
def __init__(self, config=None):
|
|
34
43
|
super().__init__(config)
|
|
35
44
|
self._session: Optional[aiohttp.ClientSession] = None
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def iiif_size(self) -> str:
|
|
48
|
+
"""
|
|
49
|
+
Resolve IIIF Image API size parameter for downloads.
|
|
50
|
+
|
|
51
|
+
Priority:
|
|
52
|
+
1. BOOKGET_<SITE>_IIIF_SIZE environment variable
|
|
53
|
+
2. BOOKGET_IIIF_SIZE environment variable (global)
|
|
54
|
+
3. self.DEFAULT_IIIF_SIZE
|
|
55
|
+
"""
|
|
56
|
+
site_var = f"BOOKGET_{(self.site_id or '').upper()}_IIIF_SIZE"
|
|
57
|
+
return (
|
|
58
|
+
os.environ.get(site_var)
|
|
59
|
+
or os.environ.get("BOOKGET_IIIF_SIZE")
|
|
60
|
+
or self.DEFAULT_IIIF_SIZE
|
|
61
|
+
)
|
|
36
62
|
|
|
37
63
|
async def get_session(self) -> aiohttp.ClientSession:
|
|
38
64
|
"""Get or create HTTP session."""
|
|
@@ -187,10 +213,10 @@ class BaseIIIFAdapter(BaseSiteAdapter):
|
|
|
187
213
|
width = resource_data.get("width", canvas.get("width", 0))
|
|
188
214
|
height = resource_data.get("height", canvas.get("height", 0))
|
|
189
215
|
|
|
190
|
-
# Construct
|
|
216
|
+
# Construct image URL at the configured size if we have a service ID
|
|
191
217
|
if service_id:
|
|
192
|
-
# IIIF Image API
|
|
193
|
-
image_url = f"{service_id}/full/
|
|
218
|
+
# IIIF Image API: {service_id}/full/{size}/0/default.jpg
|
|
219
|
+
image_url = f"{service_id}/full/{self.iiif_size}/0/default.jpg"
|
|
194
220
|
|
|
195
221
|
resource = Resource(
|
|
196
222
|
url=image_url,
|
|
@@ -205,6 +231,101 @@ class BaseIIIFAdapter(BaseSiteAdapter):
|
|
|
205
231
|
|
|
206
232
|
return resources
|
|
207
233
|
|
|
234
|
+
async def download_node(
|
|
235
|
+
self,
|
|
236
|
+
book_id: str,
|
|
237
|
+
node: ManifestNode,
|
|
238
|
+
output_dir: Path,
|
|
239
|
+
progress_callback=None,
|
|
240
|
+
) -> ManifestNode:
|
|
241
|
+
"""
|
|
242
|
+
Download all images for a manifest volume node.
|
|
243
|
+
|
|
244
|
+
Reads ``node.source_data["images"]`` (list of {url, filename, page,
|
|
245
|
+
volume} dicts) populated by ``_discover_from_legacy``, and writes
|
|
246
|
+
each image into ``output_dir`` using its filename. Falls back to
|
|
247
|
+
``image_urls`` for backward compatibility.
|
|
248
|
+
|
|
249
|
+
Concurrency is controlled by the adapter's config
|
|
250
|
+
(``config.download.concurrent_downloads``, default 4).
|
|
251
|
+
"""
|
|
252
|
+
images = node.source_data.get("images")
|
|
253
|
+
if not images:
|
|
254
|
+
urls = node.source_data.get("image_urls", [])
|
|
255
|
+
images = [
|
|
256
|
+
{"url": u, "filename": f"{i + 1:04d}.jpg"}
|
|
257
|
+
for i, u in enumerate(urls)
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
if not images:
|
|
261
|
+
logger.warning(f"Node {node.id} has no images")
|
|
262
|
+
node.status = NodeStatus.FAILED
|
|
263
|
+
return node
|
|
264
|
+
|
|
265
|
+
node.status = NodeStatus.DOWNLOADING
|
|
266
|
+
node.total_items = len(images)
|
|
267
|
+
output_dir = Path(output_dir)
|
|
268
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
269
|
+
|
|
270
|
+
session = await self.get_session()
|
|
271
|
+
headers = self.get_headers()
|
|
272
|
+
|
|
273
|
+
# Concurrency from config; fallback to 4
|
|
274
|
+
concurrency = 4
|
|
275
|
+
min_size = 1024
|
|
276
|
+
if self.config and hasattr(self.config, "download"):
|
|
277
|
+
concurrency = max(1, self.config.download.concurrent_downloads)
|
|
278
|
+
min_size = self.config.download.min_image_size
|
|
279
|
+
|
|
280
|
+
semaphore = asyncio.Semaphore(concurrency)
|
|
281
|
+
downloaded = 0
|
|
282
|
+
failed = 0
|
|
283
|
+
|
|
284
|
+
async def fetch_one(item: dict) -> bool:
|
|
285
|
+
nonlocal downloaded, failed
|
|
286
|
+
url = item["url"]
|
|
287
|
+
filename = item.get("filename") or url.rsplit("/", 1)[-1]
|
|
288
|
+
out_path = output_dir / filename
|
|
289
|
+
|
|
290
|
+
if out_path.exists() and out_path.stat().st_size >= min_size:
|
|
291
|
+
downloaded += 1
|
|
292
|
+
if progress_callback:
|
|
293
|
+
progress_callback(downloaded, len(images))
|
|
294
|
+
return True
|
|
295
|
+
|
|
296
|
+
async with semaphore:
|
|
297
|
+
try:
|
|
298
|
+
async with session.get(url, headers=headers) as resp:
|
|
299
|
+
resp.raise_for_status()
|
|
300
|
+
content = await resp.read()
|
|
301
|
+
if len(content) < min_size:
|
|
302
|
+
logger.warning(f"Image too small: {filename}")
|
|
303
|
+
failed += 1
|
|
304
|
+
return False
|
|
305
|
+
out_path.write_bytes(content)
|
|
306
|
+
downloaded += 1
|
|
307
|
+
if progress_callback:
|
|
308
|
+
progress_callback(downloaded, len(images))
|
|
309
|
+
return True
|
|
310
|
+
except Exception as e:
|
|
311
|
+
logger.warning(f"Failed {url}: {e}")
|
|
312
|
+
failed += 1
|
|
313
|
+
return False
|
|
314
|
+
|
|
315
|
+
await asyncio.gather(*[fetch_one(it) for it in images])
|
|
316
|
+
|
|
317
|
+
node.downloaded_items = downloaded
|
|
318
|
+
node.failed_items = failed
|
|
319
|
+
if downloaded == len(images):
|
|
320
|
+
node.status = NodeStatus.COMPLETED
|
|
321
|
+
elif downloaded > 0:
|
|
322
|
+
# Partial — keep DISCOVERED so it gets retried next run
|
|
323
|
+
node.status = NodeStatus.DISCOVERED
|
|
324
|
+
else:
|
|
325
|
+
node.status = NodeStatus.FAILED
|
|
326
|
+
|
|
327
|
+
return node
|
|
328
|
+
|
|
208
329
|
async def close(self):
|
|
209
330
|
"""Close HTTP session."""
|
|
210
331
|
if self._session and not self._session.closed:
|
|
@@ -32,10 +32,10 @@ class KyotoRMDAAdapter(BaseIIIFAdapter):
|
|
|
32
32
|
supports_iiif = True
|
|
33
33
|
supports_text = False
|
|
34
34
|
|
|
35
|
-
# IIIF
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
DEFAULT_IIIF_SIZE =
|
|
35
|
+
# RMDA serves IIIF Presentation 3.0; "max" is the canonical "original size"
|
|
36
|
+
# parameter (≈4 MB JPEG for typical pages). Use BOOKGET_KYOTO_IIIF_SIZE
|
|
37
|
+
# or BOOKGET_IIIF_SIZE env var to override (e.g. "2400," / "1600,").
|
|
38
|
+
DEFAULT_IIIF_SIZE = "max"
|
|
39
39
|
|
|
40
40
|
def extract_book_id(self, url: str) -> str:
|
|
41
41
|
"""
|
|
@@ -154,7 +154,7 @@ class KyotoRMDAAdapter(BaseIIIFAdapter):
|
|
|
154
154
|
"""
|
|
155
155
|
resources: List[Resource] = []
|
|
156
156
|
canvases = manifest.get("items", []) or []
|
|
157
|
-
size = self.
|
|
157
|
+
size = self.iiif_size
|
|
158
158
|
|
|
159
159
|
for idx, canvas in enumerate(canvases):
|
|
160
160
|
page_label = self._extract_label(canvas.get("label", "")) or str(idx + 1)
|
|
@@ -13,6 +13,7 @@ Usage:
|
|
|
13
13
|
import argparse
|
|
14
14
|
import asyncio
|
|
15
15
|
import json
|
|
16
|
+
import os
|
|
16
17
|
import sys
|
|
17
18
|
from pathlib import Path
|
|
18
19
|
|
|
@@ -441,6 +442,19 @@ async def _interactive_mode():
|
|
|
441
442
|
except ValueError:
|
|
442
443
|
concurrency = 3
|
|
443
444
|
print(f" → 并行数:{concurrency}")
|
|
445
|
+
|
|
446
|
+
# --- Step 3b: IIIF image resolution (only for IIIF adapters) ---
|
|
447
|
+
if getattr(adapter, "supports_iiif", False):
|
|
448
|
+
print("\n选择图片分辨率:")
|
|
449
|
+
print(" 1) 最高清 (原始尺寸 max/full,文件最大)")
|
|
450
|
+
print(" 2) 高清 (2400px 宽)")
|
|
451
|
+
print(" 3) 阅读 (1600px 宽) ← 默认")
|
|
452
|
+
print(" 4) 缩略 (800px 宽)")
|
|
453
|
+
size_input = input("输入序号 [3]: ").strip() or "3"
|
|
454
|
+
size_map = {"1": "max", "2": "2400,", "3": "1600,", "4": "800,"}
|
|
455
|
+
chosen = size_map.get(size_input, "1600,")
|
|
456
|
+
os.environ["BOOKGET_IIIF_SIZE"] = chosen
|
|
457
|
+
print(f" → 分辨率:{chosen}")
|
|
444
458
|
print()
|
|
445
459
|
|
|
446
460
|
# --- Step 4: Discover ---
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bookget
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Download and parse ancient Chinese book resources from digital libraries
|
|
5
5
|
Keywords: ancient-books,digital-library,downloader,classical-chinese
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|