private void ListboxArtistsUpdate(object sender, EventArgs e) { _mMDb = MusicDatabase.Instance; var artists = new ArrayList(); //mdb.GetArtists(0, String.Empty, ref artists); _mMDb.GetAllArtists(ref artists); lvArtists.Items.Clear(); lbSelectedArtist.Text = String.Empty; MDelegateStringUpdate = UpdateStringMethod; MDelegateStatusUpdate = UpdateStatusMethod; MDelegateLyricFound = LyricFoundMethod; MDelegateLyricNotFound = LyricNotFoundMethod; MDelegateThreadFinished = ThreadFinishedMethod; MDelegateThreadException = ThreadExceptionMethod; foreach (var artist in artists) { var lvi = new ListViewItem((string)artist); lvArtists.Items.Add(lvi); } lvArtists.Sorting = SortOrder.Ascending; lvSongs.Items.Clear(); lbArtistNumber.Text = String.Format("{0} artists found", lvArtists.Items.Count); }
private void buttonCoverArtistsRefresh_Click(object sender, EventArgs e) { buttonCoverArtistsRefresh.Enabled = false; buttonCoverArtistsLookup.Enabled = false; listViewCoverArtists.Clear(); ArrayList CoverArtists = new ArrayList(); MusicDatabase mdb = MusicDatabase.Instance; if (mdb.GetAllArtists(ref CoverArtists)) { listViewCoverArtists.Columns.Add("Artist", 300); listViewCoverArtists.Columns.Add("Low res", 60); listViewCoverArtists.Columns.Add("High res", 60); progressBarCoverArtists.Maximum = CoverArtists.Count; progressBarCoverArtists.Value = 0; progressBarCoverArtists.Visible = true; for (int i = 0; i < CoverArtists.Count; i++) { try { string curArtist = CoverArtists[i].ToString(); ListViewItem listItem = new ListViewItem(curArtist); // check low res string strThumb = Util.Utils.GetCoverArt(Thumbs.MusicArtists, curArtist); if (File.Exists(strThumb)) { listItem.SubItems.Add((new FileInfo(strThumb).Length / 1024) + "KB"); } else { listItem.SubItems.Add("none"); Log.Info("Audioscrobbler: Artist cover missing: {0}", curArtist); } // check high res strThumb = Util.Utils.ConvertToLargeCoverArt(strThumb); if (File.Exists(strThumb)) { listItem.SubItems.Add((new FileInfo(strThumb).Length / 1024) + "KB"); } else { listItem.SubItems.Add("none"); } listViewCoverArtists.Items.Add(listItem); progressBarCoverArtists.Value = i + 1; } catch (Exception) {} } progressBarCoverArtists.Visible = false; } buttonCoverArtistsRefresh.Enabled = true; buttonCoverArtistsLookup.Enabled = 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 }