Commit d91d3adb authored by Hermann Krumrey's avatar Hermann Krumrey

Fix some kinks in the program

parent 3ff9c8b5
......@@ -24,7 +24,7 @@ import cfscrape
from puffotter.os import makedirs
from typing import Callable, List
from typing import Optional
from subprocess import Popen
from subprocess import Popen, DEVNULL
from urllib.request import urlretrieve
......@@ -41,7 +41,8 @@ class Chapter:
chapter_number: str,
destination_dir: str,
_format: str,
page_load_callback: Callable[['Chapter', str], List[str]]
page_load_callback: Callable[['Chapter', str], List[str]],
title: Optional[str] = None
):
"""
Initializes the manga chapter
......@@ -53,6 +54,7 @@ class Chapter:
downloaded files by default
:param _format: The format in which to store the chapter when
downloading by default
:param title: The title of the chapter
:param page_load_callback:
"""
self.logger = logging.getLogger(self.__class__.__name__)
......@@ -64,13 +66,20 @@ class Chapter:
self.format = _format
self._page_load_callback = page_load_callback
self._pages = [] # type: List[str]
self.title = title
if self.chapter_number == "":
self.chapter_number = "0"
@property
def name(self) -> str:
"""
:return: The name of the chapter
"""
return "{} - Chapter {}".format(self.series_name, self.chapter_number)
name = "{} - Chapter {}".format(self.series_name, self.chapter_number)
if self.title is not None:
name += " - " + self.title
return name
@property
def pages(self) -> List[str]:
......@@ -133,7 +142,9 @@ class Chapter:
downloaded.append(image_file)
if _format in ["cbz", "zip"]:
Popen(["zip", "-j", dest_path] + downloaded).wait()
self.logger.debug("Zipping Files")
Popen(["zip", "-j", dest_path] + downloaded,
stdout=DEVNULL, stderr=DEVNULL).wait()
shutil.rmtree(tempdir)
elif _format == "dir":
os.rename(tempdir, dest_path)
......@@ -141,3 +152,9 @@ class Chapter:
self.logger.warning("Invalid format {}".format(_format))
return dest_path
def __str__(self) -> str:
"""
:return: The string representation of the object
"""
return self.name
......@@ -29,15 +29,15 @@ class Scraper:
def __init__(
self,
destination: str,
_format: str = "cbz",
destination: Optional[str] = None,
languages: Optional[Set[str]] = None
):
"""
Initializes the Scraper object
:param _format: The format in which to store chapters
:param destination: The destination directory in
which to store chapters
:param _format: The format in which to store chapters
:param languages: Set of languages for which to check
"""
self.logger = logging.getLogger(self.__class__.__name__)
......
......@@ -75,7 +75,12 @@ class MangaDexScraper(Scraper):
series_info = json.loads(resp.text)
series_title = series_info["manga"]["title"]
chapter_list = series_info["chapter"]
chapter_list = series_info.get("chapter", {})
if self.destination is None:
destination = series_title
else:
destination = self.destination
chapters = []
......@@ -86,9 +91,10 @@ class MangaDexScraper(Scraper):
chapter["lang_code"],
series_title,
chapter["chapter"],
self.destination,
destination,
self.format,
self.get_image_pages
self.get_image_pages,
chapter["title"],
))
return chapters
......
0.1.6
\ No newline at end of file
0.2.0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment