Пример #1
0
    //-------------------------------------------------------------------------------------------
    //  Grab URL Internet Movie Informations and update the XML database and refresh screen
    //  -> Selection of grabber script
    //-------------------------------------------------------------------------------------------        
    public static void grabb_Internet_Informations(string fullMovieName, int GetID, bool choosescript, string wscript, string fullMoviePath, GrabType grabtype, bool showAll, Searchtitles sTitles, GUIAnimation searchanimation)
    {
      LogMyFilms.Debug("(grabb_Internet_Informations) with grabtype = '" + grabtype + "', title = '" + fullMovieName + "', choosescript = '" + choosescript + "', grabberfile = '" + wscript + "'");
      if (choosescript)
      {
        if (!Directory.Exists(MyFilmsSettings.GetPath(MyFilmsSettings.Path.GrabberScripts)))
        {
          GUIUtils.ShowOKDialog(string.Format(GUILocalizeStrings.Get(1079876), MyFilmsSettings.GetPath(MyFilmsSettings.Path.GrabberScripts)), GUILocalizeStrings.Get(1079877), "", "");
          LogMyFilms.Info("My Films : The Directory grabber config files doesn't exists. Verify your Configuration !");
          return;
        }

        if (!Directory.Exists(MyFilmsSettings.GetPath(MyFilmsSettings.Path.GrabberScripts) + @"\user"))
        {
          try { Directory.CreateDirectory(MyFilmsSettings.GetPath(MyFilmsSettings.Path.GrabberScripts) + @"\user"); }
          catch (Exception ex) { LogMyFilms.Debug("Error creating user script directory: '" + ex.Message + "'"); }
        }

        // Grabber Directory filled, search for XML scripts files
        var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
        dlg.Reset();
        dlg.SetHeading(GUILocalizeStrings.Get(10798706)); // "Choose internet grabber script"
        if (dlg == null) return;
        var scriptfile = new ArrayList();

        if (MyFilms.conf.StrGrabber_cnf.Length > 0 && (grabtype == GrabType.Details || grabtype == GrabType.All))
        {
          try
          {
            var defaultScript = new GrabberScript(MyFilms.conf.StrGrabber_cnf);
            defaultScript.Load(MyFilms.conf.StrGrabber_cnf);
            scriptfile.Add(MyFilms.conf.StrGrabber_cnf);
            dlg.Add(MyFilms.conf.StrGrabber_cnf.Substring(MyFilms.conf.StrGrabber_cnf.LastIndexOf("\\", System.StringComparison.Ordinal) + 1) + " (default)");
            dlg.SelectedLabel = 0;
          }
          catch (Exception)
          {
            LogMyFilms.Error("The default script is not compatible with current MyFilms version - please change your settings !");
          }
        }
        var dirsInf = new DirectoryInfo(MyFilmsSettings.GetPath(MyFilmsSettings.Path.GrabberScripts));
        FileSystemInfo[] sfiles = dirsInf.GetFileSystemInfos();

        foreach (FileSystemInfo sfi in sfiles)
        {
          if ((sfi.Extension.ToLower() == ".xml") && (sfi.FullName != MyFilms.conf.StrGrabber_cnf))
          {
            var script = new GrabberScript(sfi.FullName);
            script.Load(sfi.FullName);
            string displayName = "";
            string displayNamePost = "";
            switch (grabtype)
            {
              case GrabType.MultiCovers:
                displayNamePost = script.Type.ToLower().Contains("multicovers") ? " - (Multi Cover)" : " - (Single Cover)";
                break;
            }
            if (ShouldGrabberBeAdded(script, grabtype, showAll))
            {
              if (!string.IsNullOrEmpty(script.DBName))
              {
                displayName += script.DBName;
                if (!string.IsNullOrEmpty(script.Language)) displayName += " (" + script.Language + ")";
                displayName += displayNamePost;
              }
              else displayName += sfi.Name;
              dlg.Add(displayName);
              scriptfile.Add(sfi.FullName);
            }
          }
        }
        // add choice to show all languages
        if (!showAll && !string.IsNullOrEmpty(MyFilms.conf.ItemSearchGrabberScriptsFilter))
          dlg.Add(GUILocalizeStrings.Get(10798765)); // Show all

        if (scriptfile.Count > 0)
        {
          dlg.DoModal(GetID);
          if (dlg.SelectedLabel == -1)
            return;
          if (dlg.SelectedLabelText == GUILocalizeStrings.Get(10798765))
          {
            grabb_Internet_Informations(fullMovieName, GetID, true, wscript, fullMoviePath, grabtype, true, sTitles, searchanimation);
            return;
          }
          if (dlg.SelectedLabel > -1)
            wscript = scriptfile[dlg.SelectedLabel].ToString();
        }
      }
      grabb_Internet_Informations_Search(fullMovieName, GetID, wscript, fullMoviePath, grabtype, sTitles, searchanimation);
    }
