music-kraken-core/src/music_kraken/__main__.py

128 lines
3.3 KiB
Python
Raw Normal View History

2023-06-21 06:19:39 +00:00
def cli():
2023-04-12 11:02:19 +00:00
import argparse
parser = argparse.ArgumentParser(
description="A simple yet powerful cli to download music with music-kraken.",
epilog="This is a cli for the developers, and it is shipped with music-krakens core.\n"
"While it is a nice and solid cli it will lack some features.\n"
"The proper cli and other frontends will be made or already have been made.\n"
"To see all current frontends check the docs at: https://github.com/HeIIow2/music-downloader"
2023-04-12 11:02:19 +00:00
)
# arguments for debug purposes
parser.add_argument(
'-v', '--verbose',
action="store_true",
help="Sets the logging level to debug."
)
2023-06-20 17:30:48 +00:00
parser.add_argument(
2023-06-21 06:19:39 +00:00
'-m', '--force-post-process',
2023-06-20 17:30:48 +00:00
action="store_true",
help="If a to downloaded thing is skipped due to being found on disc,\nit will still update the metadata accordingly."
)
2023-04-12 11:02:19 +00:00
parser.add_argument(
'-t', '--test',
action="store_true",
2023-06-20 17:30:48 +00:00
help="For the sake of testing. Equals: '-vp -g test'"
2023-04-12 11:02:19 +00:00
)
# general arguments
parser.add_argument(
'-a', '--all',
action="store_true",
help="If set it will download EVERYTHING the music downloader can find.\n"
"For example weird compilations from musify."
)
parser.add_argument(
'-g', '--genre',
help="Specifies the genre. (Will be overwritten by -t)"
)
2023-04-12 11:13:02 +00:00
parser.add_argument(
'-u', '--url',
help="Downloads the content of given url."
)
2023-04-15 09:54:17 +00:00
parser.add_argument(
'--settings',
help="Opens a menu to modify the settings",
action="store_true"
)
parser.add_argument(
'-s',
'--setting',
help="Modifies a setting directly.",
nargs=2
)
parser.add_argument(
"--paths",
"-p",
help="Prints an overview over all music-kraken paths.",
action="store_true"
)
2023-04-18 07:02:03 +00:00
parser.add_argument(
"-r",
help="Resets the config file to the default one.",
action="store_true"
)
parser.add_argument(
2023-06-19 12:32:32 +00:00
"--frontend",
"-f",
help="Set a good and fast invidious/piped instance from your homecountry, to reduce the latency.",
action="store_true"
)
2023-04-12 11:02:19 +00:00
arguments = parser.parse_args()
if arguments.verbose or arguments.test:
import logging
print("Setting logging-level to DEBUG")
logging.getLogger().setLevel(logging.DEBUG)
2023-06-20 14:40:34 +00:00
from . import cli
from .utils.config import read_config
from .utils import shared
if arguments.r:
2023-10-12 23:07:52 +00:00
from .utils.config import write_config
write_config()
2023-06-20 14:40:34 +00:00
exit()
2023-04-14 15:01:32 +00:00
2023-06-20 14:40:34 +00:00
read_config()
2023-04-15 15:17:33 +00:00
if arguments.setting is not None:
2023-06-20 14:40:34 +00:00
cli.settings(*arguments.setting)
2023-04-15 09:54:17 +00:00
if arguments.settings:
2023-06-20 14:40:34 +00:00
cli.settings()
2023-04-15 09:54:17 +00:00
if arguments.paths:
2023-06-20 14:40:34 +00:00
cli.print_paths()
2023-06-19 12:32:32 +00:00
if arguments.frontend:
2023-06-20 14:40:34 +00:00
cli.set_frontend(silent=False)
2023-04-18 07:02:03 +00:00
2023-04-12 11:02:19 +00:00
# getting the genre
genre: str = arguments.genre
if arguments.test:
genre = "test"
2023-06-20 14:40:34 +00:00
cli.download(
genre=genre,
download_all=arguments.all,
2023-06-20 17:30:48 +00:00
direct_download_url=arguments.url,
process_metadata_anyway=arguments.force_post_process or arguments.test
2023-06-21 06:19:39 +00:00
)
if __name__ == "__main__":
cli()