Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library items like artists (db:contributor.name=...) favorites don't return the URL in the CLI #459

Closed
Gagi2k opened this issue Nov 19, 2020 · 14 comments
Assignees
Milestone

Comments

@Gagi2k
Copy link

Gagi2k commented Nov 19, 2020

The CLI provides an API for adding new entries to the favorites list. For all entries a URL and a Name needs to be provided.

Right now it's not possible to add an Artist or a complete Album to the favorites as no URL can be retrieved for those entries.

Adding Artists/Albums using the WebUI seems to work fine and results in entries with the following URL:

db:contributor.name=AC%20DC&libraryTracks.library=-1

If this is generic and can be done also from the CLI, it would be great if this convention is documented somwhere

@mherger
Copy link
Contributor

mherger commented Nov 20, 2020

Would you get an error back or something? Anything in server.log? What LMS version?

I don't see any code validating the URL.

@Gagi2k
Copy link
Author

Gagi2k commented Nov 20, 2020

LMS version latest 7.9

you missunderstood me.
I'm not sure on how it is supposed to work. For artitsts/albums/genres there is no URL. So what am i supposed to use as URL to make this work ?
I also noticed that for all favorites which are artists/albums/genres... or also playlists i can't retrieve a URL from the CLI using

< favorites items 0 100 with_url:1

@michaelherger
Copy link
Member

It would be good to show what exact queries you're using, what you expect them to do, and what you actually get. I still don't understand what you're trying to do.

The parameter to get URLs is called want_url, not with_url.

@Gagi2k
Copy link
Author

Gagi2k commented Nov 20, 2020

It would be good to show what exact queries you're using, what you expect them to do, and what you actually get. I still don't understand what you're trying to do.

The problem can be split into two parts. First storing an artist as favorite and then retrieving it from the list of favorites again:

  1. I'm requesting a list of artists:

<<< artists 0 100 tags:u

The response looks like this:
<<< artists 0 100 tags%3Au id%3A232 artist%3A01 id%3A250 artist%3A28 id%3A251 artist%3A3%20Doors%20Down ...

Now the question is how can i store one of the artists in favorites. I tried to use the u (url) tag, but artists don't have a url (which makes sense).

Doing the same using the webui, shows that its possible to store artists in favorites.

  1. Retrieving this stored artist:

<<< favorites items 0 100 want_url:1

The response for the same artist like above is this:

<<< id%3A10 name%3A30%20Seconds%20to%20Mars type%3Aplaylist image%3Ahtml%2Fimages%2Fartists.png isaudio%3A1 hasitems%3A1

Also those items don't have a url, which is ok, but i have a hard time to identify that this favorite item is an artist and there is also no artist_id, which i could use for example to retrieve more information about the artist.

The parameter to get URLs is called want_url, not with_url.

yeah, sorry i just posted it wrong in the comment, my code is using it correctly ;-)

@mherger
Copy link
Contributor

mherger commented Nov 20, 2020

Now the question is how can i store one of the artists in favorites. I tried to use the u (url) tag, but artists don't have a url (which makes sense).

Ok, I see. Yes, there's no URL provided for artists. But what you posted in your initial comment shows how they are created:

db:contributor.name=AC%20DC

That's a LMS custom schema which says: this is a db query, give me contributors with name "AC DC". I believe the decision to do it this way was taken because IDs change between scans. So this will not be a 1:1 mapping. This URL will create a search and can potentially return multiple artists.

What you need to do is to create the "URL" by appending the URL escaped name to the db prefix. There are various prefixes available:

db:contributor.name
db:genre.name
db:year.id
db:album.title

@Gagi2k
Copy link
Author

Gagi2k commented Nov 20, 2020

ok, i can try to do this for saving the favorite, but is there a smart way to retrieve this information again from the favorite list ?

id%3A10 name%3A30%20Seconds%20to%20Mars type%3Aplaylist image%3Ahtml%2Fimages%2Fartists.png isaudio%3A1 hasitems%3A1

That tells me that this favorite doesn't have an url, is not a folder, but has items and using the image i could guess that this is an artist, but is this how it supposed to work, or is there a tag which gives me more information about the type e.g. that this is an artist ? and maybe also which artist. I know that i could use the name, but this is something the user could change and then it doesn't work anymore, while the webui still works, as it can use the internally stored url which i cannot retrieve from the CLI ?

@mherger
Copy link
Contributor

mherger commented Nov 20, 2020

Ok, we're getting closer... so the problem is not storing the favorite, but retrieving it. That looks like an actual bug. I'm always surprised when something basic like this turns out to be broken after years of use...

