Skip to content

Commit

Permalink
Merge pull request #1272 from darrell-k/noncontiguous-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelherger authored Jan 3, 2025
2 parents 1dcf963 + f3e4df0 commit f35d39a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Slim/Control/Queries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ sub albumsQuery {
my $col = '(SELECT COUNT(1) FROM (SELECT 1 FROM tracks WHERE tracks.album=albums.id GROUP BY work,grouping,performance))';
$c->{$col} = 1;
$as->{$col} = 'group_count';
$col = "(SELECT GROUP_CONCAT(SUBSTR('00000'||tracknum,-5) || COALESCE(work,'') || '##' || COALESCE(performance,'') || '##' || COALESCE(grouping,''),',,') FROM tracks WHERE tracks.album = albums.id)";
$c->{$col} = 1;
$as->{$col} = 'group_structure';
}

if ( @{$w} ) {
Expand Down Expand Up @@ -835,7 +838,28 @@ sub albumsQuery {
$tags =~ /W/ && $request->addResultLoopIfValueDefined($loopname, $chunkCount, 'release_type', $wantsReleaseTypes ? $c->{'albums.release_type'} : 'ALBUM');
$tags =~ /E/ && $request->addResultLoopIfValueDefined($loopname, $chunkCount, 'extid', $c->{'albums.extid'});
$tags =~ /X/ && $request->addResultLoopIfValueDefined($loopname, $chunkCount, 'album_replay_gain', $c->{'albums.replay_gain'});
$tags =~ /2/ && $request->addResultLoopIfValueDefined($loopname, $chunkCount, 'group_count', $c->{'group_count'});

if ( $tags =~ /2/ ) {
my $nonContiguous;
if ( $c->{'group_count'} > 1 ) {
my $previousGroup;
my $groupSeen = {};
foreach ( sort split(',,', $c->{'group_structure'}) ) {
my $thisTrackGroup = substr($_, 5);
if ( $previousGroup ne $thisTrackGroup ) {
if ( $nonContiguous = $groupSeen->{$thisTrackGroup} && $thisTrackGroup ne '####' ) {
last;
}
else {
$groupSeen->{$thisTrackGroup} = 1;
$previousGroup = $thisTrackGroup;
}
}
}
}
$request->addResultLoopIfValueDefined($loopname, $chunkCount, 'group_count', $c->{'group_count'});
$request->addResultLoop($loopname, $chunkCount, 'contiguous_groups', $nonContiguous ? 0 : 1);
}

#Don't use albums.contributor to set artist_id/artist for Works, it may well be completely wrong!
if ( !$work ) {
Expand Down

0 comments on commit f35d39a

Please sign in to comment.