public void Set(AlbumInfo album)
 {
     Artist            = album.Artist;
     Title             = album.Album;
     _strDateOfRelease = String.Format("{0}", album.Year);
     Genre             = album.Genre;
     Tones             = album.Tones;
     Styles            = album.Styles;
     Review            = album.Review;
     ImageURL          = album.Image;
     Rating            = album.Rating;
     Tracks            = album.Tracks;
     Title2            = "";
     Loaded            = true;
 }
 public AlbumInfo Clone()
 {
   AlbumInfo newalbum = new AlbumInfo();
   newalbum.Album = Album;
   newalbum.Asin = Asin;
   newalbum.Artist = Artist;
   newalbum.Genre = Genre;
   newalbum.Image = Image;
   newalbum.Rating = Rating;
   newalbum.Review = Review;
   newalbum.Styles = Styles;
   newalbum.Tones = Tones;
   newalbum.Tracks = Tracks;
   newalbum.Year = Year;
   return newalbum;
 }
Exemple #3
0
        public AlbumInfo Clone()
        {
            AlbumInfo newalbum = new AlbumInfo();

            newalbum.Album  = Album;
            newalbum.Asin   = Asin;
            newalbum.Artist = Artist;
            newalbum.Genre  = Genre;
            newalbum.Image  = Image;
            newalbum.Rating = Rating;
            newalbum.Review = Review;
            newalbum.Styles = Styles;
            newalbum.Tones  = Tones;
            newalbum.Tracks = Tracks;
            newalbum.Year   = Year;
            return(newalbum);
        }
Exemple #4
0
 public AlbumInfo Clone()
 {
   var newalbum = new AlbumInfo
     {
       Album = Album,
       Asin = Asin,
       Artist = Artist,
       Genre = Genre,
       Image = Image,
       Rating = Rating,
       Review = Review,
       Styles = Styles,
       Tones = Tones,
       Tracks = Tracks,
       Year = Year
     };
   return newalbum;
 }
Exemple #5
0
        public AlbumInfo Clone()
        {
            var newalbum = new AlbumInfo
            {
                Album  = Album,
                Asin   = Asin,
                Artist = Artist,
                Genre  = Genre,
                Image  = Image,
                Rating = Rating,
                Review = Review,
                Styles = Styles,
                Tones  = Tones,
                Tracks = Tracks,
                Year   = Year
            };

            return(newalbum);
        }
        /// <summary>
        /// Return the Album Info
        /// </summary>
        /// <returns></returns>
        public AlbumInfo Get()
        {
            var album = new AlbumInfo();

            if (_bLoaded)
            {
                int iYear;

                album.Artist = _artist;
                album.Album  = _strTitle;
                Int32.TryParse(_strDateOfRelease, out iYear);
                album.Year   = iYear;
                album.Genre  = _strGenre;
                album.Tones  = _strTones;
                album.Styles = _strStyles;
                album.Review = _strReview;
                album.Image  = _strImageURL;
                album.Rating = _iRating;
                album.Tracks = _strTracks;
            }
            return(album);
        }
    /// <summary>
    /// Take URL of an album details page and scrape details
    /// </summary>
    /// <param name="strUrl">URL of album details page</param>
    /// <returns>True if scrape was successful</returns>
    public bool Parse(string strUrl)
    {
      var albumPage = new HtmlWeb().Load(strUrl);

      // artist
      var strAlbumArtist = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//h3[@class=""album-artist""]/span/a"));
      
      // album
      var strAlbum = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//h2[@class=""album-title""]"));

      // Image URL
      var imgURL =
        AllmusicSiteScraper.CleanAttribute(
          albumPage.DocumentNode.SelectSingleNode(@"//div[@class=""album-cover""]/div[@class=""album-contain""]/img"),
          "src");
    
      // Rating
      var iRating = 0;
      var ratingMatch = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//div[starts-with(@class,""allmusic-rating rating-allmusic"")]"));
      int.TryParse(ratingMatch, out iRating);  
      
      // year
      var iYear = 0;
      var yearMatch = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//div[@class=""release-date""]/span"));
      yearMatch = Regex.Replace(yearMatch, @".*(\d{4})", @"$1");
      int.TryParse(yearMatch, out iYear);

      // review
      var strReview = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//div[@itemprop=""reviewBody""]"));

      // build up track listing into one string
      var strTracks = string.Empty;
      var trackNodes = albumPage.DocumentNode.SelectNodes(@"//tr[@itemprop=""track""]");
      if (trackNodes != null)
      {
        foreach (var track in trackNodes)
        {
          var trackNo = AllmusicSiteScraper.CleanInnerText(track.SelectSingleNode(@"td[@class=""tracknum""]"));
          var title =
            AllmusicSiteScraper.CleanInnerText(
              track.SelectSingleNode(@"td[@class=""title-composer""]/div[@class=""title""]/a"));
          var strDuration = AllmusicSiteScraper.CleanInnerText(track.SelectSingleNode(@"td[@class=""time""]"));
          var iDuration = 0;
          var iPos = strDuration.IndexOf(":", StringComparison.Ordinal);
          if (iPos >= 0)
          {
            var strMin = strDuration.Substring(0, iPos);
            var strSec = strDuration.Substring(iPos + 1);
            int iMin = 0, iSec = 0;
            Int32.TryParse(strMin, out iMin);
            Int32.TryParse(strSec, out iSec);
            iDuration = (iMin*60) + iSec;
          }

          strTracks += trackNo + "@" + title + "@" + iDuration.ToString(CultureInfo.InvariantCulture) + "|";
        }
      }

      // genres
      var strGenres = string.Empty;
      var genreNodes = albumPage.DocumentNode.SelectNodes(@"//section[@class=""basic-info""]/div[@class=""genre""]/div/a");
      if (genreNodes != null)
      {
        strGenres = genreNodes.Aggregate(strGenres, (current, genre) => current + (AllmusicSiteScraper.CleanInnerText(genre) + ", "));
        strGenres = strGenres.TrimEnd(new[] { ',', ' ' }); // remove trailing ", "        
      }

      // build up styles into one string
      var strThemes = string.Empty;
      var themeNodes = albumPage.DocumentNode.SelectNodes(@"//section[@class=""themes""]/div/span[@class=""theme""]/a");
      if (themeNodes != null)
      {
        strThemes = themeNodes.Aggregate(strThemes, (current, theme) => current + (AllmusicSiteScraper.CleanInnerText(theme) + ", "));
        strThemes = strThemes.TrimEnd(new[] { ',', ' ' }); // remove trailing ", "
      }

      // build up moods into one string
      var strMoods = string.Empty;
      var moodNodes = albumPage.DocumentNode.SelectNodes(@"//section[@class=""moods""]/div/span[@class=""mood""]/a");
      if (moodNodes != null)
      {
        strMoods = moodNodes.Aggregate(strMoods, (current, mood) => current + (AllmusicSiteScraper.CleanInnerText(mood) + ", "));
        strMoods = strMoods.TrimEnd(new[] { ',', ' ' }); // remove trailing ", "
      }

      var album = new AlbumInfo
      {
        Album = strAlbum,
        Artist = strAlbumArtist,
        Genre = strGenres,
        Tones = strMoods,
        Styles = strThemes,
        Review = strReview,
        Image = imgURL,
        Rating = iRating,
        Tracks = strTracks,
        AlbumArtist = strAlbumArtist,
        Year = iYear
      };

      Set(album);

      Loaded = true;
      return true;
    }
    public void GetAlbumCovers(string artist, string album, string strPath, int parentWindowID,
                               bool checkForCompilationAlbum)
    {
      _SelectedAlbum = null;
      IsCompilationAlbum = false;

      if (checkForCompilationAlbum)
      {
        IsCompilationAlbum = GetIsCompilationAlbum(strPath, -1);
      }

      _Artist = artist;
      _Album = album;
      _AlbumPath = strPath;
      string origAlbumName = _Album;
      string filteredAlbumFormatString = GUILocalizeStrings.Get(4518);

      if (filteredAlbumFormatString.Length == 0)
      {
        filteredAlbumFormatString = "Album title not found\r\nTrying: {0}";
      }

      _ThumbPath = GetCoverArtThumbPath(artist, album, strPath);
      amazonWS = new AmazonWebservice();
      amazonWS.MaxSearchResultItems = MAX_SEARCH_ITEMS;

      amazonWS.FindCoverArtProgress += new AmazonWebservice.FindCoverArtProgressHandler(amazonWS_GetAlbumInfoProgress);
      amazonWS.FindCoverArtDone += new AmazonWebservice.FindCoverArtDoneHandler(amazonWS_FindCoverArtDone);

      Log.Info("Cover art grabber:getting cover art for [{0}-{1}]...", _Artist, _Album);

      if (IsCompilationAlbum)
      {
        Log.Info("Cover art grabber:compilation album found", _Artist, _Album);

        amazonWS.MaxSearchResultItems = MAX_UNFILTERED_SEARCH_ITEMS;
        _Artist = "";
        string filterString = string.Format("{0} = \"{1}\"", GUILocalizeStrings.Get(484), " ");
        string filter = string.Format(filteredAlbumFormatString, filterString);

        Log.Info("Cover art grabber:trying again with blank artist name...");
        InternalGetAlbumCovers(_Artist, _Album, filter);
      }

      else
      {
        InternalGetAlbumCovers(_Artist, _Album, string.Empty);
      }

      // Did we fail to find any albums?
      if (!amazonWS.HasAlbums && !amazonWS.AbortGrab)
      {
        // Check if the album title includes a disk number description that might 
        // be altering the proper album title such as: White album (Disk 2)

        string cleanAlbumName = string.Empty;

        if (StripDiskNumberFromAlbumName(_Album, ref cleanAlbumName))
        {
          amazonWS.MaxSearchResultItems = MAX_UNFILTERED_SEARCH_ITEMS;

          if (AlbumNotFoundRetryingFiltered != null)
          {
            AlbumNotFoundRetryingFiltered(amazonWS, origAlbumName, cleanAlbumName);
          }

          Log.Info("Cover art grabber:[{0}-{1}] not found. Trying [{0}-{2}]...", _Artist, _Album, cleanAlbumName);

          string filter = string.Format(filteredAlbumFormatString, cleanAlbumName);
          origAlbumName = _Album;
          InternalGetAlbumCovers(_Artist, cleanAlbumName, filter);
        }

        else if (GetProperAlbumName(_Album, ref cleanAlbumName))
        {
          amazonWS.MaxSearchResultItems = MAX_UNFILTERED_SEARCH_ITEMS;

          if (AlbumNotFoundRetryingFiltered != null)
          {
            AlbumNotFoundRetryingFiltered(amazonWS, origAlbumName, cleanAlbumName);
          }

          Log.Info("Cover art grabber:[{0}-{1}] not found. Trying album name without sub-title [{0}-{2}]...", _Artist,
                   _Album, cleanAlbumName);

          string filter = string.Format(filteredAlbumFormatString, cleanAlbumName);
          origAlbumName = _Album;
          InternalGetAlbumCovers(_Artist, cleanAlbumName, filter);
        }
      }

      // Still no albums?
      if (!IsCompilationAlbum && !amazonWS.HasAlbums && !amazonWS.AbortGrab)
      {
        amazonWS.MaxSearchResultItems = MAX_UNFILTERED_SEARCH_ITEMS;

        if (AlbumNotFoundRetryingFiltered != null)
        {
          AlbumNotFoundRetryingFiltered(amazonWS, origAlbumName, GUILocalizeStrings.Get(4506));
        }

        string filterString = string.Format("{0} = \"{1}\"", GUILocalizeStrings.Get(483), " ");
        string filter = string.Format(filteredAlbumFormatString, filterString);

        // Try searching by artist only to get all albums for this artist...
        Log.Info("Cover art grabber:[{0}-{1}] not found. Trying again with blank album name...", _Artist, _Album);
        InternalGetAlbumCovers(_Artist, "", filter);
      }

      // if we're searching for a single album the progress dialog will 
      // be displayed so we need to close it...
      if (SearchMode == SearchDepthMode.Album)
      {
        GUIDialogProgress dlgProgress =
          (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
        if (dlgProgress != null)
        {
          dlgProgress.SetPercentage(100);
          dlgProgress.Progress();
          dlgProgress.Close();
        }
      }

      amazonWS.FindCoverArtProgress -= new AmazonWebservice.FindCoverArtProgressHandler(amazonWS_GetAlbumInfoProgress);
      amazonWS.FindCoverArtDone -= new AmazonWebservice.FindCoverArtDoneHandler(amazonWS_FindCoverArtDone);
    }
    protected virtual void item_OnItemSelected(GUIListItem item, GUIControl parent)
    {
      MusicTag tag = (MusicTag)item.MusicTag;
      if (tag != null)
      {
        // none text values default to 0 and datetime.minvalue so
        // set the appropriate properties to string.empty

        // Duration
        string strDuration = tag.Duration <= 0 ? string.Empty : MediaPortal.Util.Utils.SecondsToHMSString(tag.Duration);
        // Track
        string strTrack = tag.Track <= 0 ? string.Empty : tag.Track.ToString();
        // Year
        string strYear = tag.Year <= 1900 ? string.Empty : tag.Year.ToString();
        // Rating
        string strRating = (Convert.ToDecimal(2 * tag.Rating + 1)).ToString();
        // Bitrate
        string strBitrate = tag.BitRate <= 0 ? string.Empty : tag.BitRate.ToString();
        // Disc ID
        string strDiscID = tag.DiscID <= 0 ? string.Empty : tag.DiscID.ToString();
        // Disc Total
        string strDiscTotal = tag.DiscTotal <= 0 ? string.Empty : tag.DiscTotal.ToString();
        // Times played
        string strTimesPlayed = tag.TimesPlayed <= 0 ? string.Empty : tag.TimesPlayed.ToString();
        // track total
        string strTrackTotal = tag.TrackTotal <= 0 ? string.Empty : tag.TrackTotal.ToString();
        // BPM
        string strBPM = tag.BPM <= 0 ? string.Empty : tag.BPM.ToString();
        // Channels
        string strChannels = tag.Channels <= 0 ? string.Empty : tag.Channels.ToString();
        // Sample Rate
        string strSampleRate = tag.SampleRate <= 0 ? string.Empty : tag.SampleRate.ToString();
        // Date Last Played
        string strDateLastPlayed = tag.DateTimePlayed == DateTime.MinValue
                                     ? string.Empty
                                     : tag.DateTimePlayed.ToShortDateString();
        // Date Added
        string strDateAdded = tag.DateTimeModified == DateTime.MinValue
                                ? string.Empty
                                : tag.DateTimeModified.ToShortDateString();

        if (item.IsFolder || item.Label == "..")
        {
          GUIPropertyManager.SetProperty("#music.title", string.Empty);
          GUIPropertyManager.SetProperty("#music.track", string.Empty);
          GUIPropertyManager.SetProperty("#music.rating", string.Empty);
          GUIPropertyManager.SetProperty("#music.duration", string.Empty);
          GUIPropertyManager.SetProperty("#music.artist", string.Empty);
          GUIPropertyManager.SetProperty("#music.bitRate", string.Empty);
          GUIPropertyManager.SetProperty("#music.comment", string.Empty);
          GUIPropertyManager.SetProperty("#music.composer", string.Empty);
          GUIPropertyManager.SetProperty("#music.conductor", string.Empty);
          GUIPropertyManager.SetProperty("#music.lyrics", string.Empty);
          GUIPropertyManager.SetProperty("#music.timesplayed", string.Empty);
          GUIPropertyManager.SetProperty("#music.filetype", string.Empty);
          GUIPropertyManager.SetProperty("#music.codec", string.Empty);
          GUIPropertyManager.SetProperty("#music.bitratemode", string.Empty);
          GUIPropertyManager.SetProperty("#music.bpm", string.Empty);
          GUIPropertyManager.SetProperty("#music.channels", string.Empty);
          GUIPropertyManager.SetProperty("#music.samplerate", string.Empty);
        }
        else
        {
          GUIPropertyManager.SetProperty("#music.title", tag.Title);
          GUIPropertyManager.SetProperty("#music.track", strTrack);
          GUIPropertyManager.SetProperty("#music.rating", strRating);
          GUIPropertyManager.SetProperty("#music.duration", strDuration);
          GUIPropertyManager.SetProperty("#music.artist", tag.Artist);
          GUIPropertyManager.SetProperty("#music.bitRate", strBitrate);
          GUIPropertyManager.SetProperty("#music.comment", tag.Comment);
          GUIPropertyManager.SetProperty("#music.composer", tag.Composer);
          GUIPropertyManager.SetProperty("#music.conductor", tag.Conductor);
          GUIPropertyManager.SetProperty("#music.lyrics", tag.Lyrics);
          GUIPropertyManager.SetProperty("#music.timesplayed", strTimesPlayed);
          GUIPropertyManager.SetProperty("#music.filetype", tag.FileType);
          GUIPropertyManager.SetProperty("#music.codec", tag.Codec);
          GUIPropertyManager.SetProperty("#music.bitratemode", tag.BitRateMode);
          GUIPropertyManager.SetProperty("#music.bpm", strBPM);
          GUIPropertyManager.SetProperty("#music.channels", strChannels);
          GUIPropertyManager.SetProperty("#music.samplerate", strSampleRate);
        }

        GUIPropertyManager.SetProperty("#music.album", tag.Album);
        GUIPropertyManager.SetProperty("#music.genre", tag.Genre);
        GUIPropertyManager.SetProperty("#music.year", strYear);
        GUIPropertyManager.SetProperty("#music.albumArtist", tag.AlbumArtist);
        GUIPropertyManager.SetProperty("#music.discid", strDiscID);
        GUIPropertyManager.SetProperty("#music.disctotal", strDiscTotal);
        GUIPropertyManager.SetProperty("#music.trackTotal", strTrackTotal);
        GUIPropertyManager.SetProperty("#music.datelastplayed", strDateLastPlayed);
        GUIPropertyManager.SetProperty("#music.dateadded", strDateAdded);

        // see if we have album info
        AlbumInfo _albumInfo = new AlbumInfo();
        if (MusicDatabase.Instance.GetAlbumInfo(tag.Album, tag.AlbumArtist, ref _albumInfo))
        {
          GUIPropertyManager.SetProperty("#AlbumInfo.Review", _albumInfo.Review);
          GUIPropertyManager.SetProperty("#AlbumInfo.Rating", _albumInfo.Rating.ToString());
          GUIPropertyManager.SetProperty("#AlbumInfo.Genre", _albumInfo.Genre);
          GUIPropertyManager.SetProperty("#AlbumInfo.Styles", _albumInfo.Styles);
          GUIPropertyManager.SetProperty("#AlbumInfo.Tones", _albumInfo.Tones);
          GUIPropertyManager.SetProperty("#AlbumInfo.Year", _albumInfo.Year.ToString());
        }
        else
        {
          GUIPropertyManager.SetProperty("#AlbumInfo.Review", string.Empty);
          GUIPropertyManager.SetProperty("#AlbumInfo.Rating", string.Empty);
          GUIPropertyManager.SetProperty("#AlbumInfo.Genre", string.Empty);
          GUIPropertyManager.SetProperty("#AlbumInfo.Styles", string.Empty);
          GUIPropertyManager.SetProperty("#AlbumInfo.Tones", string.Empty);
          GUIPropertyManager.SetProperty("#AlbumInfo.Year", string.Empty);
        }

        // see if we have artist info
        ArtistInfo _artistInfo = new ArtistInfo();
        String strArtist;
        if (string.IsNullOrEmpty(tag.Artist))
        {
          strArtist = tag.AlbumArtist;
        }
        else
        {
          strArtist = tag.Artist;
        }
        if (MusicDatabase.Instance.GetArtistInfo(strArtist, ref _artistInfo))
        {
          GUIPropertyManager.SetProperty("#ArtistInfo.Bio", _artistInfo.AMGBio);
          GUIPropertyManager.SetProperty("#ArtistInfo.Born", _artistInfo.Born);
          GUIPropertyManager.SetProperty("#ArtistInfo.Genres", _artistInfo.Genres);
          GUIPropertyManager.SetProperty("#ArtistInfo.Instruments", _artistInfo.Instruments);
          GUIPropertyManager.SetProperty("#ArtistInfo.Styles", _artistInfo.Styles);
          GUIPropertyManager.SetProperty("#ArtistInfo.Tones", _artistInfo.Tones);
          GUIPropertyManager.SetProperty("#ArtistInfo.YearsActive", _artistInfo.YearsActive);
        }
        else
        {
          GUIPropertyManager.SetProperty("#ArtistInfo.Bio", string.Empty);
          GUIPropertyManager.SetProperty("#ArtistInfo.Born", string.Empty);
          GUIPropertyManager.SetProperty("#ArtistInfo.Genres", string.Empty);
          GUIPropertyManager.SetProperty("#ArtistInfo.Instruments", string.Empty);
          GUIPropertyManager.SetProperty("#ArtistInfo.Styles", string.Empty);
          GUIPropertyManager.SetProperty("#ArtistInfo.Tones", string.Empty);
          GUIPropertyManager.SetProperty("#ArtistInfo.YearsActive", string.Empty);
        }
      }
      else
      {
        GUIPropertyManager.SetProperty("#music.title", string.Empty);
        GUIPropertyManager.SetProperty("#music.track", string.Empty);
        GUIPropertyManager.SetProperty("#music.album", string.Empty);
        GUIPropertyManager.SetProperty("#music.artist", string.Empty);
        GUIPropertyManager.SetProperty("#music.genre", string.Empty);
        GUIPropertyManager.SetProperty("#music.year", string.Empty);
        GUIPropertyManager.SetProperty("#music.rating", string.Empty);
        GUIPropertyManager.SetProperty("#music.duration", string.Empty);
        GUIPropertyManager.SetProperty("#music.albumArtist", string.Empty);
        GUIPropertyManager.SetProperty("#music.bitRate", string.Empty);
        GUIPropertyManager.SetProperty("#music.comment", string.Empty);
        GUIPropertyManager.SetProperty("#music.composer", string.Empty);
        GUIPropertyManager.SetProperty("#music.conductor", string.Empty);
        GUIPropertyManager.SetProperty("#music.discid", string.Empty);
        GUIPropertyManager.SetProperty("#music.disctotal", string.Empty);
        GUIPropertyManager.SetProperty("#music.lyrics", string.Empty);
        GUIPropertyManager.SetProperty("#music.timesplayed", string.Empty);
        GUIPropertyManager.SetProperty("#music.trackTotal", string.Empty);
        GUIPropertyManager.SetProperty("#music.filetype", string.Empty);
        GUIPropertyManager.SetProperty("#music.codec", string.Empty);
        GUIPropertyManager.SetProperty("#music.bitratemode", string.Empty);
        GUIPropertyManager.SetProperty("#music.bpm", string.Empty);
        GUIPropertyManager.SetProperty("#music.channels", string.Empty);
        GUIPropertyManager.SetProperty("#music.samplerate", string.Empty);
        GUIPropertyManager.SetProperty("#music.datelastplayed", string.Empty);
        GUIPropertyManager.SetProperty("#music.dateadded", string.Empty);
      }

      GUIFilmstripControl filmstrip = parent as GUIFilmstripControl;
      if (filmstrip == null)
      {
        return;
      }

      if (item.Label == "..")
      {
        filmstrip.InfoImageFileName = string.Empty;
        return;
      }
      else
      {
        filmstrip.InfoImageFileName = item.ThumbnailImage;
      }
    }
    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);
        }
      }
    }
    /// <summary>
    /// Return the Album Info
    /// </summary>
    /// <returns></returns>
    public AlbumInfo Get()
    {
     var album = new AlbumInfo();
      if (_bLoaded)
      {
        int iYear;

        album.Artist = _artist;
        album.Album = _strTitle;
        Int32.TryParse(_strDateOfRelease, out iYear);
        album.Year = iYear;
        album.Genre = _strGenre;
        album.Tones = _strTones;
        album.Styles = _strStyles;
        album.Review = _strReview;
        album.Image = _strImageURL;
        album.Rating = _iRating;
        album.Tracks = _strTracks;

      }
      return album;
    }
    public bool GetAlbumInfo(string aAlbumName, string aArtistName, ref AlbumInfo aAlbumInfo)
    {
      try
      {
        string strArtist = aArtistName;
        DatabaseUtility.RemoveInvalidChars(ref strArtist);

        string strAlbum = aAlbumName;
        DatabaseUtility.RemoveInvalidChars(ref strAlbum);

        string strSQL;
        strSQL = String.Format("select * from albuminfo where strArtist like '{0}%' and strAlbum  like '{1}'", strArtist,
                               strAlbum);
        SQLiteResultSet results;
        results = MusicDbClient.Execute(strSQL);
        if (results.Rows.Count != 0)
        {
          aAlbumInfo.Rating = DatabaseUtility.GetAsInt(results, 0, "albuminfo.iRating");
          aAlbumInfo.Year = DatabaseUtility.GetAsInt(results, 0, "albuminfo.iYear");
          aAlbumInfo.Album = DatabaseUtility.Get(results, 0, "album.strAlbum");
          aAlbumInfo.Artist = DatabaseUtility.Get(results, 0, "artist.strArtist");
          aAlbumInfo.Genre = DatabaseUtility.Get(results, 0, "genre.strGenre");
          aAlbumInfo.Image = DatabaseUtility.Get(results, 0, "albuminfo.strImage");
          aAlbumInfo.Review = DatabaseUtility.Get(results, 0, "albuminfo.strReview");
          aAlbumInfo.Styles = DatabaseUtility.Get(results, 0, "albuminfo.strStyles");
          aAlbumInfo.Tones = DatabaseUtility.Get(results, 0, "albuminfo.strTones");
          aAlbumInfo.Tracks = DatabaseUtility.Get(results, 0, "albuminfo.strTracks");
          //album.Path   = DatabaseUtility.Get(results,0,"path.strPath");
          return true;
        }
        return false;
      }
      catch (Exception ex)
      {
        Log.Error("musicdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        Open();
      }

      return false;
    }
    public bool GetAlbums(int aSearchKind, string aAlbum, ref ArrayList aAlbumArray)
    {
      try
      {
        string strAlbum = aAlbum;
        aAlbumArray.Clear();

        DatabaseUtility.RemoveInvalidChars(ref strAlbum);

        string strSQL = "SELECT * FROM tracks WHERE strAlbum LIKE ";
        switch (aSearchKind)
        {
          case 0:
            strSQL += String.Format("'{0}%'", strAlbum);
            break;
          case 1:
            strSQL += String.Format("'%{0}%'", strAlbum);
            break;
          case 2:
            strSQL += String.Format("'%{0}'", strAlbum);
            break;
          case 3:
            strSQL += String.Format("'{0}'", strAlbum);
            break;
          default:
            return false;
        }
        strSQL += " GROUP BY strAlbum";

        SQLiteResultSet results = DirectExecute(strSQL);
        if (results.Rows.Count == 0)
        {
          return false;
        }

        for (int i = 0; i < results.Rows.Count; ++i)
        {
          AlbumInfo album = new AlbumInfo();
          album.Album = DatabaseUtility.Get(results, i, "strAlbum");
          album.AlbumArtist = DatabaseUtility.Get(results, i, "strAlbumArtist");
          album.Artist = DatabaseUtility.Get(results, i, "strArtist");
          //album.IdAlbum = DatabaseUtility.GetAsInt(results, i, "album.idAlbumArtist");  //album.IdAlbum contains IdAlbumArtist
          aAlbumArray.Add(album);
        }
        if (aAlbumArray.Count > 0)
        {
          return true;
        }
      }
      catch (Exception ex)
      {
        Log.Error("musicdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        Open();
      }

      return false;
    }
    public bool GetAllAlbums(ref List<AlbumInfo> aAlbumInfoList)
    {
      try
      {
        aAlbumInfoList.Clear();

        string strSQL;
        strSQL =
          String.Format(
            "SELECT strAlbum, strAlbumArtist, strArtist, iYear FROM tracks GROUP BY strAlbum ORDER BY strAlbumArtist, strAlbum, iYear");

        SQLiteResultSet results = DirectExecute(strSQL);
        if (results.Rows.Count == 0)
        {
          return false;
        }

        for (int i = 0; i < results.Rows.Count; ++i)
        {
          AlbumInfo album = new AlbumInfo();
          album.Album = DatabaseUtility.Get(results, i, "strAlbum");
          album.AlbumArtist = DatabaseUtility.Get(results, i, "strAlbumArtist");
          album.Artist = DatabaseUtility.Get(results, i, "strArtist");

          aAlbumInfoList.Add(album);
        }
        if (aAlbumInfoList.Count > 0)
        {
          return true;
        }
      }
      catch (Exception ex)
      {
        Log.Error("musicdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        Open();
      }

      return false;
    }
    /// <summary>
    /// Return the Album Info
    /// </summary>
    /// <returns></returns>
    public AlbumInfo Get()
    {
     var album = new AlbumInfo();
      if (_bLoaded)
      {
        int iYear;

        album.Artist = Artist;
        album.Album = Title;
        Int32.TryParse(DateOfRelease, out iYear);
        album.Year = iYear;
        album.Genre = Genre;
        album.Tones = Tones;
        album.Styles = Styles;
        album.Review = Review;
        album.Image = ImageURL;
        album.Rating = Rating;
        album.Tracks = Tracks;

      }
      return album;
    }
    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);
          }
        }
      }
    }
