private void LyricNotFoundMethod(String artist, String title, String message, String site, int row) { foreach (ListViewItem lvi in lvSelectedSongs.Items) { if (lvi.Text.Equals(artist) && lvi.SubItems[1].Text.Equals(title) && !lvi.SubItems[3].Text.Equals("OK")) { lvi.SubItems[2].Text = "MarkedDB"; lvi.SubItems[3].Text = "miss"; lvi.EnsureVisible(); var capArtist = LyricUtil.CapatalizeString(artist); var capTitle = LyricUtil.CapatalizeString(title); if ( DatabaseUtil.IsSongInLyricsMarkedDatabase(MyLyricsUtils.LyricsMarkedDB, capArtist, capTitle).Equals(DatabaseUtil.LyricNotFound)) { MyLyricsUtils.LyricsMarkedDB.Add(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, "", "")); } DatabaseUtil.SerializeLyricMarkedDB(); _mNoOfCurrentlySearches -= 1; ++_mNoOfSearchesCompleted; break; } } //lvSelectedSongs.Update(); }
private void btSave_Click(object sender, EventArgs e) { CurrentDB[DatabaseUtil.CorrectKeyFormat(LyricUtil.CapatalizeString(m_CurrentArtist), LyricUtil.CapatalizeString(m_CurrentTitle))].Lyrics = tbLyrics.Text; DatabaseUtil.SerializeDB(CurrentDB); btSave.Enabled = false; treeView.Focus(); }
private bool isSelectedLyricALRC() { if (treeView.SelectedNode != null && treeView.SelectedNode.Parent != null) { string artist = treeView.SelectedNode.Parent.Text; string title = treeView.SelectedNode.Text; if (artist.Length != 0 && title.Length != 0) { m_CurrentArtist = artist; m_CurrentTitle = LyricUtil.CapatalizeString(title); string lyricsText = (string)CurrentDB[DatabaseUtil.CorrectKeyFormat(artist, title)].Lyrics; SimpleLRC lrc = new SimpleLRC(artist, title, lyricsText); if (lrc.IsValid) { return(true); } else { return(false); } } } return(false); }
private void btSave_Click(object sender, EventArgs e) { var capArtist = LyricUtil.CapatalizeString(_mCurrentArtist); var capTitle = LyricUtil.CapatalizeString(_mCurrentTitle); var lyrics = LyricUtil.FixLyrics(tbLyrics.Text); CurrentLyricsDatabase[DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)].Lyrics = lyrics; DatabaseUtil.SerializeDB(CurrentLyricsDatabase); if (SettingManager.GetParamAsBool(SettingManager.AutomaticWriteToMusicTag, true)) { TagReaderUtil.WriteLyrics(capArtist, capTitle, lyrics); } if (CurrentLyricsDatabase.Equals(MyLyricsUtils.LyricsMarkedDB)) { if (SettingManager.GetParamAsBool(SettingManager.MoveLyricFromMarkedDatabase, true)) { MoveLyricToOtherDatabase(); } } var lrc = new SimpleLRC(capArtist, capTitle, lyrics); if (lrc.IsValid && _parentMyLyricsSetup.cbUploadLrcAutomatically.Checked) { LrcFinder.SaveLrcWithGuid(lyrics, _parentMyLyricsSetup.MGuid); } btSave.Enabled = false; treeView.Focus(); }
private void LyricNotFoundMethod(String artist, String title, String message, String site, int row) { _mLyricsNotFound += 1; --_mSongsToSearch; lbSongsToSearch2.Text = _mSongsToSearch.ToString(CultureInfo.InvariantCulture); lbLyricsNotFound2.Text = _mLyricsNotFound.ToString(CultureInfo.InvariantCulture); var capArtist = LyricUtil.CapatalizeString(artist); var capTitle = LyricUtil.CapatalizeString(title); if (_mMarkSongsWhenNoLyricFound && DatabaseUtil.IsSongInLyricsMarkedDatabase(MyLyricsUtils.LyricsMarkedDB, capArtist, capTitle).Equals( DatabaseUtil.LyricNotFound)) { MyLyricsUtils.LyricsMarkedDB.Add(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, "", "")); } _mSongsWithMark += 1; lbSongsWithMark2.Text = _mSongsWithMark.ToString(CultureInfo.InvariantCulture); var logText = "No match found to " + capArtist + " - " + capTitle; lbLastActivity2.Text = logText; BatchLogger.Info("Miss: {0}", logText); progressBar.PerformStep(); Update(); }
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { lbSongsToSearch2.Text = "0"; if (_tags.Count > 0) { var dlgResult = MessageBox.Show( string.Format( "{0} lyric were found in the search.{1}Do you want to import these into your lyrics database?", _tags.Count, Environment.NewLine), "Import tags", MessageBoxButtons.YesNo); if (dlgResult.Equals(DialogResult.Yes)) { foreach (var tag in _tags) { var capArtist = LyricUtil.CapatalizeString(tag.Artist); var capTitle = LyricUtil.CapatalizeString(tag.Title); DatabaseUtil.ReplaceInLyricsDatabase(MyLyricsUtils.LyricsDB, capArtist, capTitle, tag.Lyrics, "music tag"); } DatabaseUtil.SerializeLyricDB(); } } lbInfo.Text = "The search has ended."; lbCurrentArtist.Text = string.Empty; btStart.Enabled = true; btCancel.Enabled = false; btClose.Enabled = true; }
public void UpdateInfo() { _mCurrentArtist = ""; _mCurrentTitle = ""; tbLyrics.Text = ""; lbTitle.Text = ""; lbLRCTest.Text = ""; tbLyrics.Enabled = false; // Selected a title if (treeView.SelectedNode != null && treeView.SelectedNode.Parent != null) { var artist = treeView.SelectedNode.Parent.Text; var title = treeView.SelectedNode.Text; if (artist.Length != 0 && title.Length != 0) { _mCurrentArtist = LyricUtil.CapatalizeString(artist); _mCurrentTitle = LyricUtil.CapatalizeString(title); if ( DatabaseUtil.IsSongInLyricsDatabase(CurrentLyricsDatabase, _mCurrentArtist, _mCurrentTitle).Equals(DatabaseUtil.LyricFound)) { var item = CurrentLyricsDatabase[DatabaseUtil.CorrectKeyFormat(_mCurrentArtist, _mCurrentTitle)]; var lyricsText = item.Lyrics; lyricsText = LyricUtil.ReturnEnvironmentNewLine(lyricsText); _mOriginalLyric = lyricsText; tbLyrics.Text = _mOriginalLyric; tbLyrics.Enabled = true; lbTitle.Text = "\"" + _mCurrentArtist + " - " + _mCurrentTitle + "\"" + (!item.Source.Equals("") ? " found at " + item.Source : ""); btSearchSingle.Enabled = true; } } } // Selected an artist else if (treeView.SelectedNode != null) { var artist = treeView.SelectedNode.Text; _mCurrentArtist = LyricUtil.CapatalizeString(artist); btSearchSingle.Enabled = false; } else { btSearchSingle.Enabled = false; } }
internal void AddNewSongToDatabase(string artist, string title, string lyrics) { _mCurrentArtist = LyricUtil.CapatalizeString(artist); _mCurrentTitle = LyricUtil.CapatalizeString(title); if (AddSong(_mCurrentArtist, _mCurrentTitle, lyrics, "Manual added")) { HighlightSong(_mCurrentArtist, _mCurrentTitle, false); UpdateLyricDatabaseStats(); } else { MessageBox.Show("The title \"" + artist + " - " + title + "\" is already in the database"); } }
internal static int IsSongInLyricsDatabaseAsLRC(LyricsDatabase lyricDB, string artist, string title) { var capatalizedArtist = LyricUtil.CapatalizeString(artist); var capatalizedTitle = LyricUtil.CapatalizeString(title); var key = CorrectKeyFormat(capatalizedArtist, capatalizedTitle); if (lyricDB.ContainsKey(key)) { var lyricText = lyricDB[key].Lyrics; return(new SimpleLRC(capatalizedArtist, capatalizedTitle, lyricText).IsValid ? LRCFound : LyricFound); } return(LRCNotFound); }
internal static int IsSongInLyricsDatabase(LyricsDatabase lyricDB, string artist, string title) { var capatalizedArtist = LyricUtil.CapatalizeString(artist); var capatalizedTitle = LyricUtil.CapatalizeString(title); var key = CorrectKeyFormat(capatalizedArtist, capatalizedTitle); if (lyricDB.ContainsKey(key)) { var lyricText = lyricDB[key].Lyrics; return(lyricText.Equals(Mark) ? LyricMarked : LyricFound); } return(LyricNotFound); }
private void bw_DoWork(object sender, DoWorkEventArgs e) { var mDB = MusicDatabase.Instance; var counter = 0; for (var i = 0; i < _artists.Count; i++) { if (bw.CancellationPending) { return; } var artist = (string)_artists[i]; bw.ReportProgress(counter, artist); mDB.GetSongsByArtist(artist, ref _songs); foreach (var song in _songs) { var tag = TagReader.ReadTag(song.FileName); if (tag != null && tag.Lyrics != string.Empty) { var capArtist = LyricUtil.CapatalizeString(tag.Artist); var capTitle = LyricUtil.CapatalizeString(tag.Title); if ( DatabaseUtil.IsSongInLyricsDatabase(MyLyricsUtils.LyricsDB, capArtist, capTitle).Equals( DatabaseUtil.LyricFound)) { // If lyric exists in LyricsDb then only import (and overwrite) if it isn't an LRC-file var lyricsText = MyLyricsUtils.LyricsDB[DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)].Lyrics; var lrc = new SimpleLRC(capArtist, capTitle, lyricsText); if (!lrc.IsValid) { _tags.Add(tag); ++counter; } } else { _tags.Add(tag); ++counter; } } } } }
public LyricWiki(string artist, string title, ManualResetEvent m_EventStop_SiteSearches, int timeLimit) { this.timeLimit = timeLimit / 2; timer = new Timer(); artist = LyricUtil.RemoveFeatComment(artist); artist = LyricUtil.CapatalizeString(artist); artist = artist.Replace(" ", "_"); title = LyricUtil.TrimForParenthesis(title); title = LyricUtil.CapatalizeString(title); title = title.Replace(" ", "_"); title = title.Replace("?", "%3F"); if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title)) { return; } string urlString = "http://lyricwiki.org/" + artist + ":" + title; LyricsWebClient client = new LyricsWebClient(); timer.Enabled = true; timer.Interval = timeLimit; timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); timer.Start(); Uri uri = new Uri(urlString); client.OpenReadCompleted += new OpenReadCompletedEventHandler(callbackMethod); client.OpenReadAsync(uri); while (complete == false) { if (m_EventStop_SiteSearches.WaitOne(1, true)) { complete = true; } else { Thread.Sleep(300); } } }
public void updateInfo() { m_CurrentArtist = ""; m_CurrentTitle = ""; tbLyrics.Text = ""; lbTitle.Text = ""; lbSource.Text = ""; lbLRCTest.Text = ""; tbLyrics.Enabled = false; // Selected a title if (treeView.SelectedNode != null && treeView.SelectedNode.Parent != null) { string artist = treeView.SelectedNode.Parent.Text; string title = treeView.SelectedNode.Text; if (artist.Length != 0 && title.Length != 0) { m_CurrentArtist = LyricUtil.CapatalizeString(artist); m_CurrentTitle = LyricUtil.CapatalizeString(title); if (DatabaseUtil.IsTrackInLyricsDatabase(CurrentDB, m_CurrentArtist, m_CurrentTitle).Equals(DatabaseUtil.LYRIC_FOUND)) { LyricsItem item = CurrentDB[DatabaseUtil.CorrectKeyFormat(m_CurrentArtist, m_CurrentTitle)]; string lyricsText = item.Lyrics; lyricsText = LyricsEngine.LyricUtil.ReturnEnvironmentNewLine(lyricsText); m_OriginalLyric = lyricsText; tbLyrics.Text = m_OriginalLyric; tbLyrics.Enabled = true; lbTitle.Text = "\"" + m_CurrentArtist + " - " + m_CurrentTitle + "\""; lbSource.Text = "(" + item.Source + ")"; } } } // Selected an artist else if (treeView.SelectedNode != null) { string artist = treeView.SelectedNode.Text; m_CurrentArtist = LyricUtil.CapatalizeString(artist); } }
// Returns latests settings from the MediaPortal.xml file. Reload on access to ensure any changes made while the program runs are honored. public static string[] GetStrippedPrefixStringArray() { string strippedPrefixes; using (var xmlreader = SettingManager.MediaPortalSettings) { strippedPrefixes = (xmlreader.GetValueAsString("musicfiles", "artistprefixes", "the,les,die")); } var strippedPrefixesArray = strippedPrefixes.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < strippedPrefixesArray.Length; i++) { var temp = strippedPrefixesArray[i]; strippedPrefixesArray[i] = LyricUtil.CapatalizeString(", " + temp.Trim()); } return(strippedPrefixesArray); }
protected override void FindLyricsWithTimer() { // Clean artist name var artist = LyricUtil.RemoveFeatComment(Artist); artist = LyricUtil.CapatalizeString(artist); artist = artist.Replace(" ", "_"); // Clean title name var title = LyricUtil.TrimForParenthesis(Title); title = LyricUtil.CapatalizeString(title); title = title.Replace(" ", "_"); title = title.Replace("?", "%3F"); // Validate not empty if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title)) { return; } var urlString = SiteBaseUrl + "/" + artist + ":" + title; var client = new LyricsWebClient(); var uri = new Uri(urlString); client.OpenReadCompleted += CallbackMethod; client.OpenReadAsync(uri); while (Complete == false) { if (MEventStopSiteSearches.WaitOne(1, true)) { Complete = true; } else { Thread.Sleep(300); } } }
private int InspectFileNameAndAddToDatabaseIfValidLyrics(string filePath) { var fileInfo = new FileInfo(filePath); if (fileInfo.Extension.Equals(".txt")) { var fileName = fileInfo.Name; var index = fileName.IndexOf("-", StringComparison.Ordinal); var fileStringArtist = fileName.Substring(0, index); var fileStringTitle = fileName.Substring(index + 1); fileStringArtist = fileStringArtist.Trim(); fileStringTitle = fileStringTitle.Trim(); index = fileStringTitle.LastIndexOf('.'); fileStringTitle = fileStringTitle.Substring(0, index); var textReader = new StreamReader(filePath); string line; var lyrics = ""; while ((line = textReader.ReadLine()) != null) { lyrics += line + Environment.NewLine; } lyrics = lyrics.Trim(); textReader.Close(); var capArtist = LyricUtil.CapatalizeString(fileStringArtist); var capTitle = LyricUtil.CapatalizeString(fileStringTitle); return(AddSong(capArtist, capTitle, lyrics, "Text file") ? (int)TypeOfLyrics.Normal : (int)TypeOfLyrics.None); } _lrc = new SimpleLRC(filePath); if (_lrc.IsValid && _lrc.Artist.Length != 0 && _lrc.Title.Length != 0) { return(AddSong(_lrc.Artist, _lrc.Title, _lrc.LyricAsLRC.Trim(), "LRC-file") ? (int)TypeOfLyrics.LRC : (int)TypeOfLyrics.None); } return((int)TypeOfLyrics.None); }
private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { UpdateInfo(); if (treeView.SelectedNode != null && treeView.SelectedNode.Parent != null) { var title = treeView.SelectedNode.Text; _mCurrentArtist = treeView.SelectedNode.Parent.Text; _mCurrentTitle = LyricUtil.CapatalizeString(title); if (IsSelectedLyricLRC(_mCurrentArtist, title)) { lbLRCTest.Text = "(valid LRC)"; } else { lbLRCTest.Text = ""; } } }
/// <summary> /// AddSong adds a lyric to the treeView and not to the lyric database /// </summary> /// <param name="lyricsItem">lyrics item</param> private void AddSong(LyricsItem lyricsItem) { var artist = LyricUtil.CapatalizeString(lyricsItem.Artist); var title = LyricUtil.CapatalizeString(lyricsItem.Title); // add artist, if it doesn't exists if (!treeView.Nodes.ContainsKey(artist)) { treeView.Nodes.Add(artist, artist); ++_mNoOfArtists; } // add title, if it doesn't exists var artistIndex = treeView.Nodes.IndexOfKey(artist); if (artistIndex >= 0 && !treeView.Nodes[artistIndex].Nodes.ContainsKey(title)) { treeView.Nodes[artistIndex].Nodes.Add(title, title); treeView.Nodes[artistIndex].Nodes[treeView.Nodes[artistIndex].Nodes.Count - 1].Tag = lyricsItem; ++_mNoOfTitles; } }
private void LyricFoundMethod(String lyricStrings, String artist, String title, String site, int row) { foreach (ListViewItem lvi in lvSelectedSongs.Items) { if (lvi.Text.Equals(artist) && lvi.SubItems[1].Text.Equals(title)) { if (lvi.SubItems[3].Text.Equals("miss")) { MessageBox.Show("This is an error and should not be able to happen!"); } lvi.ImageIndex = 0; lvi.SubItems[2].Text = "LyricsDB"; lvi.SubItems[3].Text = "OK"; lvi.EnsureVisible(); var capArtist = LyricUtil.CapatalizeString(artist); var capTitle = LyricUtil.CapatalizeString(title); DatabaseUtil.WriteToLyricsDatabase(MyLyricsUtils.LyricsDB, MyLyricsUtils.LyricsMarkedDB, capArtist, capTitle, lyricStrings, site); DatabaseUtil.SerializeLyricDB(); if (!site.Equals("music tag")) { if (SettingManager.GetParamAsBool(SettingManager.AutomaticWriteToMusicTag, true)) { TagReaderUtil.WriteLyrics(capArtist, capTitle, lyricStrings); } } _mNoOfCurrentlySearches -= 1; ++_mNoOfSearchesCompleted; break; } } //lvSelectedSongs.Update(); }
private void lyricNotFoundMethod(String artist, String title, String message, String site) { m_LyricsNotFound += 1; --m_SongsToSearch; lbSongsToSearch2.Text = m_SongsToSearch.ToString(); lbLyricsNotFound2.Text = m_LyricsNotFound.ToString(); string capArtist = LyricUtil.CapatalizeString(artist); string capTitle = LyricUtil.CapatalizeString(title); if (m_MarkSongsWhenNoLyricFound && DatabaseUtil.IsTrackInLyricsMarkedDatabase(MyLyricsSettings.LyricsMarkedDB, capArtist, capTitle).Equals(DatabaseUtil.LYRIC_NOT_FOUND)) { MyLyricsSettings.LyricsMarkedDB.Add(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, "", "")); } m_SongsWithMark += 1; lbSongsWithMark2.Text = m_SongsWithMark.ToString(); StreamReader sr = File.OpenText(logFullFileName); log = sr.ReadToEnd(); sr.Close(); string logText = "No match found to " + capArtist + " - " + capTitle + ".\r\n"; log += DateTime.Now.ToString() + " " + logText; lbLastActivity2.Text = logText; System.IO.StreamWriter writerLog = new System.IO.StreamWriter(logFullFileName); writerLog.Write(log); writerLog.Close(); m_noOfCurrentlySearches -= 1; progressBar.PerformStep(); this.Update(); }
private void lyricFoundMethod(String lyricStrings, String artist, String track, String site) { m_LyricText = lyricStrings; m_artist = artist; m_track = track; --m_SongsToSearch; lbSongsToSearch2.Text = m_SongsToSearch.ToString(); m_SongsWithLyric += 1; m_LyricsFound += 1; lbSongsWithLyric2.Text = m_SongsWithLyric.ToString(); lbLyricsFound2.Text = m_LyricsFound.ToString(); string capArtist = LyricUtil.CapatalizeString(m_artist); string capTitle = LyricUtil.CapatalizeString(m_track); DatabaseUtil.WriteToLyricsDatabase(MyLyricsSettings.LyricsDB, MyLyricsSettings.LyricsMarkedDB, capArtist, capTitle, lyricStrings, site); StreamReader sr = File.OpenText(logFullFileName); log = sr.ReadToEnd(); sr.Close(); string logText = capArtist + " - " + capTitle + " has a match at " + site + ".\r\n"; log += DateTime.Now.ToString() + " " + logText; lbLastActivity2.Text = logText; System.IO.StreamWriter writerLog = new System.IO.StreamWriter(logFullFileName); writerLog.Write(log); writerLog.Close(); m_noOfCurrentlySearches -= 1; progressBar.PerformStep(); this.Update(); }
private void LyricFoundMethod(String lyricStrings, String artist, String track, String site, int row) { _mArtist = artist; _mTrack = track; --_mSongsToSearch; lbSongsToSearch2.Text = _mSongsToSearch.ToString(CultureInfo.InvariantCulture); _mSongsWithLyric += 1; _mLyricsFound += 1; IncrementLyricsFoundBySite(site); lbSongsWithLyric2.Text = _mSongsWithLyric.ToString(CultureInfo.InvariantCulture); lbLyricsFound2.Text = _mLyricsFound.ToString(CultureInfo.InvariantCulture); var capArtist = LyricUtil.CapatalizeString(_mArtist); var capTitle = LyricUtil.CapatalizeString(_mTrack); DatabaseUtil.WriteToLyricsDatabase(MyLyricsUtils.LyricsDB, MyLyricsUtils.LyricsMarkedDB, capArtist, capTitle, lyricStrings, site); lbMessage.Text = GetLyricsFoundBySite(); if (!site.Equals("music tag") && _mAutomaticWriteToMusicTag) { TagReaderUtil.WriteLyrics(capArtist, capTitle, lyricStrings); } var logText = capArtist + " - " + capTitle + " has a match at " + site; lbLastActivity2.Text = logText; BatchLogger.Info("HIT!: {0}", logText); progressBar.PerformStep(); Update(); }
private void bgWorkerSearch_DoWork(object sender, DoWorkEventArgs e) { // Thread.CurrentThread.Name = "bgWorker - Search"; #region 1. Sorting song lyricConfigInfosQueue = new Queue(); if (m_SearchOnlyMarkedSongs == false) { //System.IO.Directory.SetCurrentDirectory(@"C:\Program Files\Team MediaPortal\MediaPortal"); //string test = System.IO.Directory.GetCurrentDirectory(); MusicDatabase dbs = new MusicDatabase(); dbs.GetArtists(ref artists); m_noOfArtistsToSearch = artists.Count; for (int albumIndex = 0; albumIndex < artists.Count; albumIndex++) { // If the user has cancelled the search => end this if (stopCollectingOfTitles) { bgWorkerSearch.CancelAsync(); return; } string currentArtist = (string)artists[albumIndex]; dbs.GetSongsByArtist(currentArtist, ref songs); for (int i = 0; i < songs.Count; i++) { // if song isn't known in lyric database the progressbar should not be incremented int songNotKnown = -1; Song song = (Song)songs[i]; /* Don't include song if one of the following is true * 1. The artist isn't known (MP issue - should be deleted?) * 2. Various artister should not be considered and the artist is "various artist" * 3. Song with a lyric in the tag should not be considered, but instead include the file to the database right away */ MusicTag tag = null; if (song.Artist.Equals("unknown") || (m_DisregardVariousArtist && (song.Artist.ToLower().Equals("various artists") || song.Artist.ToLower().Equals("diverse kunstnere")))) { m_DisregardedSongs += 1; } else if ((m_DisregardSongWithLyricInTag == false && ((tag = MediaPortal.TagReader.TagReader.ReadTag(song.FileName)) != null) && tag.Lyrics.Length > 0)) { m_SongsWithLyric += 1; string capArtist = LyricUtil.CapatalizeString(tag.Artist); string capTitle = LyricUtil.CapatalizeString(tag.Title); if (DatabaseUtil.IsTrackInLyricsDatabase(MyLyricsSettings.LyricsDB, capArtist, capTitle).Equals(DatabaseUtil.LYRIC_NOT_FOUND)) { MyLyricsSettings.LyricsDB.Add(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, tag.Lyrics, "Tag")); } if (DatabaseUtil.IsTrackInLyricsMarkedDatabase(MyLyricsSettings.LyricsMarkedDB, capArtist, capTitle).Equals(DatabaseUtil.LYRIC_MARKED)) { MyLyricsSettings.LyricsMarkedDB.Remove(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)); } } else { int status = DatabaseUtil.IsTrackInLyricsDatabase(MyLyricsSettings.LyricsDB, song.Artist, song.Title); bool isTrackInLyricsMarkedDatabase = true; if (!m_DisregardKnownLyric && status.Equals(DatabaseUtil.LYRIC_FOUND) || (!m_DisregardMarkedLyric && ((isTrackInLyricsMarkedDatabase = DatabaseUtil.IsTrackInLyricsMarkedDatabase(MyLyricsSettings.LyricsMarkedDB, song.Artist, song.Title).Equals(DatabaseUtil.LYRIC_MARKED)) || status.Equals(DatabaseUtil.LYRIC_MARKED))) || (status.Equals(DatabaseUtil.LYRIC_NOT_FOUND) && !DatabaseUtil.IsTrackInLyricsMarkedDatabase(MyLyricsSettings.LyricsMarkedDB, song.Artist, song.Title).Equals(DatabaseUtil.LYRIC_MARKED))) { songNotKnown = 1; if (++m_SongsNotKnown > m_Limit) { songNotKnown = 0; bgWorkerSearch.ReportProgress(songNotKnown); goto startSearch; } string[] lyricId = new string[2] { song.Artist, song.Title }; lyricConfigInfosQueue.Enqueue(lyricId); m_SongsToSearch = lyricConfigInfosQueue.Count; bgWorkerSearch.ReportProgress(songNotKnown); } else if (status.Equals(DatabaseUtil.LYRIC_FOUND)) { m_SongsWithLyric += 1; } else //if (status.Equals(MyLyricsUtil.LYRIC_MARKED)) { m_SongsWithMark += 1; } } bgWorkerSearch.ReportProgress(songNotKnown); } } } else { foreach (KeyValuePair <string, LyricsItem> kvp in MyLyricsSettings.LyricsMarkedDB) { int songNotKnown = 1; if (++m_SongsNotKnown > m_Limit) { songNotKnown = 0; bgWorkerSearch.ReportProgress(-1); goto startSearch; } string[] lyricId = new string[2] { kvp.Value.Artist, kvp.Value.Title }; lyricConfigInfosQueue.Enqueue(lyricId); m_SongsToSearch = lyricConfigInfosQueue.Count; bgWorkerSearch.ReportProgress(songNotKnown); } } startSearch: # endregion #region 2. Searching for lyrics // create worker thread instance if (lyricConfigInfosQueue.Count > 0) { // start running the lyricController lc = new LyricsController(this, m_EventStopThread, sitesToSearchArray, false); lc.NoOfLyricsToSearch = lyricConfigInfosQueue.Count; ThreadStart runLyricController = delegate { lc.Run(); }; m_LyricControllerThread = new Thread(runLyricController); m_LyricControllerThread.Start(); lc.StopSearches = false; while (lyricConfigInfosQueue.Count != 0) { // If the user has cancelled the search => end this if (stopCollectingOfTitles && lc != null) { bgWorkerSearch.CancelAsync(); return; } else if (lc == null) { return; } if (m_noOfCurrentlySearches < m_NoOfCurrentSearchesAllowed && lc.StopSearches == false) { m_noOfCurrentlySearches += 1; string[] lyricID = (string[])lyricConfigInfosQueue.Dequeue(); lc.AddNewLyricSearch(lyricID[0], lyricID[1]); } Thread.Sleep(100); } } else { ThreadFinished = new string[] { "", "", "There is no titles to search", "" }; } #endregion }
internal static int IsSongInLyricsMarkedDatabase(LyricsDatabase lyricMarkedDB, string artist, string title) { var key = CorrectKeyFormat(LyricUtil.CapatalizeString(artist), LyricUtil.CapatalizeString(title)); return(lyricMarkedDB.ContainsKey(key) ? LyricMarked : LyricNotFound); }
private bool getLRCinfoFromFile(ref string line, bool originalLine) { Match m; if ((m = SimpleLRCFormat.LineLineRegex.Match(line)).Success) { line = line.Trim(); int index; if ((index = m.Value.IndexOf("[")) > 0) { line = line.Substring(index); } string lineWithTimeAndNewLine = line + Environment.NewLine; // if a line with multiple timetags, only add the first which is the complete with all tags. if (originalLine) { lyricAsLRC += lineWithTimeAndNewLine; } // we update the line for potential further time-tags. This will natural not be regarded as an original line // and will therefore not be added to the lyric. It will however be added to the LRC-object just as every other line line = line.Replace(m.Value, ""); string lineWithNewLine = line + Environment.NewLine; lyricLines.Add(lineWithNewLine); int NEXT = 1; int minStart, minLength, secStart, secLength, msecStart, msecLength = 0; int min, sec, msec = 0; sec = 0; minStart = NEXT; minLength = m.Value.IndexOf(":") - minStart; min = int.Parse(m.Value.Substring(minStart, minLength)); secStart = minStart + minLength + NEXT; if (m.Value.IndexOf(".") != -1 && m.Value.IndexOf(".") < m.Value.IndexOf("]")) { secLength = m.Value.IndexOf(".") - secStart; sec = int.Parse(m.Value.Substring(secStart, secLength)); msecStart = secStart + secLength + NEXT; msecLength = m.Value.IndexOf("]") - msecStart; msec = int.Parse(m.Value.Substring(msecStart, msecLength)); } else { secLength = m.Value.IndexOf("]") - secStart; sec = int.Parse(m.Value.Substring(secStart, secLength)); } string lineTemp = lineWithNewLine; bool done = true; while ((m = SimpleLRCFormat.LineLineRegex.Match(lineTemp)).Success) { lineTemp = lineTemp.Replace(m.Value, ""); done = false; } simpleLRCTimeAndLineArray.Add(new SimpleLRCTimeAndLine(min, sec, msec, lineTemp)); return(done); } else if ((m = SimpleLRCFormat.ArtistLineStartRegex.Match(line)).Success) { artist = line.Substring(m.Index + m.Length); artist = LyricUtil.CapatalizeString(artist.Substring(0, artist.LastIndexOf("]"))); return(true); } else if ((m = SimpleLRCFormat.TitleLineStartRegex.Match(line)).Success) { title = line.Substring(m.Index + m.Length); title = LyricUtil.CapatalizeString(title.Substring(0, title.LastIndexOf("]"))); return(true); } else if ((m = SimpleLRCFormat.AlbumLineStartRegex.Match(line)).Success) { album = line.Substring(m.Index + m.Length); album = LyricUtil.CapatalizeString((album.Substring(0, album.LastIndexOf("]")))); return(true); } else if ((m = SimpleLRCFormat.OffsetLineStartRegex.Match(line)).Success) { offset = line.Substring(m.Index + m.Length); offset = LyricUtil.CapatalizeString((offset.Substring(0, offset.LastIndexOf("]")))); return(true); } else { return(true); } }
private void bw_DoWork(object sender, DoWorkEventArgs e) { var mDB = MusicDatabase.Instance; var counter = 0; for (var i = 0; i < _artists.Count; i++) { if (bw.CancellationPending) { return; } var artist = (string)_artists[i]; Thread.Sleep(100); // Give the GUI thread some time to update bw.ReportProgress(counter, artist); try { mDB.GetSongsByArtist(artist, ref _songs); foreach (var song in _songs) { var capArtist = LyricUtil.CapatalizeString(song.Artist); var capTitle = LyricUtil.CapatalizeString(song.Title); if (DatabaseUtil.IsSongInLyricsDatabase(MyLyricsUtils.LyricsDB, capArtist, capTitle).Equals(DatabaseUtil.LyricFound)) { var lyric = MyLyricsUtils.LyricsDB[DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)].Lyrics; var lrcInLyricsDb = new SimpleLRC(capArtist, capTitle, lyric); // If the lyricsDB lyric is LRC always export if (lrcInLyricsDb.IsValid) { if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) { ++counter; } continue; } var tag = TagReader.ReadTag(song.FileName); // If there is a musictag lyric if (tag != null && !tag.Lyrics.Equals(string.Empty)) { // if there is no LRC lyric in the tag, then simple export var lrcInTag = new SimpleLRC(capArtist, capTitle, tag.Lyrics); if (!lrcInTag.IsValid) { if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) { ++counter; } } } // Al if no lyric in musictag simple export else { if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) { ++counter; } } } } } catch (Exception) { ; } } }
private int inspectFileNameAndAddToDatabaseIfValidLyrics(string filePath) { TextReader textReader = null; FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.Extension.Equals(".txt")) { string fileStringArtist = ""; string fileStringTitle = ""; string fileName = fileInfo.Name; int index = fileName.IndexOf("-"); fileStringArtist = fileName.Substring(0, index); fileStringTitle = fileName.Substring(index + 1); fileStringArtist = fileStringArtist.Trim(); fileStringTitle = fileStringTitle.Trim(); index = fileStringTitle.LastIndexOf('.'); fileStringTitle = fileStringTitle.Substring(0, index); textReader = new StreamReader(filePath); string line = ""; string lyrics = ""; while ((line = textReader.ReadLine()) != null) { lyrics += line + Environment.NewLine; } lyrics = lyrics.Trim(); textReader.Close(); string capArtist = LyricUtil.CapatalizeString(fileStringArtist); string capTitle = LyricUtil.CapatalizeString(fileStringTitle); if (AddSong(capArtist, capTitle, lyrics, "Text file")) { return((int)TYPEOFLYRICS.NORMAL); } else { return((int)TYPEOFLYRICS.NONE); } } else { lrc = new SimpleLRC(filePath); if (lrc.IsValid && lrc.Artist.Length != 0 && lrc.Title.Length != 0) { if (AddSong(lrc.Artist, lrc.Title, lrc.Lyric.Trim(), "LRC-file")) { return((int)TYPEOFLYRICS.LRC); } else { return((int)TYPEOFLYRICS.NONE); } } else { return((int)TYPEOFLYRICS.NONE); } } }
private void listViewArtists_SelectedIndexChanged(object sender, EventArgs e) { var mdb = MusicDatabase.Instance; var songs = new List <Song>(); _mSelectedArtist = ((ListView)(sender)).SelectedItems.Count > 0 ? ((ListView)(sender)).SelectedItems[0].Text : ""; mdb.GetSongsByArtist(_mSelectedArtist, ref songs); lbSelectedArtist.Text = String.Format("Artist: {0}", _mSelectedArtist); lvSongs.Items.Clear(); foreach (var song in songs) { var capatalizedArtist = LyricUtil.CapatalizeString(song.Artist); var capatalizedTitle = LyricUtil.CapatalizeString(song.Title); var lvi = new ListViewItem(capatalizedTitle); lvi.Tag = capatalizedTitle; var status = DatabaseUtil.IsSongInLyricsDatabase(MyLyricsUtils.LyricsDB, capatalizedArtist, capatalizedTitle); switch (status) { case DatabaseUtil.LyricFound: lvi.ImageIndex = 0; lvi.SubItems.Add("LyricsDB"); lvi.SubItems.Add("-"); break; case DatabaseUtil.LyricMarked: lvi.SubItems.Add("MarkedDB"); lvi.SubItems.Add("-"); break; case DatabaseUtil.LyricNotFound: if ( DatabaseUtil.IsSongInLyricsMarkedDatabase(MyLyricsUtils.LyricsMarkedDB, capatalizedArtist, capatalizedTitle).Equals(DatabaseUtil.LyricMarked)) { lvi.SubItems.Add("MarkedDB"); lvi.SubItems.Add("-"); } else { lvi.SubItems.Add("-"); lvi.SubItems.Add("-"); } break; default: lvi.SubItems.Add("no"); lvi.SubItems.Add("-"); break; } var alreadyInCollection = false; foreach (ListViewItem lviColl in lvSongs.Items) { if (lvi.Tag.Equals(lviColl.Tag)) { alreadyInCollection = true; break; } } if (!alreadyInCollection) { lvSongs.Items.Add(lvi); } } RefreshArtistStats(); }
private bool GetLRCinfoFromFile(ref string line, bool originalLine) { Match m; if ((m = SimpleLRCFormat.LineLineRegex.Match(line)).Success) { line = line.Trim(); int index; if ((index = m.Value.IndexOf("[", StringComparison.Ordinal)) > 0) { line = line.Substring(index); } var lineWithTimeAndNewLine = line + Environment.NewLine; // if a line with multiple timetags, only add the first which is the complete with all tags. if (originalLine) { _lyricAsLRC += lineWithTimeAndNewLine; } // we update the line for potential further time-tags. This will natural not be regarded as an original line // and will therefore not be added to the lyric. It will however be added to the LRC-object just as every other line line = line.Replace(m.Value, ""); var lineWithNewLine = line + Environment.NewLine; _lyricLines.Add(lineWithNewLine); const int next = 1; int secLength; int sec; var msec = 0; const int minStart = next; var minLength = m.Value.IndexOf(":", StringComparison.Ordinal) - minStart; var min = int.Parse(m.Value.Substring(minStart, minLength)); var secStart = minStart + minLength + next; if (m.Value.IndexOf(".", StringComparison.Ordinal) != -1 && m.Value.IndexOf(".", StringComparison.Ordinal) < m.Value.IndexOf("]", StringComparison.Ordinal)) { secLength = m.Value.IndexOf(".", StringComparison.Ordinal) - secStart; sec = int.Parse(m.Value.Substring(secStart, secLength)); var msecStart = secStart + secLength + next; var msecLength = m.Value.IndexOf("]", StringComparison.Ordinal) - msecStart; msec = int.Parse(m.Value.Substring(msecStart, msecLength)); } else { secLength = m.Value.IndexOf("]", StringComparison.Ordinal) - secStart; sec = int.Parse(m.Value.Substring(secStart, secLength)); } var lineTemp = lineWithNewLine; var done = true; while ((m = SimpleLRCFormat.LineLineRegex.Match(lineTemp)).Success) { lineTemp = lineTemp.Replace(m.Value, ""); done = false; } _simpleLRCTimeAndLineArray.Add(new SimpleLRCTimeAndLine(min, sec, msec, lineTemp)); return(done); } if ((m = SimpleLRCFormat.ArtistLineStartRegex.Match(line)).Success) { _artist = line.Substring(m.Index + m.Length); _artist = LyricUtil.CapatalizeString(_artist.Substring(0, _artist.LastIndexOf("]", StringComparison.Ordinal))); return(true); } if ((m = SimpleLRCFormat.TitleLineStartRegex.Match(line)).Success) { _title = line.Substring(m.Index + m.Length); _title = LyricUtil.CapatalizeString(_title.Substring(0, _title.LastIndexOf("]", StringComparison.Ordinal))); return(true); } if ((m = SimpleLRCFormat.AlbumLineStartRegex.Match(line)).Success) { _album = line.Substring(m.Index + m.Length); _album = LyricUtil.CapatalizeString((_album.Substring(0, _album.LastIndexOf("]", StringComparison.Ordinal)))); return(true); } if ((m = SimpleLRCFormat.OffsetLineStartRegex.Match(line)).Success) { _offset = line.Substring(m.Index + m.Length); _offset = LyricUtil.CapatalizeString( (_offset.Substring(0, _offset.LastIndexOf("]", StringComparison.Ordinal)))); return(true); } return(true); }
private void bgWorkerSearch_DoWork(object sender, DoWorkEventArgs e) { #region 1. Sorting song _lyricConfigInfosQueue = new Queue(); _mMusicDatabase = MusicDatabase.Instance; if (_mSearchOnlyMarkedSongs == false) { //System.IO.Directory.SetCurrentDirectory(@"C:\Program Files\Team MediaPortal\MediaPortal"); //string test = System.IO.Directory.GetCurrentDirectory(); _mMusicDatabase.GetAllArtists(ref _artists); var canStartSearch = false; foreach (var artist in _artists) { // If the user has cancelled the search => end this if (_stopCollectingOfTitles) { bgWorkerSearch.CancelAsync(); return; } // Reached the limit if (canStartSearch) { break; } var currentArtist = (string)artist; _mMusicDatabase.GetSongsByArtist(currentArtist, ref _songs); foreach (var song in _songs) { if (canStartSearch) { break; } /* Don't include song if one of the following is true * 1. The artist is unknown or empty * 2. The title is empty * 3. Various artister should not be considered and the artist is "various artist" * 4. Song with a lyric in the tag should not be considered, but instead include the file to the database right away */ MusicTag tag; if (song.Artist.Equals("unknown") || string.IsNullOrEmpty(song.Artist) || string.IsNullOrEmpty(song.Title) || (_mDisregardVariousArtist && (song.Artist.ToLower().Equals("various artists")))) { } else if ((_mDisregardSongWithLyricInTag && ((tag = TagReader.ReadTag(song.FileName)) != null) && tag.Lyrics.Length > 0)) { _mSongsWithLyric += 1; var capArtist = LyricUtil.CapatalizeString(tag.Artist); var capTitle = LyricUtil.CapatalizeString(tag.Title); if ( DatabaseUtil.IsSongInLyricsDatabase(MyLyricsUtils.LyricsDB, capArtist, capTitle). Equals(DatabaseUtil.LyricNotFound)) { MyLyricsUtils.LyricsDB.Add(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, tag.Lyrics, "music tag")); } if ( DatabaseUtil.IsSongInLyricsMarkedDatabase(MyLyricsUtils.LyricsMarkedDB, capArtist, capTitle) .Equals(DatabaseUtil.LyricMarked)) { MyLyricsUtils.LyricsMarkedDB.Remove(DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)); } } else { var status = DatabaseUtil.IsSongInLyricsDatabase(MyLyricsUtils.LyricsDB, song.Artist, song.Title); if (!_mDisregardKnownLyric && status.Equals(DatabaseUtil.LyricFound) || (!_mDisregardMarkedLyric && ((DatabaseUtil.IsSongInLyricsMarkedDatabase(MyLyricsUtils.LyricsMarkedDB, song.Artist, song.Title).Equals( DatabaseUtil.LyricMarked)) || status.Equals(DatabaseUtil.LyricMarked))) || (status.Equals(DatabaseUtil.LyricNotFound) && !DatabaseUtil.IsSongInLyricsMarkedDatabase(MyLyricsUtils.LyricsMarkedDB, song.Artist, song.Title).Equals( DatabaseUtil.LyricMarked))) { if (++_mSongsNotKnown > _mLimit) { bgWorkerSearch.ReportProgress(0); canStartSearch = true; continue; } var lyricId = new[] { song.Artist, song.Title }; _lyricConfigInfosQueue.Enqueue(lyricId); _mSongsToSearch = _lyricConfigInfosQueue.Count; } else if (status.Equals(DatabaseUtil.LyricFound)) { _mSongsWithLyric += 1; } else //if (status.Equals(MyLyricsUtil.LYRIC_MARKED)) { _mSongsWithMark += 1; } } bgWorkerSearch.ReportProgress(-1); } } } else { foreach (var kvp in MyLyricsUtils.LyricsMarkedDB) { if (++_mSongsNotKnown > _mLimit) { break; } var lyricId = new[] { kvp.Value.Artist, kvp.Value.Title }; _lyricConfigInfosQueue.Enqueue(lyricId); _mSongsToSearch = _lyricConfigInfosQueue.Count; bgWorkerSearch.ReportProgress(-1); } } bgWorkerSearch.ReportProgress(0); #endregion #region 2. Search music tags for lyrics // only if user wants to read from music tag and the music tags already aren't disregarded in the search if (_mAutomaticReadFromToMusicTag && !_mDisregardSongWithLyricInTag) { var mSongsToSearchOnline = new Queue(); foreach (string[] song in _lyricConfigInfosQueue) { if (!LyricFoundInMusicTag(song[0], song[1])) { mSongsToSearchOnline.Enqueue(new[] { song[0], song[1] }); } if (_stopCollectingOfTitles) { bgWorkerSearch.CancelAsync(); return; } } _lyricConfigInfosQueue = mSongsToSearchOnline; } #endregion #region 3. Searching for lyrics // create worker thread instance if (_lyricConfigInfosQueue.Count > 0) { _mFind = SettingManager.GetParamAsString(SettingManager.Find, ""); _mReplace = SettingManager.GetParamAsString(SettingManager.Replace, ""); _mEventStopThread = new ManualResetEvent(false); _lyricsController = new LyricsController(this, _mEventStopThread, _sitesToSearchArray, false, false, _mFind, _mReplace); _lyricsController.NoOfLyricsToSearch = _lyricConfigInfosQueue.Count; ThreadStart runLyricController = delegate { _lyricsController.Run(); }; _mLyricControllerThread = new Thread(runLyricController); _mLyricControllerThread.Start(); _lyricsController.StopSearches = false; while (_lyricConfigInfosQueue.Count != 0) { // If the user has cancelled the search => end this if (_stopCollectingOfTitles && _lyricsController != null) { bgWorkerSearch.CancelAsync(); return; } if (_lyricsController == null) { return; } if (_lyricsController.NoOfCurrentSearches < NumberOfCurrentSearchesAllowed && _lyricsController.StopSearches == false) { var lyricID = (string[])_lyricConfigInfosQueue.Dequeue(); //TODO: if there is a lyric in the music tag of the file, then include this in the db and don't search online var artist = lyricID[0]; var title = lyricID[1]; BatchLogger.Info("New!: Looking for {0} - {1}.", artist, title); _lyricsController.AddNewLyricSearch(artist, title, MediaPortalUtil.GetStrippedPrefixArtist(artist, _mStrippedPrefixStrings)); } Thread.Sleep(100); } } else { ThreadFinished = new[] { "", "", "No titles left for online search", "" }; } #endregion }