Skip to content

Commit

Permalink
classical genre processing - adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
darrell-k committed Dec 10, 2024
1 parent 3ee7283 commit 0a753ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Slim/Control/Queries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5527,8 +5527,11 @@ sub _songDataFromHash {

# Special case for G (genres name) - include isClassical as well
elsif ( $tag eq 'G' ) {
$returnHash{'genres'} = $res->{'genres'} if $res->{'genres'};
$returnHash{'isClassical'} = $res->{'isClassical'};
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,
Expand Down Expand Up @@ -6436,14 +6439,12 @@ sub _getTagDataForTracks {
$genre_sth->execute;

my %values;
my $isMyClassical = 0;
while ( my ($id, $name, $track) = $genre_sth->fetchrow_array ) {
my $genre_info = $values{$track} ||= {};

utf8::decode($name);
$genre_info->{ids} .= $genre_info->{ids} ? ',' . $id : $id;
$genre_info->{names} .= $genre_info->{names} ? ', ' . $name : $name;
$isMyClassical ||= Slim::Schema::Genre->isMyClassicalGenre($name);
}

my $want_names = $tags =~ /G/;
Expand All @@ -6453,7 +6454,6 @@ sub _getTagDataForTracks {
my $track = $results{$id};
$track->{genre_ids} = $genre_info->{ids} if $want_ids;
$track->{genres} = $genre_info->{names} if $want_names;
$track->{isClassical} = $isMyClassical if $want_names;
}
}

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
4 changes: 2 additions & 2 deletions Slim/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,8 @@ sub _newTrack {
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 @@ -3306,8 +3308,6 @@ sub canFulltextSearch {
sub _workRequired {
if ( (defined $scanWorks ? $scanWorks : $prefs->get('worksScan')) == SCAN_WORKS_FOR_MY_CLASSICAL_GENRES ) {
my $genres = shift;
# input will be an array if multiple genre tags
$genres = join(';', @$genres) if ref $genres eq 'ARRAY';
return Slim::Schema::Genre->isMyClassicalGenre($genres);
} else {
return defined $scanWorks ? $scanWorks : $prefs->get('worksScan');
Expand Down
9 changes: 6 additions & 3 deletions Slim/Schema/Genre.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use Slim::Utils::Prefs;

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

{
my $class = __PACKAGE__;
Expand Down Expand Up @@ -41,7 +43,7 @@ my $myClassicalGenreIds;

sub loadMyClassicalGenreMap {
my $prefs = preferences('server');
%$myClassicalGenreMap = map {$_ => 1} split(/,\s*/, uc($prefs->get('myClassicalGenres')));
%$myClassicalGenreMap = map {$_ => 1} split(/\s*,\s*/, uc($prefs->get('myClassicalGenres')));
if ( !%$myClassicalGenreMap ) {
$myClassicalGenreIds = undef;
return;
Expand All @@ -61,8 +63,9 @@ sub isMyClassicalGenre {
loadMyClassicalGenreMap() if !$myClassicalGenreMap;
my $class = shift;
my $genres = shift;
foreach (Slim::Music::Info::splitTag(uc($genres))) {
return 1 if %$myClassicalGenreMap{$_}
my $sep = shift;
foreach ( Slim::Music::Info::splitTag($genres, $sep) ) {
return 1 if %$myClassicalGenreMap{uc($_)}
}
return 0;
}
Expand Down

0 comments on commit 0a753ba

Please sign in to comment.