Skip to content
Snippets Groups Projects
Verified Commit 069fcfa5 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added search, artists and albums

parent f6a827cd
No related branches found
No related tags found
No related merge requests found
......@@ -211,6 +211,7 @@ def get_pagination_data(payload):
def get_ls_command(group, endpoint, output_conf):
@group.command("ls")
@click.argument("query", nargs=-1)
@click.option("--raw", is_flag=True)
@click.option("--page", "-p", type=click.INT, default=1)
@click.option("--page-size", "-s", type=click.INT, default=None)
......@@ -218,7 +219,7 @@ def get_ls_command(group, endpoint, output_conf):
@click.option("--filter", "-f", multiple=True)
@click.pass_context
@async_command
async def ls(ctx, raw, page, page_size, ordering, filter):
async def ls(ctx, raw, page, page_size, ordering, filter, query):
async with ctx.obj["remote"]:
params = {"page": page}
......@@ -226,6 +227,8 @@ def get_ls_command(group, endpoint, output_conf):
params["page_size"] = page_size
if ordering:
params["ordering"] = ordering
if query:
params['q'] = ' '.join(query)
if filter:
for f in filter:
query = urllib.parse.parse_qs(f)
......@@ -333,10 +336,22 @@ def artists(ctx):
artists_ls = get_ls_command(
artists,
"api/v1/artists/",
output_conf={"labels": ["ID", "Name", "Created"], "type": "ARTIST"},
output_conf={"labels": ["ID", "Name", "Albums", "Tracks", "Created"], "type": "ARTIST"},
)
@cli.group()
@click.pass_context
def albums(ctx):
pass
albums_ls = get_ls_command(
albums,
"api/v1/albums/",
output_conf={"labels": ["ID", "Title", "Artist", "Tracks", "Created"], "type": "ALBUM"},
)
@cli.group()
@click.pass_context
def tracks(ctx):
......@@ -346,7 +361,7 @@ def tracks(ctx):
tracks_ls = get_ls_command(
tracks,
"api/v1/tracks/",
output_conf={"labels": ["ID", "Title", "Artist", "Album"], "type": "TRACK"},
output_conf={"labels": ["ID", "Title", "Artist", "Album", "Disc", "Position"], "type": "TRACK"},
)
......
......@@ -2,10 +2,25 @@ import tabulate
FIELDS = {
"ARTIST": {
"Albums": {"field": "albums", "handler": lambda v: len(v), "truncate": 0},
"Tracks": {
"field": "albums",
"handler": lambda v: sum([a["tracks_count"] for a in v]),
"truncate": 0,
},
"Artist": {"field": ["album.artist.name", "track.artist.name"]},
"Album": {"field": "album.title"},
},
"ALBUM": {
"Tracks": {"field": "tracks", "handler": lambda v: len(v), "truncate": 0},
"Artist": {"field": "artist.name"},
},
"TRACK": {
"Title": {"field": "title"},
"Artist": {"field": ["album.artist.name", "track.artist.name"]},
"Album": {"field": "album.title"},
"Disc": {"field": "disc", "handler": lambda v: v or 1},
"Position": {"field": "position"},
},
"UPLOAD": {
"Source": {"field": "source"},
......@@ -21,6 +36,7 @@ FIELDS = {
"Uploads": {"field": "uploads_count"},
},
"*": {
"Title": {"field": "title"},
"Created": {"field": "creation_date"},
"Name": {"field": "name"},
"ID": {"field": "id", "truncate": 0},
......@@ -56,8 +72,11 @@ def get_value(obj, config, truncate=30):
value = [recursive_getattr(obj, f, permissive=True) for f in field]
value = "/".join([str(v) for v in value if v is not None])
else:
value = str(recursive_getattr(obj, field, permissive=True))
value = recursive_getattr(obj, field, permissive=True)
if config.get("handler"):
value = config["handler"](value)
value = str(value)
if truncate and len(value) > truncate:
value = value[:truncate] + ""
return value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment