Skip to content

Commit

Permalink
Merge pull request #1240 from darrell-k/works-classical-genre-only
Browse files Browse the repository at this point in the history
Option to limit works scanning to classical
  • Loading branch information
michaelherger authored Dec 10, 2024
2 parents ab80f7e + 0a753ba commit 712b53f
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 26 deletions.
15 changes: 13 additions & 2 deletions HTML/EN/settings/server/behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@
<input type="radio" name="pref_useTPE2AsAlbumArtist" id="pref_useTPE2AsAlbumArtist1" value="1" [% IF prefs.pref_useTPE2AsAlbumArtist %]checked="checked"[% END %] />
<label for="pref_useTPE2AsAlbumArtist1" class="stdlabel">[% 'SETUP_USETPE2ASALBUMARTIST_1' | getstring %]</label><br/>
[% END %]

[% WRAPPER settingGroup title="SETUP_MYCLASSICALGENRES" desc="SETUP_MYCLASSICALGENRES_DESC" %]
<input type="text" class="stdedit" name="pref_myClassicalGenres" id="myClassicalGenres" value="[% prefs.pref_myClassicalGenres | html %]" size="40" placeholder="[% "GENRES" | string | html %]"><br/>
[% END %]

[% WRAPPER settingGroup title="SETUP_WORKSSCAN" desc="" %]
<input type="radio" name="pref_worksScan" id="pref_worksScan0" value="0" [% IF prefs.pref_worksScan == 0 %]checked="checked"[% END %] />
<label for="pref_worksScan0" class="stdlabel">[% 'SETUP_WORKSSCAN_0' | getstring %]</label><br/>
<input type="radio" name="pref_worksScan" id="pref_worksScan1" value="1" [% IF prefs.pref_worksScan == 1 %]checked="checked"[% END %] />
<label for="pref_worksScan1" class="stdlabel">[% 'SETUP_WORKSSCAN_1' | getstring %]</label><br/>
<input type="radio" name="pref_worksScan" id="pref_worksScan2" value="2" [% IF prefs.pref_worksScan == 2 %]checked="checked"[% END %] />
<label for="pref_worksScan2" class="stdlabel">[% 'SETUP_WORKSSCAN_2' | getstring %]</label><br/>
[% END %]
[% END %]

[% WRAPPER settingSection %]
Expand Down Expand Up @@ -152,10 +165,8 @@
<label for="pref_showComposerReleasesbyAlbum1" class="stdlabel">[% 'SETUP_RELEASE_TYPES_COMPOSER_ROLE_GROUPING_1' | getstring %]</label><br/>
<input type="radio" name="pref_showComposerReleasesbyAlbum" id="pref_showComposerReleasesbyAlbum2" value="2" [% IF prefs.pref_showComposerReleasesbyAlbum == 2 %]checked="checked"[% END %] />
<label for="pref_showComposerReleasesbyAlbum2" class="stdlabel">[% 'SETUP_RELEASE_TYPES_COMPOSER_ROLE_GROUPING_2' | getstring %]</label>
<input type="text" class="stdedit" name="pref_showComposerReleasesbyAlbumGenres" id="showComposerReleasesbyAlbumGenres" value="[% prefs.pref_showComposerReleasesbyAlbumGenres | html %]" size="40" placeholder="[% "GENRES" | string | html %]"><br/>
[% END; ELSE %]
<input type="hidden" name="pref_showComposerReleasesbyAlbum" value="[% prefs.pref_showComposerReleasesbyAlbum %]" />
<input type="hidden" name="pref_showComposerReleasesbyAlbumGenres" value="[% prefs.pref_showComposerReleasesbyAlbumGenres %]" />
[% END %]
[% END %]

Expand Down
9 changes: 9 additions & 0 deletions Slim/Control/Queries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5525,6 +5525,15 @@ sub _songDataFromHash {
$returnHash{'discsubtitle'} = $res->{'tracks.discsubtitle'} if $res->{'tracks.discsubtitle'};
}

# Special case for G (genres name) - include isClassical as well
elsif ( $tag eq 'G' ) {
if ( $res->{'genres'} ) {
$returnHash{'genres'} = $res->{'genres'};
my $isClassical = Slim::Schema::Genre->isMyClassicalGenre($res->{'genres'}, ',');
$returnHash{'isClassical'} = $isClassical if $isClassical;
}
}

