move list processing to input.py
All checks were successful
ci/woodpecker/push/tests Pipeline was successful
All checks were successful
ci/woodpecker/push/tests Pipeline was successful
This commit is contained in:
parent
61a66e79ec
commit
b4340a93b8
7 changed files with 70 additions and 65 deletions
|
@ -16,7 +16,6 @@ class MangaDLP:
|
|||
:param url_uuid: URL or UUID of the manga
|
||||
:param language: Manga language with country codes. "en" --> english
|
||||
:param chapters: Chapters to download, "all" for every chapter available
|
||||
:param readlist: Path of file with manga links to download. One per line
|
||||
:param list_chapters: List all available chapters and exit
|
||||
:param file_format: Archive format to create. An empty string means don't archive the folder
|
||||
:param forcevol: Force naming of volumes. Useful for mangas where chapters reset each volume
|
||||
|
@ -29,10 +28,9 @@ class MangaDLP:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
url_uuid: str = "",
|
||||
url_uuid: str,
|
||||
language: str = "en",
|
||||
chapters: str = "",
|
||||
readlist: str = None,
|
||||
list_chapters: bool = False,
|
||||
file_format: str = "cbz",
|
||||
forcevol: bool = False,
|
||||
|
@ -44,53 +42,46 @@ class MangaDLP:
|
|||
self.url_uuid = url_uuid
|
||||
self.language = language
|
||||
self.chapters = chapters
|
||||
self.readlist = readlist
|
||||
self.list_chapters = list_chapters
|
||||
self.file_format = file_format
|
||||
self.forcevol = forcevol
|
||||
self.download_path = download_path
|
||||
self.download_wait = download_wait
|
||||
self.verbose = verbose
|
||||
# prepare everything
|
||||
self.__prepare__()
|
||||
|
||||
def __main__(self) -> None:
|
||||
def __prepare__(self) -> None:
|
||||
# additional stuff
|
||||
# set manga format suffix
|
||||
if self.file_format and "." not in self.file_format:
|
||||
self.file_format = f".{self.file_format}"
|
||||
# start prechecks
|
||||
self.pre_checks()
|
||||
# check if a list was provided
|
||||
if self.readlist:
|
||||
self.url_list = self.readin_list(self.readlist)
|
||||
else:
|
||||
self.url_list = [self.url_uuid]
|
||||
# loop through every link
|
||||
for url in self.url_list:
|
||||
# init api
|
||||
self.api_used = self.check_api(url)
|
||||
self.api = self.api_used(url, self.language, self.forcevol, self.verbose)
|
||||
# get manga title and uuid
|
||||
self.manga_uuid = self.api.manga_uuid
|
||||
self.manga_title = self.api.manga_title
|
||||
# get chapter list
|
||||
self.manga_chapter_list = self.api.chapter_list
|
||||
self.manga_path = Path(f"{self.download_path}/{self.manga_title}")
|
||||
# start flow
|
||||
self.get_manga()
|
||||
# init api
|
||||
self.api_used = self.check_api(self.url_uuid)
|
||||
self.api = self.api_used(
|
||||
self.url_uuid, self.language, self.forcevol, self.verbose
|
||||
)
|
||||
# get manga title and uuid
|
||||
self.manga_uuid = self.api.manga_uuid
|
||||
self.manga_title = self.api.manga_title
|
||||
# get chapter list
|
||||
self.manga_chapter_list = self.api.chapter_list
|
||||
self.manga_path = Path(f"{self.download_path}/{self.manga_title}")
|
||||
|
||||
def __main__(self):
|
||||
# start flow
|
||||
self.get_manga()
|
||||
|
||||
def pre_checks(self) -> None:
|
||||
# prechecks userinput/options
|
||||
# no url and no readin list given
|
||||
if not self.url_uuid and not self.readlist:
|
||||
if not self.url_uuid:
|
||||
print(
|
||||
f'ERR: You need to specify a manga url/uuid with "-u" or a list with "--read"'
|
||||
)
|
||||
exit(1)
|
||||
# url and readin list given
|
||||
if self.url_uuid and self.readlist:
|
||||
print(f'ERR: You can only use "-u" or "--read". Dont specify both')
|
||||
exit(1)
|
||||
|
||||
# checks if --list is not used
|
||||
if not self.list_chapters:
|
||||
if self.chapters is None:
|
||||
|
@ -130,17 +121,6 @@ class MangaDLP:
|
|||
print(f"ERR: No supported api in link/uuid found: {url_uuid}")
|
||||
raise ValueError
|
||||
|
||||
# read in the list of links from a file
|
||||
def readin_list(self, readlist: str) -> list:
|
||||
list_file = Path(readlist)
|
||||
try:
|
||||
url_str = list_file.read_text()
|
||||
url_list = url_str.splitlines()
|
||||
except:
|
||||
raise IOError
|
||||
|
||||
return url_list
|
||||
|
||||
# once called per manga
|
||||
def get_manga(self) -> None:
|
||||
# create empty skipped chapters list
|
||||
|
|
|
@ -8,7 +8,7 @@ import mangadlp.utils as utils
|
|||
|
||||
# download images
|
||||
def download_chapter(
|
||||
image_urls: list, chapter_path: str, download_wait: float, verbose: bool
|
||||
image_urls: list, chapter_path: str or Path, download_wait: float, verbose: bool
|
||||
) -> None:
|
||||
total_img = len(image_urls)
|
||||
for img_num, img in enumerate(image_urls, 1):
|
||||
|
|
|
@ -1,20 +1,45 @@
|
|||
import argparse
|
||||
import mangadlp.app as app
|
||||
from pathlib import Path
|
||||
|
||||
mangadlp_version = "2.1.1"
|
||||
|
||||
|
||||
def call_app(args):
|
||||
def check_args(args):
|
||||
# check if --version was used
|
||||
if args.version:
|
||||
print(f"manga-dlp version: {mangadlp_version}")
|
||||
exit(0)
|
||||
# check if a readin list was provided
|
||||
if not args.read:
|
||||
# single manga, no readin list
|
||||
call_app(args)
|
||||
else:
|
||||
# multiple mangas
|
||||
url_list = readin_list(args.read)
|
||||
for url in url_list:
|
||||
args.url_uuid = url
|
||||
call_app(args)
|
||||
|
||||
|
||||
# read in the list of links from a file
|
||||
def readin_list(readlist: str) -> list:
|
||||
list_file = Path(readlist)
|
||||
try:
|
||||
url_str = list_file.read_text()
|
||||
url_list = url_str.splitlines()
|
||||
except:
|
||||
raise IOError
|
||||
|
||||
return url_list
|
||||
|
||||
|
||||
def call_app(args):
|
||||
# call main function with all input arguments
|
||||
mdlp = app.MangaDLP(
|
||||
args.url_uuid,
|
||||
args.lang,
|
||||
args.chapters,
|
||||
args.read,
|
||||
args.list,
|
||||
args.format,
|
||||
args.forcevol,
|
||||
|
@ -121,7 +146,7 @@ def get_args():
|
|||
# parser.print_help()
|
||||
args = parser.parse_args()
|
||||
|
||||
call_app(args)
|
||||
check_args(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import mangadlp.app as app
|
||||
from mangadlp.api.mangadex import Mangadex
|
||||
|
||||
|
||||
def test_readin_list():
|
||||
list_file = "tests/test_list.txt"
|
||||
test = app.MangaDLP(readlist=list_file, list_chapters=True)
|
||||
test.__main__()
|
||||
test_list = test.url_list
|
||||
|
||||
assert test_list == [
|
||||
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu",
|
||||
"https://mangadex.org/title/bd6d0982-0091-4945-ad70-c028ed3c0917/mushoku-tensei-isekai-ittara-honki-dasu",
|
||||
"37f5cce0-8070-4ada-96e5-fa24b1bd4ff9",
|
||||
]
|
||||
|
||||
|
||||
def test_check_api():
|
||||
def test_check_api_mangadex():
|
||||
url = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
|
||||
test = app.MangaDLP(url_uuid=url, list_chapters=True)
|
||||
test.__main__()
|
||||
|
||||
assert test.api_used == Mangadex
|
||||
|
||||
|
||||
def test_check_api_none():
|
||||
url = "https://abc.defghjk/title/abc/def"
|
||||
with pytest.raises(ValueError) as e:
|
||||
app.MangaDLP(url_uuid=url, list_chapters=True)
|
||||
assert e.type == ValueError
|
||||
|
|
|
@ -52,7 +52,6 @@ def test_chapter_list_full():
|
|||
url_uuid="https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie",
|
||||
language="en",
|
||||
chapters="",
|
||||
readlist="",
|
||||
list_chapters=True,
|
||||
file_format="cbz",
|
||||
forcevol=True,
|
||||
|
@ -60,7 +59,6 @@ def test_chapter_list_full():
|
|||
download_wait=0.5,
|
||||
verbose=True,
|
||||
)
|
||||
mdlp.__main__()
|
||||
chap_list = utils.get_chapter_list("1:1,1:2,1:4-1:7,2:", mdlp.manga_chapter_list)
|
||||
assert chap_list == [
|
||||
"1:1",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from pathlib import Path
|
||||
import pytest
|
||||
import requests
|
||||
import mangadlp.input as input
|
||||
import mangadlp.input as mdlpinput
|
||||
import os
|
||||
|
||||
|
||||
|
@ -49,3 +48,14 @@ def test_no_volume():
|
|||
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --verbose --forcevol"
|
||||
script_path = "manga-dlp.py"
|
||||
assert os.system(f"python3 {script_path} {command_args}") != 0
|
||||
|
||||
|
||||
def test_readin_list():
|
||||
list_file = "tests/test_list.txt"
|
||||
test_list = mdlpinput.readin_list(list_file)
|
||||
|
||||
assert test_list == [
|
||||
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu",
|
||||
"https://mangadex.org/title/bd6d0982-0091-4945-ad70-c028ed3c0917/mushoku-tensei-isekai-ittara-honki-dasu",
|
||||
"37f5cce0-8070-4ada-96e5-fa24b1bd4ff9",
|
||||
]
|
||||
|
|
|
@ -12,7 +12,6 @@ def test_full_api_mangadex():
|
|||
url_uuid="https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie",
|
||||
language="en",
|
||||
chapters="1",
|
||||
readlist="",
|
||||
list_chapters=False,
|
||||
file_format="cbz",
|
||||
forcevol=False,
|
||||
|
|
Loading…
Reference in a new issue