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 void ShowAlbumInfo(int parentWindowID, string artistName, string albumName, string strPath, MusicTag tag)
    {
      Log.Debug("Searching for album: {0} - {1}", albumName, artistName);

      var dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
      var pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);

      var errorEncountered = true;
      var album = new AlbumInfo();
      var albumInfo = new MusicAlbumInfo();
      if (m_database.GetAlbumInfo(albumName, artistName, ref album))
      {
        // we already have album info in database so just use that
        albumInfo.Set(album);
        errorEncountered = false;
      }
      else
      {// lookup details.  start with artist

        if (null != pDlgOK && !Win32API.IsConnectedToInternet())
        {
          pDlgOK.SetHeading(703);
          pDlgOK.SetLine(1, 703);
          pDlgOK.SetLine(2, string.Empty);
          pDlgOK.DoModal(GetID);
          return;
        }

        // show dialog box indicating we're searching the album
        if (dlgProgress != null)
        {
          dlgProgress.Reset();
          dlgProgress.SetHeading(326);
          dlgProgress.SetLine(1, albumName);
          dlgProgress.SetLine(2, artistName);
          dlgProgress.SetPercentage(0);
          dlgProgress.StartModal(GetID);
          dlgProgress.Progress();
          dlgProgress.ShowProgressBar(true);
        }

        var scraper = new AllmusicSiteScraper();
        List<AllMusicArtistMatch> artists;
        var selectedMatch = new AllMusicArtistMatch();

        if (scraper.GetArtists(artistName, out artists))
        {
          if (null != dlgProgress)
          {
            dlgProgress.SetPercentage(20);
            dlgProgress.Progress();
          }
          if (artists.Count == 1)
          {
            // only have single match so no need to ask user
            Log.Debug("Single Artist Match Found");
            selectedMatch = artists[0];
          }
          else
          {
            // need to get user to choose which one to use
            Log.Debug("Muliple Artist Match Found ({0}) prompting user", artists.Count);
            var pDlg = (GUIDialogSelect2) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_SELECT2);
            if (null != pDlg)
            {
              pDlg.Reset();
              pDlg.SetHeading(GUILocalizeStrings.Get(1303));

              foreach (var i in artists.Select(artistMatch => new GUIListItem
                                                                {
                                                                  Label = artistMatch.Artist + " - " + artistMatch.Genre,
                                                                  Label2 = artistMatch.YearsActive,
                                                                  Path = artistMatch.ArtistUrl,
                                                                  IconImage = artistMatch.ImageUrl
                                                                }))
              {
                pDlg.Add(i);
              }
              pDlg.DoModal(GetID);

              // and wait till user selects one
              var iSelectedMatch = pDlg.SelectedLabel;
              if (iSelectedMatch < 0)
              {
                return;
              }
              selectedMatch = artists[iSelectedMatch];
            }
            
            if (null != dlgProgress)
            {
              dlgProgress.Reset();
              dlgProgress.SetHeading(326);
              dlgProgress.SetLine(1, albumName);
              dlgProgress.SetLine(2, artistName);
              dlgProgress.SetPercentage(40);
              dlgProgress.StartModal(GetID);
              dlgProgress.ShowProgressBar(true);
              dlgProgress.Progress();
            }
          }

          string strAlbumHtml;
          if (scraper.GetAlbumHtml(albumName, selectedMatch.ArtistUrl, out strAlbumHtml))
          {
            if (null != dlgProgress)
            {
              dlgProgress.SetPercentage(60);
              dlgProgress.Progress();
            }
            if (albumInfo.Parse(strAlbumHtml))
            {
              if (null != dlgProgress)
              {
                dlgProgress.SetPercentage(80);
                dlgProgress.Progress();
              }
              m_database.AddAlbumInfo(albumInfo.Get());
              errorEncountered = false;
            }

          }
        }
      }

      if (null != dlgProgress)
      {
        dlgProgress.SetPercentage(100);
        dlgProgress.Progress();
        dlgProgress.Close();
        dlgProgress = null;
      }

      if (!errorEncountered)
      {
        var pDlgAlbumInfo = (GUIMusicInfo)GUIWindowManager.GetWindow((int)Window.WINDOW_MUSIC_INFO);
        if (null != pDlgAlbumInfo)
        {
          pDlgAlbumInfo.Album = albumInfo;
          pDlgAlbumInfo.Tag = tag;

          pDlgAlbumInfo.DoModal(parentWindowID);
          if (pDlgAlbumInfo.NeedsRefresh)
          {
            m_database.DeleteAlbumInfo(albumName, artistName);
            ShowAlbumInfo(parentWindowID, artistName, albumName, strPath, tag);
            return;
          }
        }
      }
      else
      {
        Log.Debug("No Album Found");

        if (null != pDlgOK)
        {
          pDlgOK.SetHeading(187);
          pDlgOK.SetLine(1, 187);
          pDlgOK.SetLine(2, string.Empty);
          pDlgOK.DoModal(GetID);
        }
      }
    }
    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;
    }
        /// <summary>
        /// Get the details of the track
        /// </summary>
        /// <param name="trackObject"></param>
        private void GetDVDDetails(DBTrackInfo trackObject)
        {
            string strArtistHTML;
              string strAlbumHTML;
              string strArtistURL;
              bool songFound = false;

              List<DBTrackInfo> results = new List<DBTrackInfo>();

              string artist = trackObject.ArtistInfo[0].Artist;

              if (GetArtistHTML(artist, out strArtistHTML, out strArtistURL))
              {
            var artistInfo = new MusicArtistInfo();
            if (artistInfo.Parse(strArtistHTML))
            {
              artistInfo.Artist = artist;
              if (GetDVDURLList(strArtistURL))
              {
            // we have some albums - now check the tracks in each album
            foreach (string albumURL in _albumUrlList)
            {
              if (GetPageHTMLOnly(albumURL, out strAlbumHTML))
              {
                var albumInfo = new MusicAlbumInfo();
                if (albumInfo.Parse(strAlbumHTML))
                {
                  string[] tracksOnAlbum = albumInfo.Tracks.Split('|');
                  foreach (string track in tracksOnAlbum)
                  {
                    if (!string.IsNullOrEmpty(track.Trim()))
                    {
                      string[] trackData = track.Split('@');
                      if (trackObject.Track == trackData[1])
                      {
                        songFound = getTrackComposers(trackObject, strAlbumHTML, trackData[3]);
                        break;
                      }
                    }
                  }
                }
              }
            }
              }
            }
              }
        }
        /// <summary>
        /// Get the Album Art
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public bool GetAlbumArt(DBAlbumInfo mvAlbumObject)
        {
            Logger.Debug("In Method : GetAlbumArt(DBAlbumInfo mv)");

              if (mvAlbumObject == null)
            return false;

              List<string> albumImageList = mvAlbumObject.ArtUrls;
              // Reload existing Artwork - Why springs to mind??
              if (albumImageList.Count > 0)
              {
            // grab album art loading settings
            int maxAlbumArt = mvCentralCore.Settings.MaxAlbumArts;

            int albumartAdded = 0;
            int count = 0;
            foreach (string albumImage in albumImageList)
            {
              if (mvAlbumObject.AlternateArts.Count >= maxAlbumArt)
            break;

              if (mvAlbumObject.AddArtFromURL(albumImage) == ImageLoadResults.SUCCESS)
            albumartAdded++;

              count++;
            }
            // We added some artwork so commit
            if (count > 0)
              mvAlbumObject.Commit();
              }

              // Now add any new art from this provider
              string strAlbumHTML;
              DBArtistInfo artist = null;
              List<DBTrackInfo> tracksOnAlbum = DBTrackInfo.GetEntriesByAlbum(mvAlbumObject);

              if (tracksOnAlbum.Count > 0)
              {
            artist = DBArtistInfo.Get(tracksOnAlbum[0]);

            if (GetAlbumHTML(artist.Artist, mvAlbumObject.Album, out strAlbumHTML))
            {
              var albumInfo = new MusicAlbumInfo();

              if (albumInfo.Parse(strAlbumHTML))
              {
            ImageLoadResults imageLoadResults = mvAlbumObject.AddArtFromURL(albumInfo.ImageURL);

            if (imageLoadResults == ImageLoadResults.SUCCESS || imageLoadResults == ImageLoadResults.SUCCESS_REDUCED_SIZE)
              mvAlbumObject.Commit();
              }
            }
              }
              // We always return sucess...
              return true;
        }
    public void ShowAlbumInfo(int parentWindowID, bool isFolder, string artistName, string albumName, string strPath,
                              MusicTag tag)
    {
      GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);
      GUIDialogProgress dlgProgress =
        (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);

      bool bDisplayErr = false;
      AlbumInfo album = new AlbumInfo();
      MusicAlbumInfo albumInfo = new MusicAlbumInfo();
      if (m_database.GetAlbumInfo(albumName, artistName, ref album))
      {
        albumInfo.Set(album);
      }
      else
      {
        if (null != pDlgOK && !Win32API.IsConnectedToInternet())
        {
          pDlgOK.SetHeading(703);
          pDlgOK.SetLine(1, 703);
          pDlgOK.SetLine(2, string.Empty);
          pDlgOK.DoModal(GetID);
          return;
        }

        // show dialog box indicating we're searching the album
        if (dlgProgress != null)
        {
          dlgProgress.Reset();
          dlgProgress.SetHeading(185);
          dlgProgress.SetLine(1, albumName);
          dlgProgress.SetLine(2, artistName);
          dlgProgress.SetLine(3, tag.Year.ToString());
          dlgProgress.SetPercentage(0);
          //dlgProgress.StartModal(GetID);
          dlgProgress.StartModal(parentWindowID);
          dlgProgress.ShowProgressBar(true);
          dlgProgress.Progress();
        }

        // find album info
        AllmusicSiteScraper scraper = new AllmusicSiteScraper();
        if (scraper.FindAlbumInfo(albumName, artistName, tag.Year))
        {
          if (dlgProgress != null)
          {
            dlgProgress.SetPercentage(30);
            dlgProgress.Progress();
            dlgProgress.Close();
          }
          // Did we find multiple albums?
          int iSelectedAlbum = 0;
          if (scraper.IsMultiple())
          {
            string szText = GUILocalizeStrings.Get(181);
            GUIDialogSelect pDlg = (GUIDialogSelect)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_SELECT);
            if (null != pDlg)
            {
              pDlg.Reset();
              pDlg.SetHeading(szText);
              foreach (MusicAlbumInfo foundAlbum in scraper.GetAlbumsFound())
              {
                pDlg.Add(string.Format("{0} - {1}", foundAlbum.Title, foundAlbum.Artist));
              }
              pDlg.DoModal(parentWindowID);

              // and wait till user selects one
              iSelectedAlbum = pDlg.SelectedLabel;
              if (iSelectedAlbum < 0)
              {
                return;
              }
            }
            // ok, now show dialog we're downloading the album info
            MusicAlbumInfo selectedAlbum = scraper.GetAlbumsFound()[iSelectedAlbum];
            if (null != dlgProgress)
            {
              dlgProgress.Reset();
              dlgProgress.SetHeading(185);
              dlgProgress.SetLine(1, selectedAlbum.Title2);
              dlgProgress.SetLine(2, selectedAlbum.Artist);
              dlgProgress.StartModal(parentWindowID);
              dlgProgress.ShowProgressBar(true);
              dlgProgress.SetPercentage(40);
              dlgProgress.Progress();
            }

            if (!scraper.FindInfoByIndex(iSelectedAlbum))
            {
              if (null != dlgProgress)
              {
                dlgProgress.Close();
              }
              return;
            }
          }

          if (null != dlgProgress)
          {
            dlgProgress.SetPercentage(60);
            dlgProgress.Progress();
          }

          // Now we have either a Single hit or a selected Artist
          // Parse it
          if (albumInfo.Parse(scraper.GetHtmlContent()))
          {
            if (null != dlgProgress)
            {
              dlgProgress.SetPercentage(80);
              dlgProgress.Progress();
            }
            // set album title and artist from musicinfotag, not the one we got from allmusic.com
            albumInfo.Title = albumName;
            albumInfo.Artist = artistName;

            // set path, needed to store album in database
            albumInfo.AlbumPath = strPath;
            album = new AlbumInfo();
            album.Album = albumInfo.Title;
            album.Artist = albumInfo.Artist;
            album.Genre = albumInfo.Genre;
            album.Tones = albumInfo.Tones;
            album.Styles = albumInfo.Styles;
            album.Review = albumInfo.Review;
            album.Image = albumInfo.ImageURL;
            album.Rating = albumInfo.Rating;
            album.Tracks = albumInfo.Tracks;
            try
            {
              album.Year = Int32.Parse(albumInfo.DateOfRelease);
            }
            catch (Exception) {}

            // save to database
            m_database.AddAlbumInfo(album);
            if (null != dlgProgress)
            {
              dlgProgress.SetPercentage(100);
              dlgProgress.Progress();
              dlgProgress.Close();
            }

            if (isFolder)
            {
              // if there's an album thumb
              string thumb = Util.Utils.GetAlbumThumbName(albumInfo.Artist, albumInfo.Title);
              // use the better one
              thumb = Util.Utils.ConvertToLargeCoverArt(thumb);
              // to create a folder.jpg from it
              if (Util.Utils.FileExistsInCache(thumb) && _createMissingFolderThumbs)
              {
                try
                {
                  string folderjpg = Util.Utils.GetFolderThumbForDir(strPath);
                  Util.Utils.FileDelete(folderjpg);
                  File.Copy(thumb, folderjpg);
                }
                catch (Exception) {}
              }
            }
          }
          else
          {
            bDisplayErr = true;
          }
        }
        else
        {
          bDisplayErr = true;
        }
      }

      if (null != dlgProgress)
      {
        dlgProgress.Close();
      }

      if (!bDisplayErr)
      {
        GUIMusicInfo pDlgAlbumInfo = (GUIMusicInfo)GUIWindowManager.GetWindow((int)Window.WINDOW_MUSIC_INFO);
        if (null != pDlgAlbumInfo)
        {
          pDlgAlbumInfo.Album = albumInfo;
          pDlgAlbumInfo.Tag = tag;

          pDlgAlbumInfo.DoModal(parentWindowID);
          if (pDlgAlbumInfo.NeedsRefresh)
          {
            m_database.DeleteAlbumInfo(albumName, artistName);
            ShowAlbumInfo(isFolder, artistName, albumName, strPath, tag);
            return;
          }
        }
        else
        {
          if (null != dlgProgress)
          {
            dlgProgress.Close();
          }
          if (null != pDlgOK)
          {
            pDlgOK.SetHeading(702);
            pDlgOK.SetLine(1, 702);
            pDlgOK.SetLine(2, string.Empty);
            pDlgOK.DoModal(GetID);
          }
        }
      }
    }