mirror of
https://github.com/subutux/rmapy.git
synced 2025-12-08 14:43:24 +00:00
fix(download): Ignore missing thumbnail files (#9)
* Ignore missing thumbnail files * Change logger name
This commit is contained in:
committed by
GitHub
parent
29d113f3af
commit
8bb29e3bd7
@@ -5,9 +5,11 @@ import shutil
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import json
|
import json
|
||||||
from typing import TypeVar, List, Tuple
|
from typing import TypeVar, List, Tuple
|
||||||
|
from logging import getLogger
|
||||||
from requests import Response
|
from requests import Response
|
||||||
from .meta import Meta
|
from .meta import Meta
|
||||||
|
|
||||||
|
log = getLogger("rmapy")
|
||||||
BytesOrString = TypeVar("BytesOrString", BytesIO, str)
|
BytesOrString = TypeVar("BytesOrString", BytesIO, str)
|
||||||
|
|
||||||
|
|
||||||
@@ -311,7 +313,6 @@ class ZipDocument(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Get the RM pages
|
# Get the RM pages
|
||||||
|
|
||||||
pages = [x for x in zf.namelist()
|
pages = [x for x in zf.namelist()
|
||||||
if x.startswith(f"{self.ID}/") and x.endswith('.rm')]
|
if x.startswith(f"{self.ID}/") and x.endswith('.rm')]
|
||||||
for p in pages:
|
for p in pages:
|
||||||
@@ -322,11 +323,16 @@ class ZipDocument(object):
|
|||||||
page.seek(0)
|
page.seek(0)
|
||||||
with zf.open(p.replace(".rm", "-metadata.json"), 'r') as md:
|
with zf.open(p.replace(".rm", "-metadata.json"), 'r') as md:
|
||||||
metadata = json.load(md)
|
metadata = json.load(md)
|
||||||
|
|
||||||
thumbnail_name = p.replace(".rm", ".jpg")
|
thumbnail_name = p.replace(".rm", ".jpg")
|
||||||
thumbnail_name = thumbnail_name.replace("/", ".thumbnails/")
|
thumbnail_name = thumbnail_name.replace("/", ".thumbnails/")
|
||||||
with zf.open(thumbnail_name, 'r') as tn:
|
try:
|
||||||
thumbnail = BytesIO(tn.read())
|
with zf.open(thumbnail_name, 'r') as tn:
|
||||||
thumbnail.seek(0)
|
thumbnail = BytesIO(tn.read())
|
||||||
|
thumbnail.seek(0)
|
||||||
|
except KeyError:
|
||||||
|
log.debug(f"missing thumbnail: {thumbnail_name}")
|
||||||
|
thumbnail = None
|
||||||
|
|
||||||
self.rm.append(RmPage(page, metadata, page_number, thumbnail,
|
self.rm.append(RmPage(page, metadata, page_number, thumbnail,
|
||||||
self.ID))
|
self.ID))
|
||||||
|
|||||||
Reference in New Issue
Block a user