replace exit with sys.exit and add option to list chapters in interactive input
This commit is contained in:
parent
ae42a19aed
commit
cbf62b26db
5 changed files with 47 additions and 25 deletions
31
manga-dlp.py
31
manga-dlp.py
|
@ -1,7 +1,8 @@
|
|||
from mangadlp.input import get_args
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from mangadlp.input import get_args
|
||||
|
||||
mangadlp_version = "2.1.2"
|
||||
|
||||
|
||||
|
@ -12,22 +13,36 @@ def get_input():
|
|||
try:
|
||||
url_uuid = str(input("Url or UUID: "))
|
||||
readlist = str(input("List with links (optional): "))
|
||||
language = str(input("Language: "))
|
||||
language = str(input("Language: ")) or "en"
|
||||
list_chapters = str(input("List chapters? y/N: "))
|
||||
if list_chapters.lower() != "y" or list_chapters.lower() != "yes":
|
||||
chapters = str(input("Chapters: "))
|
||||
except KeyboardInterrupt:
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
args = [f"-l {language}", f"-c {chapters}"]
|
||||
|
||||
args = [
|
||||
"python3",
|
||||
"manga-dlp.py",
|
||||
"-l",
|
||||
language,
|
||||
"-c",
|
||||
chapters,
|
||||
]
|
||||
if url_uuid:
|
||||
args.append(f"-u {url_uuid}")
|
||||
args.append("-u")
|
||||
args.append(url_uuid)
|
||||
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
|
||||
os.system(f"python3 manga-dlp.py {' '.join(args)}")
|
||||
subprocess.call(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import re
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
import requests
|
||||
|
||||
import mangadlp.utils as utils
|
||||
|
||||
|
||||
|
@ -43,7 +46,7 @@ class Mangadex:
|
|||
except:
|
||||
if counter >= 3:
|
||||
print("ERR: Maybe the MangaDex API is down?")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("ERR: Mangadex API not reachable. Retrying")
|
||||
sleep(2)
|
||||
|
@ -53,7 +56,7 @@ class Mangadex:
|
|||
# check if manga exists
|
||||
if manga_data.json()["result"] != "ok":
|
||||
print("ERR: Manga not found")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
return manga_data
|
||||
|
||||
|
@ -66,7 +69,7 @@ class Mangadex:
|
|||
# check for new mangadex id
|
||||
if not uuid_regex.search(self.url_uuid):
|
||||
print("ERR: No valid UUID found")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
manga_uuid = uuid_regex.search(self.url_uuid)[0]
|
||||
return manga_uuid
|
||||
|
||||
|
@ -86,7 +89,7 @@ class Mangadex:
|
|||
title = alt_titles[self.language]
|
||||
except: # no title on requested language found
|
||||
print("ERR: Chapter in requested language not found.")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
return utils.fix_name(title)
|
||||
|
||||
# check if chapters are available in requested language
|
||||
|
@ -120,7 +123,7 @@ class Mangadex:
|
|||
# check for chapters in specified lang
|
||||
total_chapters = self.check_chapter_lang()
|
||||
if total_chapters == 0:
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
chapter_data = {}
|
||||
last_chapter = ["", ""]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import mangadlp.downloader as downloader
|
||||
|
@ -81,7 +82,7 @@ class MangaDLP:
|
|||
print(
|
||||
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
|
||||
if not self.list_chapters:
|
||||
if self.chapters is None:
|
||||
|
@ -89,15 +90,15 @@ class MangaDLP:
|
|||
print(
|
||||
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 self.forcevol and ":" not in self.chapters:
|
||||
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 not self.forcevol and ":" in self.chapters:
|
||||
print(f"ERR: Don't specify the volume without --forcevol")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
# check the api which needs to be used
|
||||
def check_api(self, url_uuid: str) -> type:
|
||||
|
@ -115,7 +116,7 @@ class MangaDLP:
|
|||
# this is only for testing multiple apis
|
||||
if api_test.search(url_uuid):
|
||||
print("Not supported yet")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
# no supported api found
|
||||
print(f"ERR: No supported api in link/uuid found: {url_uuid}")
|
||||
|
@ -197,7 +198,7 @@ class MangaDLP:
|
|||
)
|
||||
except KeyboardInterrupt:
|
||||
print("ERR: Stopping")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
# check if the image urls are empty. if yes skip this chapter (for mass downloads)
|
||||
if not chapter_image_urls:
|
||||
|
@ -258,7 +259,7 @@ class MangaDLP:
|
|||
)
|
||||
except KeyboardInterrupt:
|
||||
print("ERR: Stopping")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
except:
|
||||
print(f"ERR: Cant download: '{chapter_filename}'. Skipping")
|
||||
# add to skipped chapters list
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
import shutil
|
||||
|
||||
import requests
|
||||
|
||||
import mangadlp.utils as utils
|
||||
|
@ -29,7 +31,7 @@ def download_chapter(
|
|||
raise ConnectionError
|
||||
except KeyboardInterrupt:
|
||||
print("ERR: Stopping")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
except:
|
||||
if counter >= 3:
|
||||
print("ERR: Maybe the MangaDex Servers are down?")
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import argparse
|
||||
import mangadlp.app as app
|
||||
from pathlib import Path
|
||||
|
||||
import mangadlp.app as app
|
||||
|
||||
mangadlp_version = "2.1.2"
|
||||
|
||||
|
||||
|
@ -9,7 +10,7 @@ def check_args(args):
|
|||
# check if --version was used
|
||||
if args.version:
|
||||
print(f"manga-dlp version: {mangadlp_version}")
|
||||
exit(0)
|
||||
sys.exit(0)
|
||||
# check if a readin list was provided
|
||||
if not args.read:
|
||||
# single manga, no readin list
|
||||
|
|
Loading…
Reference in a new issue