replace exit with sys.exit and add option to list chapters in interactive input

This commit is contained in:
Ivan Schaller 2022-05-25 20:10:43 +02:00
parent ae42a19aed
commit cbf62b26db
5 changed files with 47 additions and 25 deletions

View file

@ -1,7 +1,8 @@
from mangadlp.input import get_args import subprocess
import os
import sys import sys
from mangadlp.input import get_args
mangadlp_version = "2.1.2" mangadlp_version = "2.1.2"
@ -12,22 +13,36 @@ def get_input():
try: try:
url_uuid = str(input("Url or UUID: ")) url_uuid = str(input("Url or UUID: "))
readlist = str(input("List with links (optional): ")) readlist = str(input("List with links (optional): "))
language = str(input("Language: ")) language = str(input("Language: ")) or "en"
chapters = str(input("Chapters: ")) list_chapters = str(input("List chapters? y/N: "))
if list_chapters.lower() != "y" or list_chapters.lower() != "yes":
chapters = str(input("Chapters: "))
except KeyboardInterrupt: except KeyboardInterrupt:
exit(1) sys.exit(1)
except: except:
continue continue
else: else:
break break
args = [f"-l {language}", f"-c {chapters}"]
args = [
"python3",
"manga-dlp.py",
"-l",
language,
"-c",
chapters,
]
if url_uuid: if url_uuid:
args.append(f"-u {url_uuid}") args.append("-u")
args.append(url_uuid)
if readlist: if readlist:
args.append(f"--read {readlist}") args.append("--read")
args.append(readlist)
if list_chapters.lower() == "y" or list_chapters.lower() == "yes":
args.append("--list")
# start script again with the arguments # start script again with the arguments
os.system(f"python3 manga-dlp.py {' '.join(args)}") subprocess.call(args)
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -1,6 +1,9 @@
import re import re
import sys
from time import sleep from time import sleep
import requests import requests
import mangadlp.utils as utils import mangadlp.utils as utils
@ -43,7 +46,7 @@ class Mangadex:
except: except:
if counter >= 3: if counter >= 3:
print("ERR: Maybe the MangaDex API is down?") print("ERR: Maybe the MangaDex API is down?")
exit(1) sys.exit(1)
else: else:
print("ERR: Mangadex API not reachable. Retrying") print("ERR: Mangadex API not reachable. Retrying")
sleep(2) sleep(2)
@ -53,7 +56,7 @@ class Mangadex:
# check if manga exists # check if manga exists
if manga_data.json()["result"] != "ok": if manga_data.json()["result"] != "ok":
print("ERR: Manga not found") print("ERR: Manga not found")
exit(1) sys.exit(1)
return manga_data return manga_data
@ -66,7 +69,7 @@ class Mangadex:
# check for new mangadex id # check for new mangadex id
if not uuid_regex.search(self.url_uuid): if not uuid_regex.search(self.url_uuid):
print("ERR: No valid UUID found") print("ERR: No valid UUID found")
exit(1) sys.exit(1)
manga_uuid = uuid_regex.search(self.url_uuid)[0] manga_uuid = uuid_regex.search(self.url_uuid)[0]
return manga_uuid return manga_uuid
@ -86,7 +89,7 @@ class Mangadex:
title = alt_titles[self.language] title = alt_titles[self.language]
except: # no title on requested language found except: # no title on requested language found
print("ERR: Chapter in requested language not found.") print("ERR: Chapter in requested language not found.")
exit(1) sys.exit(1)
return utils.fix_name(title) return utils.fix_name(title)
# check if chapters are available in requested language # check if chapters are available in requested language
@ -120,7 +123,7 @@ class Mangadex:
# check for chapters in specified lang # check for chapters in specified lang
total_chapters = self.check_chapter_lang() total_chapters = self.check_chapter_lang()
if total_chapters == 0: if total_chapters == 0:
exit(1) sys.exit(1)
chapter_data = {} chapter_data = {}
last_chapter = ["", ""] last_chapter = ["", ""]

View file

@ -1,5 +1,6 @@
import re import re
import shutil import shutil
import sys
from pathlib import Path from pathlib import Path
import mangadlp.downloader as downloader import mangadlp.downloader as downloader
@ -81,7 +82,7 @@ class MangaDLP:
print( print(
f'ERR: You need to specify a manga url/uuid with "-u" or a list with "--read"' f'ERR: You need to specify a manga url/uuid with "-u" or a list with "--read"'
) )
exit(1) sys.exit(1)
# checks if --list is not used # checks if --list is not used
if not self.list_chapters: if not self.list_chapters:
if self.chapters is None: if self.chapters is None:
@ -89,15 +90,15 @@ class MangaDLP:
print( print(
f'ERR: You need to specify one or more chapters to download. To see all chapters use "--list"' f'ERR: You need to specify one or more chapters to download. To see all chapters use "--list"'
) )
exit(1) sys.exit(1)
# 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:
print(f"ERR: You need to specify the volume if you use --forcevol") print(f"ERR: You need to specify the volume if you use --forcevol")
exit(1) sys.exit(1)
# 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:
print(f"ERR: Don't specify the volume without --forcevol") print(f"ERR: Don't specify the volume without --forcevol")
exit(1) sys.exit(1)
# 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:
@ -115,7 +116,7 @@ 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):
print("Not supported yet") print("Not supported yet")
exit(1) sys.exit(1)
# no supported api found # no supported api found
print(f"ERR: No supported api in link/uuid found: {url_uuid}") print(f"ERR: No supported api in link/uuid found: {url_uuid}")
@ -197,7 +198,7 @@ class MangaDLP:
) )
except KeyboardInterrupt: except KeyboardInterrupt:
print("ERR: Stopping") print("ERR: Stopping")
exit(1) sys.exit(1)
# 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:
@ -258,7 +259,7 @@ class MangaDLP:
) )
except KeyboardInterrupt: except KeyboardInterrupt:
print("ERR: Stopping") print("ERR: Stopping")
exit(1) sys.exit(1)
except: except:
print(f"ERR: Cant download: '{chapter_filename}'. Skipping") print(f"ERR: Cant download: '{chapter_filename}'. Skipping")
# add to skipped chapters list # add to skipped chapters list

View file

@ -1,6 +1,8 @@
import shutil
import sys
from pathlib import Path from pathlib import Path
from time import sleep from time import sleep
import shutil
import requests import requests
import mangadlp.utils as utils import mangadlp.utils as utils
@ -29,7 +31,7 @@ def download_chapter(
raise ConnectionError raise ConnectionError
except KeyboardInterrupt: except KeyboardInterrupt:
print("ERR: Stopping") print("ERR: Stopping")
exit(1) sys.exit(1)
except: except:
if counter >= 3: if counter >= 3:
print("ERR: Maybe the MangaDex Servers are down?") print("ERR: Maybe the MangaDex Servers are down?")

View file

@ -1,7 +1,8 @@
import argparse import argparse
import mangadlp.app as app
from pathlib import Path from pathlib import Path
import mangadlp.app as app
mangadlp_version = "2.1.2" mangadlp_version = "2.1.2"
@ -9,7 +10,7 @@ def check_args(args):
# check if --version was used # check if --version was used
if args.version: if args.version:
print(f"manga-dlp version: {mangadlp_version}") print(f"manga-dlp version: {mangadlp_version}")
exit(0) sys.exit(0)
# check if a readin list was provided # check if a readin list was provided
if not args.read: if not args.read:
# single manga, no readin list # single manga, no readin list