Skip to content

Commit

Permalink
Fix #785 - improve album handling when storing favorites
Browse files Browse the repository at this point in the history
* use unique `extid` to identify albums imported from an online service
* use artist name in addition to album title to identify locally stored albums
  • Loading branch information
mherger committed Apr 24, 2022
1 parent 23526b0 commit 6a1df80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changelog8.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h2><a name="v8.3.0" id="v8.3.0"></a>Version 8.3.0</h2>
<li><a href="https://github.com/Logitech/slimserver/pull/708">#708</a> - Update to MP3, FLAC, Ogg and WMA Formats to use BPM tags - thanks kwarklabs!</li>
<li><a href="https://github.com/Logitech/slimserver/pull/751">#751</a> - Shuffle tracks added with "playlist loadtracks" for a given year (thanks philchillbill!)</li>
<li><a href="https://github.com/Logitech/slimserver/pull/758">#758</a> - Allow selection of regional language (eg. ZH_CH or EN_GB) through JSONRPC (thanks expectingtofly!)</li>
<li><a href="https://github.com/Logitech/slimserver/issues/785">#785</a> - Improve adding albums as favorites: don't rely on the album title alone, but use the artist to identify the album, too.</li>
<li>Remove support for media types other than audio (video, pictures).</li>
<li>Remove more legacy plugins: Amazon, MP3Tunes, Orange, YALP</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions Slim/Menu/BrowseLibrary.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 /(?<!\s),(?!\s)/, $_->{'artists'} ] : [ $_->{'artists'} ];
Expand Down
29 changes: 22 additions & 7 deletions Slim/Player/ProtocolHandlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 6a1df80

Please sign in to comment.