Exemple #1
0
        public LyricsOnDemand(string artist, string title, ManualResetEvent m_EventStop_SiteSearches, int timeLimit)
        {
            this.timeLimit = timeLimit;
            timer          = new Timer();

            artist = LyricUtil.RemoveFeatComment(artist);
            artist = LyricUtil.DeleteSpecificChars(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.TrimForParenthesis(title);
            title  = LyricUtil.DeleteSpecificChars(title);
            title  = title.Replace(" ", "");
            title  = title.Replace("#", "");
            artist = artist.Replace("-", "");

            // Danish letters
            title = title.Replace("æ", "");
            title = title.Replace("ø", "");
            title = title.Replace("å", "");
            title = title.Replace("Æ", "");
            title = title.Replace("Ø", "");
            title = title.Replace("Å", "");
            title = title.Replace("ö", "");
            title = title.Replace("Ö", "");

            title = title.ToLower();

            if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title))
            {
                return;
            }

            string firstLetter = artist[0].ToString();

            int firstNumber = 0;

            if (int.TryParse(firstLetter, out firstNumber))
            {
                firstLetter = "0";
            }

            string urlString = "http://www.lyricsondemand.com/" + firstLetter + "/" + artist + "lyrics/" + title +
                               "lyrics.html";

            LyricsWebClient client = new LyricsWebClient();

            timer.Enabled  = true;
            timer.Interval = timeLimit;
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Start();

            Uri uri = new Uri(urlString);

            client.OpenReadCompleted += new OpenReadCompletedEventHandler(callbackMethod);
            client.OpenReadAsync(uri);

            while (complete == false)
            {
                if (m_EventStop_SiteSearches.WaitOne(1, true))
                {
                    complete = true;
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }
Exemple #2
0
        protected override void FindLyricsWithTimer()
        {
            var artist = LyricUtil.RemoveFeatComment(Artist);

            artist = LyricUtil.DeleteSpecificChars(artist);
            artist = artist.Replace(" ", "");
            artist = artist.Replace("The ", "");
            artist = artist.Replace("the ", "");
            artist = artist.Replace("-", "");

            artist = artist.ToLower();

            // Cannot find lyrics containing non-English letters!

            var title = LyricUtil.TrimForParenthesis(Title);

            title  = LyricUtil.DeleteSpecificChars(title);
            title  = title.Replace(" ", "");
            title  = title.Replace("#", "");
            artist = artist.Replace("-", "");

            // Danish letters
            title = title.Replace("æ", "");
            title = title.Replace("ø", "");
            title = title.Replace("å", "");
            title = title.Replace("Æ", "");
            title = title.Replace("Ø", "");
            title = title.Replace("Å", "");
            title = title.Replace("ö", "");
            title = title.Replace("Ö", "");

            title = title.ToLower();

            // Validation
            if (string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(title))
            {
                return;
            }

            var firstLetter = artist[0].ToString(CultureInfo.InvariantCulture);

            int firstNumber;

            if (int.TryParse(firstLetter, out firstNumber))
            {
                firstLetter = "0";
            }

            var urlString = SiteBaseUrl + "/" + firstLetter + "/" + artist + "lyrics/" + title + "lyrics.html";

            var client = new LyricsWebClient();

            var uri = new Uri(urlString);

            client.OpenReadCompleted += CallbackMethod;
            client.OpenReadAsync(uri);

            while (Complete == false)
            {
                if (MEventStopSiteSearches.WaitOne(1, true))
                {
                    Complete = true;
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }