This commit is contained in:
parent
059aca80ef
commit
5eb333f1ca
3 changed files with 39 additions and 37 deletions
|
@ -1,6 +1,5 @@
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
|
@ -78,9 +77,9 @@ class MangaDLP:
|
||||||
try:
|
try:
|
||||||
log.debug("Initializing api")
|
log.debug("Initializing api")
|
||||||
self.api = self.api_used(self.url_uuid, self.language, self.forcevol)
|
self.api = self.api_used(self.url_uuid, self.language, self.forcevol)
|
||||||
except Exception:
|
except Exception as exc:
|
||||||
log.error("Can't initialize api. Exiting")
|
log.error("Can't initialize api. Exiting")
|
||||||
sys.exit(1)
|
raise exc
|
||||||
# get manga title and uuid
|
# get manga title and uuid
|
||||||
self.manga_uuid = self.api.manga_uuid
|
self.manga_uuid = self.api.manga_uuid
|
||||||
self.manga_title = self.api.manga_title
|
self.manga_title = self.api.manga_title
|
||||||
|
@ -96,7 +95,7 @@ class MangaDLP:
|
||||||
log.error(
|
log.error(
|
||||||
'You need to specify a manga url/uuid with "-u" or a list with "--read"'
|
'You need to specify a manga url/uuid with "-u" or a list with "--read"'
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
raise ValueError
|
||||||
# checks if --list is not used
|
# checks if --list is not used
|
||||||
if not self.list_chapters:
|
if not self.list_chapters:
|
||||||
if not self.chapters:
|
if not self.chapters:
|
||||||
|
@ -104,15 +103,15 @@ class MangaDLP:
|
||||||
log.error(
|
log.error(
|
||||||
'You need to specify one or more chapters to download. To see all chapters use "--list"'
|
'You need to specify one or more chapters to download. To see all chapters use "--list"'
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
raise ValueError
|
||||||
# if forcevol is used, but didn't specify a volume in the chapters selected
|
# if forcevol is used, but didn't specify a volume in the chapters selected
|
||||||
if self.forcevol and ":" not in self.chapters:
|
if self.forcevol and ":" not in self.chapters:
|
||||||
log.error("You need to specify the volume if you use --forcevol")
|
log.error("You need to specify the volume if you use --forcevol")
|
||||||
sys.exit(1)
|
raise ValueError
|
||||||
# if forcevol is not used, but a volume is specified
|
# if forcevol is not used, but a volume is specified
|
||||||
if not self.forcevol and ":" in self.chapters:
|
if not self.forcevol and ":" in self.chapters:
|
||||||
log.error("Don't specify the volume without --forcevol")
|
log.error("Don't specify the volume without --forcevol")
|
||||||
sys.exit(1)
|
raise ValueError
|
||||||
|
|
||||||
# check the api which needs to be used
|
# check the api which needs to be used
|
||||||
def check_api(self, url_uuid: str) -> type:
|
def check_api(self, url_uuid: str) -> type:
|
||||||
|
@ -129,11 +128,11 @@ class MangaDLP:
|
||||||
# this is only for testing multiple apis
|
# this is only for testing multiple apis
|
||||||
if api_test.search(url_uuid):
|
if api_test.search(url_uuid):
|
||||||
log.critical("Not supported yet")
|
log.critical("Not supported yet")
|
||||||
sys.exit(1)
|
raise ValueError
|
||||||
|
|
||||||
# no supported api found
|
# no supported api found
|
||||||
log.error(f"No supported api in link/uuid found: {url_uuid}")
|
log.error(f"No supported api in link/uuid found: {url_uuid}")
|
||||||
sys.exit(1)
|
raise ValueError
|
||||||
|
|
||||||
# once called per manga
|
# once called per manga
|
||||||
def get_manga(self) -> None:
|
def get_manga(self) -> None:
|
||||||
|
@ -206,6 +205,8 @@ class MangaDLP:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chapter_path = self.get_chapter(chapter)
|
chapter_path = self.get_chapter(chapter)
|
||||||
|
except KeyboardInterrupt as exc:
|
||||||
|
raise exc
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
skipped_chapters.append(chapter)
|
skipped_chapters.append(chapter)
|
||||||
# update cache
|
# update cache
|
||||||
|
@ -273,9 +274,9 @@ class MangaDLP:
|
||||||
chapter_image_urls = self.api.get_chapter_images(
|
chapter_image_urls = self.api.get_chapter_images(
|
||||||
chapter, self.download_wait
|
chapter, self.download_wait
|
||||||
)
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt as exc:
|
||||||
log.critical("Stopping")
|
log.critical("Keyboard interrupt. Stopping")
|
||||||
sys.exit(1)
|
raise exc
|
||||||
|
|
||||||
# check if the image urls are empty. if yes skip this chapter (for mass downloads)
|
# check if the image urls are empty. if yes skip this chapter (for mass downloads)
|
||||||
if not chapter_image_urls:
|
if not chapter_image_urls:
|
||||||
|
@ -364,9 +365,9 @@ class MangaDLP:
|
||||||
downloader.download_chapter(
|
downloader.download_chapter(
|
||||||
chapter_image_urls, chapter_path, self.download_wait
|
chapter_image_urls, chapter_path, self.download_wait
|
||||||
)
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt as exc:
|
||||||
log.critical("Stopping")
|
log.critical("Keyboard interrupt. Stopping")
|
||||||
sys.exit(1)
|
raise exc
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.error(f"Cant download: '{chapter_filename}'. Skipping")
|
log.error(f"Cant download: '{chapter_filename}'. Skipping")
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,7 @@ def main(
|
||||||
requested_mangas = [url_uuid] if url_uuid else read_mangas
|
requested_mangas = [url_uuid] if url_uuid else read_mangas
|
||||||
|
|
||||||
for manga in requested_mangas:
|
for manga in requested_mangas:
|
||||||
|
try:
|
||||||
mdlp = app.MangaDLP(
|
mdlp = app.MangaDLP(
|
||||||
url_uuid=manga,
|
url_uuid=manga,
|
||||||
language=lang,
|
language=lang,
|
||||||
|
@ -274,6 +275,8 @@ def main(
|
||||||
cache_path=cache_path,
|
cache_path=cache_path,
|
||||||
)
|
)
|
||||||
mdlp.get_manga()
|
mdlp.get_manga()
|
||||||
|
except (KeyboardInterrupt, Exception) as exc:
|
||||||
|
log.error(f"Skipping: {manga}. Reason={exc}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
@ -35,9 +34,8 @@ def download_chapter(
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
log.error(f"Request for image {image} failed, retrying")
|
log.error(f"Request for image {image} failed, retrying")
|
||||||
raise ConnectionError
|
raise ConnectionError
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt as exc:
|
||||||
log.critical("Stopping")
|
raise exc
|
||||||
sys.exit(1)
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if counter >= 3:
|
if counter >= 3:
|
||||||
log.error("Maybe the MangaDex Servers are down?")
|
log.error("Maybe the MangaDex Servers are down?")
|
||||||
|
|
Loading…
Reference in a new issue