From: <sa...@us...> - 2007-03-14 17:01:16
|
Revision: 188 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=188&view=rev Author: saamand Date: 2007-03-14 10:01:09 -0700 (Wed, 14 Mar 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj trunk/plugins/MyLyrics/My Lyrics/MyLyrics.cs trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.cs trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.cs trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.resx trunk/plugins/MyLyrics/My Lyrics/MyLyricsUtil.cs Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -108,7 +108,7 @@ ((Thread)threadList[i]).Abort(); } - bool stillThreadsAlive = true; + bool stillThreadsAlive = (threadList.Count > 0 ? true : false); while (stillThreadsAlive) { for (int i = 0; i < threadList.Count; i++) @@ -118,8 +118,6 @@ stillThreadsAlive = true; } } - - Thread.Sleep(500); m_EventStopped_LyricController.Set(); break; } Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj 2007-03-14 17:01:09 UTC (rev 188) @@ -125,7 +125,7 @@ </Target> --> <PropertyGroup> - <PostBuildEvent>copy $(TargetFileName) "C:\Program Files\Team MediaPortal\MediaPortal"</PostBuildEvent> + <PostBuildEvent>::copy $(TargetFileName) "C:\Program Files\Team MediaPortal\MediaPortal"</PostBuildEvent> <PreBuildEvent> </PreBuildEvent> </PropertyGroup> Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -517,11 +517,29 @@ if (MyLyricsUtil.isTrackInLyricsDatabase(LyricsDB, capArtist, capTitle).Equals(MyLyricsUtil.LYRIC_NOT_FOUND)) { LyricsDB.Add(MyLyricsUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, m_LyricText, site)); + + string path = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, LyricsDBName); + using (FileStream fs = new FileStream(path, FileMode.Open)) + { + BinaryFormatter bf = new BinaryFormatter(); + LyricsDB.SetLastModified(); + bf.Serialize(fs, LyricsDB); + fs.Close(); + } } if (MyLyricsUtil.isTrackInLyricsMarkedDatabase(LyricsMarkedDB, capArtist, capTitle).Equals(MyLyricsUtil.LYRIC_MARKED)) { LyricsMarkedDB.Remove(MyLyricsUtil.CorrectKeyFormat(capArtist, capTitle)); + + string path = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, LyricsMarkedDBName); + using (FileStream fs = new FileStream(path, FileMode.Open)) + { + BinaryFormatter bf = new BinaryFormatter(); + LyricsMarkedDB.SetLastModified(); + bf.Serialize(fs, LyricsMarkedDB); + fs.Close(); + } } } Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.Designer.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.Designer.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -100,11 +100,12 @@ this.tabControl.Controls.Add(this.tabPageLyricsDatabase); this.tabControl.Controls.Add(this.tabPageSetup); this.tabControl.Controls.Add(this.tabPageDatabase); - this.tabControl.Location = new System.Drawing.Point(12, 12); + this.tabControl.Location = new System.Drawing.Point(7, 12); this.tabControl.Name = "tabControl"; this.tabControl.SelectedIndex = 0; this.tabControl.Size = new System.Drawing.Size(528, 494); this.tabControl.TabIndex = 1; + this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged); // // tabPageLyricsDatabase // @@ -123,7 +124,7 @@ this.tabPageSetup.Location = new System.Drawing.Point(4, 22); this.tabPageSetup.Name = "tabPageSetup"; this.tabPageSetup.Padding = new System.Windows.Forms.Padding(3); - this.tabPageSetup.Size = new System.Drawing.Size(520, 454); + this.tabPageSetup.Size = new System.Drawing.Size(520, 468); this.tabPageSetup.TabIndex = 2; this.tabPageSetup.Text = "General setup"; this.tabPageSetup.UseVisualStyleBackColor = true; @@ -242,7 +243,7 @@ this.tabPageDatabase.Location = new System.Drawing.Point(4, 22); this.tabPageDatabase.Name = "tabPageDatabase"; this.tabPageDatabase.Padding = new System.Windows.Forms.Padding(3); - this.tabPageDatabase.Size = new System.Drawing.Size(520, 454); + this.tabPageDatabase.Size = new System.Drawing.Size(520, 468); this.tabPageDatabase.TabIndex = 2; this.tabPageDatabase.Text = "Search music database"; this.tabPageDatabase.UseVisualStyleBackColor = true; @@ -400,6 +401,7 @@ // this.lbLimit.BorderColor = System.Drawing.Color.Empty; this.lbLimit.Location = new System.Drawing.Point(158, 19); + this.lbLimit.MaxLength = 6; this.lbLimit.Name = "lbLimit"; this.lbLimit.Size = new System.Drawing.Size(44, 20); this.lbLimit.TabIndex = 1; @@ -684,6 +686,7 @@ // bgWorkerSearch // this.bgWorkerSearch.WorkerReportsProgress = true; + this.bgWorkerSearch.WorkerSupportsCancellation = true; this.bgWorkerSearch.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bgWorkerSearch_DoWork); this.bgWorkerSearch.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bgWorkerSearch_RunWorkerCompleted); this.bgWorkerSearch.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bgWorkerSearch_ProgressChanged); @@ -692,7 +695,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(538, 543); + this.ClientSize = new System.Drawing.Size(540, 539); this.ControlBox = false; this.Controls.Add(this.btClose); this.Controls.Add(this.tabControl); Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -33,7 +33,7 @@ Thread m_LyricControllerThread; LyricsController lc = null; - MyLyricsSetup_LyricsLibrary lyricUC; + MyLyricsSetup_LyricsLibrary lyricsLibraryUC; // events used to stop worker thread ManualResetEvent m_EventStopThread; @@ -106,13 +106,15 @@ private string logFileName = "MyLyricsBatch.log"; private string logFullFileName = ""; + bool stopCollectingOfTitles = false; + public MyLyricsSetup() { // Initialize GUI InitializeComponent(); - lyricUC = new MyLyricsSetup_LyricsLibrary(this); - this.tabPageLyricsDatabase.Controls.Add(lyricUC); + lyricsLibraryUC = new MyLyricsSetup_LyricsLibrary(this); + this.tabPageLyricsDatabase.Controls.Add(lyricsLibraryUC); // initialize delegates m_DelegateLyricFound = new DelegateLyricFound(this.lyricFoundMethod); @@ -225,7 +227,7 @@ } MyLyricsSetup_LyricsLibrary.CurrentDB = LyricsDB; - lyricUC.updateLyricsTree(); + lyricsLibraryUC.updateLyricsTree(); } @@ -284,30 +286,36 @@ { if (searching) { - lyricUC.btAdd.Enabled = false; - lyricUC.btDelete.Enabled = false; - lyricUC.btImportSingle.Enabled = false; - lyricUC.btImportLRC.Enabled = false; - lyricUC.btResetLyricsDatabase.Enabled = false; - lyricUC.btResetMarkedLyricsDatabase.Enabled = false; - lyricUC.btSave.Enabled = false; + lyricsLibraryUC.btAdd.Enabled = false; + lyricsLibraryUC.btDelete.Enabled = false; + lyricsLibraryUC.btImportFiles.Enabled = false; + lyricsLibraryUC.btImportDirs.Enabled = false; + lyricsLibraryUC.btResetLyricsDatabase.Enabled = false; + lyricsLibraryUC.btResetMarkedLyricsDatabase.Enabled = false; + lyricsLibraryUC.btSave.Enabled = false; btClose.Enabled = false; } else { - lyricUC.btAdd.Enabled = true; - lyricUC.btDelete.Enabled = true; - lyricUC.btImportSingle.Enabled = true; - lyricUC.btImportLRC.Enabled = true; - lyricUC.btResetLyricsDatabase.Enabled = true; - lyricUC.btResetMarkedLyricsDatabase.Enabled = true; - lyricUC.btSave.Enabled = true; + lyricsLibraryUC.btAdd.Enabled = true; + lyricsLibraryUC.btDelete.Enabled = true; + lyricsLibraryUC.btImportFiles.Enabled = true; + lyricsLibraryUC.btImportDirs.Enabled = true; + lyricsLibraryUC.btResetLyricsDatabase.Enabled = true; + lyricsLibraryUC.btResetMarkedLyricsDatabase.Enabled = true; + lyricsLibraryUC.btSave.Enabled = true; btClose.Enabled = true; } } private void btImportAll_Click(object sender, System.EventArgs e) { + + if (bgWorkerSearch.IsBusy) + { + Thread.Sleep(2000); + } + stopwatch.StartZero(); lbTimer.Text = "00:00.00"; timer = new System.Windows.Forms.Timer(); @@ -316,6 +324,7 @@ timer.Tick += new EventHandler(timer_Tick); timer.Start(); + stopCollectingOfTitles = false; isSearching(true); lbStep1a.Text = "The collecting of songs has started."; lbStep2a.Text = ""; @@ -332,9 +341,6 @@ m_noOfCurrentlySearches = 0; btImportAll.Enabled = false; - progressBar.Enabled = true; - progressBar.Value = 0; - progressBar.Maximum = m_TotalTitles; logFullFileName = Config.GetFile(Config.Dir.Log, logFileName); @@ -361,6 +367,18 @@ m_DisregardVariousArtist = cbDisregardVariousArtist.Enabled && cbDisregardVariousArtist.Checked; m_SearchOnlyMarkedSongs = cbSearchOnlyForMarkedSongs.Enabled && cbSearchOnlyForMarkedSongs.Checked; + if (m_SearchOnlyMarkedSongs) + { + progressBar.Maximum = LyricsMarkedDB.Count; + } + else + { + progressBar.Maximum = m_TotalTitles; + } + + progressBar.Enabled = true; + progressBar.Value = 0; + m_SongsNotKnown = 0; m_SongsWithLyric = 0; m_SongsWithMark = 0; @@ -374,6 +392,8 @@ lbSongsWithMark2.Text = "-"; lbLyricsFound2.Text = "-"; lbLyricsNotFound2.Text = "-"; + lbSongsToSearch2.Text = "-"; + lbDisregardedSongs2.Text = "-"; ArrayList sitesToSearch = new ArrayList(); @@ -491,7 +511,12 @@ if (lc != null) { lc.StopSearches = true; + // Save databases to disc + SerializeDB(LyricsDB); + SerializeDB(LyricsMarkedDB); + lyricsLibraryUC.updateLyricsTree(); } + bgWorkerSearch.CancelAsync(); StopThread(); progressBar.ResetText(); progressBar.Enabled = false; @@ -501,12 +526,6 @@ btImportAll.Enabled = true; btCancel.Enabled = false; isSearching(false); - - // Save databases to disc - SerializeDB(LyricsDB); - SerializeDB(LyricsMarkedDB); - - lyricUC.updateLyricsTree(); } // Called from worker thread using delegate and Control.Invoke @@ -582,6 +601,14 @@ 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); @@ -594,16 +621,32 @@ /* 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 and the music tag has an lyrictext included */ + * 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_DisregardSongWithLyricInTag && ((tag = MediaPortal.TagReader.TagReader.ReadTag(song.FileName)) != null) && tag.Lyrics.Equals("") == false)) + || (m_DisregardVariousArtist && (song.Artist.ToLower().Equals("various artists") || song.Artist.ToLower().Equals("diverse kunstnere")))) { m_DisregardedSongs += 1; } + else if ((m_DisregardSongWithLyricInTag && ((tag = MediaPortal.TagReader.TagReader.ReadTag(song.FileName)) != null) && tag.Lyrics.Equals("") == false)) + { + m_SongsWithLyric += 1; + + string capArtist = LyricUtil.capatalizeString(tag.Artist); + string capTitle = LyricUtil.capatalizeString(tag.Title); + + if (MyLyricsUtil.isTrackInLyricsDatabase(LyricsDB, capArtist, capTitle).Equals(MyLyricsUtil.LYRIC_NOT_FOUND)) + { + LyricsDB.Add(MyLyricsUtil.CorrectKeyFormat(capArtist, capTitle), new LyricsItem(capArtist, capTitle, tag.Lyrics, "Tag")); + } + + if (MyLyricsUtil.isTrackInLyricsMarkedDatabase(LyricsMarkedDB, capArtist, capTitle).Equals(MyLyricsUtil.LYRIC_MARKED)) + { + LyricsMarkedDB.Remove(MyLyricsUtil.CorrectKeyFormat(capArtist, capTitle)); + } + } else { int status = MyLyricsUtil.isTrackInLyricsDatabase(LyricsDB, song.Artist, song.Title); @@ -624,6 +667,9 @@ string[] lyricId = new string[2] { song.Artist, song.Title }; lyricConfigInfosQueue.Enqueue(lyricId); + + m_SongsToSearch = lyricConfigInfosQueue.Count; + bgWorkerSearch.ReportProgress(songNotKnown); } else if (status.Equals(MyLyricsUtil.LYRIC_FOUND)) { @@ -634,7 +680,6 @@ m_SongsWithMark += 1; } } - m_SongsToSearch = lyricConfigInfosQueue.Count; bgWorkerSearch.ReportProgress(songNotKnown); } } @@ -643,17 +688,18 @@ { foreach (KeyValuePair<string, LyricsItem> kvp in 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); } - - m_SongsToSearch = lyricConfigInfosQueue.Count; - //bgWorkerSearch.ReportProgress(songNotKnown); } startSearch: @@ -679,10 +725,17 @@ lc.StopSearches = false; + while (lyricConfigInfosQueue.Count != 0) { - if (lc == null) + // 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) { @@ -690,6 +743,7 @@ string[] lyricID = (string[])lyricConfigInfosQueue.Dequeue(); lc.addNewLyricSearch(lyricID[0], lyricID[1]); } + Thread.Sleep(100); } } @@ -725,19 +779,24 @@ private void btCancel_Click(object sender, EventArgs e) { + stopCollectingOfTitles = true; + if (lc != null) { lc.finishThread(m_artist, m_track, "The search has been cancelled by the user.", "none"); lc.Dispose(); lc = null; - progressBar.ResetText(); - progressBar.Value = 0; + } + else + { + m_EventStopThread.Set(); + ThreadFinishedMethod(m_artist, m_track, "The search has been cancelled by the user.", "none"); + } - m_LyricControllerThread = null; - - //bgWorkerSearch.Dispose(); - //bgWorkerSearch = null; - } + bgWorkerSearch.CancelAsync(); + progressBar.ResetText(); + progressBar.Value = 0; + m_LyricControllerThread = null; } internal static void SerializeDB(LyricsDatabase ldb) @@ -811,5 +870,13 @@ cbMarkSongsWithNoLyrics.Enabled = true; } } + + private void tabControl_SelectedIndexChanged(object sender, EventArgs e) + { + if (tabControl.SelectedIndex == 0) + { + lyricsLibraryUC.treeView.Select(); + } + } } } \ No newline at end of file Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.Designer.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.Designer.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -22,12 +22,12 @@ this.lbSource = new MediaPortal.UserInterface.Controls.MPLabel(); this.comboDatabase = new MediaPortal.UserInterface.Controls.MPComboBox(); this.lbDatabase = new MediaPortal.UserInterface.Controls.MPLabel(); - this.lbTestSecondsLeft = new System.Windows.Forms.Label(); - this.btImportLRC = new MediaPortal.UserInterface.Controls.MPButton(); + this.lbLRCTest = new System.Windows.Forms.Label(); + this.btImportDirs = new MediaPortal.UserInterface.Controls.MPButton(); this.lbSongs2 = new MediaPortal.UserInterface.Controls.MPLabel(); this.tbLyrics = new MediaPortal.UserInterface.Controls.MPTextBox(); this.lbSongs = new MediaPortal.UserInterface.Controls.MPLabel(); - this.btImportSingle = new MediaPortal.UserInterface.Controls.MPButton(); + this.btImportFiles = new MediaPortal.UserInterface.Controls.MPButton(); this.lbArtists2 = new MediaPortal.UserInterface.Controls.MPLabel(); this.lbTitle = new MediaPortal.UserInterface.Controls.MPLabel(); this.lbArtists = new MediaPortal.UserInterface.Controls.MPLabel(); @@ -36,7 +36,7 @@ this.btResetMarkedLyricsDatabase = new System.Windows.Forms.Button(); this.btResetLyricsDatabase = new System.Windows.Forms.Button(); this.lbResetDatabase = new MediaPortal.UserInterface.Controls.MPLabel(); - this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog(); + this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); this.gbLibrary.SuspendLayout(); this.gbResetDatabase.SuspendLayout(); this.SuspendLayout(); @@ -54,11 +54,12 @@ // // openFileDialog1 // - this.openFileDialog1.FileName = "ARTIST - TITLE.txt"; - this.openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; + this.openFileDialog1.Filter = "Text and LRC files|*-*.txt;*.lrc|Text files|*-*.txt|LRC files|*.lrc|All files|*.*" + + ""; this.openFileDialog1.InitialDirectory = "c:\\\\"; this.openFileDialog1.Multiselect = true; this.openFileDialog1.RestoreDirectory = true; + this.openFileDialog1.Title = "Select lyrics files to include"; // // btDelete // @@ -85,12 +86,12 @@ this.gbLibrary.Controls.Add(this.lbSource); this.gbLibrary.Controls.Add(this.comboDatabase); this.gbLibrary.Controls.Add(this.lbDatabase); - this.gbLibrary.Controls.Add(this.lbTestSecondsLeft); - this.gbLibrary.Controls.Add(this.btImportLRC); + this.gbLibrary.Controls.Add(this.lbLRCTest); + this.gbLibrary.Controls.Add(this.btImportDirs); this.gbLibrary.Controls.Add(this.lbSongs2); this.gbLibrary.Controls.Add(this.tbLyrics); this.gbLibrary.Controls.Add(this.lbSongs); - this.gbLibrary.Controls.Add(this.btImportSingle); + this.gbLibrary.Controls.Add(this.btImportFiles); this.gbLibrary.Controls.Add(this.lbArtists2); this.gbLibrary.Controls.Add(this.lbTitle); this.gbLibrary.Controls.Add(this.lbArtists); @@ -99,6 +100,7 @@ this.gbLibrary.Controls.Add(this.btDelete); this.gbLibrary.Controls.Add(this.btSave); this.gbLibrary.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.gbLibrary.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.gbLibrary.Location = new System.Drawing.Point(3, 3); this.gbLibrary.Name = "gbLibrary"; this.gbLibrary.Size = new System.Drawing.Size(515, 362); @@ -137,25 +139,27 @@ this.lbDatabase.TabIndex = 26; this.lbDatabase.Text = "Database:"; // - // lbTestSecondsLeft + // lbLRCTest // - this.lbTestSecondsLeft.AutoSize = true; - this.lbTestSecondsLeft.Location = new System.Drawing.Point(215, 335); - this.lbTestSecondsLeft.Name = "lbTestSecondsLeft"; - this.lbTestSecondsLeft.Size = new System.Drawing.Size(93, 13); - this.lbTestSecondsLeft.TabIndex = 25; - this.lbTestSecondsLeft.Text = "SecondsLeftLabel"; - this.lbTestSecondsLeft.Visible = false; + this.lbLRCTest.AutoSize = true; + this.lbLRCTest.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbLRCTest.Location = new System.Drawing.Point(440, 313); + this.lbLRCTest.MaximumSize = new System.Drawing.Size(60, 13); + this.lbLRCTest.MinimumSize = new System.Drawing.Size(60, 13); + this.lbLRCTest.Name = "lbLRCTest"; + this.lbLRCTest.Size = new System.Drawing.Size(60, 13); + this.lbLRCTest.TabIndex = 25; + this.lbLRCTest.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // btImportLRC + // btImportDirs // - this.btImportLRC.Location = new System.Drawing.Point(95, 330); - this.btImportLRC.Name = "btImportLRC"; - this.btImportLRC.Size = new System.Drawing.Size(75, 23); - this.btImportLRC.TabIndex = 24; - this.btImportLRC.Text = "Import &lrc"; - this.btImportLRC.UseVisualStyleBackColor = true; - this.btImportLRC.Click += new System.EventHandler(this.btImportLRC_Click); + this.btImportDirs.Location = new System.Drawing.Point(95, 330); + this.btImportDirs.Name = "btImportDirs"; + this.btImportDirs.Size = new System.Drawing.Size(75, 23); + this.btImportDirs.TabIndex = 24; + this.btImportDirs.Text = "Import &dirs"; + this.btImportDirs.UseVisualStyleBackColor = true; + this.btImportDirs.Click += new System.EventHandler(this.btImportDIRS_Click); // // lbSongs2 // @@ -186,15 +190,15 @@ this.lbSongs.TabIndex = 22; this.lbSongs.Text = "Songs:"; // - // btImportSingle + // btImportFiles // - this.btImportSingle.Location = new System.Drawing.Point(14, 330); - this.btImportSingle.Name = "btImportSingle"; - this.btImportSingle.Size = new System.Drawing.Size(75, 23); - this.btImportSingle.TabIndex = 4; - this.btImportSingle.Text = "Import &files"; - this.btImportSingle.UseVisualStyleBackColor = true; - this.btImportSingle.Click += new System.EventHandler(this.btImportSingle_Click); + this.btImportFiles.Location = new System.Drawing.Point(14, 330); + this.btImportFiles.Name = "btImportFiles"; + this.btImportFiles.Size = new System.Drawing.Size(75, 23); + this.btImportFiles.TabIndex = 4; + this.btImportFiles.Text = "Import &files"; + this.btImportFiles.UseVisualStyleBackColor = true; + this.btImportFiles.Click += new System.EventHandler(this.btImportSingle_Click); // // lbArtists2 // @@ -270,15 +274,14 @@ this.lbResetDatabase.Name = "lbResetDatabase"; this.lbResetDatabase.Size = new System.Drawing.Size(320, 41); this.lbResetDatabase.TabIndex = 9; - this.lbResetDatabase.Text = "Reset the lyrics database or the database with marked titles.\r\n\r\nAll data in each" + - " database that is reset is lost for ever"; + this.lbResetDatabase.Text = "Reset the lyrics database or the database with marked titles.\r\n\r\nAll data in a re" + + "set database is lost forever."; // - // openFileDialog2 + // folderBrowserDialog1 // - this.openFileDialog2.Filter = "lrc files (*.lrc)|*.lrc|All files (*.*)|*.*"; - this.openFileDialog2.InitialDirectory = "c:\\\\"; - this.openFileDialog2.Multiselect = true; - this.openFileDialog2.RestoreDirectory = true; + this.folderBrowserDialog1.Description = "Select a directory to search for lyrics or lrc-files. All files matching the patt" + + "erns [Artist]-[Title].txt and *.lrc will be included to the lyrics database."; + this.folderBrowserDialog1.ShowNewFolderButton = false; // // MyLyricsSetup_LyricsLibrary // @@ -300,7 +303,6 @@ private System.Windows.Forms.OpenFileDialog openFileDialog1; private MediaPortal.UserInterface.Controls.MPGroupBox gbLibrary; private MediaPortal.UserInterface.Controls.MPTextBox tbLyrics; - private System.Windows.Forms.TreeView treeView; private MediaPortal.UserInterface.Controls.MPGroupBox gbResetDatabase; private MediaPortal.UserInterface.Controls.MPLabel lbSongs; private MediaPortal.UserInterface.Controls.MPLabel lbArtists; @@ -309,17 +311,18 @@ internal MediaPortal.UserInterface.Controls.MPButton btSave; internal System.Windows.Forms.Button btDelete; internal System.Windows.Forms.Button btAdd; - internal MediaPortal.UserInterface.Controls.MPButton btImportSingle; - internal MediaPortal.UserInterface.Controls.MPButton btImportLRC; - private System.Windows.Forms.OpenFileDialog openFileDialog2; + internal MediaPortal.UserInterface.Controls.MPButton btImportFiles; + internal MediaPortal.UserInterface.Controls.MPButton btImportDirs; private MediaPortal.UserInterface.Controls.MPLabel lbDatabase; internal System.Windows.Forms.Button btResetMarkedLyricsDatabase; internal System.Windows.Forms.Button btResetLyricsDatabase; private MediaPortal.UserInterface.Controls.MPLabel lbResetDatabase; private MediaPortal.UserInterface.Controls.MPComboBox comboDatabase; - private System.Windows.Forms.Label lbTestSecondsLeft; + private System.Windows.Forms.Label lbLRCTest; private MediaPortal.UserInterface.Controls.MPLabel lbTitle; private MediaPortal.UserInterface.Controls.MPLabel lbSource; private System.ComponentModel.IContainer components; + private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; + internal System.Windows.Forms.TreeView treeView; } } Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -27,16 +27,16 @@ public partial class MyLyricsSetup_LyricsLibrary : UserControl { + static string m_CurrentArtist = ""; + static string m_CurrentTitle = ""; string m_OriginalLyric = ""; - string m_CurrentArtist = ""; - string m_CurrentTitle = ""; + Form m_Form = null; int m_NoOfArtists; int m_NoOfTitles; LRC.SimpleLRC lrc; - IEnumerator enumerator; System.Windows.Forms.Timer timer = null; Stopwatch stopwatch = null; string nextTimeToShow; @@ -45,7 +45,11 @@ const int SHIFT_WHEN_HIT = 15; internal static LyricsDatabase CurrentDB; private int currentDBIndex = 0; + enum TYPEOFLYRICS : int {NONE, NORMAL, LRC}; + static string lastChosenArtist = ""; + static string lastChosenTitle = ""; + public MyLyricsSetup_LyricsLibrary(Form form) { this.m_Form = form; @@ -84,6 +88,16 @@ lbSongs2.Text = m_NoOfTitles.ToString(); } + private void resetFields() + { + lbArtists2.Text = ""; + lbTitle.Text = ""; + lbLRCTest.Text = ""; + lbSongs2.Text = ""; + lbSource.Text = ""; + tbLyrics.Text = ""; + } + private ArrayList getTitlesByArtist(string artist) { ArrayList titles = new ArrayList(); @@ -131,13 +145,22 @@ /// <param name="artist"></param> /// <param name="title"></param> /// <param name="lyric"></param> - private void AddSong(string artist, string title, string lyrics, string site) + private bool AddSong(string artist, string title, string lyrics, string site) { LyricsItem item = new LyricsItem(artist, title, lyrics, site); - CurrentDB.Add(MyLyricsUtil.CorrectKeyFormat(artist, title), item); - AddSong(item); - treeView.Update(); - MyLyricsSetup.SerializeDB(CurrentDB); + + if (MyLyricsUtil.isTrackInLyricsDatabase(CurrentDB, artist, title).Equals(MyLyricsUtil.LYRIC_NOT_FOUND)) + { + CurrentDB.Add(MyLyricsUtil.CorrectKeyFormat(artist, title), item); + AddSong(item); + treeView.Update(); + MyLyricsSetup.SerializeDB(CurrentDB); + return true; + } + else + { + return false; + } } private void RemoveArtist(string artist) @@ -198,7 +221,7 @@ return false; } - private void updateInfo() + internal void updateInfo() { m_CurrentArtist = ""; m_CurrentTitle = ""; @@ -316,7 +339,14 @@ private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { updateInfo(); - lbTestSecondsLeft.Text = "The selected lyric is " + (isSelectedLyricALRC() ? "" : "NOT ") + "a valid LRC-file." ; + if (isSelectedLyricALRC()) + { + lbLRCTest.Text = "(valid LRC)"; + } + else + { + lbLRCTest.Text = ""; + } } private void btAdd_Click(object sender, EventArgs e) @@ -330,12 +360,18 @@ m_CurrentArtist = LyricUtil.capatalizeString(artist); m_CurrentTitle = LyricUtil.capatalizeString(title); - AddSong(m_CurrentArtist, m_CurrentTitle, lyrics, "Manual added"); - highlightSong(m_CurrentArtist, m_CurrentTitle, false); - updateLyricDatabaseStats(); + if (AddSong(m_CurrentArtist, m_CurrentTitle, lyrics, "Manual added")) + { + highlightSong(m_CurrentArtist, m_CurrentTitle, false); + updateLyricDatabaseStats(); + } + else + { + MessageBox.Show("The title \"" + artist + " - " + title + "\" is already in the database"); + } } - private void highlightSong(string artist, string title, bool previousSong) + internal void highlightSong(string artist, string title, bool previousSong) { if (artist.Equals("") || title.Equals("")) { @@ -367,48 +403,29 @@ private void btImportSingle_Click(object sender, EventArgs e) { - TextReader textReader = null; - if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { - string[] files = openFileDialog1.FileNames; for (int i = 0; i < files.Length; i++) { - FileInfo fileInfo = new FileInfo(files[i]); - string fileStringArtist = ""; - string fileStringTitle = ""; - string fileName = fileInfo.Name; + string fileName = new FileInfo(files[i]).Name; if (fileName.Contains("-")) { - int index = fileName.IndexOf("-"); - fileStringArtist = fileName.Substring(0, index); - fileStringTitle = fileName.Substring(index + 1); - fileStringArtist = fileStringArtist.Trim(); - fileStringTitle = fileStringTitle.Trim(); - fileStringTitle = fileStringTitle.Replace(".txt", ""); - textReader = new StreamReader(files[i]); - string line = ""; - string lyrics = ""; - - while ((line = textReader.ReadLine()) != null) + if (inspectFileNameAndAddToDatabaseIfValidLyrics(files[i]) != (int)TYPEOFLYRICS.NONE) { - lyrics += line + Environment.NewLine; + updateLyricDatabaseStats(); } - lyrics = lyrics.Trim(); - textReader.Close(); - - string capArtist = LyricUtil.capatalizeString(fileStringArtist); - string capTitle = LyricUtil.capatalizeString(fileStringTitle); - - AddSong(capArtist, capTitle, lyrics, "Text file"); - updateLyricDatabaseStats(); + else + { + MessageBox.Show("The title is already in the database"); + } + } else { - MessageBox.Show("The file \"" + fileName + "\" do not have a valid filename (ARTIST - TITLE.txt)."); + MessageBox.Show("The file \"" + fileName + "\" does not have a valid filename ([Artist]-[Title].txt or *.lrc)."); } } } @@ -419,7 +436,77 @@ } } + 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 LRC.SimpleLRC(filePath); + + if (lrc.IsValid && !lrc.Artist.Equals("") && !lrc.Title.Equals("")) + { + 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 btUpgradeDatabase_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "Are you sure the lyrics database should be upgraded?", "Upgrade lyrics database", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) @@ -428,119 +515,94 @@ } } - private void btImportLRC_Click(object sender, EventArgs e) + private void btImportDIRS_Click(object sender, EventArgs e) { - if (openFileDialog2.ShowDialog() == DialogResult.OK) + if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { try { - string[] files = openFileDialog2.FileNames; - for (int i = 0; i < files.Length; i++) + string path = folderBrowserDialog1.SelectedPath; + + int numberOfLyrics = 0; + int numberOfLRCS = 0; + int numberOfExisting = 0; + + DirectoryInfo dirInfo = new DirectoryInfo(path); + FileInfo[] fileInfos = dirInfo.GetFiles("*-*.txt", SearchOption.AllDirectories); + + foreach (FileInfo fileInfo in fileInfos) { - lrc = new LRC.SimpleLRC(files[i]); - - if (lrc == null) + int typeAdded; + if ((typeAdded = inspectFileNameAndAddToDatabaseIfValidLyrics(fileInfo.FullName)) == (int)TYPEOFLYRICS.NORMAL) { - MessageBox.Show("The lrc-file couldn't not be read properly." + Environment.NewLine + "The reading of the files was suspended."); - return; + ++numberOfLyrics; } - else if (lrc.IsValid == false) + else if (typeAdded == (int)TYPEOFLYRICS.LRC) { - MessageBox.Show("The selected file is not a valid lrc-file."); - return; + ++numberOfLRCS; } - else if (lrc.Lyric.Equals("")) + else { - MessageBox.Show("The lrc-file couldn't not be read properly." + Environment.NewLine + "It seemed to be empty."); - return; + ++numberOfExisting; } + } - enumerator = lrc.SimpleLRCTimeAndLineCollection.GetEnumerator(); + dirInfo = new DirectoryInfo(path); + fileInfos = dirInfo.GetFiles("*.lrc", SearchOption.AllDirectories); - if (!lrc.Artist.Equals("") && !lrc.Title.Equals("")) + foreach (FileInfo fileInfo in fileInfos) + { + int typeAdded; + if ((typeAdded = inspectFileNameAndAddToDatabaseIfValidLyrics(fileInfo.FullName)) == (int)TYPEOFLYRICS.NORMAL) { - AddSong(LyricUtil.capatalizeString(lrc.Artist), LyricUtil.capatalizeString(lrc.Title), lrc.Lyric.Trim(), "LRC-file"); + ++numberOfLyrics; } + else if (typeAdded == (int)TYPEOFLYRICS.LRC) + { + ++numberOfLRCS; + } + else + { + ++numberOfExisting; + } + } - updateLyricDatabaseStats(); - } + + updateLyricDatabaseStats(); + + MessageBox.Show("Number of lyris added :" + (numberOfLRCS + numberOfLyrics + numberOfExisting) + Environment.NewLine + + "Number of basic lyrics added:" + numberOfLyrics + Environment.NewLine + + "Number of LRCs added: " + numberOfLRCS + Environment.NewLine + + "Number of lyrics already in database: " + numberOfExisting); + } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } - - //DialogResult result = MessageBox.Show("Vil du teste?", "Test af lrc-file", MessageBoxButtons.YesNo); - - //if (result == System.Windows.Forms.DialogResult.Yes) - //{ - // tbLyrics.Enabled = true; - // tbLyrics.Text = ""; - // // setup timer and stopwatch - // timer = new System.Windows.Forms.Timer(); - // stopwatch = new Stopwatch(); - - // calculateNextInterval(); - - // timer.Enabled = true; - // timer.Tick += new System.EventHandler(OnTimerEvent); - - // timer.Start(); - // stopwatch.Start(); - //} } - public void OnTimerEvent(object source, EventArgs e) - { - if (++lineCounter > SHIFT_WHEN_HIT) - { - lineCounter = 0; - tbLyrics.Text = ""; - } - tbLyrics.Text += (nextTimeToShow + " - " + nextLineToShow); - calculateNextInterval(); - } - private void calculateNextInterval() - { - if (enumerator.MoveNext()) - { - LRC.SimpleLRCTimeAndLine currentLine = (LRC.SimpleLRCTimeAndLine)enumerator.Current; - while (currentLine.Time == 0) - { - tbLyrics.Text += (currentLine.TimeString + " - " + currentLine.Line); - ++lineCounter; - enumerator.MoveNext(); - currentLine = (LRC.SimpleLRCTimeAndLine)enumerator.Current; - } - - nextTimeToShow = currentLine.TimeString; - nextLineToShow = currentLine.Line; - timer.Interval = (int)(currentLine.Time - stopwatch.ElapsedMilliseconds); - lbTestSecondsLeft.Text = ((long)(stopwatch.ElapsedMilliseconds/1000)).ToString(); - } - else - { - timer.Stop(); - stopwatch.Stop(); - timer.Dispose(); - } - } - private void comboDatabase_SelectedIndexChanged(object sender, EventArgs e) { if (comboDatabase.SelectedIndex == 0 && currentDBIndex != 0) { + resetFields(); currentDBIndex = 0; CurrentDB = MyLyricsSetup.LyricsDB; + btImportFiles.Enabled = true; + btImportDirs.Enabled = true; updateLyricsTree(); } else if (comboDatabase.SelectedIndex == 1 && currentDBIndex != 1) { + resetFields(); currentDBIndex = 1; CurrentDB = MyLyricsSetup.LyricsMarkedDB; + btImportFiles.Enabled = false; + btImportDirs.Enabled = false; updateLyricsTree(); } } @@ -552,7 +614,8 @@ string path = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Database) + "\\" + MyLyricsSetup.LyricsDBName; FileStream fs = new FileStream(path, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); - bf.Serialize(fs, new LyricsDatabase()); + MyLyricsSetup.LyricsDB = new LyricsDatabase(); + bf.Serialize(fs, MyLyricsSetup.LyricsDB); fs.Close(); CurrentDB = MyLyricsSetup.LyricsDB; @@ -570,10 +633,11 @@ string path = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Database) + "\\" + MyLyricsSetup.LyricsMarkedDBName; FileStream fs = new FileStream(path, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); - bf.Serialize(fs, new LyricsDatabase()); + MyLyricsSetup.LyricsMarkedDB = new LyricsDatabase(); + bf.Serialize(fs, MyLyricsSetup.LyricsMarkedDB); fs.Close(); - CurrentDB = MyLyricsSetup.LyricsDB; + CurrentDB = MyLyricsSetup.LyricsMarkedDB; comboDatabase.SelectedIndex = 1; updateLyricsTree(); updateInfo(); Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.resx =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.resx 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyricsSetup_LyricsLibrary.resx 2007-03-14 17:01:09 UTC (rev 188) @@ -120,7 +120,7 @@ <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>17, 17</value> </metadata> - <metadata name="openFileDialog2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>147, 17</value> </metadata> </root> \ No newline at end of file Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyricsUtil.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyricsUtil.cs 2007-03-14 13:51:47 UTC (rev 187) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyricsUtil.cs 2007-03-14 17:01:09 UTC (rev 188) @@ -23,17 +23,20 @@ string capatalizedTitle = LyricUtil.capatalizeString(title); lyricText = lyricDB[CorrectKeyFormat(capatalizedArtist, capatalizedTitle)].Lyrics; - } catch { return LYRIC_NOT_FOUND; } - if (lyricText.Equals("")) - return LYRIC_NOT_FOUND; - else if (lyricText.Equals(MARK)) + + if (lyricText.Equals(MARK)) + { return LYRIC_MARKED; - return LYRIC_FOUND; + } + else + { + return LYRIC_FOUND; + } } internal static int isTrackInLyricsMarkedDatabase(LyricsDatabase lyricMarkedDB, string artist, string title) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |