Skip to content

Commit

Permalink
Some calls do access the "album URL", rather than building the favori…
Browse files Browse the repository at this point in the history
…te's URL themselves. Extend `Slim::Schema::Album->url()` to apply the same logic as we applied in browsing code.
  • Loading branch information
mherger committed Apr 27, 2022
1 parent 461f54b commit 2226904
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Slim/Menu/BrowseLibrary.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ sub _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'} = $_->{'extid'}
|| sprintf('db:album.title=%s&contributor.name=%s', URI::Escape::uri_escape_utf8($_->{'name'}), URI::Escape::uri_escape_utf8( $_->{'artist'}));
|| 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
31 changes: 16 additions & 15 deletions Slim/Schema/Album.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ my $log = logger('database.info');
sub url {
my $self = shift;

return sprintf('db:album.title=%s', URI::Escape::uri_escape_utf8($self->title));
return $self->extid
|| sprintf('db:album.title=%s&contributor.name=%s', URI::Escape::uri_escape_utf8($self->title), URI::Escape::uri_escape_utf8($self->contributor->name))
}

sub name {
sub name {
return shift->title;
}

Expand Down Expand Up @@ -99,7 +100,7 @@ sub title {
# return the raw title untainted by Logitech Media Server logic
sub rawtitle {
my $self = shift;

return $self->get_column('title');
}

Expand Down Expand Up @@ -129,7 +130,7 @@ sub displayAsHTML {
FROM contributor_album, contributors
WHERE contributor_album.album = ? AND contributor_album.role IN (%s,%s) AND contributors.id = contributor_album.contributor
), map { Slim::Schema::Contributor->typeToRole($_) } qw(ARTIST TRACKARTIST)) );

my ($contributorId, $contributorName);
$contributor_sth->execute($form->{'albumId'});
$contributor_sth->bind_col( 1, \$contributorId );
Expand Down Expand Up @@ -240,39 +241,39 @@ sub contributorid {

sub findhash {
my ( $class, $id ) = @_;

my $sth = Slim::Schema->dbh->prepare_cached( qq{
SELECT * FROM albums WHERE id = ?
} );

$sth->execute($id);
my $hash = $sth->fetchrow_hashref;
$sth->finish;

return $hash || {};
}

# Rescan list of albums, this simply means to make sure at least 1 track
# from this album still exists in the database. If not, delete the album.
sub rescan {
my ( $class, @ids ) = @_;

my $slog = logger('scan.scanner');

my $dbh = Slim::Schema->dbh;
for my $id ( @ids ) {

for my $id ( @ids ) {
my $sth = $dbh->prepare_cached( qq{
SELECT COUNT(*) FROM tracks WHERE album = ?
} );
$sth->execute($id);
my ($count) = $sth->fetchrow_array;
$sth->finish;

if ( !$count ) {
main::DEBUGLOG && $slog->is_debug && $slog->debug("Removing unused album: $id");
main::DEBUGLOG && $slog->is_debug && $slog->debug("Removing unused album: $id");
$dbh->do( "DELETE FROM albums WHERE id = ?", undef, $id );

# Bug 17283, this removed album may be cached as lastAlbum in Schema
Slim::Schema->wipeLastAlbumCache($id);
}
Expand All @@ -281,7 +282,7 @@ sub rescan {

sub duration {
my $self = shift;

my $secs = 0;
foreach ($self->tracks) {
return if !defined $_->secs;
Expand Down

0 comments on commit 2226904

Please sign in to comment.