/// <summary> /// Return a textual description of the status of the fetch request /// </summary> /// <param name="song"></param> /// <returns></returns> public string GetStatusString(Song song) { LyricsFetchStatus status = this.GetStatus(song); switch (status) { case LyricsFetchStatus.NotFound: return("Not found"); case LyricsFetchStatus.Fetching: FetchRequestData data = this.GetFetchRequestData(song); if (data != null) { ILyricsSource source = data.Source; if (source != null) { return(String.Format("Trying {0}...", source.Name)); } } return("Trying ..."); default: return(status.ToString()); } }
public LyricEventArgs(ILyricsSource s, string lyrics, bool found, iTunesLib.IITFileOrCDTrack t) { this.Source = s; this.Lyrics = lyrics; this.Track = t; this.LyricsFound = found; }
private void FinishSource(ILyricsSource source, string lyrics, int elapsedTime) { this.args.Status = LyricsFetchStatus.SourceDone; this.args.LyricsSource = source; this.args.Lyrics = lyrics; this.args.ElapsedTime = elapsedTime; this.OnStatusEvent(args); }
public SourceData(ILyricsSource source) { Source = source; LyricsTotal = 0; LyricsFound = 0; SuggestionsTotal = 0; SuggestionsFound = 0; }
private void UpdateLyrics(Song s, string lyrics, ILyricsSource source) { lyrics = lyrics.Trim(); if (lyrics == "") { // If we didn't find lyrics, we only write out a Failed marker, if the songs doesn't // have any lyrics or if it only has an old failed marker. // We do NOT want to replace existing lyrics with a failed marker :) if (s.LyricsStatus != LyricsStatus.Success) { string sources = ""; foreach (ILyricsSource x in this.Sources) { sources += (x.Name + " "); } s.Lyrics = String.Format( "[[LyricsFetcher failed to find lyrics\r\nSources: {1}\r\nDate: {2:yyyy-MM-dd HH:mm:ss}]]", lyrics, sources, DateTime.Now); try { s.Commit(); } catch (COMException) { // There are quite a few reasons why these might fail. If the track // is locked, or the underlying file has been deleted/moved. // There is nothing we can do if this fails. } } } else { s.Lyrics = String.Format( "{0}\r\n\r\n[[Found by LyricsFetcher\r\nSource: {1}\r\nDate: {2:yyyy-MM-dd HH:mm:ss}]]", lyrics, source.Name, DateTime.Now); try { s.Commit(); } catch (COMException) { // There are quite a few reasons why these might fail. If the track // is locked, or the underlying file has been deleted/moved. // There is nothing we can do if this fails. } } }
private static void TestOneSource(List <Song> songs, ILyricsSource source) { Console.WriteLine("Testing {0}...", source.Name); int successes = 0; int failures = 0; Stopwatch sw = new Stopwatch(); sw.Start(); foreach (Song song in songs) { if (source.GetLyrics(song) == string.Empty) { failures++; } else { successes++; } } sw.Stop(); Console.WriteLine("Successes: {0}, failure: {1}, time: {2} seconds ({3} per song)", successes, failures, sw.Elapsed, sw.ElapsedMilliseconds / songs.Count); }
/// <summary> /// Register the given source so it is used by all subsequent fetches /// </summary> /// <param name="source">A source for lyrics</param> public void RegisterSource(ILyricsSource source) { this.Sources.Add(source); }
public void Start() { foreach (iTunesLib.IITFileOrCDTrack t2 in this.t.Tracks) { iTunesLib.IITFileOrCDTrack t = t2; if (t == null) { onSkip(); continue; } if (t.Location == null) { onSkip(); continue; } if (t.Podcast) { onSkip(); continue; } if (t.Location == "") { onSkip(); continue; } if (t.Location.ToLower().EndsWith(".m4") || t.Location.ToLower().EndsWith(".m4v")) { onSkip(); continue; } // skip ones that already have lyrics if (!string.IsNullOrEmpty(t.Lyrics)) { onSkip(); continue; } string result = string.Empty; ILyricsSource rSource = null; Thread thrd = new Thread(new ThreadStart(delegate { threads++; onNewThread(); foreach (ILyricsSource source in this.Sources) { if (source == null) { continue; } string s = source.GetLyrics(t); //System.Windows.Forms.MessageBox.Show(source.Name + " :: " + s); if (OnStatusChanged != null) { OnStatusChanged(null, new LyricEventArgs(source, s, !string.IsNullOrEmpty(s), t)); } if (string.IsNullOrEmpty(s) == false) { result = s; rSource = source; break; } } if (string.IsNullOrEmpty(result) == false) { t.Lyrics = result; try { //t.Info.Save(); //MainWindow.Instance.StatusMessage = String.Format("Saved lyrics from {0}!", rSource.Name); } catch (Exception ex) { //MainWindow.Instance.StatusMessage = String.Format("Error saving lyrics: {0}", ex.Message); } } if (OnTrackFinished != null) { OnTrackFinished(null, null); } threads--; onRemoveThread(); })); while (threads >= 500) { ; } thrd.Start(); } }
public void RegisterSource(ILyricsSource s) { Sources.Add(s); }
private static void TestOneSource(List<Song> songs, ILyricsSource source) { Console.WriteLine("Testing {0}...", source.Name); int successes = 0; int failures = 0; Stopwatch sw = new Stopwatch(); sw.Start(); foreach (Song song in songs) { if (source.GetLyrics(song) == string.Empty) failures++; else successes++; } sw.Stop(); Console.WriteLine("Successes: {0}, failure: {1}, time: {2} seconds ({3} per song)", successes, failures, sw.Elapsed, sw.ElapsedMilliseconds / songs.Count); }
public SongLyricsMiddleware(RequestDelegate next, ILyricsSource lyricsSource) { _next = next; _lyricsSource = lyricsSource; }
public SongLyricsController(ILyricsSource lyricsSource) { _lyricsSource = lyricsSource; }
private void StartSource(ILyricsSource source) { this.args.Status = LyricsFetchStatus.Fetching; this.args.LyricsSource = source; this.OnStatusEvent(args); }
private void UpdateLyrics(Song s, string lyrics, ILyricsSource source) { lyrics = lyrics.Trim(); if (lyrics == "") { // If we didn't find lyrics, we only write out a Failed marker, if the songs doesn't // have any lyrics or if it only has an old failed marker. // We do NOT want to replace existing lyrics with a failed marker :) if (s.LyricsStatus != LyricsStatus.Success) { string sources = ""; foreach (ILyricsSource x in this.Sources) sources += (x.Name + " "); s.Lyrics = String.Format( "[[LyricsFetcher failed to find lyrics\r\nSources: {1}\r\nDate: {2:yyyy-MM-dd HH:mm:ss}]]", lyrics, sources, DateTime.Now); try { s.Commit(); } catch (COMException) { // There are quite a few reasons why these might fail. If the track // is locked, or the underlying file has been deleted/moved. // There is nothing we can do if this fails. } } } else { s.Lyrics = String.Format( "{0}\r\n\r\n[[Found by LyricsFetcher\r\nSource: {1}\r\nDate: {2:yyyy-MM-dd HH:mm:ss}]]", lyrics, source.Name, DateTime.Now); try { s.Commit(); } catch (COMException) { // There are quite a few reasons why these might fail. If the track // is locked, or the underlying file has been deleted/moved. // There is nothing we can do if this fails. } } }
public SourceData (ILyricsSource source) { Source = source; LyricsTotal = 0; LyricsFound = 0; SuggestionsTotal = 0; SuggestionsFound = 0; }
public SongLyricsResult(ILyricsSource lyricsSource) { _lyricsSource = lyricsSource; }