Split cli into commands

This commit is contained in:
nathom 2021-03-22 13:40:29 -07:00
parent bd52681623
commit 72a79d0c32
1 changed files with 66 additions and 17 deletions

View File

@ -6,7 +6,7 @@ import os
import click
from qobuz_dl_rewrite.config import Config
from qobuz_dl_rewrite.constants import CACHE_DIR, CONFIG_DIR
from qobuz_dl_rewrite.constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH
from qobuz_dl_rewrite.core import MusicDL
from qobuz_dl_rewrite.utils import init_log
@ -26,27 +26,26 @@ def _get_config(ctx):
# fmt: off
@click.group()
@click.option("--disable", metavar="PROVIDER,...", help="Disable following providers (comma separated)")
@click.option("-q", "--quality", metavar="INT", help="Quality integer ID (5, 6, 7, 27)")
@click.option("--embed-cover", is_flag=True, help="Embed cover art into files")
@click.option("--no-extras", is_flag=True, help="Ignore extras")
@click.option("--no-features", is_flag=True, help="Ignore features")
@click.option("--studio-albums", is_flag=True, help="Ignore non-studio albums")
@click.option("--remaster-only", is_flag=True, help="Ignore non-remastered albums")
@click.option("--albums-only", is_flag=True, help="Ignore non-album downloads")
@click.option("--large-cover", is_flag=True, help="Download large covers (it might fail with embed)")
@click.option("--remove-extra-tags", default=False, is_flag=True, help="Remove extra metadata from tags and files")
@click.option("--debug", default=False, is_flag=True, help="Enable debug logging")
@click.option("-f", "--folder", metavar="PATH", help="Custom download folder")
@click.option("--default-comment", metavar="COMMENT", help="Custom comment tag for audio files")
@click.option("-c", "--config", metavar="PATH", help="Custom config file")
@click.option("--db-file", metavar="PATH", help="Custom database file")
@click.option("--log-file", metavar="PATH", help="Custom logfile")
@click.option("--flush-cache", metavar="PATH", help="Flush the cache before running (only for extreme cases)")
# TODO: add options for conversion
@click.pass_context
# fmt: on
def cli(ctx, **kwargs):
"""cli.
$ rip www.qobuz.com/album/id1089374 convert -c ALAC -sr 48000
> download and convert to alac, downsample to 48kHz
$ rip config --read
> Config(...)
$ rip config --qobuzpwd MyQobuzPwd123 --qobuzemail person@email.com
$ rip config --tidalpwd MyTidalPwd123 --tidalemail person@email.com
> sets the credentials
$ rip www.qobuz.com/artist/id223049 filter --studio-albums --no-repeats
> download discography with given filters
:param ctx:
:param kwargs:
"""
ctx.ensure_object(dict)
for key in kwargs.keys():
@ -59,6 +58,9 @@ def cli(ctx, **kwargs):
@click.command(name="dl")
@click.option("-q", "--quality", metavar="INT", help="Quality integer ID (5, 6, 7, 27)")
@click.option("--large-cover", is_flag=True, help="Download large covers (it might fail with embed)")
@click.option("-f", "--folder", metavar="PATH", help="Custom download folder")
@click.argument("items", nargs=-1)
@click.pass_context
def download(ctx, items):
@ -98,6 +100,53 @@ def download(ctx, items):
)
@click.command()
@click.argument("--path")
@click.argument("--read")
def config(path, read):
if path:
click.echo(CONFIG_PATH)
if read:
click.echo(repr(config))
@click.command()
@click.option("-t", '--type', default='album',
help='Type to search for. Can be album, artist, playlist, track')
@click.argument("QUERY")
def search(media_type, query):
pass
@click.command()
@click.option("-c", "--codec", default='ALAC')
@click.option("-sr", '--sampling-rate')
@click.option("-bd", "--bit-depth")
def convert(codec, sampling_rate, bit_depth):
pass
@click.command()
def interactive():
pass
@click.command()
@click.option("--no-extras", is_flag=True, help="Ignore extras")
@click.option("--no-features", is_flag=True, help="Ignore features")
@click.option("--studio-albums", is_flag=True, help="Ignore non-studio albums")
@click.option("--remaster-only", is_flag=True, help="Ignore non-remastered albums")
@click.option("--albums-only", is_flag=True, help="Ignore non-album downloads")
def filter():
pass
@click.command()
@click.option("--default-comment", metavar="COMMENT", help="Custom comment tag for audio files")
def tags():
pass
def main():
cli.add_command(download)
cli(obj={})