# eg. the web UI is requesting some tags which are only available for remote tracks,
# such as 'B' (custom button handler). They would return empty here - ignore them.
elsif ( my $map = $colMap{$tag} ) {
Expand Down
7 changes: 2 additions & 5 deletions Slim/Menu/BrowseLibrary/Releases.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ sub _releases {
my %isPrimaryArtist;
my %albumList;

my %composerGenres = map {
$_ => 1
} split(/,\s*/, uc($prefs->get('showComposerReleasesbyAlbumGenres')));

my $checkComposerGenres = !( $menuMode && $menuMode ne 'artists' && $menuRoles ) && $prefs->get('showComposerReleasesbyAlbum') == 2;
my $allComposers = ( $menuMode && $menuMode ne 'artists' && $menuRoles ) || $prefs->get('showComposerReleasesbyAlbum') == 1;

Expand All @@ -86,7 +82,7 @@ sub _releases {
}
else {
foreach my $genre (@{$request->getResult('genres_loop')}) {
last if $genreMatch = $composerGenres{uc($genre->{genre})};
last if $genreMatch = Slim::Schema::Genre->isMyClassicalGenre($genre->{genre});
}
}
}
Expand Down Expand Up @@ -207,6 +203,7 @@ sub _releases {

# Add item for Classical Works if the artist has any.
push @searchTags, "role_id:$menuRoles" if $menuRoles && $menuMode && $menuMode ne 'artists';
push @searchTags, "genre_id:" . Slim::Schema::Genre->myClassicalGenreIds() if $checkComposerGenres;
main::INFOLOG && $log->is_info && $log->info("works ($index, $quantity): tags ->", join(', ', @searchTags));
my $requestRef = [ 'works', 0, MAX_ALBUMS, @searchTags ];
my $request = Slim::Control::Request->new( $client ? $client->id() : undef, $requestRef );
Expand Down
9 changes: 6 additions & 3 deletions Slim/Music/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ $prefs->setChange(

sub splitTag {
my $tag = shift;
my $customSeparator = shift;

# Handle Vorbis comments where the tag can be an array.
if (ref($tag) eq 'ARRAY') {
Expand All @@ -1018,15 +1019,17 @@ sub splitTag {

my @splitTags = ();

if (!$_gotSplitList) {
if (!$_gotSplitList && !$customSeparator) {
$_splitList = $prefs->get('splitList');
$_gotSplitList = 1;
}

my $separator = $customSeparator || $_splitList;

# only bother if there are some characters in the pref
if ($_splitList) {
if ($separator) {

for my $splitOn (split(/\s+/, $_splitList),'\x00') {
for my $splitOn (split(/\s+/, $separator),'\x00') {

my @temp = ();

Expand Down
29 changes: 25 additions & 4 deletions Slim/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ use Slim::Schema::Debug;
use Slim::Schema::RemoteTrack;
use Slim::Schema::RemotePlaylist;

use constant SCAN_WORKS_FOR_MY_CLASSICAL_GENRES => 2;

my $log = logger('database.info');

my $prefs = preferences('server');
my $scanWorks = $prefs->get('worksScan') if main::SCANNER;

# Singleton objects for Unknowns
our ($_unknownArtist, $_unknownGenre, $_unknownAlbumId) = ('', '', undef);
Expand Down Expand Up @@ -1757,7 +1760,12 @@ sub _newTrack {
}

### Create Work rows
my $workID = $self->_createWork($deferredAttributes->{'WORK'}, $deferredAttributes->{'WORKSORT'}, $contributors->{'COMPOSER'}->[0], 1);
my $workID;
if ( _workRequired($deferredAttributes->{'GENRE'}) ) {
$workID = $self->_createWork($deferredAttributes->{'WORK'}, $deferredAttributes->{'WORKSORT'}, $contributors->{'COMPOSER'}->[0], 1);
}
else {
}

### Find artwork column values for the Track
if ( !$columnValueHash{cover} && $columnValueHash{audio} ) {
Expand Down Expand Up @@ -2998,9 +3006,13 @@ sub _postCheckAttributes {

#Work
if (defined $attributes->{'WORK'}) {
my $workID = $self->_createWork($attributes->{'WORK'}, $attributes->{'WORKSORT'}, $contributors->{'COMPOSER'}->[0], 1);
if ($workID) {
$track->work($workID);
if ( _workRequired($attributes->{'GENRE'}) ) {
my $workID = $self->_createWork($attributes->{'WORK'}, $attributes->{'WORKSORT'}, $contributors->{'COMPOSER'}->[0], 1);
if ($workID) {
$track->work($workID);
}
} else {
$track->work(undef);
}
}

Expand Down Expand Up @@ -3293,6 +3305,15 @@ sub canFulltextSearch {
return $canFulltextSearch;
}

sub _workRequired {
if ( (defined $scanWorks ? $scanWorks : $prefs->get('worksScan')) == SCAN_WORKS_FOR_MY_CLASSICAL_GENRES ) {
my $genres = shift;
return Slim::Schema::Genre->isMyClassicalGenre($genres);
} else {
return defined $scanWorks ? $scanWorks : $prefs->get('worksScan');
}
}

=head1 SEE ALSO
L<DBIx::Class>
Expand Down
40 changes: 40 additions & 0 deletions Slim/Schema/Genre.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ use Slim::Schema::ResultSet::Genre;

use Slim::Utils::Misc;
use Slim::Utils::Log;
use Slim::Utils::Prefs;

my $myClassicalGenreMap;
my $myClassicalGenreIds;
my $tagSeparator;
my $tagSeparatorLoaded;

{
my $class = __PACKAGE__;
Expand All @@ -35,6 +41,40 @@ use Slim::Utils::Log;
$class->resultset_class('Slim::Schema::ResultSet::Genre');
}

sub loadMyClassicalGenreMap {
my $prefs = preferences('server');
%$myClassicalGenreMap = map {$_ => 1} split(/\s*,\s*/, uc($prefs->get('myClassicalGenres')));
if ( !%$myClassicalGenreMap ) {
$myClassicalGenreIds = undef;
return;
} else {
# also load genre ids from database
my @genreNames = keys %$myClassicalGenreMap;
my $dbh = Slim::Schema->dbh;
my $sql = 'SELECT GROUP_CONCAT(id) FROM genres WHERE UPPER(name) IN (' . join(', ', map {'?'} @genreNames) . ')';
my $sth = $dbh->prepare_cached($sql);
$sth->execute(@genreNames);
($myClassicalGenreIds) = $sth->fetchrow_array;
$sth->finish;
}
}

sub isMyClassicalGenre {
loadMyClassicalGenreMap() if !$myClassicalGenreMap;
my $class = shift;
my $genres = shift;
my $sep = shift;
foreach ( Slim::Music::Info::splitTag($genres, $sep) ) {
return 1 if %$myClassicalGenreMap{uc($_)}
}
return 0;
}

sub myClassicalGenreIds {
loadMyClassicalGenreMap() if !$myClassicalGenreMap;
return $myClassicalGenreIds;
}

sub url {
my $self = shift;

Expand Down
12 changes: 10 additions & 2 deletions Slim/Utils/Prefs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ sub init {
'ignoreReleaseTypes' => 0,
'groupArtistAlbumsByReleaseType' => 0,
'showComposerReleasesbyAlbum' => 2,
'showComposerReleasesbyAlbumGenres' => "Classical, Klassik, Classique, Klassiek",
'myClassicalGenres' => $prefs->get("showComposerReleasesbyAlbumGenres") || "Classical, Klassik, Classique, Klassiek",
'ratingImplementation' => 'LOCAL_RATING_STORAGE',
# Server Settings - FileTypes
'disabledextensionsaudio' => '',
Expand Down Expand Up @@ -275,6 +275,7 @@ sub init {
'composerAlbumLink' => $prefs->get('useUnifiedArtistsList') && $prefs->get('composerInArtists'),
'conductorAlbumLink' => $prefs->get('useUnifiedArtistsList') && $prefs->get('conductorInArtists'),
'bandAlbumLink' => $prefs->get('useUnifiedArtistsList') && $prefs->get('bandInArtists'),
'worksScan'=> $prefs->get("showComposerReleasesbyAlbum") || 2,
);

# we can have different defaults depending on the OS
Expand Down Expand Up @@ -402,9 +403,16 @@ sub init {

$prefs->setChange(
sub { Slim::Control::Request::executeRequest(undef, ['wipecache', $prefs->get('dontTriggerScanOnPrefChange') ? 'queue' : undef]) },
qw(splitList groupdiscs useTPE2AsAlbumArtist cleanupReleaseTypes)
qw(splitList groupdiscs useTPE2AsAlbumArtist cleanupReleaseTypes worksScan)
);

$prefs->setChange( sub {
Slim::Schema::Genre->loadMyClassicalGenreMap();
if ( $prefs->get('worksScan') == 2 ) {
Slim::Control::Request::executeRequest(undef, ['wipecache', $prefs->get('dontTriggerScanOnPrefChange') ? 'queue' : undef]);
}
}, 'myClassicalGenres' );

$prefs->setChange( sub {
my $newRoles = $_[1];
my $oldRoles = $_[3];
Expand Down
3 changes: 2 additions & 1 deletion Slim/Web/Settings/Server/Behavior.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ sub prefs {
variousArtistAutoIdentification
ignoreReleaseTypes cleanupReleaseTypes groupArtistAlbumsByReleaseType
useTPE2AsAlbumArtist variousArtistsString ratingImplementation useUnifiedArtistsList
skipsentinel showComposerReleasesbyAlbum showComposerReleasesbyAlbumGenres onlyAlbumYears)
skipsentinel showComposerReleasesbyAlbum myClassicalGenres onlyAlbumYears
worksScan)
);
}

Expand Down
2 changes: 1 addition & 1 deletion Slim/Web/XMLBrowser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if ( !main::SCANNER ) {

$prefs->setChange( \&wipeCaches, qw(itemsPerPage thumbSize showArtist showYear additionalPlaylistButtons noGenreFilter noRoleFilter searchSubString browseagelimit
composerInArtists conductorInArtists bandInArtists trackartistInArtists variousArtistAutoIdentification titleFormat titleFormatWeb language useUnifiedArtistsList
groupArtistAlbumsByReleaseType ignoreReleaseTypes releaseTypesToIgnore showComposerReleasesbyAlbum showComposerReleasesbyAlbumGenres onlyAlbumYears userDefinedRoles
groupArtistAlbumsByReleaseType ignoreReleaseTypes releaseTypesToIgnore showComposerReleasesbyAlbum myClassicalGenres onlyAlbumYears userDefinedRoles
artistAlbumLink albumartistAlbumLink trackartistAlbumLink composerAlbumLink conductorAlbumLink bandAlbumLink) );
}

Expand Down
58 changes: 50 additions & 8 deletions strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10422,14 +10422,14 @@ SETUP_RELEASE_TYPES_COMPOSER_ROLE_GROUPING_1
ES Crear siempre un grupo de Álbum de compositor

SETUP_RELEASE_TYPES_COMPOSER_ROLE_GROUPING_2
CS Vytvořit pro tyto žánry skupinu Alba skladatele:
DA Opret en Composer Album gruppe for følgende genrer:
EN Create a Composer Album group for these genres:
FR Créer un groupe "Albums du compositeur" pour ces genres :
DE Komponistenalbengruppe für diese Stilrichtungen erstellen:
HU Hozzon létre egy zeneszerzői albumcsoportot a következő műfajokhoz:
NL Maak een groep van componistenalbums voor deze genres:
ES Crea un grupo de Álbum de compositor para estos géneros:
CS Vytvoření skupiny Skladatelské album pro "Moje klasické žánry" (výše)
DA Opret en komponistalbumgruppe for "Mine klassiske genrer" (ovenfor)
DE Erstellen einer Komponistenalbengruppe für "Meine klassischen Genres" (oben)
EN Create a Composer Album group for "My classical genres" (above)
ES Crear un grupo de álbumes de compositor para "Mis géneros clásicos" (arriba)
FR Créer un groupe d'albums de compositeur pour « Mes genres classiques » (ci-dessus)
HU Zeneszerzői albumcsoport létrehozása a "Klasszikus műfajaim" számára (fent)
NL Maak een componistenalbumgroep voor 'Mijn klassieke genres' (hierboven)

SETUP_IGNORE_RELEASE_TYPES_0
CS Povolit podporu typu vydání pro alba
Expand Down Expand Up @@ -26860,3 +26860,45 @@ SETUP_USERDEFINEDROLES_TEXT_PLURAL
HU Szöveg megjelenítése (többes számú)
NL Tekst weergeven (meervoud)

SETUP_WORKSSCAN
DE Scannen klassischer Werke
EN Classical works scanning
ES Escaneo de obras clásicas
FR Numérisation d'œuvres classiques
NL Scannen van klassieke werken

SETUP_WORKSSCAN_1
DE Durchsuchen Sie die gesamte Bibliothek nach klassischen Werken
EN Scan whole library for classical works
ES Escanea toda la biblioteca en busca de obras clásicas
FR Parcourez toute la bibliothèque à la recherche d'œuvres classiques
NL Scan de hele bibliotheek op klassieke werken

SETUP_WORKSSCAN_2
DE Klassik-Scan auf "Meine klassischen Genres" beschränken (oben)
EN Limit classical works scan to "My classical genres" (above)
ES Limitar el escaneo de obras clásicas a "Mis géneros clásicos" (arriba)
FR Limiter le balayage des œuvres classiques à « Mes genres classiques » (ci-dessus)
NL Beperk de scan van klassieke werken tot "Mijn klassieke genres" (hierboven)

SETUP_WORKSSCAN_0
DE Nicht nach Werken suchen
EN Do not scan for Works
ES No buscar obras
FR Ne pas rechercher d'œuvres
NL Niet scannen op werken

SETUP_MYCLASSICALGENRES
DE Meine klassischen Genres
EN My classical genres
ES Mis géneros clásicos
FR Mes genres classiques
NL Mijn klassieke genres

SETUP_MYCLASSICALGENRES_DESC
DE Verwenden Sie diese Genres, um klassische Musik zu identifizieren
EN Use these genres to identify classical music
ES Utiliza estos géneros para identificar la música clásica
FR Utilisez ces genres pour identifier la musique classique
NL Gebruik deze genres om klassieke muziek te identificeren

0 comments on commit 712b53f

Please sign in to comment.