Index: HTML/EN/plugins/MusicMagic/settings/musicmagic.html
===================================================================
--- HTML/EN/plugins/MusicMagic/settings/musicmagic.html (revision 22212)
+++ HTML/EN/plugins/MusicMagic/settings/musicmagic.html (working copy)
@@ -7,6 +7,11 @@
[% END %]
[% END %]
+ [% WRAPPER setting title="MUSICIP_READSONGDATA" desc="MUSICIP_READSONGDATA_DESC" %]
+
+
+ [% END %]
+
[% WRAPPER settingSection %]
[% IF prefs.exists('pref_player_settings') %]
[% WRAPPER settingGroup title="SETUP_MMMPLAYERSETTINGS" desc="SETUP_MMMPLAYERSETTINGS_DESC" %]
Index: Importer.pm
===================================================================
--- Importer.pm (revision 22212)
+++ Importer.pm (working copy)
@@ -172,84 +172,196 @@
$MMSport = $prefs->get('port') unless $MMSport;
$MMSHost = $prefs->get('host') unless $MMSHost;
- my $count = get("http://$MMSHost:$MMSport/api/getSongCount");
+ $class->exportSongs;
+ $class->exportPlaylists;
+ $class->exportDuplicates;
+}
- if ($count) {
+sub exportSongs {
+ my $class = shift;
- # convert to integer
- chomp($count);
+ my $fullRescan = $::wipe ? 1 : 0;
- $count += 0;
+ my $readSongData = $prefs->get('readSongData');
+
+ if (!defined($readSongData)) {
+ $readSongData = 0;
+ $prefs->set('readSongData', 0);
}
- $log->info("Got $count song(s).");
+ if ($fullRescan eq 1 || $readSongData eq 1) {
+ $log->info("MusicIP mixable status full scan");
- $class->exportSongs($count);
- $class->exportPlaylists;
- $class->exportDuplicates;
-}
+ my $count = get("http://$MMSHost:$MMSport/api/getSongCount");
+ if ($count) {
+ # convert to integer
+ chomp($count);
+ $count += 0;
+ }
-sub exportSongs {
- my $class = shift;
- my $count = shift;
+ $log->info("Got $count song(s).");
- my $progress = Slim::Utils::Progress->new({
- 'type' => 'importer',
- 'name' => 'musicip',
- 'total' => $count,
- 'bar' => 1
- });
+ my $progress = Slim::Utils::Progress->new({
+ 'type' => 'importer',
+ 'name' => 'musicip',
+ 'total' => $count,
+ 'bar' => 1
+ });
- # MMM Version 1.5+ adds support for /api/songs?extended, which pulls
- # down the entire library, separated by $LF$LF - this allows us to make
- # 1 HTTP request, and the process the file.
- if (Slim::Utils::Versions->compareVersions($MMMVersion, '1.5') >= 0) {
+ # MMM Version 1.5+ adds support for /api/songs?extended, which pulls
+ # down the entire library, separated by $LF$LF - this allows us to make
+ # 1 HTTP request, and the process the file.
+ if (Slim::Utils::Versions->compareVersions($MMMVersion, '1.5') >= 0) {
+ $log->info("Fetching ALL song data via songs/extended..");
- $log->info("Fetching ALL song data via songs/extended..");
+ my $MMMSongData = catdir( preferences('server')->get('cachedir'), 'mmm-song-data.txt' );
+ my $MMMDataURL = "http://$MMSHost:$MMSport/api/songs?extended";
- my $MMMSongData = catdir( preferences('server')->get('cachedir'), 'mmm-song-data.txt' );
+ getstore($MMMDataURL, $MMMSongData);
- my $MMMDataURL = "http://$MMSHost:$MMSport/api/songs?extended";
+ if (!-r $MMMSongData) {
+ logError("Couldn't connect to $MMMDataURL ! : $!");
+ return;
+ }
- getstore($MMMDataURL, $MMMSongData);
+ open(MMMDATA, $MMMSongData) || do {
+ logError("Couldn't read file: $MMMSongData : $!");
+ return;
+ };
- if (!-r $MMMSongData) {
+ $log->info("Finished fetching - processing.");
- logError("Couldn't connect to $MMMDataURL ! : $!");
- return;
+ local $/ = "$LF$LF";
+
+ if ($readSongData eq 0) {
+ while(my $content = ) {
+ $class->SetMixable($content, $progress);
+ }
+ } else {
+ while(my $content = ) {
+ $class->processSong($content, $progress);
+ }
+ }
+
+ close(MMMDATA);
+ unlink($MMMSongData);
+ } else {
+ for (my $scan = 0; $scan <= $count; $scan++) {
+ my $content = get("http://$MMSHost:$MMSport/api/getSong?index=$scan");
+
+ $class->processSong($content, $progress);
+ }
}
- open(MMMDATA, $MMMSongData) || do {
+ $progress->final($count) if $progress;
+ }
+ else {
+ $log->info("MusicIP mixable status scan for new/changed tracks");
- logError("Couldn't read file: $MMMSongData : $!");
- return;
- };
+ my $lastScanningTime = Slim::Music::Import->lastScanTime;
+ $log->info("Last scan time was $lastScanningTime");
- $log->info("Finished fetching - processing.");
+ my @tracks = Slim::Schema->rs('Track')->search({'audio' => '1', 'remote' => '0', 'timestamp' => {'>' => $lastScanningTime}});
- local $/ = "$LF$LF";
+ my $count = @tracks;
+ $log->info("Got $count song(s).");
- while(my $content = ) {
+ my $progress = Slim::Utils::Progress->new({
+ 'type' => 'importer',
+ 'name' => 'musicip',
+ 'total' => $count,
+ 'bar' => 1
+ });
- $class->processSong($content, $progress);
+ for my $track (@tracks) {
+ my $trackurl = $track->url;
+
+ # Convert $track->url to a path and call MusicIP
+ my $path = Slim::Utils::Misc::pathFromFileURL($trackurl);
+
+ # Set musicmagic_mixable on $track object and call $track->update to actually store it.
+ my $result = get("http://$MMSHost:$MMSport/api/status?song=$path");
+
+ if ($result =~ /^(\w+)\s+(.*)/) {
+ my $mixable = $1;
+ if ($mixable eq 1) {
+ $log->debug("track: $path is mixable");
+ SetSongMixable($track);
+ }
+ else {
+ $log->warn("track: $path is not mixable");
+ }
+ }
+
+ $progress->update($path);
}
- close(MMMDATA);
- unlink($MMMSongData);
+ $progress->final($count) if $progress;
+ }
+}
- } else {
+sub SetMixable
+{
+ my $class = shift;
+ my $content = shift || return;
+ my $progress = shift;
- for (my $scan = 0; $scan <= $count; $scan++) {
+ my $file;
+ my $active;
- my $content = get("http://$MMSHost:$MMSport/api/getSong?index=$scan");
-
- $class->processSong($content, $progress);
+ my @lines = split(/\n/, $content);
+ for my $line (@lines) {
+ if ($line =~ /^(\w+)\s+(.*)/) {
+ if ($1 eq 'file') {
+ # need conversion to the current charset.
+ $file = Slim::Utils::Unicode::utf8encode_locale($2);
+ }
+ elsif ($1 eq 'active') {
+ $active = $2
+ }
}
}
- $progress->final($count) if $progress;
+ if ($active eq 'yes') {
+ my $fileurl = Slim::Utils::Misc::fileURLFromPath($file);
+
+ my $track = Slim::Schema->rs('Track')->objectForUrl($fileurl)
+ || do {
+ $log->warn("Couldn't get track for $fileurl");
+ $progress->update($file);
+ return;
+ };
+
+ $log->debug("track: $file is mixable");
+ SetSongMixable($track);
+ }
+
+ $progress->update($file);
}
+sub SetSongMixable {
+ my $track = shift;
+
+ $track->musicmagic_mixable(1);
+ $track->update;
+
+ my $albumObj = $track->album;
+ if (blessed($albumObj)) {
+ $albumObj->musicmagic_mixable(1);
+ $albumObj->update;
+ }
+
+ for my $artistObj ($track->contributors) {
+ $artistObj->musicmagic_mixable(1);
+ $artistObj->update;
+ }
+
+ for my $genreObj ($track->genres) {
+ $genreObj->musicmagic_mixable(1);
+ $genreObj->update;
+ }
+}
+
sub processSong {
my $class = shift;
my $content = shift || return;
@@ -299,11 +411,11 @@
}
# Assign these after they may have been verified as UTF-8
- $attributes{'ALBUM'} = $songInfo{'album'} if $songInfo{'album'};
- $attributes{'TITLE'} = $songInfo{'name'} if $songInfo{'name'};
- $attributes{'ARTIST'} = $songInfo{'artist'} if $songInfo{'artist'};
- $attributes{'GENRE'} = $songInfo{'genre'} if $songInfo{'genre'};
- $attributes{'MUSICMAGIC_MIXABLE'} = 1 if $songInfo{'active'} eq 'yes';
+ $attributes{'ALBUM'} = $songInfo{'album'} if $songInfo{'album'} && $songInfo{'album'} ne 'Miscellaneous';
+ $attributes{'TITLE'} = $songInfo{'name'} if $songInfo{'name'};
+ $attributes{'ARTIST'} = $songInfo{'artist'} if $songInfo{'artist'} && $songInfo{'artist'} ne 'Various Artists';
+ $attributes{'GENRE'} = $songInfo{'genre'} if $songInfo{'genre'} && $songInfo{'genre'} ne 'Miscellaneous';
+ $attributes{'MUSICMAGIC_MIXABLE'} = 1 if $songInfo{'active'} eq 'yes';
# need conversion to the current charset.
$songInfo{'file'} = Slim::Utils::Unicode::utf8encode_locale($songInfo{'file'});
Index: Settings.pm
===================================================================
--- Settings.pm (revision 22212)
+++ Settings.pm (working copy)
@@ -107,7 +107,7 @@
}
sub prefs {
- return ($prefs, qw(musicip scan_interval player_settings port mix_filter reject_size reject_type
+ return ($prefs, qw(musicip readSongData scan_interval player_settings port mix_filter reject_size reject_type
mix_genre mix_variety mix_style mix_type mix_size playlist_prefix playlist_suffix));
}
@@ -116,6 +116,7 @@
# Cleanup the checkbox
$params->{'pref_musicip'} = defined $params->{'pref_musicip'} ? 1 : 0;
+ $params->{'pref_readSongData'} = defined $params->{'pref_readSongData'} ? 1 : 0;
$params->{'filters'} = grabFilters();
Index: strings.txt
===================================================================
--- strings.txt (revision 22212)
+++ strings.txt (working copy)
@@ -642,3 +642,8 @@
NO Lag MusicIP-miks
SV Skapa MusicIP Mix
+MUSICIP_READSONGDATA
+ EN Read Song Data
+
+MUSICIP_READSONGDATA_DESC
+ EN Enables MusicIP as a source for music. This will fetch all songs from MusicIP and update or create songs in SqueezeCenter. This is much slower, especially when only scanning for new and changed songs. If unticked, MusicIP will only be scanned to determine what songs are mixable.