diff --git a/tiddl/cli/commands/download/__init__.py b/tiddl/cli/commands/download/__init__.py index 93ba711..d60de0d 100644 --- a/tiddl/cli/commands/download/__init__.py +++ b/tiddl/cli/commands/download/__init__.py @@ -24,14 +24,14 @@ from tiddl.cli.config import ( from tiddl.cli.utils.resource import TidalResource from tiddl.cli.ctx import Context from tiddl.cli.commands.auth import refresh -from tiddl.cli.commands.subcommands import url_subcommand +from tiddl.cli.commands.subcommands import register_subcommands from .downloader import Downloader from .output import RichOutput download_command = typer.Typer(name="download") -download_command.add_typer(url_subcommand) +register_subcommands(download_command) log = getLogger(__name__) @@ -489,7 +489,9 @@ def download_callback( template = TEMPLATE or CONFIG.templates.playlist if "{album" in template: - album = ctx.obj.api.get_album(playlist_item.item.album.id) + album = ctx.obj.api.get_album( + playlist_item.item.album.id + ) else: album = None diff --git a/tiddl/cli/commands/subcommands/__init__.py b/tiddl/cli/commands/subcommands/__init__.py index b3dfc3f..a543eb6 100644 --- a/tiddl/cli/commands/subcommands/__init__.py +++ b/tiddl/cli/commands/subcommands/__init__.py @@ -1,9 +1,10 @@ from typer import Typer from .url import url_subcommand +from .fav import fav_subcommand -SUBCOMMANDS: list[Typer] = [url_subcommand] +SUBCOMMANDS: list[Typer] = [url_subcommand, fav_subcommand] def register_subcommands(app: Typer): diff --git a/tiddl/cli/commands/subcommands/fav.py b/tiddl/cli/commands/subcommands/fav.py new file mode 100644 index 0000000..e62036c --- /dev/null +++ b/tiddl/cli/commands/subcommands/fav.py @@ -0,0 +1,45 @@ +import typer +from typing import cast +from typing_extensions import Annotated + +from tiddl.cli.ctx import Context +from tiddl.cli.utils.resource import ResourceTypeLiteral, TidalResource + + +fav_subcommand = typer.Typer() + + +@fav_subcommand.command() +def fav( + ctx: Context, + TYPES: Annotated[ + list[str], + typer.Option( + "-t", + "--types", + metavar="", + help="Narrow resource types, usage: -t track -t album etc. Available resources: track, video, album, playlist, artist.", + ), + ] = ["track", "video", "album", "playlist", "artist"], +): + """ + Get your Tidal favorites. You can narrow them to any type of your choice. + """ + + favorites = ctx.obj.api.get_favorites() + favorites_dict = favorites.model_dump() + + stats: dict[ResourceTypeLiteral, int] = dict() + + for resource_type in cast(list[ResourceTypeLiteral], TYPES): + resources = favorites_dict[resource_type.upper()] + + stats[resource_type] = len(resources) + + for resource_id in resources: + ctx.obj.resources.append(TidalResource(id=resource_id, type=resource_type)) + + ctx.obj.console.print(f"[green]Loaded {len(ctx.obj.resources)} resources") + + for resource_type, count in stats.items(): + ctx.obj.console.print(f"{resource_type.title()}s: {count}")