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 (var 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 { using (var 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 (); }
public void Start() { ResetState (); foreach (AudioCdTrackInfo track in source.Model) { if (track.RipEnabled) { total_duration += track.Duration; queue.Enqueue (track); } } if (queue.Count == 0) { return; } source.LockAllTracks (); user_job = new UserJob (Catalog.GetString ("Importing Audio CD"), Catalog.GetString ("Initializing Drive"), "media-import-audio-cd"); user_job.CancelMessage = String.Format (Catalog.GetString ( "<i>{0}</i> is still being imported into the music library. Would you like to stop it?" ), GLib.Markup.EscapeText (source.Model.Title)); user_job.SetResources (Resource.Cpu); user_job.PriorityHints = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped; user_job.CanCancel = true; user_job.CancelRequested += OnCancelRequested; user_job.Finished += OnFinished; user_job.Register (); if (source != null && source.Model != null) { if (!source.Model.LockDoor ()) { Hyena.Log.Warning ("Could not lock CD-ROM door", false); } } ripper.Begin (source.Model.Volume.DeviceNode, AudioCdService.ErrorCorrection.Get ()); RipNextTrack (); }
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; 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 (); } }); }
protected void CreateUserJob() { lock (sync) { if (user_job != null) { return; } user_job = new UserJob (Title, Catalog.GetString ("Initializing")); user_job.SetResources (Resource.Cpu, Resource.Disk); user_job.PriorityHints = PriorityHints.SpeedSensitive | PriorityHints.DataLossIfStopped; user_job.IconNames = new string [] { Gtk.Stock.Network }; user_job.CancelMessage = CancelMessage; user_job.CanCancel = true; user_job.CancelRequested += OnCancelRequested; user_job.Register (); } }