Пример #2
0
    private static void grabb_Internet_Details_Informations_Cover(string[] Result, bool interactive, int GetID, string wscript, GrabType grabtype, Searchtitles sTitles)
    {
      string tmpPicture = "";
      string tmpPicturename = ""; // picturename only
      string newPicture = ""; // full path to new picture
      string newPictureCatalogname = ""; // entry to be stored in catalog
      string oldPicture = MyFilmsDetail.getGUIProperty("picture"); // "save" current picture for later restore...
      string oldPictureCatalogname = MyFilms.r[MyFilms.conf.StrIndex]["Picture"].ToString();

      // set defaults...
      switch (grabtype)
      {
        case GrabType.Cover:
        case GrabType.All:
          tmpPicture = Result[(int)Grabber_URLClass.Grabber_Output.PicturePathLong];
          tmpPicturename = Result[(int)Grabber_URLClass.Grabber_Output.PicturePathLong].Substring(Result[(int)Grabber_URLClass.Grabber_Output.PicturePathLong].LastIndexOf("\\") + 1);
          break;
        case GrabType.MultiCovers:
          // make difference between existing cover and new one
          //if (!string.IsNullOrEmpty(MyFilms.r[MyFilms.conf.StrIndex]["Picture"].ToString()))
          //{
          //  string tmp = MyFilms.r[MyFilms.conf.StrIndex]["Picture"].ToString();
          //  if (tmp.Contains("\\"))
          //  {
          //    tmp = tmp.Substring(tmp.LastIndexOf("\\") + 1);
          //    if (tmp.Contains("["))
          //      tmpPicturename = tmp.Substring(0, tmp.LastIndexOf("[") - 1);
          //    else tmpPicturename = tmp;
          //  }
          //  else tmpPicturename = tmp;
          //}

          //if (title.EndsWith(".jpg"))
          //  title = title.Substring(0, title.Length - 4);
          //string safeName = CreateFilename(title);
          //string dirname = artFolder;
          //// string directory = "";
          ////if (dirname.Length > dirname.LastIndexOf("\\")) 
          ////  directory = dirname.Substring(dirname.LastIndexOf("\\"));
          ////if (!System.IO.Directory.Exists(directory))
          ////  System.IO.Directory.CreateDirectory(directory);
          //if (first && !System.IO.File.Exists(dirname + safeName + ".jpg"))
          //  filename = dirname + safeName + ".jpg";
          //else
          //  filename = dirname + safeName + " [" + imageUrl.GetHashCode() + "].jpg";
          //FileInfo newFile = new FileInfo(filename);
          //bool alreadyInFolder = newFile.Exists;

          if (string.IsNullOrEmpty(tmpPicturename))
          {
            tmpPicturename = sTitles.FanartTitle + ".jpg";
          }
          break;
      }

      if (MyFilms.conf.StrPicturePrefix.Length > 0)
        newPicture = MyFilms.conf.StrPathImg + "\\" + MyFilms.conf.StrPicturePrefix + tmpPicturename;
      else
        newPicture = Path.Combine(MyFilms.conf.StrPathImg, tmpPicturename);

      newPictureCatalogname = GetPictureCatalogNameFromFilename(newPicture);

      LogMyFilms.Debug("Cover Image path : '" + MyFilms.conf.StrPathImg + "'");
      LogMyFilms.Debug("Picturehandling  : '" + MyFilms.conf.PictureHandling + "'");
      LogMyFilms.Debug("PicturePrefix    : '" + MyFilms.conf.StrPicturePrefix + "'");
      LogMyFilms.Debug("Temp Cover Image : '" + tmpPicture + "'");
      LogMyFilms.Debug("New  Cover Image : '" + newPicture + "'");
      LogMyFilms.Debug("New Catalog Entry: '" + newPictureCatalogname + "'");


      switch (grabtype)
      {
        case GrabType.MultiCovers:
          #region multiple cover images
          var script = new GrabberScript(wscript);
          var ArtworkImages = new ArtworkInfo(Result[(int)Grabber_URLClass.Grabber_Output.MultiPosters], script.URLPrefix);
          var testlist = new List<ArtworkInfoItem>();
          testlist = Grabber.GrabUtil.GetMultiImageList(script.URLPrefix, Result[(int)Grabber_URLClass.Grabber_Output.MultiPosters], "");

          var choiceViewMenu = new List<string>();
          var dlgmenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
          dlgmenu.Reset();
          dlgmenu.SetHeading(GUILocalizeStrings.Get(10798764)); // Load Covers ...
          dlgmenu.Add(GUILocalizeStrings.Get(10798622) + " (" + testlist.Count.ToString() + ")"); //all
          choiceViewMenu.Add("all");

          int i = 0;
          foreach (Grabber.ArtworkInfoItem artworkImage in testlist)
          {
            try
            {
              dlgmenu.Add(artworkImage.Name);
              choiceViewMenu.Add(artworkImage.URL);
              LogMyFilms.Debug("Coverdownload - Add to menu (" + i + ": " + artworkImage.Name + "): '" + artworkImage.URL + "'");
            }
            catch { }
            i = i + 1;
          }

          dlgmenu.DoModal(GetID);
          if (dlgmenu.SelectedLabel == -1) return;
          string strChoice = choiceViewMenu[dlgmenu.SelectedLabel];
          LogMyFilms.Debug("GrabInternetDetails - interactive choice: '" + strChoice + "'");

          //GrabberScript script = new GrabberScript(wscript);
          var dlgPrgrs = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
          if (dlgPrgrs != null)
          {
            dlgPrgrs.Reset();
            dlgPrgrs.DisplayProgressBar = true;
            dlgPrgrs.ShowWaitCursor = false;
            dlgPrgrs.DisableCancel(true);
            dlgPrgrs.SetHeading(string.Format("{0} - {1}", "MyFilms", "Internet Details Grabber"));
            dlgPrgrs.SetLine(1, "Loading Cover(s) [" + script.DBName + "] ...");
            dlgPrgrs.Percentage = 0;
            dlgPrgrs.StartModal(GUIWindowManager.ActiveWindow);

            new System.Threading.Thread(delegate()
            {
              try
              {
                string filename = string.Empty;
                string filename1 = string.Empty;
                string filename2 = string.Empty;
                //if (MasterTitle == "OriginalTitle")
                //  wtitle2 = wtitle1;
                bool first = true;
                int a = 0;

                if (strChoice != "all")
                {
                  filename1 = Grabber.GrabUtil.DownloadCovers(MyFilms.conf.StrPathImg + "\\" + MyFilms.conf.StrPicturePrefix, strChoice, tmpPicturename, true, first, out filename);
                }
                else
                {
                  foreach (Grabber.ArtworkInfoItem artworkImage in testlist)
                  {
                    filename1 = GrabUtil.DownloadCovers(MyFilms.conf.StrPathImg + "\\" + MyFilms.conf.StrPicturePrefix, artworkImage.URL, tmpPicturename, true, first, out filename);
                    if (dlgPrgrs != null) dlgPrgrs.SetLine(2, "loading '" + System.IO.Path.GetFileName(filename) + "'");
                    if (dlgPrgrs != null) dlgPrgrs.Percentage = a * 100 / testlist.Count;
                    LogMyFilms.Info("Poster " + filename1.Substring(filename1.LastIndexOf("\\") + 1) + " downloaded for " + newPictureCatalogname);
                    artworkImage.LocalPath = filename;
                    if (first)
                      newPicture = filename1;
                    if (filename == string.Empty)
                      filename = filename1;
                    if (!(filename == "already" && filename1 == "already"))
                      filename = "added";
                    first = false;
                    a++;
                  }
                }
              }
              catch (Exception ex) { LogMyFilms.DebugException("Thread 'MyFilmsCoverLoader' - exception! - ", ex); }
              if (dlgPrgrs != null)
                dlgPrgrs.Percentage = 100; dlgPrgrs.ShowWaitCursor = false; dlgPrgrs.SetLine(1, GUILocalizeStrings.Get(1079846)); dlgPrgrs.SetLine(2, ""); Thread.Sleep(50); dlgPrgrs.Close(); // Done...
              GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) =>
              {
                dlgPrgrs.ShowWaitCursor = false;
                // enter here what to load after background thread has finished !
                if (GetID == MyFilms.ID_MyFilmsCoverManager)
                {
                  if (DetailsUpdated != null) DetailsUpdated(true);
                }
                return 0;
              }, 0, 0, null);
            }) { Name = "MyFilmsCoverLoader", IsBackground = true }.Start();
            return;
          }
          #endregion
          break;
        case GrabType.Cover:
          #region single cover without confirmation dialog
          if (File.Exists(newPicture)) // if 'base file' already exists, create sub file name Result[(int)Grabber_URLClass.Grabber_Output.Country]
          {
            newPicture = Path.Combine(Path.GetDirectoryName(newPicture), Path.GetFileNameWithoutExtension(newPicture) + " [" + Result[(int)Grabber.Grabber_URLClass.Grabber_Output.PictureURL].GetHashCode() + "]" + System.IO.Path.GetExtension(newPicture));
            LogMyFilms.Debug("New Cover File Name = '" + newPicture + "'");
          }
          if (newPicture != tmpPicture)
          {
            if (!Directory.Exists(newPicture.Substring(0, newPicture.LastIndexOf("\\"))))
            {
              try { Directory.CreateDirectory(newPicture.Substring(0, newPicture.LastIndexOf("\\"))); }
              catch (Exception ex) { LogMyFilms.Debug("Could not create directory '" + newPicture.Substring(0, newPicture.LastIndexOf("\\")) + "' - Exception: " + ex); }
            }
            try
            {
              LogMyFilms.Debug("Copy '" + tmpPicture + "' to '" + newPicture + "'");
              File.Copy(tmpPicture, newPicture, true);
            }
            catch (Exception ex) { LogMyFilms.Debug("Error copy file: '" + tmpPicture + "' - Exception: " + ex); }
          }

          if (newPicture != tmpPicture)
          {
            try { File.Delete(tmpPicture); }
            catch (Exception ex) { LogMyFilms.Debug("Error deleting tmp file: '" + tmpPicture + "' - Exception: " + ex); }
          }
          #endregion
          break;
        case GrabType.All:
          #region single cover
          if (interactive)
          {
            setGUIProperty("picture", tmpPicture);
            GUIWindowManager.Process(); // To Update GUI display ...

            var dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
            dlgYesNo.SetHeading(GUILocalizeStrings.Get(1079870)); // choice
            dlgYesNo.SetLine(1, "");
            dlgYesNo.SetLine(2, GUILocalizeStrings.Get(10798733)); // Replace cover with new one
            dlgYesNo.SetLine(3, "");
            dlgYesNo.DoModal(GetID);
            if (!(dlgYesNo.IsConfirmed))
            {
              setGUIProperty("picture", oldPicture);
              GUIWindowManager.Process();
              return;
            }
            else
            {
              setGUIProperty("picture", "");
              GUIWindowManager.Process();
            }
          }
          if (newPicture != tmpPicture)
          {
            if (!Directory.Exists(newPicture.Substring(0, newPicture.LastIndexOf("\\"))))
            {
              try { Directory.CreateDirectory(newPicture.Substring(0, newPicture.LastIndexOf("\\"))); }
              catch (Exception ex) { LogMyFilms.Debug("Could not create directory '" + newPicture.Substring(0, newPicture.LastIndexOf("\\")) + "' - Exception: " + ex); }
            }
            try { File.Copy(tmpPicture, newPicture, true); }
            catch (Exception ex) { LogMyFilms.Debug("Error copy file: '" + tmpPicture + "' - Exception: " + ex); }
          }

          if (newPicture != tmpPicture)
          {
            try { File.Delete(tmpPicture); }
            catch (Exception ex) { LogMyFilms.Debug("Error deleting tmp file: '" + tmpPicture + "' - Exception: " + ex); }
          }
          #endregion
          #region collection image

          string tmpPictureCollection = Path.GetDirectoryName(tmpPicture) + @"\Collection_" + Path.GetFileName(tmpPicture);
          string newPictureCollection = MyFilms.conf.StrPathImg + "\\" + MyFilms.conf.StrTitleSelect.Replace(MyFilms.conf.TitleDelim, ".") + "." + sTitles.MasterTitle + ".jpg";
          if (System.IO.File.Exists(tmpPictureCollection))
          {
            try
            {
              File.Copy(tmpPictureCollection, newPictureCollection, true);
              LogMyFilms.Debug("Created Collection image '" + newPictureCollection + "'");
            }
            catch (Exception ex)
            {
              LogMyFilms.Debug("Error copy file: '" + tmpPictureCollection + "' - Exception: " + ex);
            }
          }
          else
          {
            LogMyFilms.Debug("Collection Cover '" + tmpPictureCollection + "' does not exists - do nothing.");
          }
          if (newPictureCollection != tmpPictureCollection)
          {
            try { File.Delete(tmpPictureCollection); }
            catch (Exception ex) { LogMyFilms.Debug("Error deleting tmp file: '" + tmpPictureCollection + "' - Exception: " + ex); }
          }
          #endregion
          break;
      }
      // update catalog entry in memory
      if (string.IsNullOrEmpty(MyFilms.r[MyFilms.conf.StrIndex]["Picture"].ToString()))
        MyFilms.r[MyFilms.conf.StrIndex]["Picture"] = newPictureCatalogname;
      else if (interactive)
        MyFilms.r[MyFilms.conf.StrIndex]["Picture"] = newPictureCatalogname;
      else if (!oldPicture.Contains(oldPictureCatalogname))
        MyFilms.r[MyFilms.conf.StrIndex]["Picture"] = newPictureCatalogname;
      // set picture to new one (full path)
      setGUIProperty("picture", newPicture);
      GUIWindowManager.Process();
      if (GetID == MyFilms.ID_MyFilmsCoverManager)
      {
        if (DetailsUpdated != null) DetailsUpdated(true);
      }
    }
