public async Task <bool> LrcAutoSearch() { LrcMissing = false; LrcSearchBusy = true; _presenter.Lyrics = null; var _ttitle = _title; var _tartist = _artist; LrcCandidates = new ObservableCollection <ExternalLrcInfo>(); ParsedLrc lrc = null; try { lrc = await LyricsAgent.FetchLyricsAsync( _title, _artist, _candidates, LyricsAgent.BuildLyricsFilename(_title, _artist)); } catch { } if (_ttitle == _title && _tartist == _artist) { _presenter.Lyrics = lrc; LrcSearchBusy = false; LrcMissing = lrc == null || lrc.Sentences.Count == 0; return(true); } return(false); }
static void SetMetadata(string line, ParsedLrc lrc) { string metadata = line.Substring(4, line.Length - 5); switch (line[1]) { case 'a': if (line[2] == 'l') { lrc.Album = metadata; } if (line[2] == 'r') { lrc.Artist = metadata; } break; case 't': if (line[2] == 'i') { lrc.Title = metadata; } break; } }
public static ParsedLrc Parse(TextReader reader) { ParsedLrc lrc = new ParsedLrc(); string line; // TextReader will handle the newline well. while ((line = reader.ReadLine()?.Trim()) != null) { var parts = ExtractMorpheme(line); if (parts == null || parts.Length < 1) { continue; } // Metadata line if (parts[0][2] == ':') { SetMetadata(line, lrc); } var content = parts[parts.Length - 1]; for (int i = 0; i < parts.Length - 1; i++) { var time = ParseTime(parts[i]); if (time != -1) { lrc.Sentences.Add(new LrcSentence(time, content)); } } } // List<T>.Sort still creates wrapper around Comparison<T>. // A straightforward method is using IComparer<T>. lrc.Sentences.Sort(Comparer.Value); return(lrc); }