hechtus / squeezebox-googlemusic

Squeezebox (Logitech Media Server) Plugin for Google Play Music
103 stars 24 forks source link

Find Albums/Artist/Tracks by first Letter on Squeezbox Touch #23

Closed mjh421 closed 9 years ago

mjh421 commented 10 years ago

Thanks hechtus for a great app. I'm using a Raspbery Pi and Squeezebox Touch and it works well.

Would it be possible to use the alpha numeric keys on the Touch remote control to find artists/albums/tracks within the Library and Playlists? It's possible on the 'My Music' sections.

Thanks again, Mike.

hechtus commented 10 years ago

As I don't have a Squeezebox Touch I can not promise, that I will able solve this. Could you please describe exactly what you are normally doing when looking for artists/albums/tracks with the numeric keys? What es the exact behavior you are expecting, in which menu etc.

mjh421 commented 10 years ago

Hello. If I select 'My Music' on the Touch, I get access to all my music stored on a USB disk connected to the Pi (running LMS). If I press the 2 button on the remote, the Touch displays a large 'A' on the screen and jumps to the first album/artist/track beginning with A (pressing 2 again giving B, C etc working the same way). I can then use the arrow keys to move to the item I'm interested in. With Google Play at present, if I have a large list of albums, I would need to down/up arrow on the Touch remote a lot to get to the item I want to play. Cheers, Mike

hechtus commented 10 years ago

OK. I think that I have an idea how to implement this. But the thing is, that this depends on the sorting of the albums and tracks. For now they are sorted by artist->year->album. Artists are simply sorted by name, which is OK and intuitive.

My plan is to implement this feature for artist lists. You should try it out and give some feedback. After that we could think how to deal with album and track lists. One option would be to make the sorting configurable. We already thought about this in issue #12.

mjh421 commented 10 years ago

That looks good. If you need me to test, just let me know.

hechtus commented 10 years ago

I think that I got a first prototype for the artists menu. Could you please patch GoogleMusic/Plugin.pm as shown below. You will probably find the file under /var/lib/squeezeboxserver/cache/InstalledPlugins/Plugins/GoogleMusic.

diff --git a/GoogleMusic/Plugin.pm b/GoogleMusic/Plugin.pm
index 7ce7b06..c5e9316 100644
--- a/GoogleMusic/Plugin.pm
+++ b/GoogleMusic/Plugin.pm
@@ -621,7 +621,25 @@ sub _artists {
                }
        }

-       $callback->(\@menu);
+       my @indexList;
+       my %alphaMap = ();
+       foreach (@menu) {
+               my $index = substr($_->{name}, 0, 1);
+               if (exists $alphaMap{$index}) {
+                       $alphaMap{$index}++;
+               } else {
+                       $alphaMap{$index} = 1;
+               }
+               $_->{textkey} = $index;
+       }
+       foreach (sort { $a cmp $b} keys %alphaMap) {
+               push @indexList, [$_, $alphaMap{$_}];
+       }
+
+       $callback->({
+               items => \@menu,
+               indexList => \@indexList,
+       });

        return;
 }
hechtus commented 10 years ago

Just a note, the code above does only work for "My Music" now.

mjh421 commented 10 years ago

Sorry Ronald, I'm new to this! Do I paste the above onto the end of the Plugin.pm file?

hechtus commented 10 years ago

No, you will have to modify the _artists function in the file. Lines starting with a minus have to be removed, lines with a plus have to be added. So, go to the line starting with "sub _artists" and modify the function as shown above. You could also use the patch tool, but I think this would be to much.... ;-)

mjh421 commented 10 years ago

You are a clever man! That works great.

hechtus commented 10 years ago

Wow, fantastic. So, I'm having an idea how to resolve this issue. What do you think. How should we fix the problem for the albums and tracks. What would you expect. What are you wishes? Thanks for trying this out!

mjh421 commented 10 years ago

Thanks are all one way! For me, to be able to use the same search function within albums and tracks would be great. I assume this would require a sort option?

hechtus commented 10 years ago

Just one thing ... Could you please try if it is still working for you when you remove the indexList entry from the the callback parameter? It shall look like this:

       $callback->({
               items => \@menu,
       });

I need to figure out, whether the indexList is only applicable for the squeebox web interface. Thanks!

mjh421 commented 10 years ago

I removed the indexList entry and it stills work fine.

hechtus commented 10 years ago

OK. Great. Thanks! Now, I will think about the sorting stuff and will include this nice feature in the next release.

hechtus commented 10 years ago

Please check out the new release v0.3.3