public int HtBackdropGetThumbsImages(string artist, DatabaseManager dbm, bool onlyMissing)
    {
      if (!Utils.UseHtBackdrops)
        return 0 ;

      try
      {
        var dbartist = Utils.GetArtist(artist, Utils.Category.MusicFanartScraped);
        if ((!dbm.StopScraper) && (!Utils.GetDbm().HasArtistThumb(dbartist) || !onlyMissing))
        {
          var path = (string) null;
          var filename = (string) null;
          var num = 0;
          if (alSearchResults != null)
          {
            logger.Debug("HtBackdrops: Trying to find thumbnail for Artist: " + artist + ".");
            var index = 0;
            while (index < alSearchResults.Count && !dbm.StopScraper)
            {
              var findartist = Utils.GetArtist(Utils.RemoveResolutionFromFileName(((SearchResults) alSearchResults[index]).Title).Trim(), Utils.Category.MusicFanartScraped);
              if (Utils.IsMatch(dbartist, findartist, ((SearchResults) alSearchResults[index]).Alias))
              {
                if (!dbm.StopScraper)
                {
                  if (((SearchResults) alSearchResults[index]).Album.Equals("5", StringComparison.CurrentCulture))
                  {
                    string mbid = ((SearchResults) alSearchResults[index]).MBID;
                    logger.Debug("HtBackdrops: Found thumbnail for Artist: " + artist + ". MBID: "+mbid);
                    var sourceFilename = "http://htbackdrops.org/api/"+ApiKeyhtBackdrops+"/download/" + ((SearchResults) alSearchResults[index]).Id + "/fullsize";
                    if (DownloadImage(ref artist, null, ref sourceFilename, ref path, ref filename, Utils.Category.MusicArtistThumbScraped, null))
                    {
                      checked { ++num; }
                      dbm.LoadFanart(dbartist, filename.Replace("_tmp.jpg", "L.jpg"), sourceFilename, Utils.Category.MusicArtistThumbScraped, null, Utils.Provider.HtBackdrops, null, mbid);
                      ExternalAccess.InvokeScraperCompleted(Utils.Category.MusicArtistThumbScraped.ToString(), dbartist);
                      break;
                    }
                  }
                }
                else
                  break;
              }
              checked { ++index; }
            }
            if (dbm.StopScraper)
              return num;
          }
          return num;
        }
      }
      catch (Exception ex)
      {
        logger.Error("HtBackdrops: GetThumbsImages:");
        logger.Error(ex);
      }
      return 9999;
    }
    // End: GethtBackdropsSearchResult

    public int HtBackdropGetFanart(string artist, int iMax, DatabaseManager dbm, bool doTriggerRefresh, bool externalAccess, bool doScrapeFanart)
    {
      if (!Utils.UseHtBackdrops)
        return 0 ;

      try
      {
        var dbartist = Utils.GetArtist(artist, Utils.Category.MusicFanartScraped);
        var facount = Utils.GetDbm().GetNumberOfFanartImages(dbartist);
        if ((iMax = iMax - facount) <= 0)
          return 8888 ;

        if ((!dbm.StopScraper) && (doScrapeFanart))
        {
          var path = (string) null;
          var filename = (string) null;

          var num = 0;
          if (alSearchResults != null)
          {
            logger.Debug("HtBackdrops: Trying to find fanart for Artist: " + artist + ".");

            var index = 0;
            while (index < alSearchResults.Count && !dbm.StopScraper)
            {
              var findartist = Utils.GetArtist(Utils.RemoveResolutionFromFileName(((SearchResults) alSearchResults[index]).Title).Trim(), Utils.Category.MusicFanartScraped);
              if (Utils.IsMatch(dbartist, findartist, ((SearchResults) alSearchResults[index]).Alias))
              {
                string sourceFilename;
                string mbid = ((SearchResults) alSearchResults[index]).MBID;
                if (num < iMax)
                {
                  if (((SearchResults) alSearchResults[index]).Album.Equals("1", StringComparison.CurrentCulture))
                  {
                    logger.Debug("HtBackdrops: Found fanart for Artist: " + artist + ". MBID: "+mbid);
                    sourceFilename = "http://htbackdrops.org/api/"+ApiKeyhtBackdrops+"/download/" + ((SearchResults) alSearchResults[index]).Id + "/fullsize";
                    if (!dbm.SourceImageExist(dbartist, null, sourceFilename, Utils.Category.MusicFanartScraped, null, Utils.Provider.HtBackdrops, ((SearchResults) alSearchResults[index]).Id, mbid))
                    {
                      if (DownloadImage(ref dbartist, null, ref sourceFilename, ref path, ref filename, Utils.Category.MusicFanartScraped, ((SearchResults) alSearchResults[index]).Id))
                      {
                        checked { ++num; }
                        dbm.LoadFanart(dbartist, filename, sourceFilename, Utils.Category.MusicFanartScraped, null, Utils.Provider.HtBackdrops, ((SearchResults) alSearchResults[index]).Id, mbid);
                        if (FanartHandlerSetup.Fh.MyScraperNowWorker != null && doTriggerRefresh && !externalAccess)
                        {
                          FanartHandlerSetup.Fh.MyScraperNowWorker.TriggerRefresh = true;
                          doTriggerRefresh = false;
                        }
                        ExternalAccess.InvokeScraperCompleted(Utils.Category.MusicFanartScraped.ToString(), dbartist);
                      }
                    }
                    else
                      logger.Debug("HtBackdrops: Will not download fanart image as it already exist an image in your fanart database with this source image name.");
                  }
                }
                else
                  num = 8888;
                if (dbm.StopScraper)
                  break;
              }
              checked { ++index; }
            } // while (index < alSearchResults.Count && !dbm.StopScraper)
            if (dbm.StopScraper)
              return num;
          } // if (alSearchResults != null)
          return num;
        }
      }
      catch (Exception ex)
      {
        logger.Error("HtBackdrops: GetFanart:");
        logger.Error(ex);
      }
      finally
      {
      }
      return 8888;
    }
    // End: GetArtistFanart

    // Begin: GetArtistThumbs (Fanart.TV, htBackdrops, Last.FM)
    public int GetArtistThumbs(string artist, DatabaseManager dbm, bool onlyMissing)
    {
      var res = 0;
      var flag = true;
      var mbid = (string) null;

      if (string.IsNullOrEmpty(artist))
        return res ;

      if (!Utils.ScrapeThumbnails)
      {
        logger.Debug("Artist Thumbnails - Disabled.");
        return res ;
      }

      if (Utils.GetDbm().HasArtistThumb(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped)) && onlyMissing)
        return 1;

      logger.Debug("--- Thumb --- " + artist + " ---");
      logger.Debug("Trying to find Thumbs for Artist: " + artist);

      // *** MusicBrainzID
      mbid = GetMusicBrainzID(artist, null) ;
      if (string.IsNullOrEmpty(mbid) || (mbid.Length < 10))
        // *** Get MBID & Search result from htBackdrop
        if (alSearchResults == null)
          flag = GethtBackdropsSearchResult(artist,"5");
      //
      while (true)
      {
        // *** Fanart.TV
        if (flag) 
          {
            if (alSearchResults != null) 
              if ((alSearchResults.Count > 0) && (string.IsNullOrEmpty(mbid) || (mbid.Length < 10)))
                mbid = ((SearchResults) alSearchResults[0]).MBID ;
            if ((mbid != null) && (mbid.Length > 10))
              res = FanartTVGetPictures(Utils.Category.MusicArtistThumbScraped, mbid, artist, null, 1, false, false, true) ;
          }
        if (dbm.StopScraper)
          break;

        // ** Get MBID & Search result from htBackdrop
        if (alSearchResults == null)
          flag = GethtBackdropsSearchResult(artist,"5");

        // *** htBackdrops
        if (res == 0)
        {
          if (flag)
            res = HtBackdropGetThumbsImages(artist, dbm, onlyMissing) ;
        }
        if (dbm.StopScraper)
          break;

        // *** Last.FM
        if (res == 0) 
        {
          res = LastFMGetTumbnails(Utils.Category.MusicArtistThumbScraped, artist, null, false);
        }
        break;
      } // while

      // *** Dummy
      if (res == 0)
      {
        if (alSearchResults != null) 
          if ((alSearchResults.Count > 0) && (string.IsNullOrEmpty(mbid) || (mbid.Length < 10)))
            mbid = ((SearchResults) alSearchResults[0]).MBID ;
        if ((mbid != null) && (mbid.Length < 10))
          mbid = string.Empty;
        dbm.InsertDummyItem(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped), null, mbid, Utils.Category.MusicArtistThumbScraped);
      }
      // 
      if (alSearchResults != null)
      {
        alSearchResults.Clear();
        ObjectMethods.SafeDispose(alSearchResults);
      }
      alSearchResults = null;
      //
      return res;
    }
    // Begin: GetArtistFanart (Fanart.TV, htBackdrops)
    public int GetArtistFanart(string artist, int iMax, DatabaseManager dbm, bool reportProgress, bool doTriggerRefresh, bool externalAccess, bool doScrapeFanart, bool onlyClearArt=false)
    {
      var res = 0;
      var flag = true;
      var mbid = (string) null;

      if (!doScrapeFanart)
        return 0;

      logger.Debug("--- Fanart --- " + artist + " ---");
      logger.Debug("Trying to find " + (onlyClearArt ? "Art from Fanart.tv" : "Fanart") + " for Artist: " + artist);

      if (dbm.TotArtistsBeingScraped == 0)
        ReportProgress (6.0, dbm, reportProgress, externalAccess) ;

      // *** MusicBrainzID
      mbid = GetMusicBrainzID(artist, null) ;
      if (string.IsNullOrEmpty(mbid) || (mbid.Length < 10))
        // *** Get MBID & Search result from htBackdrop
        if (alSearchResults == null)
          flag = GethtBackdropsSearchResult(artist, "1,5");

      ReportProgress (0.0, dbm, reportProgress, externalAccess) ;
      while (true)
      {
        // *** Fanart.TV
        if (flag) 
          {
            if (alSearchResults != null) 
              if ((alSearchResults.Count > 0) && (string.IsNullOrEmpty(mbid) || (mbid.Length < 10)))
                mbid = ((SearchResults) alSearchResults[0]).MBID ;
            if ((mbid != null) && (mbid.Length > 10))
                res = FanartTVGetPictures(Utils.Category.MusicFanartScraped, mbid, artist, null, iMax, doTriggerRefresh, externalAccess, doScrapeFanart, null, onlyClearArt) ;
          }
        ReportProgress (0.0, dbm, reportProgress, externalAccess) ;
        if (dbm.StopScraper)
          break;
        if (onlyClearArt)
          break;

        // ** Get MBID & Search result from htBackdrop
        if (alSearchResults == null)
          flag = GethtBackdropsSearchResult(artist, "1,5");
        ReportProgress (0.0, dbm, reportProgress, externalAccess) ;

        // *** htBackdrops
        if ((res == 0) || (res < iMax))
        {
          if (flag)
            res = HtBackdropGetFanart(artist, iMax, dbm, doTriggerRefresh, externalAccess, doScrapeFanart);
        }
        ReportProgress (0.0, dbm, reportProgress, externalAccess) ;
        if (dbm.StopScraper)
          break;

        // *** Dummy
        if (res == 0)
        {
          if (alSearchResults != null) 
            if ((alSearchResults.Count > 0) && (string.IsNullOrEmpty(mbid) || (mbid.Length < 10)))
              mbid = ((SearchResults) alSearchResults[0]).MBID ;
          if ((mbid != null) && (mbid.Length < 10))
            mbid = string.Empty;
          dbm.InsertDummyItem(Utils.GetArtist(artist, Utils.Category.MusicFanartScraped), null, mbid, Utils.Category.MusicFanartScraped);
        }
        ReportProgress (0.0, dbm, reportProgress, externalAccess) ;
        if (dbm.StopScraper)
          break;

        // *** Get Thumbs for Artist
        if (Utils.ScrapeThumbnails)
        {
          GetArtistThumbs(artist, dbm, true) ;
        }
        ReportProgress (0.0, dbm, reportProgress, externalAccess) ;
        break ;
      } // while
      //
      if (alSearchResults != null)
      {
        alSearchResults.Clear();
        ObjectMethods.SafeDispose(alSearchResults);
      }
      alSearchResults = null;
      //
      return res;
    }
    // End: GetMusicBrainzID
    #endregion

    #region ReportProgress
    public void ReportProgress (double Total, DatabaseManager dbm, bool reportProgress, bool externalAccess)
    {
      if (!reportProgress && !externalAccess)
      {
        if (Total > 0.0)
        {
            dbm.TotArtistsBeingScraped  = Total;
            dbm.CurrArtistsBeingScraped = 0.0;
            if (FanartHandlerSetup.Fh.MyScraperNowWorker != null)
              FanartHandlerSetup.Fh.MyScraperNowWorker.ReportProgress(0, "Ongoing");
        }
        else
        {
            ++dbm.CurrArtistsBeingScraped;
            if (dbm.CurrArtistsBeingScraped > dbm.TotArtistsBeingScraped) 
              dbm.TotArtistsBeingScraped = dbm.CurrArtistsBeingScraped;
            if (dbm.TotArtistsBeingScraped > 0.0 && FanartHandlerSetup.Fh.MyScraperNowWorker != null)
              FanartHandlerSetup.Fh.MyScraperNowWorker.ReportProgress(Utils.Percent(dbm.CurrArtistsBeingScraped, dbm.TotArtistsBeingScraped), "Ongoing");
        }
      }
    }
 public static void InitiateDbm(string type)
 {
     dbm = new DatabaseManager();
       dbm.InitDB(type);
 }