-
Notifications
You must be signed in to change notification settings - Fork 319
Browse albums by record label: initial version #1382
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
base: public/9.1
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,7 @@ sub albumsQuery { | |
my $work = $request->getParam('work_id'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the tab after |
||
my $composerID = $request->getParam('composer_id'); | ||
my $fromSearch = $request->getParam('from_search'); | ||
my $label = $request->getParam('record_label'); | ||
|
||
my $ignoreNewAlbumsCache = $search || $compilation || $contributorID || $genreID || $trackID || $albumID || $year || Slim::Music::Import->stillScanning(); | ||
|
||
|
@@ -514,6 +515,11 @@ sub albumsQuery { | |
push @{$p}, $year; | ||
} | ||
|
||
if (defined $label) { | ||
push @{$w}, 'albums.label = ?'; | ||
push @{$p}, $label; | ||
} | ||
|
||
if (defined $fromSearch && !defined $search) { | ||
# If we've got here from a search, we don't want to show the album unless it matches all the user's search criteria. | ||
# This matters for a Works search: we've shown the user a Work because it matches their criteria, but it is possible | ||
|
@@ -1989,6 +1995,147 @@ sub irenableQuery { | |
$request->setStatusDone(); | ||
} | ||
|
||
sub labelsQuery { | ||
my $request = shift; | ||
|
||
# check this is the correct query. | ||
if ($request->isNotQuery([['labels']])) { | ||
$request->setStatusBadDispatch(); | ||
return; | ||
} | ||
|
||
if (!Slim::Schema::hasLibrary()) { | ||
$request->setStatusNotDispatchable(); | ||
return; | ||
} | ||
|
||
my $sqllog = main::DEBUGLOG && logger('database.sql'); | ||
|
||
# get our parameters | ||
my $client = $request->client(); | ||
my $index = $request->getParam('_index'); | ||
my $quantity = $request->getParam('_quantity'); | ||
my $year = $request->getParam('year'); | ||
my $contributorID = $request->getParam('artist_id'); | ||
my $workID = $request->getParam('work_id'); | ||
my $libraryID = Slim::Music::VirtualLibraries->getRealId($request->getParam('library_id')); | ||
my $tags = $request->getParam('tags') || ''; | ||
|
||
my $sql = 'SELECT distinct label FROM albums '; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have an index on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the preferred method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just add it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I didn't know 'old' schema files would be run again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're actually right 😞: we only wipe the tables during a wipe & rescan. I thought we'd drop the database and build from scratch. So that won't work - unless someone went to manually delete the file. I fear we'll need another migration file. Shouldn't hurt those coming from 9.0, but only those already on 9.1 (@frank1969b). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could do something like a "create index if doesn't exist" in server startup. Maybe a bit hacky. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that we don't have indexes Anyway: we could put such a hack in place for a few weeks. Should just not forget to remove it after a while |
||
my $w = []; | ||
my $p = []; | ||
push @{$w}, 'albums.label IS NOT NULL'; | ||
|
||
if (defined $contributorID) { | ||
|
||
$sql .= 'JOIN contributor_album ON albums.id = contributor_album.contributor '; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please indent the first line by one more tab |
||
# handle the case where we're asked for the VA id => return compilations | ||
if ($contributorID == Slim::Schema->variousArtistsObject->id) { | ||
push @{$w}, 'albums.compilation = ?'; | ||
push @{$p}, 1; | ||
} | ||
else { | ||
push @{$w}, 'contributor_album.contributor = ?'; | ||
push @{$p}, $contributorID; | ||
} | ||
} | ||
|
||
if ( $libraryID ) { | ||
$sql .= 'JOIN library_album ON library_album.album = albums.id '; | ||
push @{$w}, 'library_album.library = ?'; | ||
push @{$p}, $libraryID; | ||
} | ||
|
||
if (defined $year) { | ||
push @{$w}, 'albums.year = ?'; | ||
push @{$p}, $year; | ||
} | ||
if (defined $workID) { | ||
$sql .= "JOIN tracks on tracks.album = albums.id "; | ||
if ( $workID eq "-1" ) { | ||
push @{$w}, 'tracks.work IS NOT NULL'; | ||
} else { | ||
push @{$w}, 'tracks.work = ?'; | ||
push @{$p}, $workID; | ||
} | ||
} | ||
|
||
if ( @{$w} ) { | ||
$sql .= 'WHERE '; | ||
my $s = join( ' AND ', @{$w} ); | ||
$s =~ s/\%/\%\%/g; | ||
$sql .= $s . ' '; | ||
} | ||
|
||
my $dbh = Slim::Schema->dbh; | ||
|
||
my $stillScanning = Slim::Music::Import->stillScanning(); | ||
|
||
# Get count of all results, the count is cached until the next rescan done event | ||
my $cacheKey = md5_hex($sql . join( '', @{$p} ) . Slim::Music::VirtualLibraries->getLibraryIdForClient($client)); | ||
|
||
my $count = $cache->{$cacheKey}; | ||
if ( !$count ) { | ||
my $total_sth = $dbh->prepare_cached( qq{ | ||
SELECT COUNT(1) FROM ( $sql ) AS t1 | ||
} ); | ||
|
||
$total_sth->execute( @{$p} ); | ||
($count) = $total_sth->fetchrow_array(); | ||
$total_sth->finish; | ||
|
||
if ( !$stillScanning ) { | ||
$cache->{$cacheKey} = $count; | ||
} | ||
} | ||
|
||
# now build the result | ||
|
||
if ($stillScanning) { | ||
$request->addResult('rescan', 1); | ||
} | ||
|
||
$count += 0; | ||
|
||
my ($valid, $start, $end) = $request->normalize(scalar($index), scalar($quantity), $count); | ||
|
||
if ($valid && $tags ne 'CC') { | ||
|
||
$sql .= 'ORDER BY 1 '; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow... hadn't known this shortcut. But... please use the column name for easier reading. |
||
|
||
my $loopname = 'labels_loop'; | ||
my $chunkCount = 0; | ||
|
||
# Limit the real query | ||
if ( $index =~ /^\d+$/ && $quantity =~ /^\d+$/ ) { | ||
$sql .= "LIMIT $index, $quantity "; | ||
} | ||
|
||
if ( main::DEBUGLOG && $sqllog->is_debug ) { | ||
$sqllog->debug( "Labels query: $sql / " . Data::Dump::dump($p) ); | ||
} | ||
|
||
my $sth = $dbh->prepare_cached($sql); | ||
$sth->execute( @{$p} ); | ||
|
||
my ($label); | ||
$sth->bind_columns( \$label ); | ||
|
||
while ( $sth->fetch ) { | ||
|
||
$request->addResultLoop($loopname, $chunkCount, 'record_label', $label); | ||
|
||
$chunkCount++; | ||
|
||
main::idleStreams() if !($chunkCount % 5); | ||
} | ||
} | ||
|
||
$request->addResult('count', $count); | ||
|
||
$request->setStatusDone(); | ||
} | ||
|
||
sub librariesQuery { | ||
my $request = shift; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package Slim::Menu::BrowseLibrary; | ||
|
||
use strict; | ||
|
||
use Slim::Utils::Log; | ||
use Slim::Utils::Strings qw(cstring); | ||
|
||
use constant BROWSELIBRARY => 'browselibrary'; | ||
|
||
my $log = logger('database.info'); | ||
|
||
sub _labels { | ||
my ($client, $callback, $args, $pt) = @_; | ||
my @searchTags = $pt->{'searchTags'} ? @{$pt->{'searchTags'}} : (); | ||
my $library_id = $args->{'library_id'} || $pt->{'library_id'}; | ||
my $search = $args->{'search'} || $pt->{'search'}; | ||
my $remote_library = $args->{'remote_library'} ||= $pt->{'remote_library'}; | ||
|
||
if ($library_id && !grep /library_id/, @searchTags) { | ||
push @searchTags, 'library_id:' . $library_id; | ||
} | ||
|
||
Slim::Menu::BrowseLibrary::_generic($client, $callback, $args, 'labels', | ||
[ @searchTags, ($search ? 'search:' . $search : undef) ], | ||
sub { | ||
my $results = shift; | ||
my $items = $results->{'labels_loop'}; | ||
$remote_library ||= $args->{'remote_library'}; | ||
|
||
foreach (@$items) { | ||
$_->{'name'} = $_->{'record_label'}; | ||
$_->{'image'} = 'html/images/albums.png'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was surprised by the number of labels found in my (test) collection. Must be because many of those files come from users with extensive metadata 😁. But looking at that list I was wondering... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the same thing: a job for MAI if it's feasible. I just used album as a placeholder. For the top level menu icon, we could do with a label.png but I am certainly not the right person to be designing one. Maybe you could ask AI to come up with a record label icon in the style of LMS. If it does a good job, I might change my opinion of its usefulness 😂. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI has failed me (in the short time I tried). Just in case you were considering a dedicated |
||
$_->{'type'} = 'playlist'; | ||
$_->{'playlist'} = \&_tracks; | ||
$_->{'url'} = \&_albums; | ||
$_->{'passthrough'} = [ { searchTags => [@searchTags, "record_label:" . $_->{'record_label'}], remote_library => $remote_library } ]; | ||
}; | ||
|
||
my $params = _tagsToParams(\@searchTags); | ||
my %actions = $remote_library ? ( | ||
commonVariables => [record_label => 'record_label'] | ||
) : ( | ||
allAvailableActionsDefined => 1, | ||
commonVariables => [record_label => 'record_label'], | ||
items => { | ||
command => [BROWSELIBRARY, 'items'], | ||
fixedParams => { | ||
mode => 'albums', | ||
%$params | ||
}, | ||
}, | ||
play => { | ||
command => ['playlistcontrol'], | ||
fixedParams => {cmd => 'load', %$params}, | ||
}, | ||
add => { | ||
command => ['playlistcontrol'], | ||
fixedParams => {cmd => 'add', %$params}, | ||
}, | ||
insert => { | ||
command => ['playlistcontrol'], | ||
fixedParams => {cmd => 'insert', %$params}, | ||
}, | ||
); | ||
$actions{'playall'} = $actions{'play'}; | ||
$actions{'addall'} = $actions{'add'}; | ||
|
||
return {items => $items, actions => \%actions, sorted => 1}, undef; | ||
}, undef, 1, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serverstatusQuery
&&infoTotalQuery
might need an update? They're missing eg. works, too