private void OnSubmissionEnd(object source, EventArgs args) { if (scrobble_job != null) { scrobble_job.Finish(); scrobble_job = null; } }
private void PerformSyncThreadCycle() { Hyena.Log.Debug("Starting AppleDevice sync thread cycle"); var progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"), Catalog.GetString("Preparing to synchronize..."), GetIconNames()); progressUpdater.Register(); MediaDatabase.StartSync(); SyncTracksToAdd(progressUpdater); SyncTracksToUpdate(progressUpdater); SyncTracksToRemove(progressUpdater); SyncTracksToPlaylists(); SyncDatabase(progressUpdater); MediaDatabase.StopSync(); progressUpdater.Finish(); Hyena.Log.Debug("Ending AppleDevice sync thread cycle"); }
private void DisposeSyncUserJob() { if (sync_user_job != null) { sync_user_job.Finish(); sync_user_job = null; } }
private void DestroyUserJob() { lock (user_job_mutex) { if (user_job == null) { return; } user_job.Finish(); user_job = null; } }
private void ProcessTrackQueue() { discovery_count = song_queue.Count; user_job.Status = Catalog.GetString("Processing Tracks..."); while (song_queue.Count > 0) { user_job.Progress = (double)(discovery_count - song_queue.Count) / (double)discovery_count; try { ProcessTrack(song_queue.Dequeue()); } catch { } if (user_job.IsCancelRequested) { break; } } user_job.Progress = 0.0; user_job.Status = Catalog.GetString("Ordering Tracks..."); files.Sort(new FileContainerComparer()); foreach (FileContainer container in files) { try { ProcessTrack(container); } catch { } if (user_job.IsCancelRequested) { break; } } if (!user_job.IsCancelRequested) { SaveDatabase(); } user_job.Finish(); user_job = null; OnFinished(); }
protected void DestroyUserJob() { lock (sync) { if (user_job == null) { return; } ResetCounters(); user_job.CancelRequested -= OnCancelRequested; user_job.Finish(); user_job = null; } }
private void OnReadyToScrobble(object source, ScrobblingBatchEventArgs args) { var scrobble_job = new UserJob(Catalog.GetString("Scrobbling from device"), Catalog.GetString("Scrobbling from device...")); scrobble_job.PriorityHints = PriorityHints.DataLossIfStopped; scrobble_job.Register(); try { if (!connection.Started) { connection.Start(); } int added_track_count = 0, processed_track_count = 0; string message = Catalog.GetString("Processing track {0} of {1} ..."); var batchCount = args.ScrobblingBatch.Count; foreach (var track_entry in args.ScrobblingBatch) { TrackInfo track = track_entry.Key; if (IsValidForSubmission(track)) { IList <DateTime> playtimes = track_entry.Value; foreach (DateTime playtime in playtimes) { queue.Add(track, playtime); added_track_count++; } Log.DebugFormat("Added to Last.fm queue: {0} - Number of plays: {1}", track, playtimes.Count); } else { Log.DebugFormat("Track {0} failed validation check for Last.fm submission, skipping...", track); } scrobble_job.Status = String.Format(message, ++processed_track_count, batchCount); scrobble_job.Progress = processed_track_count / (double)batchCount; } Log.InformationFormat("Number of played tracks from device added to Last.fm queue: {0}", added_track_count); } finally { scrobble_job.Finish(); } }
private void DestroyUserJob() { lock (user_job_mutex) { if (user_job == null) { return; } if (!KeepUserJobHidden) { Log.DebugTimerPrint(timer_id, Title + " duration: {0}"); } user_job.CancelRequested -= OnCancelRequested; user_job.Finish(); user_job = null; } }
public void Dispose() { ResetState(); if (source != null && source.Model != null) { source.Model.UnlockDoor(); } if (ripper != null) { ripper.Finish(); ripper = null; } if (user_job != null) { user_job.Finish(); user_job = null; } }
private void PerformSyncThreadCycle() { Hyena.Log.Debug("Starting AppleDevice sync thread cycle"); string message; int total, i = 0; var progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"), Catalog.GetString("Preparing to synchronize..."), GetIconNames()); progressUpdater.Register(); MediaDatabase.StartSync(); message = Catalog.GetString("Adding track {0} of {1}"); total = tracks_to_add.Count; while (tracks_to_add.Count > 0) { AppleDeviceTrackInfo track = null; lock (sync_mutex) { total = tracks_to_add.Count + i; track = tracks_to_add.Dequeue(); } try { UpdateProgress(progressUpdater, message, ++i, total); track.CommitToIpod(MediaDatabase); track.Save(false); tracks_map[track.TrackId] = track; } catch (Exception e) { Log.Exception("Cannot save track to the Apple device", e); } } if (total > 0) { OnTracksAdded(); OnUserNotifyUpdated(); } while (tracks_to_update.Count > 0) { AppleDeviceTrackInfo track = null; lock (sync_mutex) { track = tracks_to_update.Dequeue(); } try { track.CommitToIpod(MediaDatabase); } catch (Exception e) { Log.Exception("Cannot save track to iPod", e); } } message = Catalog.GetString("Removing track {0} of {1}"); total = tracks_to_remove.Count; while (tracks_to_remove.Count > 0) { AppleDeviceTrackInfo track = null; lock (sync_mutex) { track = tracks_to_remove.Dequeue(); } if (tracks_map.ContainsKey(track.TrackId)) { tracks_map.Remove(track.TrackId); } try { if (track.IpodTrack != null) { UpdateProgress(progressUpdater, message, total - tracks_to_remove.Count, total); DeleteTrack(track.IpodTrack, true); } else { Log.Error("The ipod track was null"); } } catch (Exception e) { Log.Exception("Cannot remove track from iPod", e); } } if (SupportsPlaylists) { // Remove playlists on the device var device_playlists = new List <GPod.Playlist> (MediaDatabase.Playlists); foreach (var playlist in device_playlists) { if (!playlist.IsMaster && !playlist.IsPodcast) { MediaDatabase.Playlists.Remove(playlist); } } // Add playlists from Banshee to the device foreach (Source child in Children) { PlaylistSource from = child as PlaylistSource; if (from != null && from.Count > 0) { var playlist = new GPod.Playlist(from.Name); MediaDatabase.Playlists.Add(playlist); foreach (int track_id in ServiceManager.DbConnection.QueryEnumerable <int> (String.Format( "SELECT CoreTracks.TrackID FROM {0} WHERE {1}", from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition))) { if (tracks_map.ContainsKey(track_id)) { playlist.Tracks.Add(tracks_map[track_id].IpodTrack); } } } } } try { message = Catalog.GetString("Writing media database"); UpdateProgress(progressUpdater, message, 1, 1); lock (write_mutex) { MediaDatabase.Write(); } Log.Information("Wrote iPod database"); } catch (Exception e) { Log.Exception("Failed to save iPod database", e); } MediaDatabase.StopSync(); progressUpdater.Finish(); Hyena.Log.Debug("Ending AppleDevice sync thread cycle"); }
private void OnGetTagFromFingerprint(object sender, EventArgs args) { active = true; Source source = ServiceManager.SourceManager.ActiveSource; UserJob job = new UserJob(AddinManager.CurrentLocalizer.GetString("Getting sound fingerprint")); job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database); job.PriorityHints = PriorityHints.SpeedSensitive; job.Status = AddinManager.CurrentLocalizer.GetString("Scanning..."); job.IconNames = new string [] { "system-search", "gtk-find" }; job.CanCancel = true; job.CancelRequested += HandleJobCancelRequested; job.Register(); if (account == null) { account = new LastfmAccount(); LoginDialog dialog = new LoginDialog(account, true); dialog.Run(); dialog.Destroy(); } //comment the timeout system for TOS because still have issue and not seems to be linked... //System.DateTime start = System.DateTime.MinValue; ThreadPool.QueueUserWorkItem(delegate { try { var selection = ((ITrackModelSource)source).TrackModel.Selection; int total = selection.Count; int count = 0; foreach (TrackInfo track in ((ITrackModelSource)source).TrackModel.SelectedItems) { if (!active) { break; } if (String.IsNullOrEmpty(track.Uri.AbsolutePath)) { continue; } ad = new AudioDecoder((int)track.Duration.TotalSeconds); //respect last fm term of service : //You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period // 2 requests are done on each loop ==> time allowed by loop : 400ms /*if (start != System.DateTime.MinValue) { * TimeSpan span = System.DateTime.Now - start; * if (lastFmTOSMinTimeout > span) * Thread.Sleep (lastFmTOSMinTimeout - span); * } * start = DateTime.Now; */ byte[] fingerprint = ad.Decode(track.Uri.AbsolutePath); FingerprintRequest request = new FingerprintRequest(); request.Send(track, fingerprint, account); int fpid = request.GetFpId(); //force GC to dispose ad = null; Log.DebugFormat("Last.fm fingerprint id for {0} is {1}", track.TrackTitle, fpid); if (fpid > 0) { FetchMetadata(track, fpid); } else { Log.WarningFormat("Could not find fingerprint id for the track {0} !", track.TrackTitle); } job.Progress = (double)++count / (double)total; } } catch (Exception e) { account = null; Log.Exception(e); } finally { job.Finish(); } }); }
private void RefreshMetadataThread(object state) { int total = ServiceManager.DbConnection.Query <int> ("SELECT count(*) FROM CoreTracks"); if (total <= 0) { return; } UserJob job = new UserJob(Catalog.GetString("Refreshing Metadata")); job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database); job.PriorityHints = PriorityHints.SpeedSensitive; job.Status = Catalog.GetString("Scanning..."); job.IconNames = new string [] { "system-search", "gtk-find" }; job.Register(); HyenaSqliteCommand select_command = new HyenaSqliteCommand( String.Format( "SELECT {0} FROM {1} WHERE {2}", DatabaseTrackInfo.Provider.Select, DatabaseTrackInfo.Provider.From, DatabaseTrackInfo.Provider.Where ) ); int count = 0; using (System.Data.IDataReader reader = ServiceManager.DbConnection.Query(select_command)) { while (reader.Read()) { DatabaseTrackInfo track = null; try { track = DatabaseTrackInfo.Provider.Load(reader); if (track != null && track.Uri != null && track.Uri.IsFile) { try { TagLib.File file = StreamTagger.ProcessUri(track.Uri); StreamTagger.TrackInfoMerge(track, file, true); } catch (Exception e) { Log.Warning(String.Format("Failed to update metadata for {0}", track), e.GetType().ToString(), false); } track.Save(false); track.Artist.Save(); track.Album.Save(); job.Status = String.Format("{0} - {1}", track.DisplayArtistName, track.DisplayTrackTitle); } } catch (Exception e) { Log.Warning(String.Format("Failed to update metadata for {0}", track), e.ToString(), false); } job.Progress = (double)++count / (double)total; } } if (ServiceManager.DbConnection.Query <int> ("SELECT count(*) FROM CoreConfiguration WHERE Key = 'MetadataVersion'") == 0) { Execute(String.Format("INSERT INTO CoreConfiguration (EntryID, Key, Value) VALUES (null, 'MetadataVersion', {0})", CURRENT_METADATA_VERSION)); } else { Execute(String.Format("UPDATE CoreConfiguration SET Value = {0} WHERE Key = 'MetadataVersion'", CURRENT_METADATA_VERSION)); } job.Finish(); ServiceManager.SourceManager.MusicLibrary.NotifyTracksChanged(); }