public static string GetAlbumForArtistTrack(string artist, string track)
 {
     Scraper scraper = new Scraper();
       string result = scraper.LastFMGetAlbum (artist, track);
       scraper = null;
       return result;
 }
 public int DoScrapeThumbs(string artist, bool onlyMissing)
 {
     if (!StopScraper)
     {
         try
         {
             var num = 0;
             if (artist != null && artist.Trim().Length > 0)
             {
                 var dbartist = Utils.GetArtist(artist, Utils.Category.MusicFanartScraped);
                 if (!HasArtistThumb(dbartist) || !onlyMissing)
                 {
                     scraper = new Scraper();
                     lock (lockObject)
                         dbClient.Execute("BEGIN TRANSACTION;");
                     num = scraper.GetArtistThumbs(artist, this, onlyMissing);
                     lock (lockObject)
                         dbClient.Execute("COMMIT;");
                     if (num == 0)
                         logger.Info("No Thumbs found for Artist: " + artist + ".");
                     scraper = null;
                 }
             }
             return num;
         }
         catch (Exception ex)
         {
             scraper = null;
             logger.Error("DoScrapeThumbs: " + ex);
             lock (lockObject)
                 dbClient.Execute("ROLLBACK;");
         }
     }
     return 0;
 }
        public int DoScrape(string artist)
        {
            if (!MediaPortal.Util.Win32API.IsConnectedToInternet())
            {
              logger.Debug("No internet connection detected. Cancelling scrape.");
              return 0 ;
            }

            if (!StopScraper)
            {
                try
                {
                    var GetImages = 0;
                    if (artist != null && artist.Trim().Length > 0)
                    {
                        var dbartist = Utils.GetArtist(artist, Utils.Category.MusicFanartScraped);
                        var MaxImages = checked(Convert.ToInt32(Utils.ScraperMaxImages,CultureInfo.CurrentCulture));
                        var numberOfFanartImages = GetNumberOfFanartImages(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped));
                        var doScrapeFanart = (numberOfFanartImages < MaxImages);

                        if (!doScrapeFanart)
                          GetImages = 8888 ;
                        else
                          {
                            scraper = new Scraper();
                            lock (lockObject)
                                dbClient.Execute("BEGIN TRANSACTION;");
                            GetImages = scraper.GetArtistFanart(artist, MaxImages, this, true, false, false, doScrapeFanart);
                            lock (lockObject)
                                dbClient.Execute("COMMIT;");
                            scraper = null;
                          }
                        if ((GetImages == 0) && (GetNumberOfFanartImages(dbartist) == 0))
                        {
                            logger.Info("No fanart found for Artist: " + artist + ".");
                        }
                        if (GetImages == 8888)
                        {
                            UpdateTimeStamp(dbartist, null, Utils.Category.MusicFanartScraped) ;
                            if (doScrapeFanart)
                              logger.Info("Artist: " + artist + " has already maximum number of images. Will not download anymore images for this artist.");
                        }
                    }
                    return GetImages;
                }
                catch (Exception ex)
                {
                    scraper = null;
                    logger.Error("DoScrape: " + ex);
                    lock (lockObject)
                        dbClient.Execute("ROLLBACK;");
                }
            }
            return 0;
        }
        public int DoScrapeNew(string artist, string album, bool externalAccess)
        {
            if (!MediaPortal.Util.Win32API.IsConnectedToInternet())
            {
              logger.Debug("No internet connection detected. Cancelling new scrape.");
              return 0 ;
            }

            if (!StopScraper)
            {
                try
                {
                    var GetImages = 0;
                    if (artist != null && artist.Trim().Length > 0)
                    {
                    #region NowPlaying Artist
                        var dbartist = Utils.GetArtist(artist, Utils.Category.MusicFanartScraped);
                        var dbalbum = Utils.GetAlbum(album, Utils.Category.MusicFanartScraped);
                        var MaxImages = checked(Convert.ToInt32(Utils.ScraperMaxImages,CultureInfo.CurrentCulture));
                        var numberOfFanartImages = GetNumberOfFanartImages(dbartist);
                        var doTriggerRefresh = (numberOfFanartImages == 0 && !externalAccess);

                        if (checked (MaxImages - numberOfFanartImages) <= 0)
                          GetImages = 8888 ;
                        else
                          {
                            scraper = new Scraper();
                            lock (lockObject)
                                dbClient.Execute("BEGIN TRANSACTION;");
                            GetImages = scraper.GetArtistFanart(artist, MaxImages, this, false, doTriggerRefresh, externalAccess, true);
                            lock (lockObject)
                                dbClient.Execute("COMMIT;");
                            scraper = null;
                          }
                        switch (GetImages)
                        {
                            case 0:
                                if (GetNumberOfFanartImages(dbartist) == 0)
                                  logger.Info("No fanart found for Artist: " + artist + ".");
                                break;
                            case 8888:
                                UpdateTimeStamp(dbartist, null, Utils.Category.MusicFanartScraped) ;
                                logger.Info("Artist: " + artist + " has already maximum number of images. Will not download anymore images for this artist.");
                                break;
                        }
                        if (StopScraper)
                            return GetImages;
                    #endregion
                    #region NowPlaying Artist Thumb
                        if (Utils.ScrapeThumbnails)
                          if (!Utils.GetDbm().HasArtistThumb(dbartist))
                          {
                            scraper = new Scraper();
                            lock (lockObject)
                                dbClient.Execute("BEGIN TRANSACTION;");
                            scraper.GetArtistThumbs(artist, this, true);
                            lock (lockObject)
                                dbClient.Execute("COMMIT;");
                            scraper = null;
                          }
                          else
                            UpdateTimeStamp(dbartist, null, Utils.Category.MusicArtistThumbScraped) ;
                        if (StopScraper)
                            return GetImages;
                    #endregion
                    #region NowPlaying Album Thumb
                        if ((album != null && album.Trim().Length > 0) && Utils.ScrapeThumbnailsAlbum)
                          if (!Utils.GetDbm().HasAlbumThumb(dbartist,dbalbum))
                          {
                            scraper = new Scraper();
                            lock (lockObject)
                                dbClient.Execute("BEGIN TRANSACTION;");
                            scraper.GetArtistAlbumThumbs(artist, album, false, externalAccess);
                            lock (lockObject)
                                dbClient.Execute("COMMIT;");
                            scraper = null;
                          }
                          else
                            UpdateTimeStamp(dbartist, dbalbum, Utils.Category.MusicAlbumThumbScraped) ;
                        if (StopScraper)
                            return GetImages;
                    #endregion
                    } // if (artist != null && artist.Trim().Length > 0)
                    return GetImages;
                }
                catch (Exception ex)
                {
                    scraper = null;
                    logger.Error("DoScrapeNew: " + ex);
                    lock (lockObject)
                        dbClient.Execute("ROLLBACK;");
                }
            }
            return 0;
        }
        public void DeleteOldImages()
        {
            try
            {
                logger.Info("Cleanup images is starting...");
                var flag = false;

                if (FanartHandlerSetup.Fh.MyScraperWorker != null)
                    FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(0, "Start");
                CurrArtistsBeingScraped = 0.0;
                TotArtistsBeingScraped = 0.0;

                #region Artists
                musicDatabaseArtists = new ArrayList();
                m_db.GetAllArtists(ref musicDatabaseArtists);

                #region mvCentral
                var musicVideoArtists = Utils.GetMusicVideoArtists("mvCentral.db3");
                if (musicVideoArtists != null && musicVideoArtists.Count > 0) {
                    logger.Debug("Cleanup images add Artists from mvCentral ["+musicVideoArtists.Count+"]...");
                    musicDatabaseArtists.AddRange(musicVideoArtists);
                }
                #endregion
                if (musicDatabaseArtists != null && musicDatabaseArtists.Count > 0)
                {
                    FanartHandlerSetup.Fh.SetProperty("#fanartHandler.scraper.task", "Cleanup images - Artists");
                    TotArtistsBeingScraped = checked (musicDatabaseArtists.Count);
                    logger.Debug("Cleanup images initiating for Artists...");
                    var htFanart = new Hashtable();

                    var SQL = "SELECT DISTINCT Key1, FullPath"+
                                  "FROM Image "+
                                  "WHERE Category in ('"+Utils.Category.MusicFanartScraped+"','"+Utils.Category.MusicArtistThumbScraped+"','"+Utils.Category.MusicAlbumThumbScraped+"') AND "+
                                        "Protected = 'False' AND "+
                                        "DummyItem = 'False' AND "+
                                        "Trim(Key1) <> '' AND "+
                                        "Key1 IS NOT NULL AND "+
                                        "Last_Access <= '" + DateTime.Today.AddDays(-100.0).ToString("yyyyMMdd", CultureInfo.CurrentCulture) + "';";

                    SQLiteResultSet sqLiteResultSet;
                    lock (lockObject)
                        sqLiteResultSet = dbClient.Execute(SQL);

                    var index = 0;
                    while (index < musicDatabaseArtists.Count)
                    {
                      var artist = musicDatabaseArtists[index].ToString();
                      var dbartist = Utils.GetArtist(artist, Utils.Category.MusicFanartScraped);
                      var htArtist = Scraper.UndoArtistPrefix(dbartist.ToLower()) ;

                      if (!htFanart.Contains(htArtist))
                          htFanart.Add(htArtist, htArtist);

                      // var chArray = new char[2] { '|', ';' };
                      string[] artists = artist.Split(Utils.PipesArray, StringSplitOptions.RemoveEmptyEntries);
                      foreach (string sartist in artists)
                      {
                        dbartist = Utils.GetArtist(sartist.Trim(), Utils.Category.MusicFanartScraped);
                        htArtist = Scraper.UndoArtistPrefix(dbartist.ToLower()) ;

                        if (!htFanart.Contains(htArtist))
                            htFanart.Add(htArtist, htArtist);
                      }

                      #region Report
                      ++CurrArtistsBeingScraped;
                      if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                        FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                      #endregion
                      checked { ++index; }
                    }
                    logger.Debug("Cleanup images Artists: ["+htFanart.Count+"]/["+sqLiteResultSet.Rows.Count+"]");
                    TotArtistsBeingScraped = checked (TotArtistsBeingScraped + sqLiteResultSet.Rows.Count);

                    var num = 0;
                    if (htFanart.Count > 0)
                      while (num < sqLiteResultSet.Rows.Count)
                      {
                          var htArtist = Scraper.UndoArtistPrefix(sqLiteResultSet.GetField(num, 0).ToLower()) ;
                          if (!htFanart.Contains(htArtist))
                          {
                            var filename = sqLiteResultSet.GetField(num, 1).Trim();
                            try
                            {
                              if (File.Exists(filename))
                              {
                                MediaPortal.Util.Utils.FileDelete(filename);
                                flag = true;
                              }
                            }
                            catch
                            {
                              logger.Debug ("Cleanup images: Delete "+filename+" failed.");
                            }

                          }
                          #region Report
                          ++CurrArtistsBeingScraped;
                          if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                            FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                          #endregion
                          checked { ++num; }
                      }
                    logger.Debug("Cleanup images: done for Artists.");
                }
                musicDatabaseArtists = null;
                #endregion

                #region Albums
                musicDatabaseAlbums = new List<AlbumInfo>();
                m_db.GetAllAlbums(ref musicDatabaseAlbums);

                #region mvCentral
                var musicVideoAlbums = Utils.GetMusicVideoAlbums("mvCentral.db3");
                if (musicVideoAlbums != null && musicVideoAlbums.Count > 0) {
                    logger.Debug("Cleanup images add Artists - Albums from mvCentral ["+musicVideoAlbums.Count+"]...");
                    musicDatabaseAlbums.AddRange(musicVideoAlbums);
                }
                #endregion
                if (musicDatabaseAlbums != null && musicDatabaseAlbums.Count > 0)
                {
                    FanartHandlerSetup.Fh.SetProperty("#fanartHandler.scraper.task", "Cleanup images - Albums");
                    CurrArtistsBeingScraped = 0.0;
                    TotArtistsBeingScraped = checked (musicDatabaseAlbums.Count);
                    logger.Debug("Cleanup images initiating for Artists - Albums...");
                    var htAlbums = new Hashtable();

                    var SQL = "SELECT DISTINCT Key1, Key2, FullPath"+
                                  "FROM Image "+
                                  "WHERE Category IN ('" + ((object) Utils.Category.MusicAlbumThumbScraped).ToString() + "') AND "+
                                        "Trim(Key1) <> '' AND "+
                                        "Key1 IS NOT NULL AND "+
                                        "Trim(Key2) <> '' AND "+
                                        "Key2 IS NOT NULL AND "+
                                        "Protected = 'False' AND "+
                                        "DummyItem = 'False' AND "+
                                        "Last_Access <= '" + DateTime.Today.AddDays(-100.0).ToString("yyyyMMdd", CultureInfo.CurrentCulture) + "';";
                    SQLiteResultSet sqLiteResultSet;
                    lock (lockObject)
                        sqLiteResultSet = dbClient.Execute(SQL);

                    var index = 0;
                    while (index < musicDatabaseAlbums.Count)
                    {
                      var album = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Album).Trim();
                      if (album != null && album.Length > 0)
                      {
                        // Artist
                        var artist   = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Artist).Trim();
                        var dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped)).ToLower();
                        var dbalbum  = Utils.GetAlbum(album, Utils.Category.MusicFanartScraped).ToLower();
                        var htArtistAlbum = dbartist + "-" + dbalbum ;

                        if (!string.IsNullOrEmpty(artist))
                          if (!htAlbums.Contains(htArtistAlbum))
                              htAlbums.Add(htArtistAlbum,htArtistAlbum);

                        // Album Artist
                        artist   = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].AlbumArtist).Trim();
                        dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped)).ToLower();
                        // dbalbum  = Utils.GetAlbum(album, Utils.Category.MusicFanartScraped).ToLower();
                        htArtistAlbum = dbartist + "-" + dbalbum ;

                        if (!string.IsNullOrEmpty(artist))
                          if (!htAlbums.Contains(htArtistAlbum))
                              htAlbums.Add(htArtistAlbum,htArtistAlbum);

                        // Piped Artists
                        artist = musicDatabaseAlbums[index].Artist.Trim()+" | "+musicDatabaseAlbums[index].AlbumArtist.Trim();
                        // var chArray = new char[2] { '|', ';' };
                        string[] artists = artist.Split(Utils.PipesArray, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string sartist in artists)
                        {
                          dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(sartist.Trim(), Utils.Category.MusicFanartScraped)).ToLower();
                          // dbalbum  = Utils.GetAlbum(album, Utils.Category.MusicFanartScraped).ToLower();
                          htArtistAlbum = dbartist + "-" + dbalbum ;

                          if (!string.IsNullOrEmpty(artist))
                            if (!htAlbums.Contains(htArtistAlbum))
                                htAlbums.Add(htArtistAlbum,htArtistAlbum);
                        }

                        #region Report
                        ++CurrArtistsBeingScraped;
                        if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                            FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                        #endregion
                        checked { ++index; }
                      }
                    }

                    logger.Debug("Cleanup images Artists - Albums: ["+htAlbums.Count+"]/["+sqLiteResultSet.Rows.Count+"]");
                    TotArtistsBeingScraped = checked (TotArtistsBeingScraped + sqLiteResultSet.Rows.Count);
                    var i = 0;
                    if (htAlbums.Count > 0)
                      while (i < sqLiteResultSet.Rows.Count)
                      {
                          var htArtistAlbum = Scraper.UndoArtistPrefix(sqLiteResultSet.GetField(i, 0).ToLower()) + "-" + sqLiteResultSet.GetField(i, 1).ToLower() ;
                          if (!htAlbums.Contains(htArtistAlbum))
                          {
                            var filename = sqLiteResultSet.GetField(i, 2).Trim();
                            try
                            {
                              if (File.Exists(filename))
                              {
                                MediaPortal.Util.Utils.FileDelete(filename);
                                flag = true;
                              }
                            }
                            catch
                            {
                              logger.Debug ("Cleanup images: Delete "+filename+" failed.");
                            }

                          }
                          #region Report
                          ++CurrArtistsBeingScraped;
                          if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                              FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                          #endregion
                          checked { ++i; }
                      }
                    logger.Debug("Cleanup images done for Artists - Albums.");
                }
                musicDatabaseAlbums = null;
                #endregion
                if (flag)
                  logger.Info("Synchronised fanart database: Removed " + Utils.GetDbm().DeleteRecordsWhereFileIsMissing() + " entries.");
                logger.Info("Cleanup images is done.");
            }
            catch (Exception ex)
            {
                scraper = null;
                logger.Error("Cleanup images: " + ex);
            }
        }
        public void InitialThumbScrape(bool onlyMissing)
        {
            CurrArtistsBeingScraped = 0.0;
            TotArtistsBeingScraped = 0.0;
            CurrTextBeingScraped = string.Empty;

            if (!MediaPortal.Util.Win32API.IsConnectedToInternet())
            {
              logger.Debug("No internet connection detected. Cancelling thumb scrape.");
              return ;
            }

            try
            {
                logger.Info("InitialThumbScrape is starting (Only missing = " + onlyMissing.ToString() + ")...");
                #region Artists
                if (Utils.ScrapeThumbnails)
                {
                  musicDatabaseArtists = new ArrayList();
                  m_db.GetAllArtists(ref musicDatabaseArtists);
                  #region mvCentral
                  var musicVideoArtists = Utils.GetMusicVideoArtists("mvCentral.db3");
                  if (musicVideoArtists != null && musicVideoArtists.Count > 0){
                    logger.Debug("InitialThumbScrape add Artists from mvCentral ["+musicVideoArtists.Count+"]...");
                    musicDatabaseArtists.AddRange(musicVideoArtists);
                  }
                  #endregion
                  if (musicDatabaseArtists != null && musicDatabaseArtists.Count > 0)
                  {
                    logger.Debug("InitialThumbScrape Artists: ["+musicDatabaseArtists.Count+"]");
                    TotArtistsBeingScraped = checked (musicDatabaseArtists.Count);
                    var index = 0;
                    while (index < musicDatabaseArtists.Count)
                    {
                      var artist = musicDatabaseArtists[index].ToString();
                      CurrTextBeingScraped = artist ;

                      if (!StopScraper && !Utils.GetIsStopping())
                        DoScrapeThumbs(artist.Trim(), onlyMissing);
                      else
                        break;
                      // Piped Artists
                      // var chArray = new char[2] { '|', ';' };
                      string[] artists = artist.Split(Utils.PipesArray, StringSplitOptions.RemoveEmptyEntries);
                      foreach (string sartist in artists)
                      {
                        if (!StopScraper && !Utils.GetIsStopping())
                          DoScrapeThumbs(sartist.Trim(), onlyMissing);
                        else
                          break;
                      }
                      ++CurrArtistsBeingScraped;
                      checked { ++index; }
                    }
                  }
                  CurrTextBeingScraped = string.Empty ;
                  musicDatabaseArtists = null;
                }
                else
                  logger.Debug("ThumbScrape for Artists disabled in config ...");
                #endregion

                #region Albums
                if ((Utils.ScrapeThumbnailsAlbum) && (!StopScraper && !Utils.GetIsStopping()))
                {
                  musicDatabaseAlbums = new List<AlbumInfo>();
                  m_db.GetAllAlbums(ref musicDatabaseAlbums);
                  #region mvCentral
                  var musicVideoAlbums = Utils.GetMusicVideoAlbums("mvCentral.db3");
                  if (musicVideoAlbums != null && musicVideoAlbums.Count > 0) {
                    logger.Debug("InitialThumbScrape add Artists - Albums from mvCentral ["+musicVideoAlbums.Count+"]...");
                    musicDatabaseAlbums.AddRange(musicVideoAlbums);
                  }
                  #endregion
                  if (musicDatabaseAlbums != null && musicDatabaseAlbums.Count > 0)
                  {
                    logger.Debug("InitialThumbScrape Artists - Albums: ["+musicDatabaseAlbums.Count+"]");
                    TotArtistsBeingScraped = checked (TotArtistsBeingScraped + musicDatabaseAlbums.Count);
                    scraper = new Scraper();
                    var index = 0;
                    while (index < musicDatabaseAlbums.Count)
                    {
                      var album = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Album).Trim();
                      if (album != null && album.Length > 0)
                      {
                        var artist = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Artist).Trim();
                        var dbartist = Utils.GetArtist(Scraper.UndoArtistPrefix(artist), Utils.Category.MusicFanartScraped);
                        var dbalbum = Utils.GetAlbum(album, Utils.Category.MusicFanartScraped);
                        CurrTextBeingScraped = artist + " - " + album ;
                        // Artist - Album
                        if (!string.IsNullOrEmpty(artist))
                          if (!Utils.GetDbm().HasAlbumThumb(dbartist,dbalbum) || !onlyMissing)
                          {
                            if (!StopScraper && !Utils.GetIsStopping())
                              scraper.GetArtistAlbumThumbs(artist, album, false, false);
                            else
                              break;
                          }
                        // AlbumArtist - Album
                        var albumartist  = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].AlbumArtist).Trim();
                        CurrTextBeingScraped = albumartist + " - " + album ;
                        if (!string.IsNullOrEmpty(albumartist))
                          if (!albumartist.Equals(artist, StringComparison.InvariantCultureIgnoreCase))
                          {
                            dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(albumartist, Utils.Category.MusicFanartScraped)).ToLower();
                            if (!Utils.GetDbm().HasAlbumThumb(dbartist,dbalbum) || !onlyMissing)
                            {
                              if (!StopScraper && !Utils.GetIsStopping())
                                scraper.GetArtistAlbumThumbs(artist, album, false, false);
                              else
                                break;
                            }
                          }
                        // Piped Artists
                        var pipedartist = musicDatabaseAlbums[index].Artist.Trim()+" | "+musicDatabaseAlbums[index].AlbumArtist.Trim();
                        // var chArray = new char[2] { '|', ';' };
                        string[] artists = pipedartist.Split(Utils.PipesArray, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string sartist in artists)
                        {
                          CurrTextBeingScraped = sartist + " - " + album ;
                          dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(sartist.Trim(), Utils.Category.MusicFanartScraped)).ToLower();
                          if (!Utils.GetDbm().HasAlbumThumb(dbartist,dbalbum) || !onlyMissing)
                          {
                            if (!StopScraper && !Utils.GetIsStopping())
                              scraper.GetArtistAlbumThumbs(sartist.Trim(), album, false, false);
                            else
                              break;
                          }
                        }
                      }
                      ++CurrArtistsBeingScraped;
                      checked { ++index; }
                    }
                    scraper = null;
                  }
                  CurrTextBeingScraped = string.Empty ;
                  musicDatabaseAlbums = null;
                }
                else
                  logger.Debug("ThumbScrape for Albums disabled in config ...");
                #endregion
                logger.Info("InitialThumbScrape is done.");
            }
            catch (Exception ex)
            {
                logger.Error("InitialThumbScrape: " + ex);
            }
        }
        public void InitialScrape()
        {
            CurrArtistsBeingScraped = 0.0;
            TotArtistsBeingScraped = 0.0;
            CurrTextBeingScraped = string.Empty ;

            if (!MediaPortal.Util.Win32API.IsConnectedToInternet())
            {
              logger.Debug("No internet connection detected. Cancelling initial scrape.");
              return ;
            }

            FanartHandlerSetup.Fh.SetProperty("#fanartHandler.scraper.task", "Initial Scrape - Initializing");

            if (Utils.DeleteMissing)
              logger.Info("Synchronised fanart database: Removed " + Utils.GetDbm().DeleteRecordsWhereFileIsMissing() + " entries.");

            try
            {
                logger.Info("InitialScrape is starting...");
                var flag = true;

                if (FanartHandlerSetup.Fh.MyScraperWorker != null)
                    FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(0, "Start");
                FanartHandlerSetup.Fh.SetProperty("#fanartHandler.scraper.task", "Initial Scrape - Artists");

                #region Artists
                musicDatabaseArtists = new ArrayList();
                m_db.GetAllArtists(ref musicDatabaseArtists);

                #region mvCentral
                var musicVideoArtists = Utils.GetMusicVideoArtists("mvCentral.db3");
                if (musicVideoArtists != null && musicVideoArtists.Count > 0) {
                    logger.Debug("InitialScrape add Artists from mvCentral ["+musicVideoArtists.Count+"]...");
                    musicDatabaseArtists.AddRange(musicVideoArtists);
                }
                #endregion

                if (musicDatabaseArtists != null && musicDatabaseArtists.Count > 0)
                {
                    CurrArtistsBeingScraped = 0.0;
                    TotArtistsBeingScraped = checked (musicDatabaseArtists.Count);
                    logger.Debug("InitialScrape initiating for Artists...");
                    var htFanart = new Hashtable();

                    var SQL = "SELECT DISTINCT Key1, sum(Count) as Count FROM ("+
                                "SELECT Key1, count(Key1) as Count "+
                                  "FROM Image "+
                                  "WHERE Category in ('" + ((object) Utils.Category.MusicFanartScraped).ToString() + "') AND "+
                                        "Time_Stamp >= '" + DateTime.Today.AddDays(-14.0).ToString("yyyyMMdd", CultureInfo.CurrentCulture) + "' "+
                                  "GROUP BY Key1 "+
                                "UNION ALL "+
                                "SELECT Key1, count(Key1) as Count "+
                                  "FROM Image "+
                                  "WHERE Category in ('" + ((object) Utils.Category.MusicFanartScraped).ToString() + "') AND "+
                                        "Enabled = 'True' AND "+
                                        "DummyItem = 'False' "+
                                  "GROUP BY Key1 "+
                                  "HAVING count(key1) >= " + Utils.ScraperMaxImages.Trim() +
                              ") GROUP BY Key1;";

                    SQLiteResultSet sqLiteResultSet;
                    lock (lockObject)
                        sqLiteResultSet = dbClient.Execute(SQL);
                    var num = 0;
                    while (num < sqLiteResultSet.Rows.Count)
                    {
                        var htArtist = Scraper.UndoArtistPrefix(sqLiteResultSet.GetField(num, 0).ToLower()) ;
                        if (!htFanart.Contains(htArtist))
                            htFanart.Add(htArtist, sqLiteResultSet.GetField(num, 1));
                        checked { ++num; }
                    }
                    logger.Debug("InitialScrape Artists: ["+htFanart.Count+"]/["+musicDatabaseArtists.Count+"]");
                    var index = 0;
                    while (index < musicDatabaseArtists.Count)
                    {
                        var artist = musicDatabaseArtists[index].ToString();
                        CurrTextBeingScraped = artist ;

                        if (!StopScraper && !Utils.GetIsStopping())
                        {
                            var dbartist = Utils.GetArtist(artist.Trim(), Utils.Category.MusicFanartScraped);
                            var htArtist = Scraper.UndoArtistPrefix(dbartist.ToLower()) ;
                            if (!htFanart.Contains(htArtist))
                            {
                              if (DoScrape(artist.Trim()) > 0 && flag)
                              {
                                  htFanart.Add(htArtist, 1);
                                  // AddScapedFanartToAnyHash();
                                  if (FanartHandlerSetup.Fh.MyScraperNowWorker != null)
                                  {
                                      FanartHandlerSetup.Fh.MyScraperNowWorker.TriggerRefresh = true;
                                      flag = false; // ??? I do not understand what for it ... // ajs
                                  }
                              }
                            }
                            // Pipes Artists
                            string[] artists = artist.Split(Utils.PipesArray, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string sartist in artists)
                            {
                              if (!sartist.Equals(artist, StringComparison.CurrentCulture))
                              {
                                dbartist = Utils.GetArtist(sartist.Trim(), Utils.Category.MusicFanartScraped);
                                htArtist = Scraper.UndoArtistPrefix(dbartist.ToLower()) ;
                                if (!htFanart.Contains(htArtist))
                                {
                                  if (DoScrape(sartist.Trim()) > 0 && flag)
                                  {
                                    htFanart.Add(htArtist, 1);
                                    // AddScapedFanartToAnyHash();
                                    if (FanartHandlerSetup.Fh.MyScraperNowWorker != null)
                                    {
                                      FanartHandlerSetup.Fh.MyScraperNowWorker.TriggerRefresh = true;
                                      flag = false; // ??? I do not understand what for it ... // ajs
                                    }
                                  }
                                }
                              }
                            }
                            //
                            #region Report
                            ++CurrArtistsBeingScraped;
                            if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                              FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                            #endregion
                            checked { ++index; }
                        }
                        else
                            break;
                    }
                    logger.Debug("InitialScrape done for Artists.");
                }
                CurrTextBeingScraped = string.Empty ;
                musicDatabaseArtists = null;
                #endregion
                AddScapedFanartToAnyHash();

                #region Albums
                if (Utils.ScrapeThumbnailsAlbum && !StopScraper && !Utils.GetIsStopping())
                {
                  TotArtistsBeingScraped = 0.0;
                  CurrArtistsBeingScraped = 0.0;
                  if (FanartHandlerSetup.Fh.MyScraperWorker != null)
                      FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(0, "Ongoing");
                  FanartHandlerSetup.Fh.SetProperty("#fanartHandler.scraper.task", "Initial Scrape - Albums");

                  musicDatabaseAlbums = new List<AlbumInfo>();
                  m_db.GetAllAlbums(ref musicDatabaseAlbums);

                  #region mvCentral
                  var musicVideoAlbums = Utils.GetMusicVideoAlbums("mvCentral.db3");
                  if (musicVideoAlbums != null && musicVideoAlbums.Count > 0) {
                      logger.Debug("InitialScrape add Artists - Albums from mvCentral ["+musicVideoAlbums.Count+"]...");
                      musicDatabaseAlbums.AddRange(musicVideoAlbums);
                  }
                  #endregion
                  if (musicDatabaseAlbums != null && musicDatabaseAlbums.Count > 0)
                  {
                      CurrArtistsBeingScraped = 0.0;
                      TotArtistsBeingScraped = musicDatabaseAlbums.Count;
                      logger.Debug("InitialScrape initiating for Artists - Albums...");
                      var htAlbums = new Hashtable();

                      var SQL = "SELECT DISTINCT Key1, Key2, sum(Count) as Count FROM ("+
                                  "SELECT Key1, Key2, count(Key1) as Count "+
                                    "FROM Image "+
                                    "WHERE Category IN ('" + ((object) Utils.Category.MusicAlbumThumbScraped).ToString() + "') AND "+
                                          "Time_Stamp >= '" + DateTime.Today.AddDays(-14.0).ToString("yyyyMMdd", CultureInfo.CurrentCulture) + "' "+
                                    "GROUP BY Key1, Key2 "+
                                  "UNION ALL "+
                                  "SELECT Key1, Key2, count(Key1) as Count "+
                                    "FROM Image "+
                                    "WHERE Category IN ('" + ((object) Utils.Category.MusicAlbumThumbScraped).ToString() + "') AND "+
                                          "Enabled = 'True' AND "+
                                          "DummyItem = 'False' "+
                                    "GROUP BY Key1, Key2 "+
                                ") GROUP BY Key1, Key2;";
                      SQLiteResultSet sqLiteResultSet;
                      lock (lockObject)
                          sqLiteResultSet = dbClient.Execute(SQL);

                      var i = 0;
                      while (i < sqLiteResultSet.Rows.Count)
                      {
                          var htArtistAlbum = Scraper.UndoArtistPrefix(sqLiteResultSet.GetField(i, 0).ToLower()) + "-" + sqLiteResultSet.GetField(i, 1).ToLower() ;
                          if (!htAlbums.Contains(htArtistAlbum))
                              htAlbums.Add(htArtistAlbum,sqLiteResultSet.GetField(i, 2));
                          checked { ++i; }
                      }

                      logger.Debug("InitialScrape Artists - Albums: ["+htAlbums.Count+"]/["+musicDatabaseAlbums.Count+"]");
                      var index = 0;
                      while (index < musicDatabaseAlbums.Count)
                      {
                          var album = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Album).Trim();
                          if (album != null && album.Length > 0)
                          {
                              // logger.Debug("*** "+Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Artist).Trim()+"/"+Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].AlbumArtist).Trim()+" - "+Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Album).Trim()) ;
                              var artist   = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].Artist).Trim();
                              var dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped)).ToLower();
                              var dbalbum  = Utils.GetAlbum(album, Utils.Category.MusicFanartScraped).ToLower();
                              var htArtistAlbum = dbartist + "-" + dbalbum ;
                              CurrTextBeingScraped = htArtistAlbum ;
                              // Artist - Album
                              if (!string.IsNullOrEmpty(artist))
                                if (!htAlbums.Contains(htArtistAlbum))
                                {
                                    if (!StopScraper && !Utils.GetIsStopping())
                                    {
                                        scraper = new Scraper();
                                        if (scraper.GetArtistAlbumThumbs(artist, album, false, false) > 0)
                                          htAlbums.Add(htArtistAlbum,1);
                                        scraper = null;
                                    }
                                    else
                                      break;
                                }
                              // AlbumArtist - Album
                              var albumartist  = Utils.RemoveMPArtistPipe(musicDatabaseAlbums[index].AlbumArtist).Trim();
                              if (!string.IsNullOrEmpty(albumartist))
                                if (!albumartist.Equals(artist, StringComparison.InvariantCultureIgnoreCase))
                                {
                                  dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(albumartist, Utils.Category.MusicFanartScraped)).ToLower();
                                  htArtistAlbum = dbartist + "-" + dbalbum ;
                                  CurrTextBeingScraped = htArtistAlbum ;
                                  if (!htAlbums.Contains(htArtistAlbum))
                                  {
                                      if (!StopScraper && !Utils.GetIsStopping())
                                      {
                                          scraper = new Scraper();
                                          if (scraper.GetArtistAlbumThumbs(albumartist, album, false, false) > 0)
                                            htAlbums.Add(htArtistAlbum,1);
                                          scraper = null;
                                      }
                                      else
                                        break;
                                  }
                                }
                              // Piped Artists
                              var pipedartist = musicDatabaseAlbums[index].Artist.Trim()+" | "+musicDatabaseAlbums[index].AlbumArtist.Trim();
                              // var chArray = new char[2] { '|', ';' };
                              string[] artists = pipedartist.Split(Utils.PipesArray, StringSplitOptions.RemoveEmptyEntries);
                              foreach (string sartist in artists)
                              {
                                dbartist = Scraper.UndoArtistPrefix(Utils.GetArtist(sartist.Trim(), Utils.Category.MusicFanartScraped)).ToLower();
                                htArtistAlbum = dbartist + "-" + dbalbum ;
                                CurrTextBeingScraped = htArtistAlbum ;
                                if (!htAlbums.Contains(htArtistAlbum))
                                {
                                    if (!StopScraper && !Utils.GetIsStopping())
                                    {
                                        scraper = new Scraper();
                                        if (scraper.GetArtistAlbumThumbs(sartist.Trim(), album, false, false) > 0)
                                          htAlbums.Add(htArtistAlbum,1);
                                        scraper = null;
                                    }
                                    else
                                      break;
                                }
                              }
                          }
                          #region Report
                          ++CurrArtistsBeingScraped;
                          if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                              FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                          #endregion
                          checked { ++index; }
                      }
                      logger.Debug("InitialScrape done for Artists - Albums.");
                  }
                  CurrTextBeingScraped = string.Empty ;
                  musicDatabaseAlbums = null;
                }
                #endregion
                #region Movies
                if (Utils.UseVideoFanart && !StopScraper && !Utils.GetIsStopping())
                {
                  CurrArtistsBeingScraped = 0.0;
                  TotArtistsBeingScraped = 0.0;
                  if (FanartHandlerSetup.Fh.MyScraperWorker != null)
                      FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(0, "Ongoing");
                  FanartHandlerSetup.Fh.SetProperty("#fanartHandler.scraper.task", "Initial Scrape - Videos");

                  FanartHandlerSetup.Fh.UpdateDirectoryTimer(Utils.FAHSMovies, false, "InitialScrape");

                  videoDatabaseMovies = new ArrayList();
                  VideoDatabase.GetMovies(ref videoDatabaseMovies);

                  if (videoDatabaseMovies != null && videoDatabaseMovies.Count > 0)
                  {
                      CurrArtistsBeingScraped = 0.0;
                      TotArtistsBeingScraped = videoDatabaseMovies.Count;
                      logger.Debug("InitialScrape initiating for Movies (MyVideo)...");
                      var htMovies = new Hashtable();

                      var SQL = "SELECT DISTINCT Key1, sum(Count) as Count FROM ("+
                                  "SELECT Key1, count(Key1) as Count "+
                                    "FROM Image "+
                                    "WHERE Category in ('" + ((object) Utils.Category.MovieScraped).ToString() + "') AND "+
                                          "Time_Stamp >= '" + DateTime.Today.AddDays(-14.0).ToString("yyyyMMdd", CultureInfo.CurrentCulture) + "' "+
                                    "GROUP BY Key1 "+
                                  "UNION ALL "+
                                  "SELECT Key1, count(Key1) as Count "+
                                    "FROM Image "+
                                    "WHERE Category in ('" + ((object) Utils.Category.MovieScraped).ToString() + "') AND "+
                                          "Enabled = 'True' AND "+
                                          "DummyItem = 'False' "+
                                    "GROUP BY Key1 "+
                                    "HAVING count(key1) >= " + Utils.ScraperMaxImages.Trim() +
                                ") GROUP BY Key1;";
                      SQLiteResultSet sqLiteResultSet;
                      lock (lockObject)
                          sqLiteResultSet = dbClient.Execute(SQL);

                      var i = 0;
                      while (i < sqLiteResultSet.Rows.Count)
                      {
                          var htMovie = sqLiteResultSet.GetField(i, 0).ToLower() ;
                          if (!htMovies.Contains(htMovie))
                              htMovies.Add(htMovie,sqLiteResultSet.GetField(i, 2));
                          checked { ++i; }
                      }

                      logger.Debug("InitialScrape Movies: ["+htMovies.Count+"]/["+videoDatabaseMovies.Count+"]");
                      var index = 0;
                      while (index < videoDatabaseMovies.Count)
                      {
                          IMDBMovie details = new IMDBMovie();
                          details = (IMDBMovie) videoDatabaseMovies[index] ;
                          var movieID = details.ID.ToString().ToLower();
                          var movieIMDBID = details.IMDBNumber.Trim().ToLower().Replace("unknown",string.Empty);
                          var movieTitle = details.Title.Trim();
                          CurrTextBeingScraped = movieIMDBID + " - " + movieTitle  ;

                          if (!string.IsNullOrEmpty(movieID) && !string.IsNullOrEmpty(movieIMDBID))
                          {
                              if (!htMovies.Contains(movieID))
                              {
                                  if (!StopScraper && !Utils.GetIsStopping())
                                  {
                                      scraper = new Scraper();
                                      scraper.GetMoviesFanart(movieID, movieIMDBID, movieTitle);
                                      scraper = null;
                                  }
                                  else
                                    break;
                              }
                          }
                          #region Report
                          ++CurrArtistsBeingScraped;
                          if (TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperWorker != null)
                              FanartHandlerSetup.Fh.MyScraperWorker.ReportProgress(Utils.Percent(CurrArtistsBeingScraped, TotArtistsBeingScraped),"Ongoing");
                          #endregion
                          checked { ++index; }
                      }
                      logger.Debug("InitialScrape done for Movies.");
                  }
                  CurrTextBeingScraped = string.Empty ;
                  videoDatabaseMovies = null;
                }
                #endregion
                AddScapedFanartToAnyHash();

                #region Statistics
                logger.Debug("InitialScrape statistic for Category:");
                GetCategoryStatistic (true) ;
                logger.Debug("InitialScrape statistic for Provider:");
                GetProviderStatistic (true) ;
                logger.Debug("InitialScrape statistic for Actual Music Fanart/Thumbs:");
                GetAccessStatistic(true) ;
                #endregion

                logger.Info("InitialScrape is done.");
            }
            catch (Exception ex)
            {
                scraper = null;
                logger.Error("InitialScrape: " + ex);
            }
        }
        public static void GetSelectedItem(ref string SelectedItem, ref string SelectedAlbum, ref string SelectedGenre, ref string SelectedStudios, ref bool isMusicVideo)
        {
            try
              {
            if (iActiveWindow == (int)GUIWindow.Window.WINDOW_INVALID)
              return;

            #region SelectedItem
            if (iActiveWindow == 6623)       // mVids plugin - Outdated.
            {
              SelectedItem = Utils.GetProperty("#mvids.artist");
              SelectedItem = Utils.GetArtistLeftOfMinusSign(SelectedItem);
            }
            else if (iActiveWindow == 47286) // Rockstar plugin
            {
              SelectedItem = Utils.GetProperty("#Rockstar.SelectedTrack.ArtistName");
              SelectedAlbum = Utils.GetProperty("#Rockstar.SelectedTrack.AlbumName") ;
            }
            else if (iActiveWindow == 759)     // My TV Recorder
              SelectedItem = Utils.GetProperty("#TV.RecordedTV.Title");
            else if (iActiveWindow == 1)       // My TV View
              SelectedItem = Utils.GetProperty("#TV.View.title");
            else if (iActiveWindow == 600)     // My TV Guide
              SelectedItem = Utils.GetProperty("#TV.Guide.Title");
            else if (iActiveWindow == 880)     // MusicVids plugin
              SelectedItem = Utils.GetProperty("#MusicVids.ArtistName");
            else if (iActiveWindow == 510 ||   // My Music Plaing Now - Why is it here?
                 iActiveWindow == 90478 || // My Lyrics - Why is it here?
                 iActiveWindow == 25652 || // Radio Time - Why is it here?
                 iActiveWindow == 35)      // Basic Home - Why is it here? And where there may appear tag: #Play.Current.Title
            {
              SelectedItem = string.Empty;

              // mvCentral
              var mvcArtist = Utils.GetProperty("#Play.Current.mvArtist");
              var mvcAlbum = Utils.GetProperty("#Play.Current.mvAlbum");
              var mvcPlay = Utils.GetProperty("#mvCentral.isPlaying");

              var selAlbumArtist = Utils.GetProperty("#Play.Current.AlbumArtist");
              var selArtist = Utils.GetProperty("#Play.Current.Artist");
              var selTitle = Utils.GetProperty("#Play.Current.Title");

              if (!string.IsNullOrEmpty(selArtist))
            if (!string.IsNullOrEmpty(selAlbumArtist))
              if (selArtist.Equals(selAlbumArtist, StringComparison.InvariantCultureIgnoreCase))
                SelectedItem = selArtist;
              else
                SelectedItem = selArtist + '|' + selAlbumArtist;
            else
              SelectedItem = selArtist;
              /*
              if (!string.IsNullOrEmpty(tuneArtist))
            SelectedItem = SelectedItem + (string.IsNullOrEmpty(SelectedItem) ? "" : "|") + tuneArtist;
              */
              SelectedAlbum = Utils.GetProperty("#Play.Current.Album");
              SelectedGenre = Utils.GetProperty("#Play.Current.Genre");

              if (!string.IsNullOrEmpty(selArtist) && !string.IsNullOrEmpty(selTitle) && string.IsNullOrEmpty(SelectedAlbum))
              {
            Scraper scraper = new Scraper();
            SelectedAlbum = scraper.LastFMGetAlbum (selArtist, selTitle);
            scraper = null;
              }
              if (!string.IsNullOrEmpty(selAlbumArtist) && !string.IsNullOrEmpty(selTitle) && string.IsNullOrEmpty(SelectedAlbum))
              {
            Scraper scraper = new Scraper();
            SelectedAlbum = scraper.LastFMGetAlbum (selAlbumArtist, selTitle);
            scraper = null;
              }
              /*
              if (!string.IsNullOrEmpty(tuneArtist) && !string.IsNullOrEmpty(tuneTrack) && string.IsNullOrEmpty(tuneAlbum) && string.IsNullOrEmpty(SelectedAlbum))
              {
            Scraper scraper = new Scraper();
            SelectedAlbum = scraper.LastFMGetAlbum (tuneArtist, tuneTrack);
            scraper = null;
              }
              */
              if (!string.IsNullOrEmpty(mvcPlay) && mvcPlay.Equals("true",StringComparison.CurrentCulture))
              {
            isMusicVideo = true;
            if (!string.IsNullOrEmpty(mvcArtist))
              SelectedItem = SelectedItem + (string.IsNullOrEmpty(SelectedItem) ? "" : "|") + mvcArtist;
            if (string.IsNullOrEmpty(SelectedAlbum))
              SelectedAlbum = string.Empty + mvcAlbum;
              }

              if (string.IsNullOrEmpty(SelectedItem) && string.IsNullOrEmpty(selArtist) && string.IsNullOrEmpty(selAlbumArtist))
            SelectedItem = selTitle;
            }
            else if (iActiveWindow == 6622)    // Music Trivia
            {
              SelectedItem = Utils.GetProperty("#selecteditem2");
              SelectedItem = Utils.GetArtistLeftOfMinusSign(SelectedItem);
            }
            else if (iActiveWindow == 2003 ||  // Dialog Video Info
                 iActiveWindow == 6 ||     // My Video
                 iActiveWindow == 25 ||    // My Video Title
                 iActiveWindow == 614 ||   // Dialog Video Artist Info
                 iActiveWindow == 28       // My Video Play List
                )
            {
              var movieID = Utils.GetProperty("#movieid");
              var selectedTitle = (iActiveWindow != 2003 ? Utils.GetProperty("#selecteditem") : Utils.GetProperty("#title"));
              SelectedItem = (movieID == null || movieID == string.Empty || movieID == "-1" || movieID == "0") ? selectedTitle : movieID;
              SelectedGenre = Utils.GetProperty("#genre");
              SelectedStudios = Utils.GetProperty("#studios");
              // logger.Debug("*** "+movieID+" - "+Utils.GetProperty("#selecteditem")+" - "+Utils.GetProperty("#title")+" - "+Utils.GetProperty("#myvideosuserfanart")+" -> "+SelectedItem+" - "+SelectedGenre);
            }
            else if (iActiveWindow == 96742)     // Moving Pictures
            {
              SelectedItem = Utils.GetProperty("#selecteditem");
              SelectedStudios = Utils.GetProperty("#MovingPictures.SelectedMovie.studios");
              SelectedGenre = Utils.GetProperty("#MovingPictures.SelectedMovie.genres");
              // logger.Debug("*** "+SelectedItem+" - "+SelectedStudios+" - "+SelectedGenre);
            }
            else if (iActiveWindow == 9811 ||    // TVSeries
                 iActiveWindow == 9813)      // TVSeries Playlist
            {
              SelectedItem = UtilsTVSeries.GetTVSeriesAttributes(ref SelectedGenre, ref SelectedStudios);
              if (string.IsNullOrEmpty(SelectedItem))
              {
            SelectedItem = Utils.GetProperty("#TVSeries.Title");
              }
              if (string.IsNullOrEmpty(SelectedStudios))
              {
            SelectedStudios = Utils.GetProperty("#TVSeries.Series.Network");
              }
              if (string.IsNullOrEmpty(SelectedGenre))
              {
            SelectedGenre = Utils.GetProperty("#TVSeries.Series.Genre");
              }
              // logger.Debug("*** TVSeries: " + SelectedItem + " - " + SelectedStudios + " - " + SelectedGenre);
            }
            else if (iActiveWindow == 112011 ||  // mvCentral
                 iActiveWindow == 112012 ||  // mvCentral Playlist
                 iActiveWindow == 112013 ||  // mvCentral StatsAndInfo
                 iActiveWindow == 112015)    // mvCentral SmartDJ
            {
              SelectedItem = Utils.GetProperty("#mvCentral.ArtistName");

              SelectedAlbum = Utils.GetProperty("#mvCentral.Album");
              SelectedGenre = Utils.GetProperty("#mvCentral.Genre");

              var mvcIsPlaying = Utils.GetProperty("#mvCentral.isPlaying");
              if (!string.IsNullOrEmpty(mvcIsPlaying) && mvcIsPlaying.Equals("true",StringComparison.CurrentCulture))
              {
            isMusicVideo = true;
              }
            }
            else if (iActiveWindow == 25650)     // Radio Time
            {
              SelectedItem = Utils.GetProperty("#RadioTime.Selected.Subtext"); // Artist - Track || TODO for: Artist - Album - Track
              SelectedItem = Utils.GetArtistLeftOfMinusSign(SelectedItem, true);
            }
            else if (iActiveWindow == 29050 || // youtube.fm videosbase
                 iActiveWindow == 29051 || // youtube.fm playlist
                 iActiveWindow == 29052    // youtube.fm info
                )
            {
              SelectedItem = Utils.GetProperty("#selecteditem");
              SelectedItem = Utils.GetArtistLeftOfMinusSign(SelectedItem);
            }
            else if (iActiveWindow == 30885)   // GlobalSearch Music
            {
              SelectedItem = Utils.GetProperty("#selecteditem");
              SelectedItem = Utils.GetArtistLeftOfMinusSign(SelectedItem);
            }
            else if (iActiveWindow == 30886)   // GlobalSearch Music Details
            {
              try
              {
            if (GUIWindowManager.GetWindow(iActiveWindow).GetControl(1) != null)
              SelectedItem = ((GUIFadeLabel) GUIWindowManager.GetWindow(iActiveWindow).GetControl(1)).Label;
              }
              catch { }
            }
            else
              SelectedItem = Utils.GetProperty("#selecteditem");

            SelectedAlbum   = (string.IsNullOrEmpty(SelectedAlbum) ? null : SelectedAlbum);
            SelectedGenre   = (string.IsNullOrEmpty(SelectedGenre) ? null : SelectedGenre.Replace(" / ", "|").Replace(", ", "|"));
            SelectedStudios = (string.IsNullOrEmpty(SelectedStudios) ? null : SelectedStudios.Replace(" / ", "|").Replace(", ", "|"));
            #endregion
              }
              catch (Exception ex)
              {
            logger.Error("GetSelectedItem: " + ex);
              }
        }
        public static void GetCurrMusicPlayItem(ref string CurrentTrackTag, ref string CurrentAlbumTag, ref string CurrentGenreTag, ref string LastArtistTrack, ref string LastAlbumArtistTrack)
        {
            try
              {
            #region Fill current tags
            if (Utils.iActiveWindow == 730718) // MP Grooveshark
            {
              CurrentTrackTag = Utils.GetProperty("#mpgrooveshark.current.artist");
              CurrentAlbumTag = Utils.GetProperty("#mpgrooveshark.current.album");
              CurrentGenreTag = null;
            }
            else
            {
              CurrentTrackTag = string.Empty;

              // Common play
              var selAlbumArtist = Utils.GetProperty("#Play.Current.AlbumArtist").Trim();
              var selArtist = Utils.GetProperty("#Play.Current.Artist").Trim();
              var selTitle = Utils.GetProperty("#Play.Current.Title").Trim();
              // Radio Time
              /*
              var tuneArtist = Utils.GetProperty("#RadioTime.Play.Artist");
              var tuneAlbum = Utils.GetProperty("#RadioTime.Play.Album");
              var tuneTrack = Utils.GetProperty("#RadioTime.Play.Song");
              */
              // mvCentral
              var mvcArtist = Utils.GetProperty("#Play.Current.mvArtist");
              var mvcAlbum = Utils.GetProperty("#Play.Current.mvAlbum");
              var mvcPlay = Utils.GetProperty("#mvCentral.isPlaying");

              if (!string.IsNullOrEmpty(selArtist))
            if (!string.IsNullOrEmpty(selAlbumArtist))
              if (selArtist.Equals(selAlbumArtist, StringComparison.InvariantCultureIgnoreCase))
                CurrentTrackTag = selArtist;
              else
                CurrentTrackTag = selArtist + '|' + selAlbumArtist;
            else
              CurrentTrackTag = selArtist;
              /*
              if (!string.IsNullOrEmpty(tuneArtist))
            CurrentTrackTag = CurrentTrackTag + (string.IsNullOrEmpty(CurrentTrackTag) ? "" : "|") + tuneArtist;
              */
              CurrentAlbumTag = Utils.GetProperty("#Play.Current.Album");
              CurrentGenreTag = Utils.GetProperty("#Play.Current.Genre");

              if (!string.IsNullOrEmpty(selArtist) && !string.IsNullOrEmpty(selTitle) && string.IsNullOrEmpty(CurrentAlbumTag))
              {
            if (!LastArtistTrack.Equals(selArtist+"#"+selTitle, StringComparison.CurrentCulture))
            {
              Scraper scraper = new Scraper();
              CurrentAlbumTag = scraper.LastFMGetAlbum(selArtist, selTitle);
              scraper = null;
              LastArtistTrack = selArtist+"#"+selTitle;
            }
              }
              if (!string.IsNullOrEmpty(selAlbumArtist) && !string.IsNullOrEmpty(selTitle) && string.IsNullOrEmpty(CurrentAlbumTag))
              {
            if (!LastAlbumArtistTrack.Equals(selAlbumArtist+"#"+selTitle, StringComparison.CurrentCulture))
            {
              Scraper scraper = new Scraper();
              CurrentAlbumTag = scraper.LastFMGetAlbum(selAlbumArtist, selTitle);
              scraper = null;
              LastAlbumArtistTrack = selAlbumArtist+"#"+selTitle;
            }
              }
              /*
              if (!string.IsNullOrEmpty(tuneArtist) && !string.IsNullOrEmpty(tuneTrack) && string.IsNullOrEmpty(tuneAlbum) && string.IsNullOrEmpty(CurrentAlbumTag))
              {
            Scraper scraper = new Scraper();
            CurrentAlbumTag = scraper.LastFMGetAlbum (tuneArtist, tuneTrack);
            scraper = null;
              }
              */
              if (!string.IsNullOrEmpty(mvcPlay) && mvcPlay.Equals("true",StringComparison.CurrentCulture))
              {
            if (!string.IsNullOrEmpty(mvcArtist))
              CurrentTrackTag = CurrentTrackTag + (string.IsNullOrEmpty(CurrentTrackTag) ? "" : "|") + mvcArtist;
            if (string.IsNullOrEmpty(CurrentAlbumTag))
              CurrentAlbumTag = string.Empty + mvcAlbum;
              }
            }
            #endregion
              }
              catch (Exception ex)
              {
            logger.Error("GetCurrMusicPlayItem: " + ex);
              }
        }