From 6a1df809e1b9a40350a8dda4dd344a71bc3450dc Mon Sep 17 00:00:00 2001 From: Michael Herger Date: Sun, 24 Apr 2022 14:13:23 +0200 Subject: [PATCH] Fix #785 - improve album handling when storing favorites * use unique `extid` to identify albums imported from an online service * use artist name in addition to album title to identify locally stored albums --- Changelog8.html | 1 + Slim/Menu/BrowseLibrary.pm | 6 +++--- Slim/Player/ProtocolHandlers.pm | 29 ++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Changelog8.html b/Changelog8.html index b09140e9ff6..4948c6724e4 100644 --- a/Changelog8.html +++ b/Changelog8.html @@ -21,6 +21,7 @@

Version 8.3.0

  • #708 - Update to MP3, FLAC, Ogg and WMA Formats to use BPM tags - thanks kwarklabs!
  • #751 - Shuffle tracks added with "playlist loadtracks" for a given year (thanks philchillbill!)
  • #758 - Allow selection of regional language (eg. ZH_CH or EN_GB) through JSONRPC (thanks expectingtofly!)
  • +
  • #785 - Improve adding albums as favorites: don't rely on the album title alone, but use the artist to identify the album, too.
  • Remove support for media types other than audio (video, pictures).
  • Remove more legacy plugins: Amazon, MP3Tunes, Orange, YALP
  • diff --git a/Slim/Menu/BrowseLibrary.pm b/Slim/Menu/BrowseLibrary.pm index e066c9cb074..fb543e8963e 100644 --- a/Slim/Menu/BrowseLibrary.pm +++ b/Slim/Menu/BrowseLibrary.pm @@ -1452,11 +1452,11 @@ sub _albums { $_->{'playlist'} = \&_tracks; $_->{'url'} = \&_tracks; $_->{'passthrough'} = [ { searchTags => [@searchTags, "album_id:" . $_->{'id'}], sort => 'sort:tracknum', remote_library => $remote_library } ]; - # the favorites url is the album title here + # the favorites url is the album title and contributor name here (or extid for online albums) # album id would be (much) better, but that would screw up the favorite on a rescan # title is a really stupid thing to use, since there's no assurance it's unique - $_->{'favorites_url'} = 'db:album.title=' . - URI::Escape::uri_escape_utf8( $_->{'name'} ); + $_->{'favorites_url'} = $_->{'extid'} + || sprintf('db:album.title=%s&contributor.name=%s', URI::Escape::uri_escape_utf8($_->{'name'}), URI::Escape::uri_escape_utf8( $_->{'artist'})); if ($_->{'artist_ids'}) { $_->{'artists'} = $_->{'artist_ids'} =~ /,/ ? [ split /(?{'artists'} ] : [ $_->{'artists'} ]; diff --git a/Slim/Player/ProtocolHandlers.pm b/Slim/Player/ProtocolHandlers.pm index d11308996db..d834355c21f 100644 --- a/Slim/Player/ProtocolHandlers.pm +++ b/Slim/Player/ProtocolHandlers.pm @@ -26,7 +26,7 @@ my %protocolHandlers = ( spdr => qw(Slim::Player::Protocols::SqueezePlayDirect), http => qw(Slim::Player::Protocols::HTTP), https => qw(Slim::Player::Protocols::HTTPS), - icy => qw(Slim::Player::Protocols::HTTP), + icy => qw(Slim::Player::Protocols::HTTP), playlist => 0, db => 1, ); @@ -155,15 +155,30 @@ sub iconForURL { return 'html/images/playlists.png'; } - elsif ($url =~ /^db:album\.(\w+)=(.+)/) { - my $value = Slim::Utils::Misc::unescape($2); + elsif ($url =~ /^db:(album\..*)/) { + my $query = {}; + for my $term (split('&', $1)) { + if ($term =~ /(.*)=(.*)/) { + my $key = $1; + my $value = Slim::Utils::Misc::unescape($2); - if (utf8::is_utf8($value)) { - utf8::decode($value); - utf8::encode($value); + $key =~ s/^album\./me./; + + if (utf8::is_utf8($value)) { + utf8::decode($value); + utf8::encode($value); + } + + $query->{$key} = $value; + } + } + + my $params; + if (grep /^contributor/, keys %$query) { + $params->{prefetch} = 'contributor'; } - my $album = Slim::Schema->search('Album', { $1 => $value })->first; + my $album = Slim::Schema->search('Album', $query, $params)->first; if ($album && $album->artwork) { return 'music/' . $album->artwork . '/cover.png';