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);
        }
        public void RemoveSong(string artist, string title)
        {
            try
            {
                int artistIndex = treeView.Nodes.IndexOfKey(artist);
                int titleIndex  = treeView.Nodes[artistIndex].Nodes.IndexOfKey(title);
                treeView.Nodes[artistIndex].Nodes.RemoveAt(titleIndex);
                --m_NoOfTitles;

                // remove title from treeView
                if (treeView.Nodes[artistIndex].Nodes.Count == 0)
                {
                    treeView.Nodes.RemoveAt(artistIndex);
                    --m_NoOfArtists;
                }
            }
            catch
            {
                if (artist.Length == 0 && title.Length == 0)
                {
                    treeView.Nodes.RemoveAt(0);
                    --m_NoOfArtists;
                    treeView.Update();
                }
            }
            finally
            {
                treeView.Update();

                // remove title from database
                CurrentDB.Remove(DatabaseUtil.CorrectKeyFormat(artist, title));
                DatabaseUtil.SerializeDB(CurrentDB);
            }
        }
Пример #3
0
        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 btUpdate_Click(object sender, EventArgs e)
        {
            if (lvSearchResults.SelectedItems.Count > 0)
            {
                stopSearch();
                ListViewItem item  = lvSearchResults.Items[0];
                string       site  = lvSearchResults.SelectedItems[0].Text;
                string       lyric = tbLyrics.Text;

                if (markedDatabase && moveLyricFromMarkedDatabase)
                {
                    parent.RemoveSong(originalArtist, originalTitle);
                    string key = DatabaseUtil.CorrectKeyFormat(originalArtist, originalTitle);
                    MyLyricsSettings.LyricsDB[key] = new LyricsItem(originalArtist, originalTitle, lyric, site);
                    DatabaseUtil.SerializeLyricDB();
                    parent.updateInfo();
                }
                else if (markedDatabase)
                {
                    DatabaseUtil.ReplaceInLyricsDatabase(MyLyricsSettings.LyricsMarkedDB, originalArtist, originalTitle, lyric, site);
                    DatabaseUtil.SerializeDBs();
                    parent.updateInfo();
                    parent.highlightSong(originalArtist, originalTitle, false);
                }
                else
                {
                    DatabaseUtil.ReplaceInLyricsDatabase(MyLyricsSettings.LyricsDB, originalArtist, originalTitle, lyric, site);
                    DatabaseUtil.SerializeDBs();
                    parent.updateInfo();
                    parent.highlightSong(originalArtist, originalTitle, false);
                }
                this.Close();
            }
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }
Пример #7
0
        /// <summary>
        /// AddSong with tree parameters adds a lyric to the treeView and the lyric database
        /// </summary>
        /// <param name="artist">artist</param>
        /// <param name="title">title</param>
        /// <param name="lyrics">lyircs</param>
        /// <param name="site">site</param>
        private bool AddSong(string artist, string title, string lyrics, string site)
        {
            var item = new LyricsItem(artist, title, lyrics, site);

            if (DatabaseUtil.IsSongInLyricsDatabase(CurrentLyricsDatabase, artist, title).Equals(DatabaseUtil.LyricNotFound))
            {
                CurrentLyricsDatabase.Add(DatabaseUtil.CorrectKeyFormat(artist, title), item);
                try
                {
                    AddSong(item);
                }
                catch
                {
                    ;
                }
                treeView.Update();
                DatabaseUtil.SerializeDB(CurrentLyricsDatabase);

                if (SettingManager.GetParamAsBool(SettingManager.AutomaticWriteToMusicTag, true))
                {
                    TagReaderUtil.WriteLyrics(artist, title, lyrics);
                }

                return(true);
            }
            return(false);
        }
 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();
 }
Пример #9
0
        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;
            }
        }
Пример #10
0
        private static bool IsSelectedLyricLRC(string artist, string title)
        {
            if (artist.Length != 0 && title.Length != 0)
            {
                var lyricsText = CurrentLyricsDatabase[DatabaseUtil.CorrectKeyFormat(artist, title)].Lyrics;

                var lrc = new SimpleLRC(artist, title, lyricsText);
                if (lrc.IsValid)
                {
                    return(true);
                }
                return(false);
            }

            return(false);
        }
