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); } }
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 }
private void btSwitch_Click(object sender, EventArgs e) { string temp = ""; string artist = ""; string title = ""; if (treeView.SelectedNode != null) { temp = treeView.SelectedNode.Text; if (treeView.SelectedNode.Parent != null) { artist = treeView.SelectedNode.Parent.Text; title = temp; } else { artist = temp; } } if (artist.Length == 0 && title.Length == 0) { MessageBox.Show("No artist or track selected"); } else if (title.Length == 0) { TreeNode artistNode = treeView.SelectedNode; LyricsDatabase otherDatabase = null; if (CurrentDB.Equals(MyLyricsSettings.LyricsDB)) { otherDatabase = MyLyricsSettings.LyricsMarkedDB; } else { otherDatabase = MyLyricsSettings.LyricsDB; } foreach (TreeNode node in artistNode.Nodes) { string key = DatabaseUtil.CorrectKeyFormat(artist, node.Text); LyricsItem item = CurrentDB[key]; CurrentDB.Remove(key); if (!DatabaseUtil.IsTrackInLyricsDatabase(otherDatabase, artist, item.Title).Equals(DatabaseUtil.LYRIC_NOT_FOUND)) { otherDatabase.Add(key, item); } else { otherDatabase[key] = item; } } updateLyricsTree(); DatabaseUtil.SerializeDBs(); } else { string key = DatabaseUtil.CorrectKeyFormat(artist, title); LyricsItem item = CurrentDB[key]; // remove song from treeview and current database RemoveSong(artist, title); // add song to other database and serialize it if (CurrentDB.Equals(MyLyricsSettings.LyricsDB)) { MyLyricsSettings.LyricsMarkedDB.Add(key, item); DatabaseUtil.SerializeDB(MyLyricsSettings.LyricsMarkedDB); } else { MyLyricsSettings.LyricsDB.Add(key, item); DatabaseUtil.SerializeDB(MyLyricsSettings.LyricsDB); } updateLyricDatabaseStats(); } treeView.Focus(); }