From: <sa...@us...> - 2008-12-22 15:44:22
|
Revision: 2456 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=2456&view=rev Author: saamand Date: 2008-12-22 15:44:17 +0000 (Mon, 22 Dec 2008) Log Message: ----------- MyLyrics version 1.10 final Modified Paths: -------------- trunk/plugins/MyLyrics/LyricsEngine/LRC/SimpleLRCTimeAndLineCollection.cs trunk/plugins/MyLyrics/LyricsEngine/LyricSearch.cs trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/About.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/AddNewSong.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.resx trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.Designer.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.resx trunk/plugins/MyLyrics/My Lyrics/MyLyrics.cs trunk/plugins/MyLyrics/My Lyrics/MyLyrics.csproj trunk/plugins/MyLyrics/My Lyrics/MyLyricsSettings.cs Added Paths: ----------- trunk/plugins/MyLyrics/change log.txt Modified: trunk/plugins/MyLyrics/LyricsEngine/LRC/SimpleLRCTimeAndLineCollection.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LRC/SimpleLRCTimeAndLineCollection.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/LyricsEngine/LRC/SimpleLRCTimeAndLineCollection.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -19,7 +19,7 @@ public int GetSimpleLRCTimeAndLineIndex(long time) { - if (time < ((SimpleLRCTimeAndLine)items[0]).Time) + if (time <= ((SimpleLRCTimeAndLine)items[0]).Time) { return 0; } Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricSearch.cs =================================================================== (Binary files differ) Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -58,17 +58,17 @@ m_noOfLyricsNotFound = 0; m_noOfCurrentSearches = 0; - ArrayList easySitesArrayList = new ArrayList(); + ArrayList sitesArrayList = new ArrayList(); // If search all, then include all foreach (string site in lyricSites) { if (Setup.IsMember(site)) { - easySitesArrayList.Add(site); + sitesArrayList.Add(site); } } - this.lyricsSites = (string[])easySitesArrayList.ToArray(typeof(string)); + this.lyricsSites = (string[])sitesArrayList.ToArray(typeof(string)); LyricSearch.LyricsSites = lyricsSites; Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -23,7 +23,7 @@ public HotLyrics(string artist, string title, ManualResetEvent m_EventStop_SiteSearches, int timeLimit) { - this.timeLimit = timeLimit; + this.timeLimit = timeLimit / 2; timer = new System.Timers.Timer(); if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.ElapsedTimeString() + "SeekLyrics(" + artist + ", " + title + ")"); @@ -119,7 +119,7 @@ } else { - System.Threading.Thread.Sleep(100); + System.Threading.Thread.Sleep(300); } } } @@ -192,7 +192,7 @@ } } } - catch (System.Reflection.TargetInvocationException) + catch { lyric = "Not found"; } Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -24,7 +24,7 @@ public Lyrics007(string artist, string title, ManualResetEvent m_EventStop_SiteSearches, int timeLimit) { - this.timeLimit = timeLimit; + this.timeLimit = timeLimit / 2; timer = new System.Timers.Timer(); if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.ElapsedTimeString() + "Lyrics007(" + artist + ", " + title + ")"); @@ -52,14 +52,10 @@ while (complete == false) { - if (m_EventStop_SiteSearches.WaitOne(1, true)) + if (m_EventStop_SiteSearches.WaitOne(500, true)) { complete = true; } - else - { - System.Threading.Thread.Sleep(100); - } } } @@ -119,7 +115,7 @@ else lyric = "Not found"; } - catch (Exception) + catch { lyric = "Not found"; } Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -165,7 +165,7 @@ } } } - catch (System.Reflection.TargetInvocationException) + catch { lyric = "Not found"; } Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs =================================================================== --- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -149,7 +149,7 @@ else lyric = "Not found"; } - catch (System.Reflection.TargetInvocationException) + catch { lyric = "Not found"; } Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/About.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/About.Designer.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/About.Designer.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -80,7 +80,7 @@ this.lbInfo1.Name = "lbInfo1"; this.lbInfo1.Size = new System.Drawing.Size(223, 18); this.lbInfo1.TabIndex = 3; - this.lbInfo1.Text = "MyLyrics plugin, version 1.1 RC1"; + this.lbInfo1.Text = "MyLyrics plugin, version 1.10"; // // label2 // Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/AddNewSong.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/AddNewSong.Designer.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/AddNewSong.Designer.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -51,7 +51,7 @@ this.gbAddNew.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.gbAddNew.Location = new System.Drawing.Point(9, 12); this.gbAddNew.Name = "gbAddNew"; - this.gbAddNew.Size = new System.Drawing.Size(508, 294); + this.gbAddNew.Size = new System.Drawing.Size(508, 283); this.gbAddNew.TabIndex = 3; this.gbAddNew.TabStop = false; this.gbAddNew.Text = "Song Info"; @@ -62,7 +62,7 @@ this.tbLyric.Multiline = true; this.tbLyric.Name = "tbLyric"; this.tbLyric.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.tbLyric.Size = new System.Drawing.Size(428, 204); + this.tbLyric.Size = new System.Drawing.Size(428, 196); this.tbLyric.TabIndex = 5; this.tbLyric.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tbLyric_KeyUp); // @@ -114,7 +114,7 @@ // btOK // this.btOK.Enabled = false; - this.btOK.Location = new System.Drawing.Point(377, 312); + this.btOK.Location = new System.Drawing.Point(377, 301); this.btOK.Name = "btOK"; this.btOK.Size = new System.Drawing.Size(59, 23); this.btOK.TabIndex = 3; @@ -124,7 +124,7 @@ // // btClose // - this.btClose.Location = new System.Drawing.Point(442, 312); + this.btClose.Location = new System.Drawing.Point(442, 301); this.btClose.Name = "btClose"; this.btClose.Size = new System.Drawing.Size(59, 23); this.btClose.TabIndex = 4; @@ -132,12 +132,12 @@ this.btClose.UseVisualStyleBackColor = true; this.btClose.Click += new System.EventHandler(this.btClose_Click); // - // MyLyricsSetup_AddNewSong + // AddNewSong // this.AcceptButton = this.btOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(525, 340); + this.ClientSize = new System.Drawing.Size(517, 331); this.ControlBox = false; this.Controls.Add(this.btClose); this.Controls.Add(this.btOK); @@ -146,7 +146,7 @@ this.MaximumSize = new System.Drawing.Size(533, 367); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(533, 367); - this.Name = "MyLyricsSetup_AddNewSong"; + this.Name = "AddNewSong"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Add new lyric"; this.gbAddNew.ResumeLayout(false); Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.Designer.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.Designer.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -74,7 +74,7 @@ // // btStart // - this.btStart.Location = new System.Drawing.Point(13, 166); + this.btStart.Location = new System.Drawing.Point(12, 163); this.btStart.Name = "btStart"; this.btStart.Size = new System.Drawing.Size(66, 23); this.btStart.TabIndex = 2; @@ -148,7 +148,7 @@ // // btCancel // - this.btCancel.Location = new System.Drawing.Point(85, 166); + this.btCancel.Location = new System.Drawing.Point(84, 163); this.btCancel.Name = "btCancel"; this.btCancel.Size = new System.Drawing.Size(66, 23); this.btCancel.TabIndex = 14; @@ -158,7 +158,7 @@ // // btClose // - this.btClose.Location = new System.Drawing.Point(196, 166); + this.btClose.Location = new System.Drawing.Point(196, 163); this.btClose.Name = "btClose"; this.btClose.Size = new System.Drawing.Size(66, 23); this.btClose.TabIndex = 15; @@ -179,7 +179,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(264, 191); + this.ClientSize = new System.Drawing.Size(270, 189); this.ControlBox = false; this.Controls.Add(this.lbCurrentArtist); this.Controls.Add(this.btClose); Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ExportTags.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -10,6 +10,7 @@ using System.Collections; using System.Threading; using System.IO; +using LyricsEngine.LRC; namespace MyLyrics { @@ -23,13 +24,13 @@ public ExportTags() { InitializeComponent(); - this.lbInfo.Text = "Press the 'Start'-button to begin the export"; - this.lbCurrentArtist.Text = "Note that the export cannot be undone"; + this.lbInfo.Text = "Press the 'Start'-button to begin the export."; + this.lbCurrentArtist.Text = "Note that the export cannot be undone."; } private void btStart_Click(object sender, EventArgs e) { - lbInfo.Text = string.Format("Currently exporting tags to the tracks of:"); + lbInfo.Text = string.Format("Currently exporting lyrics to musictags with:"); btStart.Enabled = false; btCancel.Enabled = true; @@ -80,11 +81,45 @@ if (DatabaseUtil.IsTrackInLyricsDatabase(MyLyricsSettings.LyricsDB, capArtist, capTitle).Equals(DatabaseUtil.LYRIC_FOUND)) { + string lyric = MyLyricsSettings.LyricsDB[DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)].Lyrics; - if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) + SimpleLRC lrcInLyricsDb = new SimpleLRC(capArtist, capTitle, lyric); + + // If the lyricsDB lyric is LRC always export + if (lrcInLyricsDb.IsValid) { - ++counter; + if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) + { + ++counter; + } + continue; } + + MusicTag tag = MediaPortal.TagReader.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 + SimpleLRC lrcInTag = new SimpleLRC(capArtist, capTitle, tag.Lyrics); + if (!lrcInTag.IsValid) + { + if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) + { + ++counter; + } + } + + continue; + } + // Al if no lyric in musictag simple export + else + { + if (TagReaderUtil.WriteLyrics(song.FileName, lyric)) + { + ++counter; + } + } } } } @@ -116,6 +151,8 @@ lbInfo.Text = "The export has ended."; lbCurrentArtist.Text = string.Empty; + progressBar.PerformStep(); + btStart.Enabled = true; btCancel.Enabled = false; btClose.Enabled = true; Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.Designer.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.Designer.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -49,8 +49,9 @@ // this.lbInfo.AutoSize = true; this.lbInfo.Location = new System.Drawing.Point(10, 12); + this.lbInfo.MinimumSize = new System.Drawing.Size(150, 13); this.lbInfo.Name = "lbInfo"; - this.lbInfo.Size = new System.Drawing.Size(30, 13); + this.lbInfo.Size = new System.Drawing.Size(150, 13); this.lbInfo.TabIndex = 0; this.lbInfo.Text = "[text]"; // @@ -144,7 +145,7 @@ this.lbLyricsFound.Name = "lbLyricsFound"; this.lbLyricsFound.Size = new System.Drawing.Size(162, 15); this.lbLyricsFound.TabIndex = 14; - this.lbLyricsFound.Text = "Lyrics found in tags:"; + this.lbLyricsFound.Text = "Lyrics to be imported:"; // // btCancel // @@ -169,9 +170,10 @@ // lbCurrentArtist // this.lbCurrentArtist.AutoSize = true; - this.lbCurrentArtist.Location = new System.Drawing.Point(10, 25); + this.lbCurrentArtist.Location = new System.Drawing.Point(10, 29); + this.lbCurrentArtist.MinimumSize = new System.Drawing.Size(150, 13); this.lbCurrentArtist.Name = "lbCurrentArtist"; - this.lbCurrentArtist.Size = new System.Drawing.Size(71, 13); + this.lbCurrentArtist.Size = new System.Drawing.Size(150, 13); this.lbCurrentArtist.TabIndex = 16; this.lbCurrentArtist.Text = "[current artist]"; // @@ -179,7 +181,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(264, 192); + this.ClientSize = new System.Drawing.Size(266, 193); this.ControlBox = false; this.Controls.Add(this.lbCurrentArtist); this.Controls.Add(this.btClose); Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/ImportTags.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -8,6 +8,7 @@ using MediaPortal.Music.Database; using MediaPortal.TagReader; using System.Collections; +using LyricsEngine.LRC; namespace MyLyrics { @@ -66,24 +67,35 @@ string artist = (string)artists[i]; bw.ReportProgress(counter, artist); - try + + mDB.GetSongsByArtist(artist, ref songs); + + foreach (Song song in songs) { - mDB.GetSongsByArtist(artist, ref songs); + MusicTag tag = TagReader.ReadTag(song.FileName); + if (tag != null && tag.Lyrics != string.Empty) + { + string capArtist = LyricsEngine.LyricUtil.CapatalizeString(tag.Artist); + string capTitle = LyricsEngine.LyricUtil.CapatalizeString(tag.Title); - foreach (Song song in songs) - { - MusicTag tag = TagReader.ReadTag(song.FileName); - if (tag != null && tag.Lyrics != string.Empty) + if (DatabaseUtil.IsTrackInLyricsDatabase(MyLyricsSettings.LyricsDB, capArtist, capTitle).Equals(DatabaseUtil.LYRIC_FOUND)) { + // If lyric exists in LyricsDb then only import (and overwrite) if it isn't an LRC-file + string lyricsText = (string)MyLyricsSettings.LyricsDB[DatabaseUtil.CorrectKeyFormat(capArtist, capTitle)].Lyrics; + SimpleLRC lrc = new SimpleLRC(capArtist, capTitle, lyricsText); + if (!lrc.IsValid) + { + tags.Add(tag); + ++counter; + } + } + else + { tags.Add(tag); ++counter; } } } - catch (Exception e2) - { - string s = e2.Message; - } } } Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.Designer.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.Designer.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -39,7 +39,8 @@ this.btSelectAll2 = new System.Windows.Forms.Button(); this.btRemove = new System.Windows.Forms.Button(); this.btSearch = new System.Windows.Forms.Button(); - this.bw = new System.ComponentModel.BackgroundWorker(); + this.bwOnlineSearch = new System.ComponentModel.BackgroundWorker(); + this.bwMusicTagSearch = new System.ComponentModel.BackgroundWorker(); this.gbMusicDatabase.SuspendLayout(); this.gbSelected.SuspendLayout(); this.SuspendLayout(); @@ -84,7 +85,7 @@ // columnHeaderSong // this.columnHeaderSong.Text = "Song"; - this.columnHeaderSong.Width = 205; + this.columnHeaderSong.Width = 204; // // columnHeaderDB // @@ -122,7 +123,7 @@ this.lvSelectedSongs.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.lvSelectedSongs.Location = new System.Drawing.Point(11, 19); this.lvSelectedSongs.Name = "lvSelectedSongs"; - this.lvSelectedSongs.Size = new System.Drawing.Size(510, 162); + this.lvSelectedSongs.Size = new System.Drawing.Size(510, 164); this.lvSelectedSongs.SmallImageList = this.imageList; this.lvSelectedSongs.Sorting = System.Windows.Forms.SortOrder.Ascending; this.lvSelectedSongs.TabIndex = 11; @@ -132,7 +133,7 @@ // columnHeaderArtist2 // this.columnHeaderArtist2.Text = "Artist"; - this.columnHeaderArtist2.Width = 178; + this.columnHeaderArtist2.Width = 177; // // columnHeaderSong2 // @@ -304,14 +305,22 @@ this.btSearch.UseVisualStyleBackColor = true; this.btSearch.Click += new System.EventHandler(this.btSearch_Click); // - // bw + // bwOnlineSearch // - this.bw.WorkerReportsProgress = true; - this.bw.WorkerSupportsCancellation = true; - this.bw.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bw_DoWork); - this.bw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_RunWorkerCompleted); - this.bw.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bw_ProgressChanged); + this.bwOnlineSearch.WorkerReportsProgress = true; + this.bwOnlineSearch.WorkerSupportsCancellation = true; + this.bwOnlineSearch.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bw_DoWork); + this.bwOnlineSearch.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_RunWorkerCompleted); + this.bwOnlineSearch.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bw_ProgressChanged); // + // bwMusicTagSearch + // + this.bwMusicTagSearch.WorkerReportsProgress = true; + this.bwMusicTagSearch.WorkerSupportsCancellation = true; + this.bwMusicTagSearch.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bwMusicTagSearch_DoWork); + this.bwMusicTagSearch.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bwMusicTagSearch_RunWorkerCompleted); + this.bwMusicTagSearch.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bwMusicTagSearch_ProgressChanged); + // // MusicDatabaseBrowse // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -337,7 +346,6 @@ private System.Windows.Forms.ColumnHeader columnHeaderDB; private System.Windows.Forms.ColumnHeader columnHeaderStatus; private System.Windows.Forms.Label lbArtistNumber; - private System.Windows.Forms.ListView lvSelectedSongs; private System.Windows.Forms.ColumnHeader columnHeaderSong2; private System.Windows.Forms.ColumnHeader columnHeaderDatabase2; private System.Windows.Forms.ColumnHeader columnHeaderStatus2; @@ -352,12 +360,14 @@ private System.Windows.Forms.Button btRemove; private System.Windows.Forms.Button btDeselectAll2; private System.Windows.Forms.Button btSelectAll2; - private System.ComponentModel.BackgroundWorker bw; + private System.ComponentModel.BackgroundWorker bwOnlineSearch; private System.Windows.Forms.ImageList imageList; private System.ComponentModel.IContainer components; private System.Windows.Forms.Button btAddAll; private System.Windows.Forms.Button btRemoveAll; private System.Windows.Forms.Button btCancel; private System.Windows.Forms.Label lbStats; + public System.Windows.Forms.ListView lvSelectedSongs; + private System.ComponentModel.BackgroundWorker bwMusicTagSearch; } } \ No newline at end of file Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -5,17 +5,18 @@ using System.Drawing; using System.Text; using System.Windows.Forms; -using MediaPortal.Music.Database; using System.Collections; using LyricsEngine; using System.Threading; +using MediaPortal.Music.Database; +using MediaPortal.TagReader; namespace MyLyrics { public partial class MusicDatabaseBrowse : UserControl, ILyricForm { - MyLyricsSetup parent; - string selectedArtist = String.Empty; + MyLyricsSetup m_Parent; + string m_SelectedArtist = String.Empty; public delegate void DelegateStringUpdate(String message, String site); public DelegateStringUpdate m_DelegateStringUpdate; @@ -31,8 +32,7 @@ public DelegateThreadException m_DelegateThreadException; int m_noOfCurrentlySearches = 0; - int NO_OF_SEARCHES_ALLOWED = 5; - int counter = 0; + int m_NO_OF_SEARCHES_ALLOWED = 5; int m_noOfSearchesToComplete = 0; int m_noOfSearchesCompleted = 0; @@ -43,24 +43,26 @@ Thread m_LyricControllerThread; ManualResetEvent m_EventStopThread; - Queue<string[]> songs; - LyricsController lc; + Queue<string[]> m_Songs = null; + LyricsController m_lc; string m_find = string.Empty; string m_replace = string.Empty; + MusicDatabase m_mDB = null; + public MusicDatabaseBrowse(MyLyricsSetup parent) { - this.parent = parent; + this.m_Parent = parent; InitializeComponent(); } private void ListboxArtistsUpdate(object sender, EventArgs e) { - MusicDatabase mDB = MusicDatabase.Instance; + m_mDB = MusicDatabase.Instance; ArrayList artists = new ArrayList(); //mdb.GetArtists(0, String.Empty, ref artists); - mDB.GetAllArtists(ref artists); + m_mDB.GetAllArtists(ref artists); lvArtists.Items.Clear(); lbSelectedArtist.Text = String.Empty; @@ -105,38 +107,73 @@ { foreach (ListViewItem lvi in lvSongs.SelectedItems) { - if (lvi.ImageIndex == -1) + AddToSelected(lvi); + } + + if (lvSelectedSongs.Items.Count > 0) + { + btSearch.Enabled = true; + btRemove.Enabled = true; + lvSelectedSongs.Sort(); + + } + } + + private void AddToSelected(ListViewItem lvi) + { + if (lvi.ImageIndex == -1) + { + ListViewItem newLvi = new ListViewItem(m_SelectedArtist); + + foreach (ListViewItem.ListViewSubItem lvsi in lvi.SubItems) { - ListViewItem newLvi = new ListViewItem(selectedArtist); + newLvi.SubItems.Add(lvsi); + } - foreach (ListViewItem.ListViewSubItem lvsi in lvi.SubItems) + newLvi.ImageIndex = lvi.ImageIndex; + + bool alreadySelected = false; + + foreach (ListViewItem item in lvSelectedSongs.Items) + { + if (item.SubItems[0].Text.Equals(m_SelectedArtist) && item.SubItems[1].Text.Equals(newLvi.SubItems[1].Text)) { - newLvi.SubItems.Add(lvsi); + alreadySelected = true; + continue; } + } - newLvi.ImageIndex = lvi.ImageIndex; - + if (!alreadySelected && !lvSelectedSongs.Items.ContainsKey(m_SelectedArtist + "-" + lvi.SubItems[0].Text)) + { lvSelectedSongs.Items.Add(newLvi); } } + } + private void btAddAll_Click(object sender, EventArgs e) + { + foreach (ListViewItem lvi in lvSongs.Items) + { + AddToSelected(lvi); + } + if (lvSelectedSongs.Items.Count > 0) { btSearch.Enabled = true; btRemove.Enabled = true; lvSelectedSongs.Sort(); - } } + private void listViewArtists_SelectedIndexChanged(object sender, EventArgs e) { MusicDatabase mdb = MusicDatabase.Instance; List<Song> songs = new List<Song>(); - selectedArtist = ((System.Windows.Forms.ListView)(sender)).SelectedItems.Count > 0 ? ((System.Windows.Forms.ListView)(sender)).SelectedItems[0].Text : ""; - mdb.GetSongsByArtist(selectedArtist, ref songs); + m_SelectedArtist = ((System.Windows.Forms.ListView)(sender)).SelectedItems.Count > 0 ? ((System.Windows.Forms.ListView)(sender)).SelectedItems[0].Text : ""; + mdb.GetSongsByArtist(m_SelectedArtist, ref songs); - lbSelectedArtist.Text = String.Format("Artist: {0}", selectedArtist); + lbSelectedArtist.Text = String.Format("Artist: {0}", m_SelectedArtist); lvSongs.Items.Clear(); foreach (Song song in songs) @@ -210,35 +247,61 @@ } } - private void btSearch_Click(object sender, EventArgs e) + private void SearchMusicTags() { - m_lockButtons = false; - - if (bw.IsBusy) + if (bwMusicTagSearch.IsBusy) { Thread.Sleep(2000); } + bwMusicTagSearch.RunWorkerAsync(); + } + + private void Search_Init() + { + m_lockButtons = false; + MyLyricsSetup.UpdateLibraryUI = true; ChangeButtonsEnableState(); - songs = new Queue<string[]>(); + m_Songs = new Queue<string[]>(); List<ListViewItem> items = new List<ListViewItem>(); + int count = 0; + foreach (ListViewItem lvi in lvSelectedSongs.Items) { ListViewItem lviClone = (ListViewItem)lvi.Clone(); if (lvi.ImageIndex == -1) { - songs.Enqueue(new string[2] { lviClone.SubItems[0].Text, lviClone.SubItems[1].Text }); + m_Songs.Enqueue(new string[3] { lviClone.SubItems[0].Text, lviClone.SubItems[1].Text, count.ToString() }); lviClone.SubItems[3].Text = ""; items.Add(lviClone); + ++count; } } + lvSelectedSongs.Items.Clear(); lvSelectedSongs.Items.AddRange(items.ToArray()); + m_noOfSearchesToComplete = m_Songs.Count; + m_noOfCurrentlySearches = 0; + m_noOfSearchesCompleted = 0; + } + + private void SearchOnline() + { + // After the tag search is completed, we now recalculate the number of lyrics to search for during online search + m_noOfSearchesToComplete -= m_noOfSearchesCompleted; + m_noOfSearchesCompleted = 0; + m_noOfCurrentlySearches = 0; + + if (bwOnlineSearch.IsBusy) + { + Thread.Sleep(2000); + } + List<string> sitesToSearch = new List<string>(); using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) @@ -265,26 +328,21 @@ m_EventStopThread = new ManualResetEvent(false); // If automaticUpdate is set then return after the first positive search - lc = new LyricsController(this, m_EventStopThread, (string[])sitesToSearch.ToArray(), false, false, m_find, m_replace); - m_noOfSearchesToComplete = songs.Count; + m_lc = new LyricsController(this, m_EventStopThread, (string[])sitesToSearch.ToArray(), false, false, m_find, m_replace); - lc.NoOfLyricsToSearch = m_noOfSearchesToComplete; + m_lc.NoOfLyricsToSearch = m_noOfSearchesToComplete; ThreadStart job = delegate { - lc.Run(); + m_lc.Run(); }; m_LyricControllerThread = new Thread(job); m_LyricControllerThread.Start(); - lc.StopSearches = false; + m_lc.StopSearches = false; - m_noOfCurrentlySearches = 0; - m_noOfSearchesCompleted = 0; - counter = 0; - - bw.RunWorkerAsync(); + bwOnlineSearch.RunWorkerAsync(); } private void btSelectAll2_Click(object sender, EventArgs e) @@ -322,7 +380,7 @@ foreach (ListViewItem lvi in lvSongs.Items) { - if (lvi.SubItems[1].Text.Equals("LyricsDB")) + if (lvi.SubItems[1].Text.Equals("LyricsDB")) { ++lyricsInLyricDB; } @@ -469,11 +527,14 @@ DatabaseUtil.WriteToLyricsDatabase(MyLyricsSettings.LyricsDB, MyLyricsSettings.LyricsMarkedDB, capArtist, capTitle, lyricStrings, site); DatabaseUtil.SerializeLyricDB(); - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) + if (!site.Equals("music tag")) { - if (xmlreader.GetValueAsBool("myLyrics", "automaticWriteToMusicTag", true)) + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) { - TagReaderUtil.WriteLyrics(capArtist, capTitle, lyricStrings); + if (xmlreader.GetValueAsBool("myLyrics", "automaticWriteToMusicTag", true)) + { + TagReaderUtil.WriteLyrics(capArtist, capTitle, lyricStrings); + } } } @@ -540,7 +601,7 @@ { if (m_lockButtons == false) { - ((MyLyricsSetup)parent).btClose.Enabled = !((MyLyricsSetup)parent).btClose.Enabled; + ((MyLyricsSetup)m_Parent).btClose.Enabled = !((MyLyricsSetup)m_Parent).btClose.Enabled; btSearch.Enabled = !btSearch.Enabled; btCancel.Enabled = !btCancel.Enabled; btAdd.Enabled = !btAdd.Enabled; @@ -556,22 +617,27 @@ private void bw_DoWork(object sender, DoWorkEventArgs e) { - while (songs.Count != 0) + while (m_Songs.Count != 0) { - if (lc == null) + if (m_lc == null) return; - if (bw.CancellationPending) + if (bwOnlineSearch.CancellationPending) { return; } - if (m_noOfCurrentlySearches < NO_OF_SEARCHES_ALLOWED && lc.StopSearches == false) + if (m_noOfCurrentlySearches < m_NO_OF_SEARCHES_ALLOWED && m_lc.StopSearches == false) { m_noOfCurrentlySearches += 1; - string[] lyricID = (string[])songs.Dequeue(); - bw.ReportProgress(counter++); - lc.AddNewLyricSearch(lyricID[0], lyricID[1], MediaPortalUtil.GetStrippedPrefixArtist(lyricID[0], m_strippedPrefixStrings)); + string[] lyricID = (string[])m_Songs.Dequeue(); + string artist = lyricID[0]; + string title = lyricID[1]; + int rowNumberInListView = int.Parse(lyricID[2]); + + bwOnlineSearch.ReportProgress(rowNumberInListView); + + m_lc.AddNewLyricSearch(artist, title, MediaPortalUtil.GetStrippedPrefixArtist(artist, m_strippedPrefixStrings)); } Thread.Sleep(200); @@ -579,6 +645,24 @@ } + private bool LyricFoundInMusicTag(string artist, string title) + { + Song song = new Song(); + + m_mDB.GetSongByMusicTagInfo(artist, string.Empty, title, true, ref song); + + MusicTag tag = TagReader.ReadTag(song.FileName); + if (tag != null && tag.Lyrics != string.Empty) + { + LyricFound = new Object[] { tag.Lyrics, artist, title, "music tag" }; + return true; + } + else + { + return false; + } + } + private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { lvSelectedSongs.Items[e.ProgressPercentage].SubItems[2].Text = "-"; @@ -591,40 +675,15 @@ } - private void btAddAll_Click(object sender, EventArgs e) + + private void btRemoveAll_Click(object sender, EventArgs e) { - foreach (ListViewItem lvi in lvSongs.Items) - { - if (lvi.ImageIndex == -1) - { - ListViewItem newLvi = new ListViewItem(selectedArtist); - - foreach (ListViewItem.ListViewSubItem lvsi in lvi.SubItems) - { - newLvi.SubItems.Add(lvsi); - } - - newLvi.ImageIndex = lvi.ImageIndex; - - lvSelectedSongs.Items.Add(newLvi); - } - } - - if (lvSelectedSongs.Items.Count > 0) - { - btSearch.Enabled = true; - btRemove.Enabled = true; - lvSelectedSongs.Sort(); - - } + ClearSelectedSongs(); } - private void btRemoveAll_Click(object sender, EventArgs e) + public void ClearSelectedSongs() { - foreach (ListViewItem lvi in lvSelectedSongs.Items) - { - lvSelectedSongs.Items.Remove(lvi); - } + lvSelectedSongs.Items.Clear(); if (lvSelectedSongs.Items.Count == 0) { @@ -635,19 +694,20 @@ private void btCancel_Click(object sender, EventArgs e) { - if (lc != null) + if (m_lc != null) { - lc.FinishThread(selectedArtist, string.Empty, "The search has been cancelled by the user.", "none"); - lc.Dispose(); - lc = null; + m_lc.FinishThread(m_SelectedArtist, string.Empty, "The search has been cancelled by the user.", "none"); + m_lc.Dispose(); + m_lc = null; } - else + else if (m_EventStopThread != null) { m_EventStopThread.Set(); - ThreadFinishedMethod(selectedArtist, string.Empty, "The search has been cancelled by the user.", "none"); + ThreadFinishedMethod(m_SelectedArtist, string.Empty, "The search has been cancelled by the user.", "none"); } - bw.CancelAsync(); + bwMusicTagSearch.CancelAsync(); + bwOnlineSearch.CancelAsync(); ChangeButtonsEnableState(); m_lockButtons = true; Thread.Sleep(500); @@ -655,5 +715,68 @@ RefreshArtistStats(); ChangeSearchingSubItemsToCancelled(); } + + + private void bwMusicTagSearch_DoWork(object sender, DoWorkEventArgs e) + { + Queue<string[]> m_SongsToSearchOnline = new Queue<string[]>(); + int rowNumberInListView = 0; + + foreach (string[] song in m_Songs) + { + if (bwMusicTagSearch.CancellationPending) + { + return; + } + + if (!LyricFoundInMusicTag(song[0], song[1])) + { + m_SongsToSearchOnline.Enqueue(new string[3] { song[0], song[1], rowNumberInListView.ToString() }); + } + else + { + bwMusicTagSearch.ReportProgress(rowNumberInListView); + } + + ++rowNumberInListView; + } + + m_Songs = m_SongsToSearchOnline; + } + + private void bwMusicTagSearch_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + lvSelectedSongs.Items[e.ProgressPercentage].SubItems[2].Text = "LyricsDB"; + lvSelectedSongs.Items[e.ProgressPercentage].SubItems[3].Text = "OK"; + lvSelectedSongs.Items[e.ProgressPercentage].EnsureVisible(); + } + + private void bwMusicTagSearch_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + // If all found in music tags, then no need for online search + if (m_noOfSearchesCompleted == m_noOfSearchesToComplete) + { + return; + } + + SearchOnline(); + } + + private void btSearch_Click(object sender, EventArgs e) + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) + { + if (xmlreader.GetValueAsBool("myLyrics", "automaticReadFromToMusicTag", true)) + { + Search_Init(); + SearchMusicTags(); + } + else + { + Search_Init(); + SearchOnline(); + } + } + } } } \ No newline at end of file Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.resx =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.resx 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MusicDatabaseBrowse.resx 2008-12-22 15:44:17 UTC (rev 2456) @@ -118,7 +118,7 @@ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <metadata name="imageList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>83, 17</value> + <value>291, 17</value> </metadata> <data name="imageList.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64"> <value> @@ -160,7 +160,10 @@ BwABfwcAAX8GAAEYAX8GAAE4AT8GAAH8AT8GAAH8AR8GAAH+AR8GAAH+AT8GAAH/AX8GAAs= </value> </data> - <metadata name="bw.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>17, 17</value> + <metadata name="bwOnlineSearch.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>164, 17</value> </metadata> + <metadata name="bwMusicTagSearch.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>15, 16</value> + </metadata> </root> \ No newline at end of file Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.Designer.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.Designer.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.Designer.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -75,7 +75,8 @@ this.lbLyricsFound = new MediaPortal.UserInterface.Controls.MPLabel(); this.tabPageSetup = new MediaPortal.UserInterface.Controls.MPTabPage(); this.gbTag = new MediaPortal.UserInterface.Controls.MPGroupBox(); - this.cbMusicTag = new MediaPortal.UserInterface.Controls.MPCheckBox(); + this.cbMusicTagAlwaysCheck = new MediaPortal.UserInterface.Controls.MPCheckBox(); + this.cbMusicTagWrite = new MediaPortal.UserInterface.Controls.MPCheckBox(); this.mpGroupBox3 = new MediaPortal.UserInterface.Controls.MPGroupBox(); this.cbAutomaticUpdate = new MediaPortal.UserInterface.Controls.MPCheckBox(); this.cbMoveSongFrom = new MediaPortal.UserInterface.Controls.MPCheckBox(); @@ -609,36 +610,51 @@ // // gbTag // - this.gbTag.Controls.Add(this.cbMusicTag); + this.gbTag.Controls.Add(this.cbMusicTagAlwaysCheck); + this.gbTag.Controls.Add(this.cbMusicTagWrite); this.gbTag.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.gbTag.Location = new System.Drawing.Point(4, 265); this.gbTag.Name = "gbTag"; - this.gbTag.Size = new System.Drawing.Size(538, 49); + this.gbTag.Size = new System.Drawing.Size(538, 66); this.gbTag.TabIndex = 31; this.gbTag.TabStop = false; this.gbTag.Text = "Music tags"; // - // cbMusicTag + // cbMusicTagAlwaysCheck // - this.cbMusicTag.AutoSize = true; - this.cbMusicTag.Checked = true; - this.cbMusicTag.CheckState = System.Windows.Forms.CheckState.Checked; - this.cbMusicTag.FlatStyle = System.Windows.Forms.FlatStyle.Popup; - this.cbMusicTag.Location = new System.Drawing.Point(16, 23); - this.cbMusicTag.Name = "cbMusicTag"; - this.cbMusicTag.Size = new System.Drawing.Size(203, 17); - this.cbMusicTag.TabIndex = 6; - this.cbMusicTag.Text = "Write newly found lyrics into music tag"; - this.cbMusicTag.UseVisualStyleBackColor = true; - this.cbMusicTag.Leave += new System.EventHandler(this.WriteMediaPortalXML); + this.cbMusicTagAlwaysCheck.AutoSize = true; + this.cbMusicTagAlwaysCheck.Checked = true; + this.cbMusicTagAlwaysCheck.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbMusicTagAlwaysCheck.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.cbMusicTagAlwaysCheck.Location = new System.Drawing.Point(17, 20); + this.cbMusicTagAlwaysCheck.Name = "cbMusicTagAlwaysCheck"; + this.cbMusicTagAlwaysCheck.Size = new System.Drawing.Size(278, 17); + this.cbMusicTagAlwaysCheck.TabIndex = 7; + this.cbMusicTagAlwaysCheck.Text = "Always check music tag for lyrics before online search"; + this.cbMusicTagAlwaysCheck.UseVisualStyleBackColor = true; + this.cbMusicTagAlwaysCheck.Leave += new System.EventHandler(this.WriteMediaPortalXML); // + // cbMusicTagWrite + // + this.cbMusicTagWrite.AutoSize = true; + this.cbMusicTagWrite.Checked = true; + this.cbMusicTagWrite.CheckState = System.Windows.Forms.CheckState.Checked; + this.cbMusicTagWrite.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.cbMusicTagWrite.Location = new System.Drawing.Point(17, 43); + this.cbMusicTagWrite.Name = "cbMusicTagWrite"; + this.cbMusicTagWrite.Size = new System.Drawing.Size(203, 17); + this.cbMusicTagWrite.TabIndex = 6; + this.cbMusicTagWrite.Text = "Write newly found lyrics into music tag"; + this.cbMusicTagWrite.UseVisualStyleBackColor = true; + this.cbMusicTagWrite.Leave += new System.EventHandler(this.WriteMediaPortalXML); + // // mpGroupBox3 // this.mpGroupBox3.Controls.Add(this.cbAutomaticUpdate); this.mpGroupBox3.Controls.Add(this.cbMoveSongFrom); this.mpGroupBox3.Controls.Add(this.cbAutoFetch); this.mpGroupBox3.FlatStyle = System.Windows.Forms.FlatStyle.Popup; - this.mpGroupBox3.Location = new System.Drawing.Point(5, 320); + this.mpGroupBox3.Location = new System.Drawing.Point(5, 337); this.mpGroupBox3.Name = "mpGroupBox3"; this.mpGroupBox3.Size = new System.Drawing.Size(538, 92); this.mpGroupBox3.TabIndex = 30; @@ -1088,7 +1104,6 @@ private MediaPortal.UserInterface.Controls.MPLabel lbSongsLimit; private MediaPortal.UserInterface.Controls.MPLabel lbSongsLimitNote; private MediaPortal.UserInterface.Controls.MPCheckBox cbSearchOnlyForMarkedSongs; - private MediaPortal.UserInterface.Controls.MPCheckBox cbDisregardSongWithLyricInTag; private MediaPortal.UserInterface.Controls.MPCheckBox cbDisregardVariousArtist; private MediaPortal.UserInterface.Controls.MPCheckBox cbDisregardSongsWithNoLyric; private MediaPortal.UserInterface.Controls.MPCheckBox cbMarkSongsWithNoLyrics; @@ -1101,7 +1116,7 @@ public MediaPortal.UserInterface.Controls.MPButton btClose; private System.Windows.Forms.TabPage tabPageAbout; private MediaPortal.UserInterface.Controls.MPGroupBox gbTag; - internal MediaPortal.UserInterface.Controls.MPCheckBox cbMusicTag; + internal MediaPortal.UserInterface.Controls.MPCheckBox cbMusicTagWrite; internal MediaPortal.UserInterface.Controls.MPCheckBox cbActionext; private System.Windows.Forms.TabPage tabPageReplace; private System.Windows.Forms.DataGridView dbGridView; @@ -1109,5 +1124,7 @@ private System.Windows.Forms.DataGridViewTextBoxColumn Replace; private MediaPortal.UserInterface.Controls.MPGroupBox mpGroupBox4; private MediaPortal.UserInterface.Controls.MPLabel lbArtist; + internal MediaPortal.UserInterface.Controls.MPCheckBox cbMusicTagAlwaysCheck; + private MediaPortal.UserInterface.Controls.MPCheckBox cbDisregardSongWithLyricInTag; } } \ No newline at end of file Modified: trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.cs =================================================================== --- trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.cs 2008-12-22 10:36:47 UTC (rev 2455) +++ trunk/plugins/MyLyrics/My Lyrics/MyLyrics Configuration/MyLyricsSetup.cs 2008-12-22 15:44:17 UTC (rev 2456) @@ -80,6 +80,7 @@ bool m_SearchOnlyMarkedSongs = false; bool m_automaticWriteToMusicTag = true; + bool m_automaticReadFromToMusicTag = true; string[] m_strippedPrefixStrings; @@ -103,10 +104,6 @@ System.Windows.Forms.Timer timer; StopWatch stopwatch = new StopWatch(); - // log information - private string log; - private string logFullFileName = ""; - private int lastShownLyricsTitles = 0; private int lastShownMarkedLyricsTitles = 0; @@ -114,11 +111,12 @@ public static bool UpdateLibraryUI = false; + MusicDatabase mDB = null; + public MyLyricsSetup() { - LyricDiagnostics.OpenLog(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Log, MyLyricsSettings.LogName)); - //LyricDiagnostics.OpenLog(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Log)); + //LyricDiagnostics.OpenLog(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Log, MyLyricsSettings.LogName)); #region Initialize GUI and class InitializeComponent(); @@ -150,7 +148,7 @@ //} m_TotalTitles = mDB.GetTotalSongs(); - + #endregion #region Get settings from in MediaPortal.xml @@ -164,9 +162,13 @@ cbAutoFetch.Checked = xmlreader.GetValue("myLyrics", "automaticFetch").Equals("yes"); cbAutomaticUpdate.Checked = xmlreader.GetValue("myLyrics", "automaticUpdateWhenFirstFound").Equals("yes"); cbMoveSongFrom.Checked = xmlreader.GetValue("myLyrics", "moveLyricFromMarkedDatabase").Equals("yes"); + m_automaticWriteToMusicTag = !xmlreader.GetValue("myLyrics", "automaticWriteToMusicTag").Equals("no"); - cbMusicTag.Checked = m_automaticWriteToMusicTag; + cbMusicTagWrite.Checked = m_automaticWriteToMusicTag; + m_automaticReadFromToMusicTag = !xmlreader.GetValue("myLyrics", "automaticReadFromToMusicTag").Equals("no"); + cbMusicTagAlwaysCheck.Checked = m_automaticReadFromToMusicTag; + lbSongsLimitNote.Text = ("(You have currently " + m_TotalTitles.ToString() + " titles in your music database)"); trackBar.Value = ((int)xmlreader.GetValueAsInt("myLyrics", "defaultSitesModeValue", 2)); @@ -191,7 +193,7 @@ DataGridViewRow row = dbGridView.Rows[valueIndex]; row.Cells[0].Value = findValue; row.Cells[1].Value = replaceArray[valueIndex]; - valueIndex++; + valueIndex++; } } } @@ -209,8 +211,9 @@ cbHotLyrics.Checked = ((string)xmlreader.GetValueAsString("myLyrics", "useHotLyrics", "True")).ToString().Equals("True") ? true : false; } } - catch (Exception ex) { - + catch (Exception ex) + { + MessageBox.Show("Something has gone wrong when reading Mediaportal.xml (" + ex.Message + ")"); } } @@ -329,7 +332,7 @@ // 100, // true)) //{ - //break; + //break; //} Application.DoEvents(); @@ -402,22 +405,6 @@ btStartBatchSearch.Enabled = false; - logFullFileName = Config.GetFile(Config.Dir.Log, MyLyricsSettings.LogBatchFileName); - - //if file is not found, create a new xml file - if (!System.IO.File.Exists(logFullFileName)) - { - FileStream file = new FileStream(logFullFileName, FileMode.OpenOrCreate, FileAccess.Write); - file.Close(); - StreamReader sr = File.OpenText(logFullFileName); - log = sr.ReadToEnd(); - sr.Close(); - log += DateTime.Now.ToString() + " The log has been created.\r\n"; - System.IO.StreamWriter writerLog = new System.IO.StreamWriter(logFullFileName); - writerLog.Write(log); - writerLog.Close(); - } - m_Limit = int.Parse(tbLimit.Text); m_DisregardKnownLyric = cbDisconsiderTitlesWithLyrics.Enabled && cbDisconsiderTitlesWithLyrics.Checked; @@ -488,7 +475,7 @@ m_LyricText = lyricStrings; m_artist = artist; m_track = track; - + --m_SongsToSearch; lbSongsToSearch2.Text = m_SongsToSearch.ToString(); @@ -503,20 +490,12 @@ DatabaseUtil.WriteToLyricsDatabase(MyLyricsSettings.LyricsDB, MyLyricsSettings.LyricsMarkedDB, capArtist, capTitle, lyricStrings, site); - if (m_automaticWriteToMusicTag) + if (!site.Equals("music tag") && m_automaticWriteToMusicTag) { TagReaderUtil.WriteLyrics(capArtist, capTitle, lyricStrings); } - StreamReader sr = File.OpenText(logFullFileName); - log = sr.ReadToEnd(); - sr.Close(); - string logText = capArtist + " - " + capTitle + " has a match at " + site + ".\r\n"; - log += DateTime.Now.ToString() + " " + logText; - lbLastActivity2.Text = logText; - System.IO.StreamWriter writerLog = new System.IO.StreamWriter(logFullFileName); - writerL... [truncated message content] |