@mherger mherger changed the title Adding non-playable items to favorites using the CLI is not possible Library items like artists (db:contributor.name=...) favorites don't return the URL in the CLI Nov 20, 2020
@mherger mherger added the bug label Nov 20, 2020
@Gagi2k
Copy link
Author

Gagi2k commented Nov 20, 2020

Using db:contributor.name as an url is a little bit unexpected and nothing i found in the documentation either, but atleast this part seems to work fine and i'm happy to use that ;-)

@mherger
Copy link
Contributor

mherger commented Nov 20, 2020

Could you even use this in your application? It's very LMS specific...

Here's my dilemma: I have a fix. But I wanted to release LMS 8.0.0 next week. And I'm not sure this fix is safe to include it in 8.0.0. But you can handle code? Here's the patch:

diff --git a/Slim/Plugin/Favorites/OpmlFavorites.pm b/Slim/Plugin/Favorites/OpmlFavorites.pm
index 78e82c250..d799c3a6b 100644
--- a/Slim/Plugin/Favorites/OpmlFavorites.pm
+++ b/Slim/Plugin/Favorites/OpmlFavorites.pm
@@ -180,11 +180,12 @@ sub _loadOldFavorites {
 
 sub xmlbrowser {
        my $class = shift;
+       my $dontBrowseDb = shift;
 
        my $hash = $class->SUPER::xmlbrowser;
 
        # optionally let the user browse into local favorite items
-       if ( !$prefs->get('dont_browsedb')) {
+       if ( !$prefs->get('dont_browsedb') && !$dontBrowseDb ) {
                $class->_prepareDbItems($hash->{'items'});
        }
 
diff --git a/Slim/Plugin/Favorites/Plugin.pm b/Slim/Plugin/Favorites/Plugin.pm
index 0d7720d22..7469a061f 100644
--- a/Slim/Plugin/Favorites/Plugin.pm
+++ b/Slim/Plugin/Favorites/Plugin.pm
@@ -749,7 +749,7 @@ sub cliBrowse {
                return;
        }
 
-       my $feed = Slim::Plugin::Favorites::OpmlFavorites->new($client)->xmlbrowser;
+       my $feed = Slim::Plugin::Favorites::OpmlFavorites->new($client)->xmlbrowser($request->getParam('menu') ? undef : 1);
 
        if (my $search = $request->getParam('search')) {
                my $filteredItems = _search($feed->{items}, $search);

Would you mind giving this a try?

@Gagi2k
Copy link
Author

Gagi2k commented Nov 20, 2020

Hi,

thx a lot. works good for me on 7.9.

I can see your dilemma. I guess i could a apply a workaround in my code using the name, but i would prefer having this fix. Asking the users of my app to apply this fix is not a good idea, so i guess i have to wait until this fix is released.
If you don't fix it in 8.0.0 do you have an idea when 8.0.1 would be released which could contain this fix ?

I would be happy to get this fix also in 7.9, but i guess is to much to ask for.

@michaelherger
Copy link
Member

I plan to have 8.0.1 (bugfixes only) and 8.1.0 (next feature release) start to be built the same day. And I'll stop any 7.x builds.

What kind of application is it you're working on?

Gagi2k added a commit to Gagi2k/loxberry-music-server-gateway that referenced this issue Nov 20, 2020
For most operations the id of the items is enough, but for storing
them in the LMS favorite list or in the zone favorites it isn't
as the LMS doesn't support our id schema and in zone favorites
it's also not a good idea as those ids change when the DB is
reindexed.

The change introduces function which resolves the URL for
the passed items. For some this is easy, but for artists/albums...
we are using a LMS internal schema which is also understood by
the LMS favorites.

Retrieving the URLs from the favorite list is also crucial and
until LMS-Community/slimserver#459 is fixed
Storing Albums/Artist/... works fine, but restoring them from the
zone favorites might not play the correct item.
@Gagi2k
Copy link
Author

Gagi2k commented Nov 21, 2020

I'm writing an integration into a smart home (loxone).

@Gagi2k
Copy link
Author

Gagi2k commented Nov 21, 2020

It's probably more something for the spotty plugin, but i have a similar problem retrieving URLs from there, using the following query:

spotty items 0 100 want_url:1 item_id:1.0

@mherger mherger added this to the 8.0.1 milestone Nov 22, 2020
@mherger
Copy link
Contributor

mherger commented Nov 22, 2020

Please submit an issue in http://github.com/michaelherger/Spotty-Plugin/issues instead.

@mherger mherger self-assigned this Nov 22, 2020
@mherger mherger added the patch label Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants