/// <summary>
    /// Parse the Detail Page returned from the Allmusic Scraper
    /// </summary>
    /// <param name="strHTML"></param>
    /// <returns></returns>
    public bool Parse(string strHTML)
    {
      HTMLUtil util = new HTMLUtil();
      int begIndex = 0;
      int endIndex = 0;
      string strHTMLLow = strHTML.ToLower();

      // Get the Artist Name
      string pattern = @"<h1.*class=""title"">(.*)</h1>";
      if (!FindPattern(pattern, strHTML))
      {
        return false;
      }

      _strArtistName = _match.Groups[1].Value;

      // Born
      pattern = @"<h3>.*Born.*</h3>\s*?<p>(.*)</p>";
      if (FindPattern(pattern, strHTML))
      {
        string strValue = _match.Groups[1].Value;
        util.RemoveTags(ref strValue);
        util.ConvertHTMLToAnsi(strValue, out _strBorn);
        _strBorn = _strBorn.Trim();
      }

      // Years Active
      pattern = @"(<span.*?class=""active"">(.*?)</span>)";
      if (FindPattern(pattern, strHTML))
      {
        while (_match.Success)
        {
          _strYearsActive += string.Format("{0}s, ", _match.Groups[2].Value);
          _match = _match.NextMatch();
        }
        _strYearsActive = _strYearsActive.Trim(new[] {' ', ','});
      }

      // Genre
      pattern = @"<div.*?id=""genre-style"">\s*?.*?\s*?<h3>.*?Genres.*?</h3>\s*?.*?(<p>(.*?)</p>)";
      if (FindPattern(pattern, strHTML))
      {
        string data = "";
        while (_match.Success)
        {
          data += string.Format("{0}, ", _match.Groups[2].Value);
          _match = _match.NextMatch();
        }
        util.RemoveTags(ref data);
        util.ConvertHTMLToAnsi(data, out _strGenres);
        _strGenres = _strGenres.Trim(new[] {' ', ','});
      }

      // Style
      begIndex = strHTMLLow.IndexOf("<h3>styles</h3>");
      endIndex = strHTMLLow.IndexOf("<!--end genre/styles-->", begIndex + 2);

      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = strHTML.Substring(begIndex, endIndex - begIndex);
        pattern = @"(<li>(.*?)</li>)";
        if (FindPattern(pattern, contentInfo))
        {
          string data = "";
          while (_match.Success)
          {
            data += string.Format("{0}, ", _match.Groups[2].Value);
            _match = _match.NextMatch();
          }
          util.RemoveTags(ref data);
          util.ConvertHTMLToAnsi(data, out _strStyles);
          _strStyles = _strStyles.Trim(new[] {' ', ','});
        }
      }

      // Mood
      begIndex = strHTMLLow.IndexOf("<h3>moods</h3>");
      endIndex = strHTMLLow.IndexOf("</div>", begIndex + 2);
      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = strHTML.Substring(begIndex, endIndex - begIndex);
        pattern = @"(<li>(.*?)</li>)";
        if (FindPattern(pattern, contentInfo))
        {
          string data = "";
          while (_match.Success)
          {
            data += string.Format("{0}, ", _match.Groups[2].Value);
            _match = _match.NextMatch();
          }
          util.RemoveTags(ref data);
          util.ConvertHTMLToAnsi(data, out _strTones);
          _strTones = _strTones.Trim(new[] {' ', ','});
        }
      }

      // Instruments
      begIndex = strHTMLLow.IndexOf("<h3>instruments</h3>");
      endIndex = strHTMLLow.IndexOf("</div>", begIndex + 2);
      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = strHTML.Substring(begIndex, endIndex - begIndex);
        if (FindPattern(pattern, contentInfo))
        {
          string data = "";
          while (_match.Success)
          {
            data += string.Format("{0}, ", _match.Groups[2].Value);
            _match = _match.NextMatch();
          }
          util.RemoveTags(ref data);
          util.ConvertHTMLToAnsi(data, out _strInstruments);
          _strInstruments = _strInstruments.Trim(new[] {' ', ','});
        }
      }

      // picture URL
      pattern = @"<div.*?class=""image"">\s*?.*<img.*id=""artist_image"".*?src=\""(.*?)\""";
      if (FindPattern(pattern, strHTML))
      {
        _strArtistPictureURL = _match.Groups[1].Value;
      }

      // parse AMG BIOGRAPHY
      pattern = @"<td.*?class=""tab_off""><a.*?href=""(.*?)"">.*?Biography.*?</a>";
      if (FindPattern(pattern, strHTML))
      {
        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(_match.Groups[1].Value);
          begIndex = contentinfo.IndexOf("<!--Begin Biography -->");
          endIndex = contentinfo.IndexOf("</div>", begIndex + 2);
          if (begIndex != -1 && endIndex != -1)
          {
            pattern = @"<p.*?class=""text"">(.*?)</p>";
            if (FindPattern(pattern, contentinfo))
            {
              string data = _match.Groups[1].Value;
              util.RemoveTags(ref data);
              util.ConvertHTMLToAnsi(data, out data);
              _strAMGBiography = data.Trim();
            }
          }
        }
        catch (Exception) {}
      }


      string compilationPage = "";
      string singlesPage = "";
      string dvdPage = "";
      string miscPage = "";

      // discography (albums)
      pattern = @"<td.*class=""tab_off""><a.*?href=""(.*?)"">.*Discography.*</a>";
      if (FindPattern(pattern, strHTML))
      {
        // Get Link to other sub pages
        compilationPage = _match.Groups[1].Value + "/compilations";
        singlesPage = _match.Groups[1].Value + "/singles-eps";
        dvdPage = _match.Groups[1].Value + "/dvds-videos";
        miscPage = _match.Groups[1].Value + "/other";

        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(_match.Groups[1].Value);
          pattern = @"sorted.*? cell"">(?<year>.*?)</td>\s*?.*?</td>\s*.*?<a.*?"">(?<album>.*?)" +
                    @"</a>.*?</td>\s*.*?</td>\s*.*?"">(?<label>.*?)</td>";

          if (FindPattern(pattern, contentinfo))
          {
            while (_match.Success)
            {
              string year = _match.Groups["year"].Value;
              string albumTitle = _match.Groups["album"].Value;
              string label = _match.Groups["label"].Value;

              util.RemoveTags(ref year);
              util.ConvertHTMLToAnsi(year, out year);
              util.RemoveTags(ref albumTitle);
              util.ConvertHTMLToAnsi(albumTitle, out albumTitle);
              util.RemoveTags(ref label);
              util.ConvertHTMLToAnsi(label, out label);

              try
              {
                string[] dAlbumInfo = {year.Trim(), albumTitle.Trim(), label.Trim()};
                _discographyAlbum.Add(dAlbumInfo);
              }
              catch {}

              _match = _match.NextMatch();
            }
          }
        }
        catch (Exception) {}
      }

      // Compilations
      if (compilationPage != "")
      {
        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(compilationPage);
          pattern = @"sorted.*? cell"">(?<year>.*?)</td>\s*?.*?</td>\s*.*?<a.*?"">(?<album>.*?)" +
                    @"</a>.*?</td>\s*.*?</td>\s*.*?"">(?<label>.*?)</td>";

          if (FindPattern(pattern, contentinfo))
          {
            while (_match.Success)
            {
              string year = _match.Groups["year"].Value;
              string albumTitle = _match.Groups["album"].Value;
              string label = _match.Groups["label"].Value;

              util.RemoveTags(ref year);
              util.ConvertHTMLToAnsi(year, out year);
              util.RemoveTags(ref albumTitle);
              util.ConvertHTMLToAnsi(albumTitle, out albumTitle);
              util.RemoveTags(ref label);
              util.ConvertHTMLToAnsi(label, out label);

              try
              {
                string[] dAlbumInfo = {year.Trim(), albumTitle.Trim(), label.Trim()};
                _discographyCompilations.Add(dAlbumInfo);
              }
              catch {}

              _match = _match.NextMatch();
            }
          }
        }
        catch (Exception) {}
      }

      // Singles
      if (singlesPage != "")
      {
        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(singlesPage);
          pattern = @"sorted.*? cell"">(?<year>.*?)</td>\s*?.*?</td>\s*.*?<a.*?"">(?<album>.*?)" +
                    @"</a>.*?</td>\s*.*?</td>\s*.*?"">(?<label>.*?)</td>";

          if (FindPattern(pattern, contentinfo))
          {
            while (_match.Success)
            {
              string year = _match.Groups["year"].Value;
              string albumTitle = _match.Groups["album"].Value;
              string label = _match.Groups["label"].Value;

              util.RemoveTags(ref year);
              util.ConvertHTMLToAnsi(year, out year);
              util.RemoveTags(ref albumTitle);
              util.ConvertHTMLToAnsi(albumTitle, out albumTitle);
              util.RemoveTags(ref label);
              util.ConvertHTMLToAnsi(label, out label);

              try
              {
                string[] dAlbumInfo = {year.Trim(), albumTitle.Trim(), label.Trim()};
                _discographySingles.Add(dAlbumInfo);
              }
              catch {}

              _match = _match.NextMatch();
            }
          }
        }
        catch (Exception) {}
      }

      // DVD Videos
      if (dvdPage != "")
      {
        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(dvdPage);
          pattern = @"sorted.*? cell"">(?<year>.*?)</td>\s*?.*?</td>\s*.*?<a.*?"">(?<album>.*?)" +
                    @"</a>.*?</td>\s*.*?</td>\s*.*?"">(?<label>.*?)</td>";

          if (FindPattern(pattern, contentinfo))
          {
            while (_match.Success)
            {
              string year = _match.Groups["year"].Value;
              string albumTitle = _match.Groups["album"].Value;
              string label = _match.Groups["label"].Value;

              util.RemoveTags(ref year);
              util.ConvertHTMLToAnsi(year, out year);
              util.RemoveTags(ref albumTitle);
              util.ConvertHTMLToAnsi(albumTitle, out albumTitle);
              util.RemoveTags(ref label);
              util.ConvertHTMLToAnsi(label, out label);

              try
              {
                string[] dAlbumInfo = {year.Trim(), albumTitle.Trim(), label.Trim()};
                _discographyMisc.Add(dAlbumInfo);
              }
              catch {}

              _match = _match.NextMatch();
            }
          }
        }
        catch (Exception) {}
      }

      // Other
      if (miscPage != "")
      {
        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(miscPage);
          pattern = @"sorted.*? cell"">(?<year>.*?)</td>\s*?.*?</td>\s*.*?<a.*?"">(?<album>.*?)" +
                    @"</a>.*?</td>\s*.*?</td>\s*.*?"">(?<label>.*?)</td>";

          if (FindPattern(pattern, contentinfo))
          {
            while (_match.Success)
            {
              string year = _match.Groups["year"].Value;
              string albumTitle = _match.Groups["album"].Value;
              string label = _match.Groups["label"].Value;

              util.RemoveTags(ref year);
              util.ConvertHTMLToAnsi(year, out year);
              util.RemoveTags(ref albumTitle);
              util.ConvertHTMLToAnsi(albumTitle, out albumTitle);
              util.RemoveTags(ref label);
              util.ConvertHTMLToAnsi(label, out label);

              try
              {
                string[] dAlbumInfo = {year.Trim(), albumTitle.Trim(), label.Trim()};
                _discographyMisc.Add(dAlbumInfo);
              }
              catch {}

              _match = _match.NextMatch();
            }
          }
        }
        catch (Exception) {}
      }

      _bLoaded = true;
      return _bLoaded;
    }
    public bool FindAlbuminfo(string strAlbum, string artistName, int releaseYear)
    {
      _albumList.Clear();

//     strAlbum="1999";//escapolygy";

      // make request
      // type is 
      // http://www.allmusic.com/cg/amg.dll?P=amg&SQL=escapolygy&OPT1=2

      HTMLUtil util = new HTMLUtil();
      string postData = String.Format("P=amg&SQL={0}&OPT1=2", HttpUtility.UrlEncode(strAlbum));

      string html = PostHTTP("http://www.allmusic.com/cg/amg.dll", postData);
      if (html.Length == 0)
      {
        return false;
      }

      // check if this is an album
      MusicAlbumInfo newAlbum = new MusicAlbumInfo();
      newAlbum.AlbumURL = "http://www.allmusic.com/cg/amg.dll?" + postData;
      if (newAlbum.Parse(html))
      {
        _albumList.Add(newAlbum);
        return true;
      }

      string htmlLow = html;
      htmlLow = htmlLow.ToLower();
      int startOfTable = htmlLow.IndexOf("id=\"expansiontable1\"");
      if (startOfTable < 0)
      {
        return false;
      }
      startOfTable = htmlLow.LastIndexOf("<table", startOfTable);
      if (startOfTable < 0)
      {
        return false;
      }

      HTMLTable table = new HTMLTable();
      string strTable = html.Substring(startOfTable);
      table.Parse(strTable);

      for (int i = 1; i < table.Rows; ++i)
      {
        HTMLTable.HTMLRow row = table.GetRow(i);
        string albumName = "";
        string albumUrl = "";
        string nameOfAlbum = "";
        string nameOfArtist = "";
        for (int iCol = 0; iCol < row.Columns; ++iCol)
        {
          string column = row.GetColumValue(iCol);
          if (iCol == 1 && (column.Length != 0))
          {
            albumName = "(" + column + ")";
          }
          if (iCol == 2)
          {
            nameOfArtist = column;
            util.RemoveTags(ref nameOfArtist);
            if (!column.Equals("&nbsp;"))
            {
              albumName = String.Format("- {0} {1}", nameOfArtist, albumName);
            }
          }
          if (iCol == 4)
          {
            string tempAlbum = column;
            util.RemoveTags(ref tempAlbum);
            albumName = String.Format("{0} {1}", tempAlbum, albumName);
            nameOfAlbum = tempAlbum;
          }
          if (iCol == 4 && column.IndexOf("<a href=\"") >= 0)
          {
            int pos1 = column.IndexOf("<a href=\"");
            pos1 += +"<a href=\"".Length;
            int iPos2 = column.IndexOf("\">", pos1);
            if (iPos2 >= 0)
            {
              if (nameOfAlbum.Length == 0)
              {
                nameOfAlbum = albumName;
              }

              // full album url:
              // http://www.allmusic.com/cg/amg.dll?p=amg&token=&sql=10:66jieal64xs7
              string url = column.Substring(pos1, iPos2 - pos1);
              string albumNameStripped;
              albumUrl = String.Format("http://www.allmusic.com{0}", url);
              MusicAlbumInfo newAlbumInfo = new MusicAlbumInfo();
              util.ConvertHTMLToAnsi(albumName, out albumNameStripped);
              newAlbumInfo.Title2 = albumNameStripped;
              newAlbumInfo.AlbumURL = util.ConvertHTMLToAnsi(albumUrl);
              newAlbumInfo.Artist = util.ConvertHTMLToAnsi(nameOfArtist);
              newAlbumInfo.Title = util.ConvertHTMLToAnsi(nameOfAlbum);
              _albumList.Add(newAlbumInfo);
            }
          }
        }
      }

      // now sort
      _albumList.Sort(new AlbumSort(strAlbum, artistName, releaseYear));
      return true;
    }
    public bool Parse(string html)
    {
      _songs.Clear();
      HTMLUtil util = new HTMLUtil();
      string strHtmlLow = html.ToLower();

      int begIndex = 0;
      int endIndex = 0;

      //	Extract Cover URL
      string pattern = @"<!--Begin.*?Album.*?Photo-->\s*?.*?<img.*?src=\""(.*?)\""";
      if (FindPattern(pattern, html))
      {
        _strImageURL = _match.Groups[1].Value;
      }

      //	Extract Review
      pattern = @"<td.*?class=""tab_off""><a.*?href=""(.*?)"">.*?Review.*?</a>";
      if (FindPattern(pattern, html))
      {
        try
        {
          string contentinfo = AllmusicSiteScraper.GetHTTP(_match.Groups[1].Value);
          pattern = @"<p.*?class=""author"">.*\s*?.*?<p.*?class=""text"">(.*?)</p>";
          if (FindPattern(pattern, contentinfo))
          {
            string data = _match.Groups[1].Value;
            util.RemoveTags(ref data);
            util.ConvertHTMLToAnsi(data, out data);
            _strReview = data.Trim();
          }
        }
        catch (Exception) {}
      }

      //	Extract Artist
      pattern = @"<h3.*?artist</h3>\s*?.*?<a.*"">(.*)</a>";
      if (FindPattern(pattern, html))
      {
        _artist = _match.Groups[1].Value;
        util.RemoveTags(ref _artist);
      }

      //	Extract Album
      pattern = @"<h3.*?album</h3>\s*?.*?<p>(.*)</P>";
      if (FindPattern(pattern, html))
      {
        _strTitle = _match.Groups[1].Value;
        util.RemoveTags(ref _strTitle);
      }

      // Extract Rating
      pattern = @"<h3.*?rating</h3>\s*?.*?src=""(.*?)""";
      if (FindPattern(pattern, html))
      {
        string strRating = _match.Groups[1].Value;
        util.RemoveTags(ref strRating);
        strRating = strRating.Substring(26, 1);
        try
        {
          _iRating = Int32.Parse(strRating);
        }
        catch (Exception) {}
      }

      //	Release Date
      pattern = @"<h3.*?release.*?date</h3>\s*?.*?<p>(.*)</P>";
      if (FindPattern(pattern, html))
      {
        _strDateOfRelease = _match.Groups[1].Value;
        util.RemoveTags(ref _strDateOfRelease);

        //	extract the year out of something like "1998 (release)" or "12 feb 2003"
        int nPos = _strDateOfRelease.IndexOf("19");
        if (nPos > -1)
        {
          if ((int)_strDateOfRelease.Length >= nPos + 3 && Char.IsDigit(_strDateOfRelease[nPos + 2]) &&
              Char.IsDigit(_strDateOfRelease[nPos + 3]))
          {
            string strYear = _strDateOfRelease.Substring(nPos, 4);
            _strDateOfRelease = strYear;
          }
          else
          {
            nPos = _strDateOfRelease.IndexOf("19", nPos + 2);
            if (nPos > -1)
            {
              if ((int)_strDateOfRelease.Length >= nPos + 3 && Char.IsDigit(_strDateOfRelease[nPos + 2]) &&
                  Char.IsDigit(_strDateOfRelease[nPos + 3]))
              {
                string strYear = _strDateOfRelease.Substring(nPos, 4);
                _strDateOfRelease = strYear;
              }
            }
          }
        }

        nPos = _strDateOfRelease.IndexOf("20");
        if (nPos > -1)
        {
          if ((int)_strDateOfRelease.Length > nPos + 3 && Char.IsDigit(_strDateOfRelease[nPos + 2]) &&
              Char.IsDigit(_strDateOfRelease[nPos + 3]))
          {
            string strYear = _strDateOfRelease.Substring(nPos, 4);
            _strDateOfRelease = strYear;
          }
          else
          {
            nPos = _strDateOfRelease.IndexOf("20", nPos + 1);
            if (nPos > -1)
            {
              if ((int)_strDateOfRelease.Length > nPos + 3 && Char.IsDigit(_strDateOfRelease[nPos + 2]) &&
                  Char.IsDigit(_strDateOfRelease[nPos + 3]))
              {
                string strYear = _strDateOfRelease.Substring(nPos, 4);
                _strDateOfRelease = strYear;
              }
            }
          }
        }
      }

      // Extract Genre
      begIndex = strHtmlLow.IndexOf("<h3>genre</h3>");
      endIndex = strHtmlLow.IndexOf("</div>", begIndex + 2);
      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = html.Substring(begIndex, endIndex - begIndex);
        pattern = @"(<li>(.*?)</li>)";
        if (FindPattern(pattern, contentInfo))
        {
          string data = "";
          while (_match.Success)
          {
            data += string.Format("{0}, ", _match.Groups[2].Value);
            _match = _match.NextMatch();
          }
          util.RemoveTags(ref data);
          util.ConvertHTMLToAnsi(data, out _strGenre);
          _strGenre = _strGenre.Trim(new[] {' ', ','});
        }
      }

      // Extract Styles
      begIndex = strHtmlLow.IndexOf("<h3>style</h3>");
      endIndex = strHtmlLow.IndexOf("</div>", begIndex + 2);
      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = html.Substring(begIndex, endIndex - begIndex);
        pattern = @"(<li>(.*?)</li>)";
        if (FindPattern(pattern, contentInfo))
        {
          string data = "";
          while (_match.Success)
          {
            data += string.Format("{0}, ", _match.Groups[2].Value);
            _match = _match.NextMatch();
          }
          util.RemoveTags(ref data);
          util.ConvertHTMLToAnsi(data, out _strStyles);
          _strStyles = _strStyles.Trim(new[] {' ', ','});
        }
      }

      // Extract Moods
      begIndex = strHtmlLow.IndexOf("<h3>moods</h3>");
      endIndex = strHtmlLow.IndexOf("</div>", begIndex + 2);
      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = html.Substring(begIndex, endIndex - begIndex);
        pattern = @"(<li>(.*?)</li>)";
        if (FindPattern(pattern, contentInfo))
        {
          string data = "";
          while (_match.Success)
          {
            data += string.Format("{0}, ", _match.Groups[2].Value);
            _match = _match.NextMatch();
          }
          util.RemoveTags(ref data);
          util.ConvertHTMLToAnsi(data, out _strTones);
          _strTones = _strTones.Trim(new[] {' ', ','});
        }
      }

      // Extract Songs
      begIndex = strHtmlLow.IndexOf("<!-- tracks table -->");
      endIndex = strHtmlLow.IndexOf("<!-- end tracks table -->", begIndex + 2);
      if (begIndex != -1 && endIndex != -1)
      {
        string contentInfo = html.Substring(begIndex, endIndex - begIndex);
        pattern = @"<tr.*class=""visible"".*?\s*?<td.*</td>\s*?.*<td.*</td>\s*?.*<td.*?>(?<track>.*)</td>" +
                  @"\s*?.*<td.*</td>\s*?.*<td.*?>(?<title>.*)</td>\s*?.*?<td.*?>\s*?.*</td>\s*?.*?<td.*?>(?<duration>.*)</td>";

        if (FindPattern(pattern, contentInfo))
        {
          while (_match.Success)
          {
            //	Tracknumber
            int iTrack = 0;
            try
            {
              iTrack = Int32.Parse(_match.Groups["track"].Value);
            }
            catch (Exception) {}

            // Song Title
            string strTitle = _match.Groups["title"].Value;
            util.RemoveTags(ref strTitle);
            util.ConvertHTMLToAnsi(strTitle, out strTitle);

            //	Duration
            int iDuration = 0;
            string strDuration = _match.Groups["duration"].Value;
            int iPos = strDuration.IndexOf(":");
            if (iPos >= 0)
            {
              string strMin, strSec;
              strMin = strDuration.Substring(0, iPos);
              iPos++;
              strSec = strDuration.Substring(iPos);
              int iMin = 0, iSec = 0;
              try
              {
                iMin = Int32.Parse(strMin);
                iSec = Int32.Parse(strSec);
              }
              catch (Exception) {}
              iDuration = iMin * 60 + iSec;
            }

            //	Create new song object
            MusicSong newSong = new MusicSong();
            newSong.Track = iTrack;
            newSong.SongName = strTitle;
            newSong.Duration = iDuration;
            _songs.Add(newSong);

            _match = _match.NextMatch();
          }
        }
      }

      //	Set to "Not available" if no value from web
      if (_artist.Length == 0)
      {
        _artist = GUILocalizeStrings.Get(416);
      }
      if (_strDateOfRelease.Length == 0)
      {
        _strDateOfRelease = GUILocalizeStrings.Get(416);
      }
      if (_strGenre.Length == 0)
      {
        _strGenre = GUILocalizeStrings.Get(416);
      }
      if (_strTones.Length == 0)
      {
        _strTones = GUILocalizeStrings.Get(416);
      }
      if (_strStyles.Length == 0)
      {
        _strStyles = GUILocalizeStrings.Get(416);
      }
      if (_strTitle.Length == 0)
      {
        _strTitle = GUILocalizeStrings.Get(416);
      }

      if (_strTitle2.Length == 0)
      {
        _strTitle2 = _strTitle;
      }

      Loaded = true;
      return true;
    }
    /// <summary>
    /// Search on Allmusic for the requested string
    /// </summary>
    /// <param name="searchBy"></param>
    /// <param name="searchStr"></param>
    /// <returns></returns>
    public bool FindInfo(SearchBy searchBy, string searchStr)
    {
      _searchby = searchBy;
      HTMLUtil util = new HTMLUtil();
      string strPostData = "";
      if (SearchBy.Albums == searchBy)
      {
        strPostData = string.Format(ALBUMSEARCH, HttpUtility.UrlEncode(searchStr));
      }
      else
      {
        searchStr = SwitchArtist(searchStr);
        strPostData = string.Format(ARTISTSEARCH, HttpUtility.UrlEncode(searchStr));
      }

      string strHTML = PostHTTP(MAINURL + URLPROGRAM, strPostData);
      if (strHTML.Length == 0)
      {
        return false;
      }

      _htmlCode = strHTML; // save the html content...

      Regex multiples = new Regex(
        @"\sSearch\sResults\sfor:",
        RegexOptions.IgnoreCase
        | RegexOptions.Multiline
        | RegexOptions.IgnorePatternWhitespace
        | RegexOptions.Compiled
        );

      if (multiples.IsMatch(strHTML))
      {
        string pattern = "";
        if (searchBy.ToString().Equals("Artists"))
        {
          pattern = @"<tr.*?>\s*?.*?<td\s*?class=""relevance\stext-center"">\s*?.*\s*?.*</td>" +
                    @"\s*?.*<td.*\s*?.*</td>\s*?.*<td>.*<a.*href=""(?<code>.*?)"">(?<name>.*)</a>.*</td>" +
                    @"\s*?.*<td>(?<detail>.*)</td>\s*?.*<td>(?<detail2>.*)</td>";
        }
        else if (searchBy.ToString().Equals("Albums"))
        {
          pattern = @"<tr.*?>\s*?.*?<td\s*?class=""relevance\stext-center"">\s*?.*\s*?.*</td>" +
                    @"\s*?.*<td.*\s*?.*</td>\s*?.*<td>.*<a.*href=""(?<code>.*?)"">(?<name>.*)</a>.*</td>" +
                    @"\s*?.*<td>(?<detail>.*)</td>\s*?.*<td>.*</td>\s*?.*<td>(?<detail2>.*)</td>";
        }


        Match m;
        Regex itemsFoundFromSite = new Regex(
          pattern,
          RegexOptions.IgnoreCase
          | RegexOptions.Multiline
          | RegexOptions.IgnorePatternWhitespace
          | RegexOptions.Compiled
          );


        for (m = itemsFoundFromSite.Match(strHTML); m.Success; m = m.NextMatch())
        {
          string code = m.Groups["code"].ToString();
          string name = m.Groups["name"].ToString();
          string detail = m.Groups["detail"].ToString();
          string detail2 = m.Groups["detail2"].ToString();

          util.RemoveTags(ref name);
          util.ConvertHTMLToAnsi(name, out name);

          util.RemoveTags(ref detail);
          util.ConvertHTMLToAnsi(detail, out detail);

          util.RemoveTags(ref detail2);
          util.ConvertHTMLToAnsi(detail2, out detail2);

          if (SearchBy.Artists == searchBy)
          {
            detail += " - " + detail2;
            if (detail.Length > 0)
            {
              _codes.Add(code);
              _values.Add(name + " - " + detail);
            }
            else
            {
              _codes.Add(code);
              _values.Add(name);
            }
          }
          else
          {
            MusicAlbumInfo albumInfo = new MusicAlbumInfo();
            albumInfo.AlbumURL = code;
            albumInfo.Artist = detail;
            albumInfo.Title = name;
            albumInfo.DateOfRelease = detail2;
            _albumList.Add(albumInfo);
          }
        }
        _multiple = true;
      }
      else // found the right one
      {}
      return true;
    }
Esempio n. 5
0
        public static string FindWithAction(string body, string keyStart, string keyEnd, string param1, string param2, string param3, string maxItems, string languages, out string allNames, out string allRoles, bool grabActorRoles)
        {
            allNames = string.Empty;
              allRoles = string.Empty;
              int iStart = 0;
              int iEnd = 0;
              int iLength = 0;
              int maxItemsToAdd = 999; // Max number of items to add to matchgroup
              if (!string.IsNullOrEmpty(maxItems)) maxItemsToAdd = Convert.ToInt32(maxItems);
              string strTemp = String.Empty;
              var htmlUtil = new HTMLUtil();
              bool bregexs = false;
              bool bregexe = false;
              if (keyStart.StartsWith("#REGEX#"))
            bregexs = true;
              if (keyEnd.StartsWith("#REGEX#"))
            bregexe = true;

              if (keyStart != "" && keyEnd != "")
              {
            iLength = keyStart.Length;
            if (param1.StartsWith("#REVERSE#"))
            {
              iStart = bregexs ? FindRegEx(body, keyStart, iStart, ref iLength, false) : body.LastIndexOf(keyStart);
            }
            else
              if (bregexs)
            iStart = FindRegEx(body, keyStart, iStart, ref iLength, true);
              else
            iStart = body.IndexOf(keyStart);

            if (iStart > 0)
            {
              if (param1.StartsWith("#REVERSE#"))
              {
            iLength = keyEnd.Length;
            if (bregexe)
              iEnd = FindRegEx(body, keyEnd, iStart, ref iLength, false) + iStart;
            else
              iEnd = body.LastIndexOf(keyEnd, iStart);
              }
              else
              {
            iStart += iLength;
            if (bregexe)
              iEnd = FindRegEx(body, keyEnd, iStart, ref iLength, true) + iStart;
            else
              iEnd = body.IndexOf(keyEnd, iStart);
              }
              if (iEnd > 0)
              {
            if (param1.StartsWith("#REVERSE#"))
            {
              param1 = param1.Substring(9);
              iEnd += iLength;
              strTemp = body.Substring(iEnd, iStart - iEnd);
            }
            else
              strTemp = body.Substring(iStart, iEnd - iStart);
            if (strTemp != "")
            {
              //if (param3.Length > 0)
              //{
              //  Regex oRegex = new Regex(param3);
              //  Regex oRegexReplace = new Regex(string.Empty);
              //  System.Text.RegularExpressions.MatchCollection oMatches = oRegex.Matches(strTemp);
              //  foreach (System.Text.RegularExpressions.Match oMatch in oMatches)
              //  {
              //    if (param1.StartsWith("#REGEX#"))
              //    {
              //      oRegexReplace = new Regex(param1.Substring(7));
              //      strTemp = strTemp.Replace(oMatch.Value, oRegexReplace.Replace(oMatch.Value, param2));
              //    }
              //    else
              //      strTemp = strTemp.Replace(param1, param2);
              //  }
              //}
              //else
              //{
              //  if (param1.StartsWith("#REGEX#"))
              //    strTemp = Regex.Replace(strTemp, param1.Substring(7), param2);
              //  else
              //    if (param1.Length > 0)
              //      strTemp = strTemp.Replace(param1, param2);
              //}
              if (param3.Length > 0)
              {
                RegexOptions regexoption = new RegexOptions();
                regexoption = RegexOptions.Singleline;
                if (param3.StartsWith("#MULTILINE#"))
                {
                  regexoption = RegexOptions.Multiline;
                  param3 = param3.Substring(11);
                }

                //Regex oRegex = new Regex(param3, RegexOptions.Singleline);
                Regex oRegex = new Regex(param3, regexoption);
                Regex oRegexReplace = new Regex(string.Empty);
                strTemp = HttpUtility.HtmlDecode(strTemp);
                if (regexoption != RegexOptions.Multiline)
                  strTemp = HttpUtility.HtmlDecode(strTemp).Replace("\n", "");
                // System.Windows.Forms.Clipboard.SetDataObject(strTemp, false); // Must not be set when called by AMCupdater -> STAThread exception !
                MatchCollection oMatches = oRegex.Matches(strTemp);

                string strPerson = string.Empty;
                string strRole = string.Empty;

                if (oMatches.Count > 0)
                {
                  string strCastDetails = "";
                  int i = 0;
                  foreach (System.Text.RegularExpressions.Match oMatch in oMatches)
                  {
                    strPerson = oMatch.Groups["person"].Value;
                    strPerson = Utils.stripHTMLtags(strPerson).Trim().Replace("\n", "");
                    //strPerson = HttpUtility.HtmlDecode(strPerson).Replace(",", ";");

                    strRole = oMatch.Groups["role"].Value;
                    strRole = Utils.stripHTMLtags(strRole).Trim().Replace("\n", "");
                    //strRole = HttpUtility.HtmlDecode(strRole).Replace(",", ";");

                    if (param1.Length > 0)
                    {
                      if (!string.IsNullOrEmpty(strPerson))
                        strPerson = ReplaceNormalOrRegex(strPerson, param1, "");
                      if (!string.IsNullOrEmpty(strRole))
                        strRole = ReplaceNormalOrRegex(strRole, param1, "");

                      //if (param1.StartsWith("#REGEX#"))
                      //{
                      //  oRegexReplace = new Regex(param1.Substring(7));
                      //  if (!string.IsNullOrEmpty(strPerson))
                      //    strPerson = strPerson.Replace(strPerson, oRegexReplace.Replace(strPerson, param2)).Trim();
                      //  if (!string.IsNullOrEmpty(strRole))
                      //    strRole = strRole.Replace(strRole, oRegexReplace.Replace(strRole, param2)).Trim();
                      //}
                      //else
                      //{
                      //  if (!string.IsNullOrEmpty(strActor))
                      //    strActor = strActor.Replace(param1, param2).Trim();
                      //  if (!string.IsNullOrEmpty(strRole))
                      //    strRole = strRole.Replace(param1, param2).Trim();
                      //}
                    }

                    // build allNames & allRoles strings for dropdowns
                    if (!string.IsNullOrEmpty(allNames)) allNames += ", ";
                    allNames += strPerson;
                    if (!string.IsNullOrEmpty(allRoles)) allRoles += ", ";
                    allRoles += strRole;

                    if (i < maxItemsToAdd) // Limit number of items to add
                    {
                      string[] langSplit = languages.Split(new Char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); // language filter (grabber script or override)

                      if (string.IsNullOrEmpty(languages))
                      {
                        if (!string.IsNullOrEmpty(strCastDetails)) strCastDetails += ", ";
                        strCastDetails += strPerson;
                        if (strRole != string.Empty && grabActorRoles)
                          strCastDetails += " (" + strRole + ")";
                        //strCastDetails += "\n";
                        i = i + 1;
                      }
                      else
                      {
                        foreach (var s in langSplit)
                        {
                          if (strPerson.ToLower().Contains(s.Trim().ToLower()) || strRole.ToLower().Contains(s.Trim().ToLower()))
                          {
                            if (!string.IsNullOrEmpty(strCastDetails)) strCastDetails += ", ";
                            strCastDetails += strPerson;
                            if (strRole != string.Empty && grabActorRoles)
                              strCastDetails += " (" + strRole + ")";
                            // Don't add groupnames when adding TTitles
                            //strCastDetails += "\n";
                            i = i + 1;
                          }
                        }
                        strCastDetails = ReplaceNormalOrRegex(strCastDetails, param1, "");
                        //if (param1.StartsWith("#REGEX#"))
                        //  strCastDetails = Regex.Replace(strCastDetails, param1.Substring(7), param2);
                        //else if (param1.Length > 0)
                        //  strCastDetails = strCastDetails.Replace(param1, param2);
                      }
                    }
                  }
                  strTemp = strCastDetails;
                  if (param2.StartsWith("#")) strTemp = ReplaceNormalOrRegex(strTemp, param2, ""); // Cleanup only - no replacement of inner regex values
                }
                else // no matchcollection found
                {
                  // strTemp = param2.StartsWith("#") ? ReplaceNormalOrRegex(strTemp, param2, "") : ReplaceNormalOrRegex(strTemp, param1, param2);
                  strTemp = ""; // set output to empty string, as no matches were found
                }

                string[] split = allNames.Split(new Char[] { ',', ';', '/' }, StringSplitOptions.RemoveEmptyEntries);
                string strT = string.Empty;
                string strTname = string.Empty;
                string strTrole = string.Empty;
                foreach (var str in split)
                {
                  strT = str.Trim();
                  if (!string.IsNullOrEmpty(strTname)) strTname += ", ";
                  strTname += strT;
                }
                allNames = strTname;

                split = allRoles.Split(new Char[] { ',', ';', '/' }, StringSplitOptions.RemoveEmptyEntries);
                strT = string.Empty;
                strTname = string.Empty;
                strTrole = string.Empty;
                foreach (var str in split)
                {
                  strT = str.Trim();
                  if (!string.IsNullOrEmpty(strTrole)) strTrole += ", ";
                  strTrole += strT;
                }
                allRoles = strTrole;
              }
              else
              {
                strTemp = ReplaceNormalOrRegex(strTemp, param1, param2);
                //System.Windows.Forms.Clipboard.SetDataObject(strTemp, false); // Must NOT be called, when using from AMCupdater, cause it's giving STAThread error !!!
              }

              // Added to enable the addition of surrounding chars for results...
              if (param1.StartsWith("#ADD#") && param2.Length > 0)
              {
                string strExtend = param2;
                string[] strExtendSplit = strExtend.Split(new Char[] { '|' }, StringSplitOptions.None); // { ',', ';', '|' }
                if (strExtendSplit.Length == 2)
                {
                  strTemp = strExtendSplit[0] + strTemp.Trim() + strExtendSplit[1];
                }
                else
                {
                  strTemp = strExtend + strTemp.Trim() + strExtend;
                }
              }

              strTemp = strTemp.Replace("„", "'").Replace("“", "'");
              htmlUtil.RemoveTags(ref strTemp);
              htmlUtil.ConvertHTMLToAnsi(strTemp, out strTemp);
              // strTemp = System.Security.SecurityElement.Escape(strTemp); // escape invalid chars for valid XML value generation
              // strTemp = strTemp.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
              // strTemp = strTemp.Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
            }
              }
            }

              }
              return strTemp.Trim();
        }
Esempio n. 6
0
        public static string Find(string body, string keyStart, ref int iStart, string keyEnd)
        {
            int iEnd = 0;
              int iLength = 0;

              string strTemp = String.Empty;
              var htmlUtil = new HTMLUtil();
              bool bregexs = false;
              bool bregexe = false;
              if (keyStart.StartsWith("#REGEX#"))
            bregexs = true;
              if (keyEnd.StartsWith("#REGEX#"))
            bregexe = true;
              if (keyStart != "" && keyEnd != "")
              {
            iLength = keyStart.Length;
            if (bregexs)
              iStart = FindRegEx(body, keyStart, iStart, ref iLength, true) + iStart;
            else
              iStart = body.IndexOf(keyStart, iStart);

            if (iStart >= 0)
            {
              iStart += iLength;
              iLength = keyEnd.Length;
              if (bregexe)
            iEnd = FindRegEx(body, keyEnd, iStart, ref iLength, true) + iStart;
              else
            iEnd = body.IndexOf(keyEnd, iStart);
              if (iEnd > 0)
              {
            strTemp = body.Substring(iStart, iEnd - iStart);
            if (strTemp != "")
            {
              htmlUtil.RemoveTags(ref strTemp);
              htmlUtil.ConvertHTMLToAnsi(strTemp, out strTemp);
            }
              }
            }

              }
              return strTemp.Trim();
        }
Esempio n. 7
0
        public static string FindWithAction(string body, string keyStart, ref int iStart, string keyEnd, string param1, string param2, string param3)
        {
            int iEnd = 0;
              int iLength = 0;

              var strTemp = String.Empty;
              var htmlUtil = new HTMLUtil();
              bool bregexs = false;
              bool bregexe = false;
              if (keyStart.StartsWith("#REGEX#"))
            bregexs = true;
              if (keyEnd.StartsWith("#REGEX#"))
            bregexe = true;

              if (keyStart != "" && keyEnd != "")
              {
            iLength = keyStart.Length;
            if (bregexs)
              iStart = FindRegEx(body, keyStart, iStart, ref iLength, true) + iStart;
            else
              iStart = body.IndexOf(keyStart, iStart);
            if (iStart > 0)
            {
              iStart += iLength;
              if (bregexe)
            iEnd = FindRegEx(body, keyEnd, iStart, ref iLength, true) + iStart;
              else
            iEnd = body.IndexOf(keyEnd, iStart);
              if (iEnd > 0)
              {
            strTemp = body.Substring(iStart, iEnd - iStart);
            if (strTemp != "")
            {
              if (param3.Length > 0)
              {
                var oRegex = new Regex(param3);
                var oRegexReplace = new Regex(string.Empty);
                MatchCollection oMatches = oRegex.Matches(strTemp);
                foreach (Match oMatch in oMatches)
                {
                  if (param1.StartsWith("#REGEX#"))
                  {
                    oRegexReplace = new Regex(param1.Substring(7));
                    strTemp = strTemp.Replace(oMatch.Value, oRegexReplace.Replace(oMatch.Value, param2));
                  }
                  else
                    strTemp = strTemp.Replace(param1, param2);
                }
              }
              else
              {
                strTemp = ReplaceNormalOrRegex(strTemp, param1, param2);
              }

              // Added to enable the addition of surrounding chars for results...
              if (param1.StartsWith("#ADD#") && param2.Length > 0)
              {
                string strExtend = param2;
                string[] strExtendSplit = strExtend.Split(new Char[] { '|' }, StringSplitOptions.None);
                if (strExtendSplit.Length == 2)
                {
                  strTemp = strExtendSplit[0] + strTemp.Trim() + strExtendSplit[1];
                }
                else
                {
                  strTemp = strExtend + strTemp.Trim() + strExtend;
                }
              }

              strTemp = strTemp.Replace("„", "'").Replace("“", "'");
              htmlUtil.RemoveTags(ref strTemp);
              htmlUtil.ConvertHTMLToAnsi(strTemp, out strTemp);
              // strTemp = strTemp.Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
            }
              }
            }

              }
              return strTemp.Trim();
        }