mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 04:05:08 +03:00
✨ Added fav subcommand
This commit is contained in:
@@ -24,14 +24,14 @@ from tiddl.cli.config import (
|
|||||||
from tiddl.cli.utils.resource import TidalResource
|
from tiddl.cli.utils.resource import TidalResource
|
||||||
from tiddl.cli.ctx import Context
|
from tiddl.cli.ctx import Context
|
||||||
from tiddl.cli.commands.auth import refresh
|
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 .downloader import Downloader
|
||||||
from .output import RichOutput
|
from .output import RichOutput
|
||||||
|
|
||||||
download_command = typer.Typer(name="download")
|
download_command = typer.Typer(name="download")
|
||||||
download_command.add_typer(url_subcommand)
|
register_subcommands(download_command)
|
||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
|
||||||
@@ -489,7 +489,9 @@ def download_callback(
|
|||||||
template = TEMPLATE or CONFIG.templates.playlist
|
template = TEMPLATE or CONFIG.templates.playlist
|
||||||
|
|
||||||
if "{album" in template:
|
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:
|
else:
|
||||||
album = None
|
album = None
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from typer import Typer
|
from typer import Typer
|
||||||
|
|
||||||
from .url import url_subcommand
|
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):
|
def register_subcommands(app: Typer):
|
||||||
|
|||||||
@@ -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="<resource>",
|
||||||
|
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}")
|
||||||
Reference in New Issue
Block a user