Exemple #17
0
        /// <summary>
        /// Grab the album data and process
        /// </summary>
        /// <param name="mv"></param>
        /// <param name="artist"></param>
        /// <param name="album"></param>
        /// <param name="mbid"></param>
        private void setMusicVideoAlbum(ref DBAlbumInfo mv, string artistName, string albumName, string mbid)
        {
            if (string.IsNullOrEmpty(artistName) && string.IsNullOrEmpty(albumName))
            {
                return;
            }
            logger.Debug(string.Format("In Method: setMusicVideoAlbum(ref DBAlbumInfo mv, Atrist: {0}, Album: {1}, MBID: {2})", artistName, albumName, mbid));

            MusicDatabase m_db = null;

            try
            {
                m_db = MusicDatabase.Instance;
            }
            catch (Exception e)
            {
                logger.Error("setMusicVideoAlbum: Music database init failed " + e.ToString());
                return;
            }

            var albumInfo = new MediaPortal.Music.Database.AlbumInfo();

            if (!m_db.GetAlbumInfo(albumName, artistName, ref albumInfo))
            {
                return;
            }

            // Album name
            if (albumInfo.Album.ToLower() == albumInfo.Album)
            {
                mv.Album = System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(albumInfo.Album);
            }
            else
            {
                mv.Album = albumInfo.Album;
            }
            // MBID
            // mv.MdID
            // Image URL
            if (!string.IsNullOrEmpty(albumInfo.Image) && !mv.ArtUrls.Contains(albumInfo.Image))
            {
                mv.ArtUrls.Add(albumInfo.Image);
            }
            // Tags: Actors, Directors and Writers
            // mv.Tag.Add(tagstr);
            // WIKI
            mv.bioSummary = albumInfo.Review;
            mv.bioContent = albumInfo.Review;
            // Tag
            char[]   delimiters = new char[] { ',' };
            string[] tags       = albumInfo.Styles.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tag in tags)
            {
                mv.Tag.Add(tag.Trim());
            }
            // Additional
            if (albumInfo.Year > 0)
            {
                mv.YearReleased = Convert.ToString(albumInfo.Year);
            }
        }
    public bool Parse(string html)
    {
      // artist
      var strAlbumArtist = string.Empty;
      var artistMatch = ArtistRegEx.Match(html);
      if (artistMatch.Success)
      {
        strAlbumArtist = artistMatch.Groups["artist"].Value.Trim();
      }

      // album
      var strAlbum = string.Empty;
      var albumMatch = AlbumRegEx.Match(html);
      if (albumMatch.Success)
      {
        strAlbum = albumMatch.Groups["album"].Value.Trim();
      }

      // Image URL
      var imgURL = string.Empty;
      var imgMatch = AlbumImgURLRegEx.Match(html);
      if (imgMatch.Success)
      {
        imgURL = imgMatch.Groups["imageURL"].Value;
        imgURL = imgURL.Replace(@"\", @"");
        if (!string.IsNullOrEmpty(imgURL))
        {
          imgURL = "http" + imgURL;
        }
      }

      // Rating
      var dRating = 0.0;
      var ratingMatch = AlbumRatingRegEx.Match(html);
      if (ratingMatch.Success)
      {
        double.TryParse(ratingMatch.Groups["rating"].Value.Trim(), out dRating);  
      }
      
      // year
      var iYear = 0;
      var yearMatch = AlbumYearRegEx.Match(html);
      if (yearMatch.Success)
      {
        int.TryParse(yearMatch.Groups["year"].Value.Trim(), out iYear);
      }

      // review
      var reviewMatch = AlbumReviewRegEx.Match(html);
      var strReview = string.Empty;
      if (reviewMatch.Success)
      {
        strReview = HTMLRegEx.Replace(reviewMatch.Groups["review"].Value.Trim(), "");
      }

      // build up track listing into one string
      var strTracks = string.Empty;
      var trackMatch = AlbumTracksRegEx.Match(html);
      if (trackMatch.Success)
      {
        var tracks = TrackRegEx.Matches(trackMatch.Groups["tracks"].Value.Trim());
        foreach (Match track in tracks)
        {
          var strDuration = track.Groups["time"].Value;
          var iDuration = 0;
          var iPos = strDuration.IndexOf(":", StringComparison.Ordinal);
          if (iPos >= 0)
          {
            var strMin = strDuration.Substring(0, iPos);
            var strSec = strDuration.Substring(iPos + 1);
            int iMin = 0, iSec = 0;
            Int32.TryParse(strMin, out iMin);
            Int32.TryParse(strSec, out iSec);
            iDuration = (iMin*60) + iSec;
          }

          strTracks += track.Groups["trackNo"].Value + "@" + track.Groups["title"].Value + "@" +
                       iDuration.ToString(CultureInfo.InvariantCulture) + "|";
        }
      }

      // build up genres into one string
      var strGenres = string.Empty;
      var genreMatch = AlbumGenreRegEx.Match(html);
      if (genreMatch.Success)
      {
        var genres = HTMLListRegEx.Matches(genreMatch.Groups["genres"].Value.Trim());
        foreach (var genre in genres)
        {
          var cleanGenre = HTMLRegEx.Replace(genre.ToString(), "");
          strGenres += cleanGenre + ", ";
        }
        strGenres = strGenres.TrimEnd(new[] {' ', ','});
      }

      // build up styles into one string
      var strStyles = string.Empty;
      var styleMatch = AlbumStylesRegEx.Match(html);
      if (styleMatch.Success)
      {
        var styles = HTMLListRegEx.Matches(styleMatch.Groups["styles"].Value.Trim());
        foreach (var style in styles)
        {
          var cleanStyle = HTMLRegEx.Replace(style.ToString(), "");
          strStyles += cleanStyle + ", ";
        }
        strStyles = strStyles.TrimEnd(new[] {' ', ','});
      }

      // build up moods into one string
      var strMoods = string.Empty;
      var moodMatch = AlbumMoodsRegEx.Match(html);
      if (moodMatch.Success)
      {
        var moods = HTMLListRegEx.Matches(moodMatch.Groups["moods"].Value.Trim());
        foreach (var mood in moods)
        {
          var cleanMood = HTMLRegEx.Replace(mood.ToString(), "");
          strMoods += cleanMood + ", ";
        }
        strMoods = strMoods.TrimEnd(new[] {' ', ','});
      }

      var album = new AlbumInfo
      {
        Album = strAlbum,
        Artist = strAlbumArtist,
        Genre = strGenres,
        Tones = strMoods,
        Styles = strStyles,
        Review = strReview,
        Image = imgURL,
        Rating = (int)(dRating * 2),
        Tracks = strTracks,
        AlbumArtist = strAlbumArtist,
        Year = iYear
      };

      Set(album);

      Loaded = true;
      return true;
    }
 public void Set(AlbumInfo album)
 {
   Artist = album.Artist;
   Title = album.Album;
   _strDateOfRelease = String.Format("{0}", album.Year);
   Genre = album.Genre;
   Tones = album.Tones;
   Styles = album.Styles;
   Review = album.Review;
   ImageURL = album.Image;
   Rating = album.Rating;
   Tracks = album.Tracks;
   Title2 = "";
   Loaded = true;
 }
Exemple #20
0
        /// <summary>
        /// Take URL of an album details page and scrape details
        /// </summary>
        /// <param name="strUrl">URL of album details page</param>
        /// <returns>True if scrape was successful</returns>
        public bool Parse(string strUrl)
        {
            var albumPage = new HtmlWeb().Load(strUrl);

            // artist
            var strAlbumArtist = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//h3[@class=""album-artist""]/span/a"));

            // album
            var strAlbum = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//h2[@class=""album-title""]"));

            // Image URL
            var imgURL =
                AllmusicSiteScraper.CleanAttribute(
                    albumPage.DocumentNode.SelectSingleNode(@"//div[@class=""album-cover""]/div[@class=""album-contain""]/img"),
                    "src");

            // Rating
            var iRating     = 0;
            var ratingMatch = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//div[starts-with(@class,""allmusic-rating rating-allmusic"")]"));

            int.TryParse(ratingMatch, out iRating);

            // year
            var iYear     = 0;
            var yearMatch = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//div[@class=""release-date""]/span"));

            yearMatch = Regex.Replace(yearMatch, @".*(\d{4})", @"$1");
            int.TryParse(yearMatch, out iYear);

            // review
            var strReview = AllmusicSiteScraper.CleanInnerText(albumPage.DocumentNode.SelectSingleNode(@"//div[@itemprop=""reviewBody""]"));

            // build up track listing into one string
            var strTracks  = string.Empty;
            var trackNodes = albumPage.DocumentNode.SelectNodes(@"//tr[@itemprop=""track""]");

            if (trackNodes != null)
            {
                foreach (var track in trackNodes)
                {
                    var trackNo = AllmusicSiteScraper.CleanInnerText(track.SelectSingleNode(@"td[@class=""tracknum""]"));
                    var title   =
                        AllmusicSiteScraper.CleanInnerText(
                            track.SelectSingleNode(@"td[@class=""title-composer""]/div[@class=""title""]/a"));
                    var strDuration = AllmusicSiteScraper.CleanInnerText(track.SelectSingleNode(@"td[@class=""time""]"));
                    var iDuration   = 0;
                    var iPos        = strDuration.IndexOf(":", StringComparison.Ordinal);
                    if (iPos >= 0)
                    {
                        var strMin = strDuration.Substring(0, iPos);
                        var strSec = strDuration.Substring(iPos + 1);
                        int iMin = 0, iSec = 0;
                        Int32.TryParse(strMin, out iMin);
                        Int32.TryParse(strSec, out iSec);
                        iDuration = (iMin * 60) + iSec;
                    }

                    strTracks += trackNo + "@" + title + "@" + iDuration.ToString(CultureInfo.InvariantCulture) + "|";
                }
            }

            // genres
            var strGenres  = string.Empty;
            var genreNodes = albumPage.DocumentNode.SelectNodes(@"//section[@class=""basic-info""]/div[@class=""genre""]/div/a");

            if (genreNodes != null)
            {
                strGenres = genreNodes.Aggregate(strGenres, (current, genre) => current + (AllmusicSiteScraper.CleanInnerText(genre) + ", "));
                strGenres = strGenres.TrimEnd(new[] { ',', ' ' }); // remove trailing ", "
            }

            // build up styles into one string
            var strThemes  = string.Empty;
            var themeNodes = albumPage.DocumentNode.SelectNodes(@"//section[@class=""themes""]/div/span[@class=""theme""]/a");

            if (themeNodes != null)
            {
                strThemes = themeNodes.Aggregate(strThemes, (current, theme) => current + (AllmusicSiteScraper.CleanInnerText(theme) + ", "));
                strThemes = strThemes.TrimEnd(new[] { ',', ' ' }); // remove trailing ", "
            }

            // build up moods into one string
            var strMoods  = string.Empty;
            var moodNodes = albumPage.DocumentNode.SelectNodes(@"//section[@class=""moods""]/div/span[@class=""mood""]/a");

            if (moodNodes != null)
            {
                strMoods = moodNodes.Aggregate(strMoods, (current, mood) => current + (AllmusicSiteScraper.CleanInnerText(mood) + ", "));
                strMoods = strMoods.TrimEnd(new[] { ',', ' ' }); // remove trailing ", "
            }

            var album = new AlbumInfo
            {
                Album       = strAlbum,
                Artist      = strAlbumArtist,
                Genre       = strGenres,
                Tones       = strMoods,
                Styles      = strThemes,
                Review      = strReview,
                Image       = imgURL,
                Rating      = iRating,
                Tracks      = strTracks,
                AlbumArtist = strAlbumArtist,
                Year        = iYear
            };

            Set(album);

            Loaded = true;
            return(true);
        }
    public void FindCoverArt(bool isFolder, string artistName, string albumName, string strPath, MusicTag tag,
                             int albumId)
    {
      GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);

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

        //throw new Exception("no internet");
        return;
      }

      else if (!Win32API.IsConnectedToInternet())
      {
        //throw new Exception("no internet");
        return;
      }

      bool bDisplayErr = false;
      GUIDialogOK dlgOk = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);
      AlbumInfo albuminfo = new AlbumInfo();
      MusicAlbumInfo album = new MusicAlbumInfo();

      GUICoverArtGrabberResults guiCoverGrabberResults =
        (GUICoverArtGrabberResults)GUIWindowManager.GetWindow((int)Window.WINDOW_MUSIC_COVERART_GRABBER_RESULTS);

      if (null != guiCoverGrabberResults)
      {
        guiCoverGrabberResults.SearchMode = GUICoverArtGrabberResults.SearchDepthMode.Album;
        GUIDialogProgress dlgProgress =
          (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);

        if (dlgProgress != null)
        {
          dlgProgress.Reset();
          dlgProgress.SetHeading(185);
          dlgProgress.SetLine(1, albumName);
          dlgProgress.SetLine(2, artistName);
          dlgProgress.SetLine(3, string.Empty);
          dlgProgress.StartModal(GetID);
        }

        guiCoverGrabberResults.GetAlbumCovers(artistName, albumName, strPath, GetID, true);
        guiCoverGrabberResults.DoModal(GetID);
        albuminfo = guiCoverGrabberResults.SelectedAlbum;

        if (GUICoverArtGrabberResults.CancelledByUser)
        {
          string line1Text = GUILocalizeStrings.Get(4507);

          if (line1Text.Length == 0)
          {
            line1Text = "Cover art grabber aborted by user";
          }

          string caption = GUILocalizeStrings.Get(4511);

          if (caption.Length == 0)
          {
            caption = "Cover Art Grabber Done";
          }

          if (null != dlgOk)
          {
            dlgOk.SetHeading(caption);
            dlgOk.SetLine(1, line1Text);
            dlgOk.SetLine(2, string.Empty);
            dlgOk.DoModal(GetID);
          }
        }

        else if (albuminfo != null)
        {
          // the GUICoverArtGrabberResults::SelectedAlbum AlbumInfo object contains
          // the Artist and Album name returned by the Amazon Webservice which may not
          // match our original artist and album.  We want to use the original artist
          // and album name...

          albuminfo.Artist = artistName;
          albuminfo.Album = albumName;
          SaveCoverArtImage(albuminfo, strPath, true, true);
          facadeLayout.RefreshCoverArt();
        }

        else
        {
          bDisplayErr = true;
        }
      }

      if (bDisplayErr)
      {
        if (null != dlgOk)
        {
          dlgOk.SetHeading(187);
          dlgOk.SetLine(1, 187);
          dlgOk.SetLine(2, string.Empty);
          dlgOk.DoModal(GetID);
        }
      }
    }
 /// <summary>
 /// Set the Album Information - override existing data
 /// </summary>
 /// <param name="mv"></param>
 /// <param name="albumInfo"></param>
 private void SetMusicVideoAlbum(ref DBAlbumInfo mv, AlbumInfo albumInfo)
 {
     mv.bioSummary = getBioSummary(albumInfo.Review, 50);
       mv.bioContent = albumInfo.Review;
       mv.YearReleased = albumInfo.Year.ToString();
       mv.Rating = albumInfo.Rating;
 }
    protected bool SaveCoverArtImage(AlbumInfo albumInfo, string aAlbumSharePath, bool aSaveToAlbumShare,
                                     bool aSaveToAlbumThumbFolder)
    {
      bool result = false;
      bool isCdOrDVD = Util.Utils.IsDVD(aAlbumSharePath);
      string sharePath = Util.Utils.RemoveTrailingSlash(aAlbumSharePath);

      try
      {
        Image coverImg = AmazonWebservice.GetImageFromURL(albumInfo.Image);
        string thumbPath = Util.Utils.GetAlbumThumbName(albumInfo.Artist, albumInfo.Album);

        if (thumbPath.Length == 0 || coverImg == null)
        {
          return false;
        }

        //if (bSaveToThumbsFolder)
        if (aSaveToAlbumShare && !isCdOrDVD)
        {
          string folderjpg = String.Format(@"{0}\folder.jpg", sharePath);

          if (Util.Utils.FileExistsInCache(folderjpg))
          {
            File.Delete(folderjpg);
          }

          coverImg.Save(folderjpg);
          File.SetAttributes(folderjpg, File.GetAttributes(folderjpg) | FileAttributes.Hidden);
          // no need to check for that option as it is the user's decision.   if (_createMissingFolderThumbCache)
          FolderThumbCacher thumbworker = new FolderThumbCacher(sharePath, true);
          result = true;
        }

        if (aSaveToAlbumThumbFolder || isCdOrDVD)
        {
          if (Util.Utils.FileExistsInCache(thumbPath))
          {
            File.Delete(thumbPath);
          }

          if (Util.Picture.CreateThumbnail(coverImg, thumbPath, (int)Thumbs.ThumbResolution,
                                           (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsSmall))
          {
            result = true;
            Util.Picture.CreateThumbnail(coverImg, thumbPath, (int)Thumbs.ThumbLargeResolution,
                                         (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsLarge);
          }
        }
      }

      catch
      {
        result = false;
      }

      return result;
    }
        public bool Parse(string html)
        {
            // artist
            var strAlbumArtist = string.Empty;
            var artistMatch    = ArtistRegEx.Match(html);

            if (artistMatch.Success)
            {
                strAlbumArtist = artistMatch.Groups["artist"].Value.Trim();
            }

            // album
            var strAlbum   = string.Empty;
            var albumMatch = AlbumRegEx.Match(html);

            if (albumMatch.Success)
            {
                strAlbum = albumMatch.Groups["album"].Value.Trim();
            }

            // Image URL
            var imgURL   = string.Empty;
            var imgMatch = AlbumImgURLRegEx.Match(html);

            if (imgMatch.Success)
            {
                imgURL = imgMatch.Groups["imageURL"].Value;
                imgURL = imgURL.Replace(@"\", @"");
                if (!string.IsNullOrEmpty(imgURL))
                {
                    imgURL = "http" + imgURL;
                }
            }

            // Rating
            var dRating     = 0.0;
            var ratingMatch = AlbumRatingRegEx.Match(html);

            if (ratingMatch.Success)
            {
                double.TryParse(ratingMatch.Groups["rating"].Value.Trim(), out dRating);
            }

            // year
            var iYear     = 0;
            var yearMatch = AlbumYearRegEx.Match(html);

            if (yearMatch.Success)
            {
                int.TryParse(yearMatch.Groups["year"].Value.Trim(), out iYear);
            }

            // review
            var reviewMatch = AlbumReviewRegEx.Match(html);
            var strReview   = string.Empty;

            if (reviewMatch.Success)
            {
                strReview = HTMLRegEx.Replace(reviewMatch.Groups["review"].Value.Trim(), "");
            }

            // build up track listing into one string
            var strTracks  = string.Empty;
            var trackMatch = AlbumTracksRegEx.Match(html);

            if (trackMatch.Success)
            {
                var tracks = TrackRegEx.Matches(trackMatch.Groups["tracks"].Value.Trim());
                foreach (Match track in tracks)
                {
                    var strDuration = track.Groups["time"].Value;
                    var iDuration   = 0;
                    var iPos        = strDuration.IndexOf(":", StringComparison.Ordinal);
                    if (iPos >= 0)
                    {
                        var strMin = strDuration.Substring(0, iPos);
                        var strSec = strDuration.Substring(iPos + 1);
                        int iMin = 0, iSec = 0;
                        Int32.TryParse(strMin, out iMin);
                        Int32.TryParse(strSec, out iSec);
                        iDuration = (iMin * 60) + iSec;
                    }

                    strTracks += track.Groups["trackNo"].Value + "@" + track.Groups["title"].Value + "@" +
                                 iDuration.ToString(CultureInfo.InvariantCulture) + "|";
                }
            }

            // build up genres into one string
            var strGenres  = string.Empty;
            var genreMatch = AlbumGenreRegEx.Match(html);

            if (genreMatch.Success)
            {
                var genres = HTMLListRegEx.Matches(genreMatch.Groups["genres"].Value.Trim());
                foreach (var genre in genres)
                {
                    var cleanGenre = HTMLRegEx.Replace(genre.ToString(), "");
                    strGenres += cleanGenre + ", ";
                }
                strGenres = strGenres.TrimEnd(new[] { ' ', ',' });
            }

            // build up styles into one string
            var strStyles  = string.Empty;
            var styleMatch = AlbumStylesRegEx.Match(html);

            if (styleMatch.Success)
            {
                var styles = HTMLListRegEx.Matches(styleMatch.Groups["styles"].Value.Trim());
                foreach (var style in styles)
                {
                    var cleanStyle = HTMLRegEx.Replace(style.ToString(), "");
                    strStyles += cleanStyle + ", ";
                }
                strStyles = strStyles.TrimEnd(new[] { ' ', ',' });
            }

            // build up moods into one string
            var strMoods  = string.Empty;
            var moodMatch = AlbumMoodsRegEx.Match(html);

            if (moodMatch.Success)
            {
                var moods = HTMLListRegEx.Matches(moodMatch.Groups["moods"].Value.Trim());
                foreach (var mood in moods)
                {
                    var cleanMood = HTMLRegEx.Replace(mood.ToString(), "");
                    strMoods += cleanMood + ", ";
                }
                strMoods = strMoods.TrimEnd(new[] { ' ', ',' });
            }

            var album = new AlbumInfo
            {
                Album       = strAlbum,
                Artist      = strAlbumArtist,
                Genre       = strGenres,
                Tones       = strMoods,
                Styles      = strStyles,
                Review      = strReview,
                Image       = imgURL,
                Rating      = (int)(dRating * 2),
                Tracks      = strTracks,
                AlbumArtist = strAlbumArtist,
                Year        = iYear
            };

            Set(album);

            Loaded = true;
            return(true);
        }
    public void AddAlbumInfo(AlbumInfo aAlbumInfo)
    {
      string strSQL;
      try
      {
        AlbumInfo album = aAlbumInfo.Clone();
        string strTmp;

        strTmp = album.Album;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Album = strTmp;

        strTmp = album.Artist;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Artist = strTmp;

        strTmp = album.Tones;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Tones = strTmp == "unknown" ? "" : strTmp;

        strTmp = album.Styles;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Styles = strTmp == "unknown" ? "" : strTmp;

        strTmp = album.Review;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Review = strTmp == "unknown" ? "" : strTmp;

        strTmp = album.Image;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Image = strTmp == "unknown" ? "" : strTmp;

        strTmp = album.Tracks;
        DatabaseUtility.RemoveInvalidChars(ref strTmp);
        album.Tracks = strTmp == "unknown" ? "" : strTmp;

        if (null == MusicDbClient)
        {
          return;
        }

        strSQL = String.Format("delete from albuminfo where strAlbum like '{0}' and strArtist like '{1}%'", album.Album,
                               album.Artist);
        MusicDbClient.Execute(strSQL);

        strSQL =
          String.Format(
            "insert into albuminfo (strAlbum,strArtist, strTones,strStyles,strReview,strImage,iRating,iYear,strTracks) values('{0}','{1}','{2}','{3}','{4}','{5}',{6},{7},'{8}')",
            album.Album,
            album.Artist,
            album.Tones,
            album.Styles,
            album.Review,
            album.Image,
            album.Rating,
            album.Year,
            album.Tracks);

        MusicDbClient.Execute(strSQL);

        return;
      }
      catch (Exception ex)
      {
        Log.Error("musicdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        Open();
      }

      return;
    }
        /// <summary>
        /// Grab the album data and process
        /// </summary>
        /// <param name="mv"></param>
        /// <param name="artist"></param>
        /// <param name="album"></param>
        /// <param name="mbid"></param>
        private void setMusicVideoAlbum(ref DBAlbumInfo mv, string artistName, string albumName, string mbid)
        {
            if (string.IsNullOrEmpty(artistName) && string.IsNullOrEmpty(albumName))
            return;
              logger.Debug(string.Format("In Method: setMusicVideoAlbum(ref DBAlbumInfo mv, Atrist: {0}, Album: {1}, MBID: {2})", artistName, albumName, mbid));

              MusicDatabase m_db = null;
              try
              {
            m_db = MusicDatabase.Instance;
              }
              catch (Exception e)
              {
            logger.Error("setMusicVideoAlbum: Music database init failed " + e.ToString());
            return;
              }

              var albumInfo = new MediaPortal.Music.Database.AlbumInfo();
              if (!m_db.GetAlbumInfo(albumName, artistName, ref albumInfo))
            return;

              // Album name
              if (albumInfo.Album.ToLower() == albumInfo.Album)
              {
            mv.Album = System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(albumInfo.Album);
              }
              else
              {
            mv.Album = albumInfo.Album;
              }
              // MBID
              // mv.MdID
              // Image URL
              if (!string.IsNullOrEmpty(albumInfo.Image) && !mv.ArtUrls.Contains(albumInfo.Image))
            mv.ArtUrls.Add(albumInfo.Image);
              // Tags: Actors, Directors and Writers
              // mv.Tag.Add(tagstr);
              // WIKI
              mv.bioSummary = albumInfo.Review;
              mv.bioContent = albumInfo.Review;
              // Tag
              char[] delimiters = new char[] { ',' };
              string[] tags = albumInfo.Styles.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
              foreach (string tag in tags)
              {
            mv.Tag.Add(tag.Trim());
              }
              // Additional
              if (albumInfo.Year > 0)
              {
            mv.YearReleased = Convert.ToString(albumInfo.Year);
              }
        }
    protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
    {
      base.OnClicked(controlId, control, actionType);

      switch (controlId)
      {
        case (int)ControlIDs.LIST_ALBUM:
          {
            int selectedItem = listView.SelectedListItemIndex;

            if (selectedItem >= amazonWS.AlbumCount)
            {
              Log.Info("Cover art grabber:user selected item #{0}", listView.SelectedListItemIndex);

              _CancelledByUser = false;
              _SelectedAlbum = null;
              PageDestroy();
              return;
            }

            _SelectedAlbum = (AlbumInfo)amazonWS.AlbumInfoList[selectedItem];
            PageDestroy();
            break;
          }

        case (int)ControlIDs.BTN_SKIP:
          {
            Log.Info("Cover art grabber:[{0}-{1}] skipped by user", _Artist, _Album);

            _CancelledByUser = false;
            _SelectedAlbum = null;
            PageDestroy();
            break;
          }

        case (int)ControlIDs.BTN_CANCEL:
          {
            Log.Info("Cover art grabber:user cancelled out of grab results");

            _CancelledByUser = true;
            PageDestroy();
            break;
          }
      }
    }
    private AlbumInfo FillAlbum(XmlNode node)
    {
      AlbumInfo album = new AlbumInfo();
      string largeImageUrl = null;
      string mediumImageUrl = null;
      string smallImageUrl = null;

      foreach (XmlNode childNode in node)
      {
        if (childNode.Name == "ASIN")
          album.Asin = childNode.InnerText;

        if (childNode.Name == "SmallImage")
        {
          smallImageUrl = GetNode(childNode, "URL");
        }

        if (childNode.Name == "MediumImage")
        {
          mediumImageUrl = GetNode(childNode, "URL");
        }

        if (childNode.Name == "LargeImage")
        {
          largeImageUrl = GetNode(childNode, "URL");
        }

        if (childNode.Name == "ItemAttributes")
        {
          foreach (XmlNode attributeNode in childNode)
          {
            if (attributeNode.Name == "Artist")
              album.Artist = attributeNode.InnerText;

            if (attributeNode.Name == "Title")
              album.Album = attributeNode.InnerText;

            if (attributeNode.Name == "ReleaseDate")
            {
              int releaseYear = 0;

              try
              {
                releaseYear = DateTime.Parse(attributeNode.InnerText).Year;
              }

              catch
              {
                // do nothing
              }
              album.Year = releaseYear;
            }
          }
        }

        if (childNode.Name == "Tracks")
        {
          // The node starts with a "<Disc Number Node" , we want all subnodes of it
          string tracks = "";

          foreach (XmlNode discNode in childNode.ChildNodes)
          {
            foreach (XmlNode trackNode in discNode)
            {
              tracks += string.Format("{0}@{1}@{2}|", Convert.ToInt32(trackNode.Attributes["Number"].Value),
                                      trackNode.InnerText, 99);
            }
          }
          album.Tracks = tracks.Trim(new char[] {'|'}).Trim();
        }
      }

      album.Image = largeImageUrl;
      if (album.Image == null)
      {
        album.Image = mediumImageUrl ?? smallImageUrl;
      }

      return album;
    }
    private static void SetCurrentSkinProperties(MusicTag tag, String fileName)
    {
      var thumb = string.Empty;
      if (tag != null)
      {
        string strThumb = Util.Utils.GetAlbumThumbName(tag.Artist, tag.Album);
        if (Util.Utils.FileExistsInCache(strThumb))
        {
          thumb = strThumb;
        }

        // no succes with album cover try folder cache
        if (string.IsNullOrEmpty(thumb))
        {
          thumb = Util.Utils.TryEverythingToGetFolderThumbByFilename(fileName, false);
        }

        // let us test if there is a larger cover art image
        string strLarge = Util.Utils.ConvertToLargeCoverArt(thumb);
        if (Util.Utils.FileExistsInCache(strLarge))
        {
          thumb = strLarge;
        }

        GUIPropertyManager.SetProperty("#Play.Current.Thumb", thumb);

        // non-text values default to 0 and datetime.minvalue so
        // set the appropriate properties to string.empty

        // Duration
        string strDuration = tag.Duration <= 0
                               ? string.Empty
                               : MediaPortal.Util.Utils.SecondsToHMSString(tag.Duration);
        // Track
        string strTrack = tag.Track <= 0 ? string.Empty : tag.Track.ToString();
        // Year
        string strYear = tag.Year <= 1900 ? string.Empty : tag.Year.ToString();
        // Rating
        string strRating = (Convert.ToDecimal(2 * tag.Rating + 1)).ToString();
        // Bitrate
        string strBitrate = tag.BitRate <= 0 ? string.Empty : tag.BitRate.ToString();
        // Disc ID
        string strDiscID = tag.DiscID <= 0 ? string.Empty : tag.DiscID.ToString();
        // Disc Total
        string strDiscTotal = tag.DiscTotal <= 0 ? string.Empty : tag.DiscTotal.ToString();
        // Times played
        string strTimesPlayed = tag.TimesPlayed <= 0
                                  ? string.Empty
                                  : tag.TimesPlayed.ToString();
        // track total
        string strTrackTotal = tag.TrackTotal <= 0 ? string.Empty : tag.TrackTotal.ToString();
        // BPM
        string strBPM = tag.BPM <= 0 ? string.Empty : tag.BPM.ToString();
        // Channels
        string strChannels = tag.Channels <= 0 ? string.Empty : tag.Channels.ToString();
        // Sample Rate
        string strSampleRate = tag.SampleRate <= 0 ? string.Empty : tag.SampleRate.ToString();
        // Date Last Played
        string strDateLastPlayed = tag.DateTimePlayed == DateTime.MinValue
                                     ? string.Empty
                                     : tag.DateTimePlayed.ToShortDateString();
        // Date Added
        string strDateAdded = tag.DateTimeModified == DateTime.MinValue
                                ? string.Empty
                                : tag.DateTimeModified.ToShortDateString();

        GUIPropertyManager.SetProperty("#Play.Current.Title", tag.Title);
        GUIPropertyManager.SetProperty("#Play.Current.Track", strTrack);
        GUIPropertyManager.SetProperty("#Play.Current.Album", tag.Album);
        GUIPropertyManager.SetProperty("#Play.Current.Artist", tag.Artist);
        GUIPropertyManager.SetProperty("#Play.Current.Genre", tag.Genre);
        GUIPropertyManager.SetProperty("#Play.Current.Year", strYear);
        GUIPropertyManager.SetProperty("#Play.Current.Rating", strRating);
        GUIPropertyManager.SetProperty("#Play.Current.Duration", strDuration);
        GUIPropertyManager.SetProperty("#duration", strDuration);
        GUIPropertyManager.SetProperty("#Play.Current.AlbumArtist", tag.AlbumArtist);
        GUIPropertyManager.SetProperty("#Play.Current.BitRate", strBitrate);
        GUIPropertyManager.SetProperty("#Play.Current.Comment", tag.Comment);
        GUIPropertyManager.SetProperty("#Play.Current.Composer", tag.Composer);
        GUIPropertyManager.SetProperty("#Play.Current.Conductor", tag.Conductor);
        GUIPropertyManager.SetProperty("#Play.Current.DiscID", strDiscID);
        GUIPropertyManager.SetProperty("#Play.Current.DiscTotal", strDiscTotal);
        GUIPropertyManager.SetProperty("#Play.Current.Lyrics", tag.Lyrics);
        GUIPropertyManager.SetProperty("#Play.Current.TimesPlayed", strTimesPlayed);
        GUIPropertyManager.SetProperty("#Play.Current.TrackTotal", strTrackTotal);
        GUIPropertyManager.SetProperty("#Play.Current.FileType", tag.FileType);
        GUIPropertyManager.SetProperty("#Play.Current.Codec", tag.Codec);
        GUIPropertyManager.SetProperty("#Play.Current.BitRateMode", tag.BitRateMode);
        GUIPropertyManager.SetProperty("#Play.Current.BPM", strBPM);
        GUIPropertyManager.SetProperty("#Play.Current.Channels", strChannels);
        GUIPropertyManager.SetProperty("#Play.Current.SampleRate", strSampleRate);
        GUIPropertyManager.SetProperty("#Play.Current.DateLastPlayed", strDateLastPlayed);
        GUIPropertyManager.SetProperty("#Play.Current.DateAdded", strDateAdded);

        var albumInfo = new AlbumInfo();
        if (MusicDatabase.Instance.GetAlbumInfo(tag.Album, tag.AlbumArtist, ref albumInfo))
        {
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Review", albumInfo.Review);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Rating", albumInfo.Rating.ToString());
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Genre", albumInfo.Genre);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Styles", albumInfo.Styles);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Tones", albumInfo.Tones);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Year", albumInfo.Year.ToString());
        }
        else
        {
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Review", String.Empty);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Rating", String.Empty);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Genre", String.Empty);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Styles", String.Empty);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Tones", String.Empty);
          GUIPropertyManager.SetProperty("#Play.AlbumInfo.Year", String.Empty);
        }
        var artistInfo = new ArtistInfo();
        if (MusicDatabase.Instance.GetArtistInfo(tag.Artist, ref artistInfo))
        {
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Bio", artistInfo.AMGBio);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Born", artistInfo.Born);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Genres", artistInfo.Genres);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Instruments", artistInfo.Instruments);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Styles", artistInfo.Styles);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Tones", artistInfo.Tones);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.YearsActive", artistInfo.YearsActive);
        }
        else
        {
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Bio", String.Empty);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Born", String.Empty);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Genres", String.Empty);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Instruments", String.Empty);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Styles", String.Empty);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.Tones", String.Empty);
          GUIPropertyManager.SetProperty("#Play.ArtistInfo.YearsActive", String.Empty);
        }
      }
      else
      {
        // there is no current track so blank all properties
        GUIPropertyManager.RemovePlayerProperties();
        GUIPropertyManager.SetProperty("#Play.Current.Title", GUILocalizeStrings.Get(4543));
      }
    }
        public static List<AlbumInfo> GetMusicVideoAlbums(string dbName)
        {
            var externalDatabaseManager1 = (ExternalDatabaseManager) null;
              var arrayList = new List<AlbumInfo>();
              try
              {
            externalDatabaseManager1 = new ExternalDatabaseManager();
            var str = string.Empty;
            if (externalDatabaseManager1.InitDB(dbName))
            {
              var data = externalDatabaseManager1.GetData(Category.MusicAlbumThumbScraped);
              if (data != null && data.Rows.Count > 0)
              {
            var num = 0;
            while (num < data.Rows.Count)
            {
              var album = new AlbumInfo();
              album.Artist      = GetArtist(data.GetField(num, 0), Category.MusicAlbumThumbScraped);
              album.AlbumArtist = album.Artist;
              album.Album       = GetAlbum(data.GetField(num, 1), Category.MusicAlbumThumbScraped);

              arrayList.Add(album);
              checked { ++num; }
            }
              }
            }
            try
            {
              externalDatabaseManager1.Close();
            }
            catch { }
            return arrayList;
              }
              catch (Exception ex)
              {
            if (externalDatabaseManager1 != null)
              externalDatabaseManager1.Close();
            logger.Error("GetMusicVideoAlbums: " + ex);
              }
              return null;
        }