|
From: <sa...@us...> - 2007-03-11 20:43:21
|
Revision: 183
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=183&view=rev
Author: saamand
Date: 2007-03-11 13:43:19 -0700 (Sun, 11 Mar 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/plugins/MyLyrics/LyricsEngine/LyricSearch.cs
trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj
trunk/plugins/MyLyrics/My Lyrics/MyLyrics.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_test.cs
trunk/plugins/MyLyrics/My Lyrics/MyLyricsUtil.cs
trunk/plugins/MyLyrics/MyLyric Windows Application/MyLyric Windows Application/LyricsEngine Tester.cs
Added Paths:
-----------
trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs
trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/
trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsDatabase.cs
trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsItem.cs
trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/
trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/EvilLabs.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/LyricsEngine/LyricsSites/Wiki.cs
trunk/plugins/MyLyrics/MyLyrics.sln
Removed Paths:
-------------
trunk/plugins/MyLyrics/LRC/
trunk/plugins/MyLyrics/LyricWiki/
trunk/plugins/MyLyrics/LyricsEngine/LyricController.cs
Deleted: trunk/plugins/MyLyrics/LyricsEngine/LyricController.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricController.cs 2007-03-11 15:18:13 UTC (rev 182)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricController.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -1,305 +0,0 @@
-using System;
-using System.Drawing;
-using System.Collections;
-using System.ComponentModel;
-using System.Windows.Forms;
-using System.Data;
-using System.Threading;
-using System.IO;
-using System.Diagnostics;
-using LyricsEngineConfig;
-using LyricsEngine;
-
-namespace LyricsEngine
-{
-
- #region Public Delegates
- // delegates used to call MainForm functions from worker thread
- public delegate void Delegate_LC_updateString(String s);
- public delegate void Delegate_LC_UpdateStatus(Boolean b1);
- public delegate void Delegate_LC_ErrorLog_LyricNotFound(String s);
- public delegate void Delegate_LC_WriteFoundLyric(String[] s, String artist, String track);
- public delegate void Delegate_LC_ThreadFinished();
- #endregion
-
- public class LyricController : IDisposable
- {
- private ILyricForm m_Form;
-
- // status
- private static int noOfLyricsToSearch;
- private static int noOfLyricsSearched;
- private static int noOfLyricsFound;
- private static int noOfLyricsNotFound;
-
- private bool m_StopSearches = false;
- public static event EventHandler StopTheSearchAndAbort = null;
-
- ArrayList threadList = new ArrayList();
- ArrayList suspendedThreadList = new ArrayList();
-
-
- // Main thread sets this event to stop LyricController
- ManualResetEvent m_EventStop_LyricController;
- // LyricController sets this event when it is stopped
- ManualResetEvent m_EventStopped_LyricController;
- // Main thread sets this event to pause all LyricSearches
- public ManualResetEvent m_EventStop_LyricSearches;
-
- // Variables related to GoogleSites
- private ArrayList m_GoogleLicenseKeysUsed = new ArrayList();
- private string m_GoogleLicenseKey = "";
- private bool m_noMoreValidLicenseKeys = false;
- int m_managedThreadId = -1;
-
- // Lyric sites
- private string[] lyricSites;
- private string[] eastSites;
-
- public LyricController(ILyricForm mainForm,
- ManualResetEvent eventStopThread, ManualResetEvent eventThreadStopped,
- string[] lyricSites)
- {
- this.m_Form = mainForm;
-
- LyricController.noOfLyricsToSearch = 1;
- LyricController.noOfLyricsSearched = 0;
- LyricController.noOfLyricsFound = 0;
- LyricController.noOfLyricsNotFound = 0;
-
- this.lyricSites = lyricSites;
-
- ArrayList easySitesArrayList = new ArrayList();
-
- foreach (string site in lyricSites)
- {
- if (Setup.IsMemberOfEasySites(site))
- {
- easySitesArrayList.Add(site);
- }
- }
- eastSites = (string[])easySitesArrayList.ToArray(typeof(string));
- LyricSearch.EasySites = eastSites;
-
- // initialize events
- m_EventStop_LyricController = eventStopThread;
- m_EventStopped_LyricController = eventThreadStopped;
-
- m_EventStop_LyricSearches = new ManualResetEvent(false);
- m_EventStop_LyricSearches.Set();
-
- LyricSearch.Abort = false;
- }
-
-
- public void Run()
- {
- // check if thread is cancelled
- while (true)
- {
- Thread.Sleep(500);
-
- // check if thread is cancelled
- if (m_EventStop_LyricController.WaitOne(0, true))
- {
- // clean-up operations may be placed here
- for (int i=0; i<threadList.Count; i++)
- {
- ((Thread)threadList[i]).Abort();
- }
-
- bool stillThreadsAlive = true;
- while (stillThreadsAlive)
- {
- for (int i = 0; i < threadList.Count; i++)
- {
- stillThreadsAlive = false; ;
- if (((Thread)threadList[i]).IsAlive)
- stillThreadsAlive = true;
- }
- }
-
- Thread.Sleep(500);
- m_EventStopped_LyricController.Set();
- break;
- }
- }
- }
-
-
- public void Dispose()
- {
- // clean-up operations may be placed here
- for (int i = 0; i < threadList.Count; i++)
- {
- ((Thread)threadList[i]).Abort();
- }
-
- bool stillThreadsAlive = true;
- while (stillThreadsAlive)
- {
- for (int i = 0; i < threadList.Count; i++)
- {
- stillThreadsAlive = false; ;
- if (((Thread)threadList[i]).IsAlive)
- stillThreadsAlive = true;
- }
- }
-
- Thread.Sleep(500);
-
- // inform main thread that this thread stopped
- m_EventStopped_LyricController.Set();
- finishThread("", "", "The search has ended.", "");
- }
-
- public void updateManualResetEvents(ManualResetEvent eventStopThread, ManualResetEvent eventThreadStopped)
- {
- this.m_EventStop_LyricController = eventStopThread;
- this.m_EventStopped_LyricController = eventThreadStopped;
- }
-
- public void addNewLyricSearch(string artist, string title)
- {
- if (eastSites.Length > 0)
- {
- // create worker thread instance
- ThreadStart easySitesThreadInstance = delegate
- {
-
- LyricSearch lyricSearch_EasySites = new LyricSearch(m_EventStop_LyricController, m_EventStopped_LyricController, this);
- lyricSearch_EasySites.setLyricInfo(artist, title);
- lyricSearch_EasySites.Run();
- };
-
- Thread lyricSearchThread = new Thread(easySitesThreadInstance);
- lyricSearchThread.Name = "BasicSearch for " + artist + " - " + title; // looks nice in Output window
- lyricSearchThread.IsBackground = true;
- lyricSearchThread.Start();
- threadList.Add(lyricSearchThread);
- }
- }
-
- public void suspendAllSearchThreadsExceptMe(int managedThreadId)
- {
- //// clean-up operations may be placed here
- //for (int i = 0; i < threadList.Count; i++)
- //{
- // if (((Thread)threadList[i]).ManagedThreadId != managedThreadId)
- // ((Thread)threadList[i]).Suspend();
- //}
-
- m_managedThreadId = managedThreadId;
- m_EventStop_LyricSearches.Reset();
- }
-
- public void resumeAllSearchThreads()
- {
- m_EventStop_LyricSearches.Reset();
- }
-
- internal void updateString(String message, String site)
- {
- m_Form.UpdateString = new Object[] { message, site };
- }
-
- internal void statusUpdate(string artist, string title, string site, bool lyricFound)
- {
- //LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + artist + " - " + title + " - " + site + " - " +lyricFound.ToString() );
- if (lyricFound)
- ++noOfLyricsFound;
- else
- ++noOfLyricsNotFound;
-
- ++noOfLyricsSearched;
-
- m_Form.UpdateStatus = new Object[] { noOfLyricsToSearch, noOfLyricsSearched, noOfLyricsFound, noOfLyricsNotFound };
-
- if (noOfLyricsSearched >= noOfLyricsToSearch)
- {
- finishThread(artist, title, "All songs have been searched!", site);
- }
- }
-
-
- internal void lyricFound(String lyricStrings, String artist, String title, String site)
- {
- if (m_StopSearches == false)
- {
- m_Form.LyricFound = new Object[] { lyricStrings, artist, title, site };
- statusUpdate(artist, title, site, true);
- }
- }
-
- internal void lyricNotFound(String artist, String title, String message, String site)
- {
- if (m_StopSearches == false)
- {
- m_Form.LyricNotFound = new Object[] { artist, title, message, site };
- statusUpdate(artist, title, site, false);
- }
- }
-
- public void finishThread(String artist, String title, String message, String site)
- {
- m_EventStop_LyricController.Set();
- m_EventStopped_LyricController.Set();
- m_Form.ThreadFinished = new Object[] { artist, title, message, site };
- }
-
- internal void ThreadException(String s)
- {
- m_Form.ThreadException = s;
- }
-
- public string GoogleLicenseKey
- {
- get { return m_GoogleLicenseKey; }
- set { m_GoogleLicenseKey = value; }
- }
-
- public bool StopSearches
- {
- get { return m_StopSearches; }
- set {
- if (value == true)
- {
- m_StopSearches = true;
- m_EventStop_LyricSearches.Reset();
- LyricSearch.Abort = true;
- //StopTheSearchAndAbort.Invoke(this, EventArgs.Empty);
- }
- else
- {
- m_StopSearches = false;
- m_EventStop_LyricSearches.Set();
- LyricSearch.Abort = false;
- }
- }
- }
-
- public ArrayList GoogleLicenseKeysUsed
- {
- get { return m_GoogleLicenseKeysUsed; }
- }
-
- public void addToGoogleLicenseKeysUsed(string key)
- {
- if (!m_GoogleLicenseKeysUsed.Contains(key))
- {
- m_GoogleLicenseKeysUsed.Add(key);
- }
- }
-
- public int NoOfLyricsToSearch
- {
- set { LyricController.noOfLyricsToSearch = value; }
- }
-
- public bool NoMoreValidLicenseKeys
- {
- get { return m_noMoreValidLicenseKeys; }
- set { m_noMoreValidLicenseKeys = value; }
- }
- }
-}
Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricSearch.cs
===================================================================
(Binary files differ)
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsController.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,305 @@
+using System;
+using System.Drawing;
+using System.Collections;
+using System.ComponentModel;
+using System.Windows.Forms;
+using System.Data;
+using System.Threading;
+using System.IO;
+using System.Diagnostics;
+using LyricsEngineConfig;
+using LyricsEngine;
+
+namespace LyricsEngine
+{
+
+ #region Public Delegates
+ // delegates used to call MainForm functions from worker thread
+ public delegate void Delegate_LC_updateString(String s);
+ public delegate void Delegate_LC_UpdateStatus(Boolean b1);
+ public delegate void Delegate_LC_ErrorLog_LyricNotFound(String s);
+ public delegate void Delegate_LC_WriteFoundLyric(String[] s, String artist, String track);
+ public delegate void Delegate_LC_ThreadFinished();
+ #endregion
+
+ public class LyricsController : IDisposable
+ {
+ private ILyricForm m_Form;
+
+ // status
+ private static int noOfLyricsToSearch;
+ private static int noOfLyricsSearched;
+ private static int noOfLyricsFound;
+ private static int noOfLyricsNotFound;
+
+ private bool m_StopSearches = false;
+ public static event EventHandler StopTheSearchAndAbort = null;
+
+ ArrayList threadList = new ArrayList();
+ ArrayList suspendedThreadList = new ArrayList();
+
+
+ // Main thread sets this event to stop LyricController
+ ManualResetEvent m_EventStop_LyricController;
+ // LyricController sets this event when it is stopped
+ ManualResetEvent m_EventStopped_LyricController;
+ // Main thread sets this event to pause all LyricSearches
+ public ManualResetEvent m_EventStop_LyricSearches;
+
+ // Variables related to GoogleSites
+ private ArrayList m_GoogleLicenseKeysUsed = new ArrayList();
+ private string m_GoogleLicenseKey = "";
+ private bool m_noMoreValidLicenseKeys = false;
+ int m_managedThreadId = -1;
+
+ // Lyric sites
+ private string[] lyricSites;
+ private string[] eastSites;
+
+ public LyricsController(ILyricForm mainForm,
+ ManualResetEvent eventStopThread, ManualResetEvent eventThreadStopped,
+ string[] lyricSites)
+ {
+ this.m_Form = mainForm;
+
+ LyricsController.noOfLyricsToSearch = 1;
+ LyricsController.noOfLyricsSearched = 0;
+ LyricsController.noOfLyricsFound = 0;
+ LyricsController.noOfLyricsNotFound = 0;
+
+ this.lyricSites = lyricSites;
+
+ ArrayList easySitesArrayList = new ArrayList();
+
+ foreach (string site in lyricSites)
+ {
+ if (Setup.IsMemberOfEasySites(site))
+ {
+ easySitesArrayList.Add(site);
+ }
+ }
+ eastSites = (string[])easySitesArrayList.ToArray(typeof(string));
+ LyricSearch.EasySites = eastSites;
+
+ // initialize events
+ m_EventStop_LyricController = eventStopThread;
+ m_EventStopped_LyricController = eventThreadStopped;
+
+ m_EventStop_LyricSearches = new ManualResetEvent(false);
+ m_EventStop_LyricSearches.Set();
+
+ LyricSearch.Abort = false;
+ }
+
+
+ public void Run()
+ {
+ // check if thread is cancelled
+ while (true)
+ {
+ Thread.Sleep(500);
+
+ // check if thread is cancelled
+ if (m_EventStop_LyricController.WaitOne(0, true))
+ {
+ // clean-up operations may be placed here
+ for (int i=0; i<threadList.Count; i++)
+ {
+ ((Thread)threadList[i]).Abort();
+ }
+
+ bool stillThreadsAlive = true;
+ while (stillThreadsAlive)
+ {
+ for (int i = 0; i < threadList.Count; i++)
+ {
+ stillThreadsAlive = false; ;
+ if (((Thread)threadList[i]).IsAlive)
+ stillThreadsAlive = true;
+ }
+ }
+
+ Thread.Sleep(500);
+ m_EventStopped_LyricController.Set();
+ break;
+ }
+ }
+ }
+
+
+ public void Dispose()
+ {
+ // clean-up operations may be placed here
+ for (int i = 0; i < threadList.Count; i++)
+ {
+ ((Thread)threadList[i]).Abort();
+ }
+
+ bool stillThreadsAlive = true;
+ while (stillThreadsAlive)
+ {
+ for (int i = 0; i < threadList.Count; i++)
+ {
+ stillThreadsAlive = false; ;
+ if (((Thread)threadList[i]).IsAlive)
+ stillThreadsAlive = true;
+ }
+ }
+
+ Thread.Sleep(500);
+
+ // inform main thread that this thread stopped
+ m_EventStopped_LyricController.Set();
+ finishThread("", "", "The search has ended.", "");
+ }
+
+ public void updateManualResetEvents(ManualResetEvent eventStopThread, ManualResetEvent eventThreadStopped)
+ {
+ this.m_EventStop_LyricController = eventStopThread;
+ this.m_EventStopped_LyricController = eventThreadStopped;
+ }
+
+ public void addNewLyricSearch(string artist, string title)
+ {
+ if (eastSites.Length > 0)
+ {
+ // create worker thread instance
+ ThreadStart easySitesThreadInstance = delegate
+ {
+
+ LyricSearch lyricSearch_EasySites = new LyricSearch(m_EventStop_LyricController, m_EventStopped_LyricController, this);
+ lyricSearch_EasySites.setLyricInfo(artist, title);
+ lyricSearch_EasySites.Run();
+ };
+
+ Thread lyricSearchThread = new Thread(easySitesThreadInstance);
+ lyricSearchThread.Name = "BasicSearch for " + artist + " - " + title; // looks nice in Output window
+ lyricSearchThread.IsBackground = true;
+ lyricSearchThread.Start();
+ threadList.Add(lyricSearchThread);
+ }
+ }
+
+ public void suspendAllSearchThreadsExceptMe(int managedThreadId)
+ {
+ //// clean-up operations may be placed here
+ //for (int i = 0; i < threadList.Count; i++)
+ //{
+ // if (((Thread)threadList[i]).ManagedThreadId != managedThreadId)
+ // ((Thread)threadList[i]).Suspend();
+ //}
+
+ m_managedThreadId = managedThreadId;
+ m_EventStop_LyricSearches.Reset();
+ }
+
+ public void resumeAllSearchThreads()
+ {
+ m_EventStop_LyricSearches.Reset();
+ }
+
+ internal void updateString(String message, String site)
+ {
+ m_Form.UpdateString = new Object[] { message, site };
+ }
+
+ internal void statusUpdate(string artist, string title, string site, bool lyricFound)
+ {
+ //LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + artist + " - " + title + " - " + site + " - " +lyricFound.ToString() );
+ if (lyricFound)
+ ++noOfLyricsFound;
+ else
+ ++noOfLyricsNotFound;
+
+ ++noOfLyricsSearched;
+
+ m_Form.UpdateStatus = new Object[] { noOfLyricsToSearch, noOfLyricsSearched, noOfLyricsFound, noOfLyricsNotFound };
+
+ if (noOfLyricsSearched >= noOfLyricsToSearch)
+ {
+ finishThread(artist, title, "All songs have been searched!", site);
+ }
+ }
+
+
+ internal void lyricFound(String lyricStrings, String artist, String title, String site)
+ {
+ if (m_StopSearches == false)
+ {
+ m_Form.LyricFound = new Object[] { lyricStrings, artist, title, site };
+ statusUpdate(artist, title, site, true);
+ }
+ }
+
+ internal void lyricNotFound(String artist, String title, String message, String site)
+ {
+ if (m_StopSearches == false)
+ {
+ m_Form.LyricNotFound = new Object[] { artist, title, message, site };
+ statusUpdate(artist, title, site, false);
+ }
+ }
+
+ public void finishThread(String artist, String title, String message, String site)
+ {
+ m_EventStop_LyricController.Set();
+ m_EventStopped_LyricController.Set();
+ m_Form.ThreadFinished = new Object[] { artist, title, message, site };
+ }
+
+ internal void ThreadException(String s)
+ {
+ m_Form.ThreadException = s;
+ }
+
+ public string GoogleLicenseKey
+ {
+ get { return m_GoogleLicenseKey; }
+ set { m_GoogleLicenseKey = value; }
+ }
+
+ public bool StopSearches
+ {
+ get { return m_StopSearches; }
+ set {
+ if (value == true)
+ {
+ m_StopSearches = true;
+ m_EventStop_LyricSearches.Reset();
+ LyricSearch.Abort = true;
+ //StopTheSearchAndAbort.Invoke(this, EventArgs.Empty);
+ }
+ else
+ {
+ m_StopSearches = false;
+ m_EventStop_LyricSearches.Set();
+ LyricSearch.Abort = false;
+ }
+ }
+ }
+
+ public ArrayList GoogleLicenseKeysUsed
+ {
+ get { return m_GoogleLicenseKeysUsed; }
+ }
+
+ public void addToGoogleLicenseKeysUsed(string key)
+ {
+ if (!m_GoogleLicenseKeysUsed.Contains(key))
+ {
+ m_GoogleLicenseKeysUsed.Add(key);
+ }
+ }
+
+ public int NoOfLyricsToSearch
+ {
+ set { LyricsController.noOfLyricsToSearch = value; }
+ }
+
+ public bool NoMoreValidLicenseKeys
+ {
+ get { return m_noMoreValidLicenseKeys; }
+ set { m_noMoreValidLicenseKeys = value; }
+ }
+ }
+}
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsDatabase.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsDatabase.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsDatabase.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,154 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.Serialization;
+
+namespace MyLyrics
+{
+ [Serializable]
+ public class LyricsDatabase : IDictionary<string, LyricsItem>, ISerializable
+ {
+ private DateTime created;
+ private DateTime lastModified;
+
+ private Dictionary<string, LyricsItem> db;
+
+ public LyricsDatabase()
+ {
+ created = DateTime.Now;
+ lastModified = DateTime.Now;
+ db = new Dictionary<string, LyricsItem>();
+ }
+
+ #region Serialization methods
+ protected LyricsDatabase(SerializationInfo info, StreamingContext context)
+ {
+ Dictionary<string, LyricsItem> dbTemp = new Dictionary<string, LyricsItem>();
+ db = (Dictionary<string, LyricsItem>)info.GetValue("db", dbTemp.GetType());
+ created = info.GetDateTime("created");
+ lastModified = info.GetDateTime("lastModified");
+ }
+
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ info.AddValue("db", db);
+ info.AddValue("created", created);
+ info.AddValue("lastModified", lastModified);
+ }
+ #endregion
+
+ public void SetLastModified()
+ {
+ lastModified = DateTime.Now;
+ }
+
+ #region IDictionary<string,LyricsItem> Members
+
+ public void Add(string key, LyricsItem value)
+ {
+ db.Add(key, value);
+ }
+
+ public bool ContainsKey(string key)
+ {
+ return db.ContainsKey(key);
+ }
+
+ public ICollection<string> Keys
+ {
+ get { return db.Keys; }
+ }
+
+ public bool Remove(string key)
+ {
+ return db.Remove(key);
+ }
+
+ public bool TryGetValue(string key, out LyricsItem value)
+ {
+ return db.TryGetValue(key, out value);
+ }
+
+ public ICollection<LyricsItem> Values
+ {
+ get { return db.Values; }
+ }
+
+ public LyricsItem this[string key]
+ {
+ get
+ {
+ return db[key];
+ }
+ set
+ {
+ db[key] = value;
+ }
+ }
+
+ #endregion
+
+ #region ICollection<KeyValuePair<string,LyricsItem>> Members
+
+ public void Add(KeyValuePair<string, LyricsItem> item)
+ {
+ db.Add(item.Key, item.Value);
+ }
+
+ public void Clear()
+ {
+ db.Clear();
+ }
+
+ public bool Contains(KeyValuePair<string, LyricsItem> item)
+ {
+ return db.ContainsKey(item.Key);
+ }
+
+ public void CopyTo(KeyValuePair<string, LyricsItem>[] array, int arrayIndex)
+ {
+ throw new Exception("The method or operation is not implemented.");
+ }
+
+ public int Count
+ {
+ get { return db.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return false; }
+ }
+
+ public bool Remove(KeyValuePair<string, LyricsItem> item)
+ {
+ return db.Remove(item.Key);
+ }
+
+ #endregion
+
+ #region IEnumerable<KeyValuePair<string,LyricsItem>> Members
+
+ public IEnumerator<KeyValuePair<string, LyricsItem>> GetEnumerator()
+ {
+ foreach (KeyValuePair<string, LyricsItem> kvp in db)
+ {
+ yield return kvp;
+ }
+ }
+
+ #endregion
+
+ #region IEnumerable Members
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ foreach (KeyValuePair<string, LyricsItem> kvp in db)
+ {
+ yield return kvp;
+ }
+ }
+
+ #endregion
+ }
+}
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsItem.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsItem.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsDatabase/LyricsItem.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.Serialization;
+
+namespace MyLyrics
+{
+ [Serializable]
+ public class LyricsItem
+ {
+ private string artist;
+ private string title;
+ private string lyrics;
+ private string source;
+
+ public LyricsItem(string artist, string title, string lyrics, string source)
+ {
+ this.artist = artist;
+ this.title = title;
+ this.lyrics = lyrics;
+ this.source = source;
+ }
+
+ #region Properties
+ public string Artist
+ {
+ get { return artist; }
+ set { artist = value; }
+ }
+
+ public string Title
+ {
+ get { return title; }
+ set { title = value; }
+ }
+
+ public string Lyrics
+ {
+ get { return lyrics; }
+ set { lyrics = value; }
+ }
+
+ public string Source
+ {
+ get { return source; }
+ set { source = value; }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Modified: trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj 2007-03-11 15:18:13 UTC (rev 182)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsEngine.csproj 2007-03-11 20:43:19 UTC (rev 183)
@@ -40,17 +40,23 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="LRC\SimpleLRC.cs" />
+ <Compile Include="LRC\SimpleLRCFormat.cs" />
+ <Compile Include="LRC\SimpleLRCTimeAndLine.cs" />
+ <Compile Include="LRC\SimpleLRCTimeAndLineCollection.cs" />
+ <Compile Include="LyricsDatabase\LyricsDatabase.cs" />
+ <Compile Include="LyricsDatabase\LyricsItem.cs" />
<Compile Include="LyricSearch.cs" />
<Compile Include="LyricDiagnostics.cs" />
- <Compile Include="LyricSites\HotLyrics.cs" />
- <Compile Include="LyricSites\EvilLabs.cs" />
- <Compile Include="LyricSites\Lyrics007.cs" />
- <Compile Include="LyricSites\LyricsOnDemand.cs" />
- <Compile Include="LyricSites\SeekLyrics.cs" />
+ <Compile Include="LyricsSites\HotLyrics.cs" />
+ <Compile Include="LyricsSites\EvilLabs.cs" />
+ <Compile Include="LyricsSites\Lyrics007.cs" />
+ <Compile Include="LyricsSites\LyricsOnDemand.cs" />
+ <Compile Include="LyricsSites\SeekLyrics.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ICommand.cs" />
<Compile Include="ILyricForm.cs" />
- <Compile Include="LyricController.cs" />
+ <Compile Include="LyricsController.cs" />
<Compile Include="LyricSiteInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@@ -92,7 +98,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Reference.map</DependentUpon>
</Compile>
- <Compile Include="LyricSites\Wiki.cs" />
+ <Compile Include="LyricsSites\Wiki.cs" />
</ItemGroup>
<ItemGroup>
<WebReferences Include="Web References\" />
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/EvilLabs.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/EvilLabs.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/EvilLabs.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,96 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace LyricsEngine.LyricSites
+{
+ class EvilLabs
+ {
+ string lyric = "";
+ LyricSearch lyricSearch = null;
+
+ public string Lyric
+ {
+ get { return lyric; }
+ }
+
+ public EvilLabs(LyricSearch lyricSearch, string artist, string title)
+ {
+ this.lyricSearch = lyricSearch;
+ if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + "EvilLabs(" + artist + ", " + title + ")");
+ bool thisMayBeTheCorrectLyric = true;
+ System.Collections.ArrayList strLyric = new System.Collections.ArrayList();
+
+ string lyricTemp = "";
+
+ artist = LyricUtil.removeFeatComment(artist);
+ LyricUtil.trimForParenthesis(ref artist);
+ artist = artist.Replace(" ", "+");
+ title = LyricUtil.removeFeatComment(title);
+ LyricUtil.trimForParenthesis(ref title);
+ title = title.Replace(" ", "+");
+ string urlString = "http://www.evillabs.sk/lyrics/" + artist + "+-+" + title;
+
+ System.Net.WebClient client = new System.Net.WebClient();
+ System.Byte[] bytes = null;
+
+
+ try
+ {
+ bytes = client.DownloadData(urlString);
+ }
+ catch (System.Net.WebException)
+ {
+ //return false;
+ }
+ finally
+ {
+ client.Dispose();
+ }
+
+ int byteIndex = 0;
+ while (byteIndex < bytes.Length && lyricSearch.SearchHasEnded == false)
+ {
+ lyricTemp += System.Char.ConvertFromUtf32(bytes[byteIndex]);
+ ++byteIndex;
+ }
+
+ MemoryStream memoryStream = new MemoryStream(System.Text.Encoding.Default.GetBytes(lyricTemp));
+
+ if (memoryStream != null)
+ {
+ string line = "";
+ int noOfLinesCount = 0;
+
+ System.IO.StreamReader sr = new System.IO.StreamReader(memoryStream);
+
+ while (line.IndexOf("</style>") == -1)
+ {
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ if (thisMayBeTheCorrectLyric)
+ {
+ line = sr.ReadLine();
+ lyric = line.Replace("<br>", "\r\n").Trim();
+
+ // if warning message from Evil Labs' sql-server, then lyric isn't found
+ if (lyric.Contains("<b>Warning</b>"))
+ {
+ lyric = "Not found";
+ }
+ }
+ }
+ }
+ }
+}
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/HotLyrics.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,180 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace LyricsEngine.LyricSites
+{
+ class HotLyrics
+ {
+ string lyric = "";
+ LyricSearch lyricSearch = null;
+
+ public string Lyric
+ {
+ get { return lyric; }
+ }
+
+ public HotLyrics(LyricSearch lyricSearch, string artist, string title)
+ {
+ this.lyricSearch = lyricSearch;
+ if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + "SeekLyrics(" + artist + ", " + title + ")");
+ bool thisMayBeTheCorrectLyric = true;
+ System.Collections.ArrayList strLyric = new System.Collections.ArrayList();
+
+ StringBuilder lyricTemp = new StringBuilder();
+
+ artist = LyricUtil.removeFeatComment(artist);
+ LyricUtil.trimForParenthesis(ref artist);
+ artist = LyricUtil.capatalizeString(artist);
+
+ artist = artist.Replace(" ", "_");
+ artist = artist.Replace(",", "_");
+ artist = artist.Replace(".", "_");
+ artist = artist.Replace("'", "_");
+ artist = artist.Replace("(", "%28");
+ artist = artist.Replace(")", "%29");
+ artist = artist.Replace(",", "");
+ artist = artist.Replace("#", "");
+ artist = artist.Replace("%", "");
+ artist = artist.Replace("+", "%2B");
+ artist = artist.Replace("=", "%3D");
+ artist = artist.Replace("-", "_");
+
+ // German letters
+ artist = artist.Replace("\xFC", "%FC");
+ artist = artist.Replace("\xDC", "");
+ artist = artist.Replace("\xE4", "%E4");
+ artist = artist.Replace("\xC4", "");
+ artist = artist.Replace("\xF6", "%E4"); // Not correct!!!
+ artist = artist.Replace("\xD6", "");
+ artist = artist.Replace("\xDF", "%DF");
+
+ // French letters
+ artist = artist.Replace("\xE9", "%E9");
+
+ title = LyricUtil.removeFeatComment(title);
+ LyricUtil.trimForParenthesis(ref title);
+ title = LyricUtil.capatalizeString(title);
+
+ title = title.Replace(" ", "_");
+ title = title.Replace(",", "_");
+ title = title.Replace(".", "_");
+ title = title.Replace("'", "_");
+ title = title.Replace("(", "%28");
+ title = title.Replace(")", "%29");
+ title = title.Replace(",", "_");
+ title = title.Replace("#", "_");
+ title = title.Replace("%", "_");
+ title = title.Replace("?", "_");
+ title = title.Replace("+", "%2B");
+ title = title.Replace("=", "%3D");
+ title = title.Replace("-", "_");
+ title = title.Replace(":", "_");
+
+ // German letters
+ title = title.Replace("\xFC", "%FC");
+ title = title.Replace("\xDC", "");
+ title = title.Replace("\xE4", "%E4");
+ title = title.Replace("\xC4", "");
+ title = title.Replace("\xF6", "%E4"); // Not correct!!!
+ title = title.Replace("\xD6", "");
+ title = title.Replace("\xDF", "%DF");
+
+ // Danish letters
+ title = title.Replace("\xE5", "%E5");
+ title = title.Replace("\xC5", "%C5");
+ title = title.Replace("\xE6", "%E6");
+ title = title.Replace("\xF8", "%F8");
+
+ // French letters
+ title = title.Replace("\xE9", "%E9");
+
+ string firstLetter = "";
+ if (artist.Length > 0)
+ firstLetter = artist[0].ToString();
+
+ string urlString = "http://www.hotlyrics.net/lyrics/" + firstLetter + "/" + artist + "/" + title + ".html";
+
+ System.Net.WebClient client = new System.Net.WebClient();
+ Stream stream = null;
+
+ try
+ {
+ stream = client.OpenRead(urlString);
+ }
+ catch (System.Net.WebException)
+ {
+ //return false;
+ }
+ finally
+ {
+ client.Dispose();
+ }
+
+
+ if (stream != null)
+ {
+ string line = "";
+
+ System.IO.StreamReader sr = new System.IO.StreamReader(stream);
+ //sr.BaseStream.Position = 18000;
+
+ while (line.IndexOf("GOOGLE END") == -1)
+ {
+ if (sr.EndOfStream)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ if (thisMayBeTheCorrectLyric)
+ {
+ lyricTemp = new StringBuilder();
+ line = sr.ReadLine();
+
+ while (line.IndexOf("<script type") == -1)
+ {
+ lyricTemp.Append(line);
+ if (sr.EndOfStream)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ lyricTemp.Replace("?s", "'s");
+ lyricTemp.Replace("?t", "'t");
+ lyricTemp.Replace("?m", "'m");
+ lyricTemp.Replace("?l", "'l");
+ lyricTemp.Replace("?v", "'v");
+ lyricTemp.Replace("<br>", "\r\n");
+ lyricTemp.Replace("<br />", "\r\n");
+ lyricTemp.Replace(""", "\"");
+ lyricTemp.Replace("</p>", "");
+ lyricTemp.Replace("<BR>", "");
+ lyricTemp.Replace("<br/>", "\r\n");
+
+ lyric = lyricTemp.ToString().Trim();
+
+ // if warning message from Evil Labs' sql-server, then lyric isn't found
+ if (lyric.Contains("<td"))
+ {
+ lyric = "Not found";
+ }
+ }
+ sr.Close();
+ }
+ }
+ }
+}
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Lyrics007.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,126 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace LyricsEngine.LyricSites
+{
+ class Lyrics007
+ {
+ string lyric = "";
+ LyricSearch lyricSearch = null;
+
+ public string Lyric
+ {
+ get { return lyric; }
+ }
+
+ public Lyrics007(LyricSearch lyricSearch, string artist, string title)
+ {
+ this.lyricSearch = lyricSearch;
+ if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + "Lyrics007(" + artist + ", " + title + ")");
+ bool thisMayBeTheCorrectLyric = true;
+ System.Collections.ArrayList strLyric = new System.Collections.ArrayList();
+
+ StringBuilder lyricTemp = new StringBuilder();
+
+ artist = LyricUtil.removeFeatComment(artist);
+ LyricUtil.trimForParenthesis(ref artist);
+ artist = artist.Replace("#", "");
+ title = LyricUtil.removeFeatComment(title);
+ LyricUtil.trimForParenthesis(ref title);
+ title = title.Replace("#", "");
+
+ // Cannot find lyrics contaning non-English letters!
+
+ string urlString = "http://www.lyrics007.com/" + artist + " Lyrics/" + title + " Lyrics.html";
+
+ System.Net.WebClient client = new System.Net.WebClient();
+ Stream stream = null;
+
+ try
+ {
+ stream = client.OpenRead(urlString);
+ }
+ catch (System.Net.WebException)
+ {
+ //return false;
+ }
+ finally
+ {
+ client.Dispose();
+ }
+
+
+ if (stream != null)
+ {
+ string line = "";
+ int noOfLinesCount = 0;
+
+ System.IO.StreamReader sr = new System.IO.StreamReader(stream);
+
+ // 1. Find beginning of lyric
+ while (line.IndexOf("<td>Song: <strong>") == -1 && line.IndexOf("polyphonic ringtone to your cell phone") == -1)
+ {
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ // 2. If start of lyric found, then continue with work
+ if (thisMayBeTheCorrectLyric)
+ {
+ lyricTemp = new StringBuilder();
+ string textToCutFrom = @"<tr><td width=10></td><td>";
+ int indexToCutFrom = line.LastIndexOf(textToCutFrom) + textToCutFrom.Length;
+ lyricTemp.Append(line.Substring(indexToCutFrom));
+ line = sr.ReadLine();
+
+ while (line.IndexOf("The hottest songs") == -1 && line.IndexOf("Maybe you are looking for:") == -1)
+ {
+ lyricTemp.Append(line);
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ lyricTemp.Replace("??s", "'s");
+ lyricTemp.Replace("??t", "'t");
+ lyricTemp.Replace("??m", "'m");
+ lyricTemp.Replace("??l", "'l");
+ lyricTemp.Replace("??v", "'v");
+ lyricTemp.Replace("?s", "'s");
+ lyricTemp.Replace("?t", "'t");
+ lyricTemp.Replace("?m", "'m");
+ lyricTemp.Replace("?l", "'l");
+ lyricTemp.Replace("?v", "'v");
+ lyricTemp.Replace("<br>", "\r\n");
+ lyricTemp.Replace("<br />", "\r\n");
+ lyricTemp.Replace("<BR>", "\r\n");
+
+ lyric = lyricTemp.ToString().Trim();
+
+ // if warning message from Evil Labs' sql-server, then lyric isn't found
+ if (lyric.Contains("<td"))
+ {
+ lyric = "Not found";
+ }
+ }
+ sr.Close();
+ }
+ }
+ }
+}
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/LyricsOnDemand.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,154 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace LyricsEngine.LyricSites
+{
+ class LyricsOnDemand
+ {
+ string lyric = "";
+ LyricSearch lyricSearch = null;
+
+ public string Lyric
+ {
+ get { return lyric; }
+ }
+
+ public LyricsOnDemand(LyricSearch lyricSearch, string artist, string title)
+ {
+ this.lyricSearch = lyricSearch;
+ if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + "LyricsOnDemand(" + artist + ", " + title + ")");
+ bool thisMayBeTheCorrectLyric = true;
+ System.Collections.ArrayList strLyric = new System.Collections.ArrayList();
+
+ StringBuilder lyricTemp = new StringBuilder();
+
+ artist = LyricUtil.removeFeatComment(artist);
+ LyricUtil.trimForParenthesis(ref artist);
+ LyricUtil.deleteSpecificChars(ref artist);
+ artist = artist.Replace(" ", "");
+ artist = artist.Replace("The ", "");
+ artist = artist.Replace("the ", "");
+ artist = artist.Replace("-", "");
+
+ artist = artist.ToLower();
+
+ // Cannot find lyrics contaning non-English letters!
+
+ title = LyricUtil.removeFeatComment(title);
+ LyricUtil.trimForParenthesis(ref title);
+ LyricUtil.deleteSpecificChars(ref title);
+ title = title.Replace(" ", "");
+ title = title.Replace("#", "");
+ artist = artist.Replace("-", "");
+
+ // Danish letters
+ title = title.Replace("\xE6", "");
+ title = title.Replace("\xF8", "");
+ title = title.Replace("\xE5", "");
+ title = title.Replace("\xC6", "");
+ title = title.Replace("\xD8", "");
+ title = title.Replace("\xC5", "");
+
+ title = title.ToLower();
+
+ string firstLetter = "";
+ if (artist.Length > 0)
+ firstLetter = artist[0].ToString();
+
+ try
+ {
+ int.Parse(firstLetter);
+ firstLetter = "0";
+ }
+ catch { ;};
+
+ string urlString = "http://www.lyricsondemand.com/" + firstLetter + "/" + artist + "lyrics/" + title + "lyrics.html";
+
+ System.Net.WebClient client = new System.Net.WebClient();
+ System.Byte[] bytes = null;
+ Stream stream = null;
+
+ try
+ {
+ stream = client.OpenRead(urlString);
+ }
+ catch (System.Net.WebException)
+ {
+ //return false;
+ }
+ finally
+ {
+ client.Dispose();
+ }
+
+ if (stream != null)
+ {
+ string line = "";
+ int noOfLinesCount = 0;
+
+ System.IO.StreamReader sr = new System.IO.StreamReader(stream);
+
+ while (line.IndexOf(@"<font size=""2"" face=""Verdana"">") == -1)
+ {
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ if (thisMayBeTheCorrectLyric)
+ {
+ lyricTemp = new StringBuilder();
+ line = sr.ReadLine().Trim();
+
+ while (line.IndexOf("<BR><BR>") == -1)
+ {
+ lyricTemp.Append(line);
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine().Trim();
+ }
+ }
+
+ lyricTemp.Replace("<br>", " \r\n");
+ lyricTemp.Replace("</font></p>", " \r\n");
+ lyricTemp.Replace("<p><font size=\"2\" face=\"Verdana\">", " \r\n");
+ lyricTemp.Replace("<i>", "");
+ lyricTemp.Replace("</i>", "");
+ lyricTemp.Replace("?s", "'s");
+ lyricTemp.Replace("?t", "'t");
+ lyricTemp.Replace("?m", "'m");
+ lyricTemp.Replace("?l", "'l");
+ lyricTemp.Replace("?v", "'v");
+ lyricTemp.Replace("<p>", " \r\n");
+ lyricTemp.Replace("<BR>", " \r\n");
+
+ lyric = lyricTemp.ToString().Trim();
+
+ // if warning message from Evil Labs' sql-server, then lyric isn't found
+ if (lyric.Contains("<td"))
+ {
+ lyric = "Not found";
+ }
+ }
+ sr.Close();
+ }
+ }
+ }
+}
+
+
+
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/SeekLyrics.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,177 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Diagnostics;
+
+namespace LyricsEngine.LyricSites
+{
+ class SeekLyrics
+ {
+ string lyric = "";
+ LyricSearch lyricSearch = null;
+
+ public string Lyric
+ {
+ get { return lyric; }
+ }
+
+ public SeekLyrics(LyricSearch lyricSearch, string artist, string title)
+ {
+ this.lyricSearch = lyricSearch;
+ if (LyricDiagnostics.TraceSource != null) LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.elapsedTimeString() + "SeekLyrics(" + artist + ", " + title + ")");
+ bool thisMayBeTheCorrectLyric = true;
+ System.Collections.ArrayList strLyric = new System.Collections.ArrayList();
+
+ StringBuilder lyricTemp = new StringBuilder();
+
+ artist = LyricUtil.removeFeatComment(artist);
+ LyricUtil.trimForParenthesis(ref artist);
+ artist = artist.Replace(" ", "-");
+ artist = artist.Replace("'", "-");
+ artist = artist.Replace("(", "");
+ artist = artist.Replace(")", "");
+ artist = artist.Replace(",", "");
+ artist = artist.Replace("#", "");
+
+ // German letters
+ artist = artist.Replace("\xFC", "%FC");
+ artist = artist.Replace("\xDC", "");
+ artist = artist.Replace("\xE4", "%E4");
+ artist = artist.Replace("\xC4", "");
+ artist = artist.Replace("\xF6", "%E4"); // Not correct!!!
+ artist = artist.Replace("\xD6", "");
+ artist = artist.Replace("\xDF", "%DF");
+
+ // French letters
+ artist = artist.Replace("\xE9", "%E9");
+
+ title = LyricUtil.removeFeatComment(title);
+ LyricUtil.trimForParenthesis(ref title);
+ title = title.Replace(" ", "-");
+ title = title.Replace("'", "-");
+ title = title.Replace("(", "");
+ title = title.Replace(")", "");
+ title = title.Replace(",", "");
+ title = title.Replace("#", "");
+ title = title.Replace("?", "");
+
+ // German letters
+ title = title.Replace("\xFC", "%FC");
+ title = title.Replace("\xDC", "");
+ title = title.Replace("\xE4", "%E4");
+ title = title.Replace("\xC4", "");
+ title = title.Replace("\xF6", "%E4"); // Not correct!!!
+ title = title.Replace("\xD6", "");
+ title = title.Replace("\xDF", "%DF");
+
+ // French letters
+ title = title.Replace("\xE9", "%E9");
+
+
+ string urlString = "http://www.seeklyrics.com/lyrics/" + artist + "/" + title + ".html";
+
+ System.Net.WebClient client = new System.Net.WebClient();
+ System.Byte[] bytes = null;
+
+ try
+ {
+ bytes = client.DownloadData(urlString);
+ }
+ catch (System.Net.WebException)
+ {
+ //return false;
+ }
+ finally
+ {
+ client.Dispose();
+ }
+
+
+
+ if (bytes != null)
+ {
+ int byteIndex = 3900;
+
+ while (byteIndex < bytes.Length && lyricSearch.SearchHasEnded == false)
+ {
+ lyricTemp.Append(System.Char.ConvertFromUtf32(bytes[byteIndex]));
+ ++byteIndex;
+ }
+
+ MemoryStream memoryStream = new MemoryStream(System.Text.Encoding.Default.GetBytes(lyricTemp.ToString()));
+
+ if (memoryStream != null)
+ {
+ string line = "";
+ int noOfLinesCount = 0;
+
+ System.IO.StreamReader sr = new System.IO.StreamReader(memoryStream);
+
+ while (line.IndexOf("<pre>") == -1)
+ {
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ if (thisMayBeTheCorrectLyric)
+ {
+ lyricTemp = new StringBuilder();
+ string textToCutFrom = "<pre>";
+ int indexToCutFrom = line.LastIndexOf(textToCutFrom) + textToCutFrom.Length;
+ lyricTemp.Append(line.Substring(indexToCutFrom));
+ if (line.Substring(indexToCutFrom).Contains("<F"))
+ lyricTemp = new StringBuilder();
+
+ line = sr.ReadLine();
+
+ while (line.IndexOf("</pre>") == -1)
+ {
+ lyricTemp.Append(line);
+ if (sr.EndOfStream || ++noOfLinesCount > 300)
+ {
+ thisMayBeTheCorrectLyric = false;
+ break;
+ }
+ else
+ {
+ line = sr.ReadLine();
+ }
+ }
+
+ textToCutFrom = "</pre>";
+ indexToCutFrom = line.LastIndexOf(textToCutFrom);
+ lyricTemp.Append(line.Substring(0, indexToCutFrom));
+
+ lyricTemp.Replace("?s", "'s");
+ lyricTemp.Replace("?t", "'t");
+ lyricTemp.Replace("?m", "'m");
+ lyricTemp.Replace("?l", "'l");
+ lyricTemp.Replace("?v", "'v");
+ lyricTemp.Replace("<br>", "\r\n");
+ lyricTemp.Replace("<br />", "\r\n");
+ lyricTemp.Replace("'", "'");
+ lyricTemp.Replace("</p>", "");
+ lyricTemp.Replace("<BR>", "");
+ lyricTemp.Replace("<br/>", "\r\n");
+
+ lyric = lyricTemp.ToString().Trim();
+
+ // if warning message from Evil Labs' sql-server, then lyric isn't found
+ if (lyric.Contains("<td"))
+ {
+ lyric = "Not found";
+ }
+ }
+ }
+ }
+ }
+ }
+}
Added: trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Wiki.cs
===================================================================
--- trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Wiki.cs (rev 0)
+++ trunk/plugins/MyLyrics/LyricsEngine/LyricsSites/Wiki.cs 2007-03-11 20:43:19 UTC (rev 183)
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using LyricsEngine.org.lyricwiki;
+using LyricsEngine;
+
+namespace MyLyricWiki
+{
+ public class Wiki
+ {
+
+ private LyricWiki lyricWiki;
+ private LyricsResult lyricsResult = null;
+ private string artist = "";
+ private string...
[truncated message content] |