2022-05-13 22:34:25 +02:00
|
|
|
import argparse
|
2022-05-25 20:15:30 +02:00
|
|
|
import sys
|
2022-05-20 19:32:36 +02:00
|
|
|
from pathlib import Path
|
2022-05-13 22:34:25 +02:00
|
|
|
|
2022-05-25 20:10:43 +02:00
|
|
|
import mangadlp.app as app
|
|
|
|
|
2022-06-26 15:54:09 +02:00
|
|
|
MDLP_VERSION = "2.1.9"
|
2022-05-16 16:09:17 +02:00
|
|
|
|
2022-05-13 22:34:25 +02:00
|
|
|
|
2022-05-20 19:32:36 +02:00
|
|
|
def check_args(args):
|
2022-05-13 22:34:25 +02:00
|
|
|
# check if --version was used
|
|
|
|
if args.version:
|
2022-06-21 17:22:43 +02:00
|
|
|
print(f"manga-dlp version: {MDLP_VERSION}")
|
2022-05-25 20:10:43 +02:00
|
|
|
sys.exit(0)
|
2022-05-20 19:32:36 +02:00
|
|
|
# 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):
|
2022-05-13 22:34:25 +02:00
|
|
|
# call main function with all input arguments
|
2022-05-16 22:03:37 +02:00
|
|
|
mdlp = app.MangaDLP(
|
2022-05-13 22:34:25 +02:00
|
|
|
args.url_uuid,
|
|
|
|
args.lang,
|
|
|
|
args.chapters,
|
|
|
|
args.list,
|
|
|
|
args.format,
|
|
|
|
args.forcevol,
|
|
|
|
args.path,
|
|
|
|
args.wait,
|
2022-06-26 15:23:19 +02:00
|
|
|
args.verbosity,
|
2022-05-13 22:34:25 +02:00
|
|
|
)
|
2022-05-25 22:18:23 +02:00
|
|
|
mdlp.get_manga()
|
2022-05-13 22:34:25 +02:00
|
|
|
|
|
|
|
|
2022-06-22 19:34:41 +02:00
|
|
|
def get_input():
|
|
|
|
print(f"manga-dlp version: {MDLP_VERSION}")
|
|
|
|
print("Enter details of the manga you want to download:")
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
url_uuid = str(input("Url or UUID: "))
|
|
|
|
readlist = str(input("List with links (optional): "))
|
|
|
|
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:
|
|
|
|
sys.exit(1)
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"-l",
|
|
|
|
language,
|
|
|
|
"-c",
|
|
|
|
chapters,
|
|
|
|
]
|
|
|
|
if url_uuid:
|
|
|
|
args.append("-u")
|
|
|
|
args.append(url_uuid)
|
|
|
|
if 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
|
2022-06-22 22:30:32 +02:00
|
|
|
sys.argv.extend(args)
|
|
|
|
get_args()
|
2022-06-22 19:34:41 +02:00
|
|
|
|
|
|
|
|
2022-05-16 16:09:17 +02:00
|
|
|
def get_args():
|
2022-05-13 22:34:25 +02:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Script to download mangas from various sites"
|
|
|
|
)
|
2022-06-26 15:23:19 +02:00
|
|
|
action = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
verbosity = parser.add_mutually_exclusive_group(required=False)
|
|
|
|
|
|
|
|
action.add_argument(
|
2022-05-13 22:34:25 +02:00
|
|
|
"-u",
|
|
|
|
"--url",
|
|
|
|
"--uuid",
|
|
|
|
dest="url_uuid",
|
|
|
|
required=False,
|
|
|
|
help="URL or UUID of the manga",
|
|
|
|
action="store",
|
|
|
|
)
|
2022-06-26 15:23:19 +02:00
|
|
|
action.add_argument(
|
2022-05-13 22:34:25 +02:00
|
|
|
"--read",
|
|
|
|
dest="read",
|
|
|
|
required=False,
|
|
|
|
help="Path of file with manga links to download. One per line",
|
|
|
|
action="store",
|
|
|
|
)
|
2022-06-26 15:23:19 +02:00
|
|
|
action.add_argument(
|
2022-05-13 22:34:25 +02:00
|
|
|
"-v",
|
|
|
|
"--version",
|
|
|
|
dest="version",
|
|
|
|
required=False,
|
|
|
|
help="Show version of manga-dlp and exit",
|
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-c",
|
|
|
|
"--chapters",
|
|
|
|
dest="chapters",
|
|
|
|
required=False,
|
|
|
|
help="Chapters to download",
|
|
|
|
action="store",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-p",
|
|
|
|
"--path",
|
|
|
|
dest="path",
|
|
|
|
required=False,
|
|
|
|
help='Download path. Defaults to "<script_dir>/downloads"',
|
|
|
|
action="store",
|
|
|
|
default="downloads",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--language",
|
|
|
|
dest="lang",
|
|
|
|
required=False,
|
|
|
|
help='Manga language. Defaults to "en" --> english',
|
|
|
|
action="store",
|
|
|
|
default="en",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--list",
|
|
|
|
dest="list",
|
|
|
|
required=False,
|
|
|
|
help="List all available chapters. Defaults to false",
|
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--format",
|
|
|
|
dest="format",
|
|
|
|
required=False,
|
|
|
|
help="Archive format to create. An empty string means dont archive the folder. Defaults to 'cbz'",
|
|
|
|
action="store",
|
|
|
|
default="cbz",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--forcevol",
|
|
|
|
dest="forcevol",
|
|
|
|
required=False,
|
|
|
|
help="Force naming of volumes. For mangas where chapters reset each volume",
|
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--wait",
|
|
|
|
dest="wait",
|
|
|
|
required=False,
|
|
|
|
type=float,
|
|
|
|
default=0.5,
|
|
|
|
help="Time to wait for each picture to download in seconds(float). Defaults 0.5",
|
|
|
|
)
|
2022-06-26 15:23:19 +02:00
|
|
|
verbosity.add_argument(
|
|
|
|
"--lean",
|
|
|
|
dest="verbosity",
|
|
|
|
required=False,
|
2022-06-26 22:14:19 +02:00
|
|
|
help="Lean logging. Minimal log output. Defaults to false",
|
2022-06-26 15:23:19 +02:00
|
|
|
action="store_const",
|
2022-07-06 22:19:40 +02:00
|
|
|
const="lean",
|
|
|
|
default="normal",
|
2022-06-26 15:23:19 +02:00
|
|
|
)
|
|
|
|
verbosity.add_argument(
|
2022-05-13 22:34:25 +02:00
|
|
|
"--verbose",
|
2022-06-26 15:23:19 +02:00
|
|
|
dest="verbosity",
|
2022-05-13 22:34:25 +02:00
|
|
|
required=False,
|
2022-06-26 22:14:19 +02:00
|
|
|
help="Verbose logging. More log output. Defaults to false",
|
2022-06-26 15:23:19 +02:00
|
|
|
action="store_const",
|
2022-07-06 22:19:40 +02:00
|
|
|
const="verbose",
|
|
|
|
default="normal",
|
2022-06-26 15:23:19 +02:00
|
|
|
)
|
|
|
|
verbosity.add_argument(
|
|
|
|
"--debug",
|
|
|
|
dest="verbosity",
|
|
|
|
required=False,
|
2022-06-26 22:14:19 +02:00
|
|
|
help="Debug logging. Most log output. Defaults to false",
|
2022-06-26 15:23:19 +02:00
|
|
|
action="store_const",
|
2022-07-06 22:19:40 +02:00
|
|
|
const="debug",
|
|
|
|
default="normal",
|
2022-05-13 22:34:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# parser.print_help()
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-05-20 19:32:36 +02:00
|
|
|
check_args(args)
|
2022-05-13 22:34:25 +02:00
|
|
|
|
|
|
|
|
2022-06-22 19:34:41 +02:00
|
|
|
def main():
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
get_args()
|
|
|
|
else:
|
|
|
|
get_input()
|
|
|
|
|
|
|
|
|
2022-05-13 22:34:25 +02:00
|
|
|
if __name__ == "__main__":
|
2022-06-22 19:34:41 +02:00
|
|
|
main()
|