Пример #3
0
    private static bool ShouldGrabberBeAdded(GrabberScript script, GrabType grabtype, bool showallLanguages)
    {
      bool add = false;
      string currentlanguagefilter = "";
      if (!string.IsNullOrEmpty(MyFilms.conf.ItemSearchGrabberScriptsFilter))
        currentlanguagefilter = MyFilms.conf.ItemSearchGrabberScriptsFilter;
      string[] sep = new string[] { ",", ";", "|", "/", ".", @"\", ":" };
      switch (grabtype)
      {
        case GrabType.All:
        case GrabType.Details:
        case GrabType.Cover:
        case GrabType.MultiCovers:
        case GrabType.Fanart:
        case GrabType.Person:
        case GrabType.Photos:
        case GrabType.Trailers:
          break;
      }

      // check, if it meets filter criteria
      string[] allowedlanguages = currentlanguagefilter.Split(sep, StringSplitOptions.RemoveEmptyEntries);
      string[] supportedlanguages = script.Language.Split(sep, StringSplitOptions.RemoveEmptyEntries);
      string[] supportedfunctions = script.Type.Split(sep, StringSplitOptions.RemoveEmptyEntries);

      if (string.IsNullOrEmpty(currentlanguagefilter) || currentlanguagefilter.Contains("*")) // if there is no filter set in config or override add script anyway...
      {
        showallLanguages = true;
      }

      if (supportedfunctions.Length == 0 && (grabtype == GrabType.Details || grabtype == GrabType.All)) // if there is no functions set and trying legacy menu ...
        add = true;
      else
      {
        foreach (string supportedfunction in supportedfunctions.Where(supportedfunction => supportedfunction.Trim().ToLower() == grabtype.ToString().ToLower() || (supportedfunction.Trim().ToLower() == "details" && grabtype.ToString().ToLower() == "all")))
        {
          if (showallLanguages)
            add = true;
          else
          {
            foreach (string allowedlanguage in from allowedlanguage in allowedlanguages from supportedlanguage in supportedlanguages where supportedlanguage.Trim().ToLower() == allowedlanguage.Trim().ToLower() select allowedlanguage)
            {
              add = true;
            }
          }
        }
      }
      return add;
    }