Пример #11
0
        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;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// AddSong with tree parameters adds a lyric to the treeView and the lyric database
        /// </summary>
        /// <param name="artist"></param>
        /// <param name="title"></param>
        /// <param name="lyric"></param>
        private bool AddSong(string artist, string title, string lyrics, string site)
        {
            LyricsItem item = new LyricsItem(artist, title, lyrics, site);

            if (DatabaseUtil.IsTrackInLyricsDatabase(CurrentDB, artist, title).Equals(DatabaseUtil.LYRIC_NOT_FOUND))
            {
                CurrentDB.Add(DatabaseUtil.CorrectKeyFormat(artist, title), item);
                AddSong(item);
                treeView.Update();
                DatabaseUtil.SerializeDB(CurrentDB);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        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);
            }
        }
Пример #14
0
        private void UpdateSong()
        {
            if (lvSearchResults.SelectedItems.Count > 0)
            {
                StopSearch();
                var site  = lvSearchResults.SelectedItems[0].Text;
                var lyric = tbLyrics.Text;

                if (_markedDatabase && _mMoveLyricFromMarkedDatabase)
                {
                    _parent.RemoveSong(_originalArtist, _originalTitle, true);
                    var key = DatabaseUtil.CorrectKeyFormat(_originalArtist, _originalTitle);
                    MyLyricsUtils.LyricsDB[key] = new LyricsItem(_originalArtist, _originalTitle, lyric, site);
                    DatabaseUtil.SerializeLyricDB();
                    _parent.UpdateInfo();
                }
                else if (_markedDatabase)
                {
                    DatabaseUtil.ReplaceInLyricsDatabase(MyLyricsUtils.LyricsMarkedDB, _originalArtist, _originalTitle,
                                                         lyric, site);
                    DatabaseUtil.SerializeDBs();
                    _parent.UpdateInfo();
                    _parent.HighlightSong(_originalArtist, _originalTitle, false);
                }
                else
                {
                    DatabaseUtil.ReplaceInLyricsDatabase(MyLyricsUtils.LyricsDB, _originalArtist, _originalTitle, lyric,
                                                         site);
                    DatabaseUtil.SerializeDBs();
                    _parent.UpdateInfo();
                    _parent.HighlightNextSong(_treeArtistIndex, _treeTitleIndex);
                }

                if (_mAutomaticWriteToMusicTag)
                {
                    TagReaderUtil.WriteLyrics(_originalArtist, _originalTitle, lyric);
                }

                _parent.UpdateLyricDatabaseStats();
            }
        }
Пример #15
0
        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();
        }
Пример #16
0
        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
        }
Пример #17
0
        private void MoveLyricToOtherDatabase()
        {
            var artist = "";
            var title  = "";

            if (treeView.SelectedNode != null)
            {
                var 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)
            {
                var artistNode = treeView.SelectedNode;

                LyricsDatabase otherDatabase;
                if (CurrentLyricsDatabase.Equals(MyLyricsUtils.LyricsDB))
                {
                    otherDatabase = MyLyricsUtils.LyricsMarkedDB;
                }
                else
                {
                    otherDatabase = MyLyricsUtils.LyricsDB;
                }

                foreach (TreeNode node in artistNode.Nodes)
                {
                    var key  = DatabaseUtil.CorrectKeyFormat(artist, node.Text);
                    var item = CurrentLyricsDatabase[key];
                    CurrentLyricsDatabase.Remove(key);

                    if (!DatabaseUtil.IsSongInLyricsDatabase(otherDatabase, artist, item.Title).Equals(DatabaseUtil.LyricNotFound))
                    {
                        otherDatabase.Add(key, item);
                    }
                    else
                    {
                        otherDatabase[key] = item;
                    }
                }
                UpdateLyricsTree(false);
                DatabaseUtil.SerializeDBs();
            }
            else
            {
                var key  = DatabaseUtil.CorrectKeyFormat(artist, title);
                var item = CurrentLyricsDatabase[key];

                // remove song from treeview and current database
                RemoveSong(artist, title, true);

                // add song to other database and serialize it
                if (CurrentLyricsDatabase.Equals(MyLyricsUtils.LyricsDB))
                {
                    MyLyricsUtils.LyricsMarkedDB.Add(key, item);
                    DatabaseUtil.SerializeDB(MyLyricsUtils.LyricsMarkedDB);
                }
                else
                {
                    MyLyricsUtils.LyricsDB.Add(key, item);
                    DatabaseUtil.SerializeDB(MyLyricsUtils.LyricsDB);
                }
                UpdateLyricDatabaseStats();
            }

            treeView.Focus();
        }
Пример #18
0
        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)
                {
                    ;
                }
            }
        }
Пример #19
0
        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
        }
        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();
        }