Added more colors

This commit is contained in:
nathom 2021-03-22 18:40:40 -07:00
parent 129f3d8fe6
commit c3da93ed08
5 changed files with 21 additions and 17 deletions

1
.gitignore vendored
View file

@ -18,7 +18,6 @@ __pycache__/
*.db *.db
*.sh *.sh
*.txt
# Distribution / packaging # Distribution / packaging
.Python .Python

View file

@ -9,6 +9,7 @@ import click
from .config import Config from .config import Config
from .constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH from .constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH
from .core import MusicDL from .core import MusicDL
from .utils import init_log
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
config = Config(CONFIG_PATH) config = Config(CONFIG_PATH)
@ -21,12 +22,7 @@ if not os.path.isdir(CACHE_DIR):
config = Config(CONFIG_PATH) config = Config(CONFIG_PATH)
def _get_config(ctx):
config.update_from_cli(**ctx.params)
@click.group() @click.group()
@click.option("--debug", default=False, is_flag=True, help="Enable debug logging")
@click.option( @click.option(
"--flush-cache", "--flush-cache",
metavar="PATH", metavar="PATH",
@ -48,7 +44,6 @@ def cli(ctx, **kwargs):
> download discography with given filters > download discography with given filters
""" """
pass
@click.command(name="dl") @click.command(name="dl")
@ -59,6 +54,7 @@ def cli(ctx, **kwargs):
@click.option("-c", "--convert", metavar="CODEC") @click.option("-c", "--convert", metavar="CODEC")
@click.option("-sr", "--sampling-rate", metavar="INT") @click.option("-sr", "--sampling-rate", metavar="INT")
@click.option("-bd", "--bit-depth", metavar="INT") @click.option("-bd", "--bit-depth", metavar="INT")
@click.option("--debug", default=False, is_flag=True, help="Enable debug logging")
@click.argument("items", nargs=-1) @click.argument("items", nargs=-1)
@click.pass_context @click.pass_context
def download(ctx, **kwargs): def download(ctx, **kwargs):
@ -82,7 +78,10 @@ def download(ctx, **kwargs):
* Tidal (album, artist, track, playlist) * Tidal (album, artist, track, playlist)
""" """
config = _get_config(ctx) if kwargs.get("debug"):
init_log()
config.update_from_cli(**ctx.params)
core = MusicDL(config, database=list() if kwargs["no_db"] else None) core = MusicDL(config, database=list() if kwargs["no_db"] else None)
for item in kwargs["items"]: for item in kwargs["items"]:
try: try:

View file

@ -1,15 +1,15 @@
import os import os
import appdirs import click
import mutagen.id3 as id3 import mutagen.id3 as id3
APPNAME = "qobuz-dl" APPNAME = "music-dl"
CACHE_DIR = appdirs.user_cache_dir(APPNAME) CACHE_DIR = click.get_app_dir(APPNAME)
CONFIG_DIR = appdirs.user_config_dir(APPNAME) CONFIG_DIR = click.get_app_dir(APPNAME)
CONFIG_PATH = os.path.join(CONFIG_DIR, "config.yaml") CONFIG_PATH = os.path.join(CONFIG_DIR, "config.yaml")
LOG_DIR = appdirs.user_config_dir(APPNAME) LOG_DIR = click.get_app_dir(APPNAME)
DB_PATH = os.path.join(LOG_DIR, "qobuz-dl.db") DB_PATH = os.path.join(LOG_DIR, "music-dl.db")
AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0" AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0"

View file

@ -125,7 +125,7 @@ class MusicDL(list):
logger.debug("Arguments from config: %s", arguments) logger.debug("Arguments from config: %s", arguments)
item.load_meta() item.load_meta()
click.secho(f"Downloading {item!s}") click.secho(f"Downloading {item!s}", fg="bright_green")
item.download(**arguments) item.download(**arguments)
def convert_all(self, codec, **kwargs): def convert_all(self, codec, **kwargs):

View file

@ -164,14 +164,15 @@ class Track:
self.__is_downloaded = True self.__is_downloaded = True
self.__is_tagged = True self.__is_tagged = True
click.secho( click.secho(
f"{self['title']} already logged in database, skipping.", fg="green" f"{self['title']} already logged in database, skipping.",
fg="magenta",
) )
return return
if os.path.isfile(self.format_final_path()): if os.path.isfile(self.format_final_path()):
self.__is_downloaded = True self.__is_downloaded = True
self.__is_tagged = True self.__is_tagged = True
click.secho(f"Track already downloaded: {self.final_path}", fg="green") click.secho(f"Track already downloaded: {self.final_path}", fg="magenta")
return False return False
if hasattr(self, "cover_url"): if hasattr(self, "cover_url"):
@ -396,6 +397,11 @@ class Track:
if not hasattr(self, "final_path"): if not hasattr(self, "final_path"):
self.format_final_path() self.format_final_path()
if not os.path.isfile(self.final_path):
logger.debug(f"File {self.final_path} does not exist. Skipping conversion.")
click.secho(f"{self!s} does not exist. Skipping conversion.", fg="red")
return
engine = CONV_CLASS[codec.upper()]( engine = CONV_CLASS[codec.upper()](
filename=self.final_path, filename=self.final_path,
sampling_rate=kwargs.get("sampling_rate"), sampling_rate=kwargs.get("sampling_rate"),