Example #1
0
        public DbPersonInfo GetPersonsById(string id, string language)
        {
            Tmdb api = new Tmdb(TmdbApiKey, language); // language is optional, default is "en"

              if (language.Length != 2) language = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead

              TmdbPerson singleperson = api.GetPersonInfo(int.Parse(id));

              DbPersonInfo result = GetPersonInformation(api, singleperson, language);
              return result;
        }
Example #2
0
        public List<Youtube> getYoutubeTrailerURL(Movie currentMovie)
        {
            bool noExist = false;
            int TmdbID = 0;
            List<Youtube> youtube = new List<Youtube>();
            Tmdb api = new Tmdb(mApiKey, "en");

            if (currentMovie.TmdbID == null)
            {
                // Search TMDB by title + year for correct movie ID
                TmdbMovieSearch movie = api.SearchMovie(currentMovie.Title, 1);
                List<MovieResult> movieResults = movie.results;
                if (movieResults.Count != 0)
                {
                    TmdbID = movieResults[0].id;
                }
                else
                {
                    noExist = true;
                }
            }
            else
            {
                // Parse String TMDBID to Int
                int.TryParse(currentMovie.TmdbID, out TmdbID);
            }

            if (noExist == false)
            {
                TmdbMovieTrailers trailers = api.GetMovieTrailers(TmdbID);
                if (trailers != null)
                {
                    if (trailers.youtube != null)
                    {
                        youtube = trailers.youtube;
                    }
                    else
                    {
                        youtube = null;
                    }
                }
                else
                {
                    youtube = null;
                }
            }
            else
            {
                youtube = null;
            }
            return youtube;
        }
Example #3
0
        static void Main(string[] args)
        {
            Tmdb api = new Tmdb("apikey", null);

            Console.Write("Enter Movie Title: ");
            var search = Console.ReadLine();
            if (string.IsNullOrEmpty(search))
                return;

            Console.WriteLine("Synchronous call...");
            {
                int page = 1;
                while (true)
                {
                    var result = api.SearchMovie(search, page);
                    if (result != null)
                    {
                        if (page == 1)
                            Console.WriteLine(string.Format("{0} matches found", result.total_results));

                        if (result.results.Count == 0)
                            break;

                        foreach (var movie in result.results)
                            Console.WriteLine(string.Format("{0} {1} {2}", movie.id, movie.title, movie.release_date));
                    }
                    else if (api.Error != null)
                        Console.WriteLine(string.Format("{0} {1}", api.Error.status_code, api.Error.status_message));
                }
            }

            Console.WriteLine("Asynchronous call...");
            {
                api.SearchMovie(search, 1, null, result =>
                    {
                        if (result.Data != null)
                        {
                            foreach (var movie in result.Data.results)
                                Console.WriteLine(string.Format("{0} {1} {2}", movie.id, movie.title, movie.release_date));
                        }
                        else
                            Console.WriteLine(string.Format("{0} {1}", result.Error.status_code, result.Error.status_message));
                    });
            }

            Console.WriteLine("Press any key...");
            Console.Read();
        }
Example #4
0
        public DbPersonInfo GetPersonsById(string id, string language)
        {
            Tmdb api = new Tmdb(TmdbApiKey, language); // language is optional, default is "en"

              if (language.Length != 2)
            language = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead

              TmdbPerson singleperson = api.GetPersonInfo(int.Parse(id));

              DbPersonInfo result = GetPersonInformation(api, singleperson, language);
              return result;

              //string apiGetPersonInfoLanguage = language.Length == 2 ? ApiGetPersonInfo.Replace("/en/", "/" + language + "/") : ApiGetPersonInfo;

              //XmlNodeList xml = GetXml(apiGetPersonInfoLanguage + id);
              //if (xml == null) return result;

              //XmlNodeList personNodes = xml.Item(0).SelectNodes("//person");
              //foreach (DbPersonInfo person in personNodes.Cast<XmlNode>().Select(node => GetPersonInformation(node)).Where(person => person != null))
              //{
              //  result = person;
              //}
              //return result;
        }
Example #5
0
        private void ApiRequest(Job job, SearchQuery query)
        {
            job.Movies.Clear();

            var searchTitle = query.Title;
            var searchYear = query.Year;

            if (_apiKey == null)
            {
                const string message = "ERROR: No API key found";
                Logger.Error(message);
                throw new Exception(message);
            }

            _tmdbApi = new Tmdb(_apiKey, _searchISO_639_1);

            // TMDb (previously) choked on dashes - not sure if it still does or not...
            // E.G.: "The Amazing Spider-Man" --> "The Amazing Spider Man"
            searchTitle = Regex.Replace(searchTitle, @"-+", " ");

            var requestParameters = new TmdbApiParameters(searchTitle, searchYear, _searchISO_639_1);

            try
            {
                SearchTmdb(requestParameters, job);
            }
            catch (Exception ex)
            {
                HandleTmdbError(ex);
            }
        }
Example #6
0
        private static DbMovieInfo GetMovieInformation(Tmdb api, TmdbMovie movieNode, string language)
        {
            LogMyFilms.Debug("GetMovieInformation() - language = '" + (language ?? "") + "'");

              if (movieNode == null) return null;
              DbMovieInfo movie = new DbMovieInfo();

              try
              {
            TmdbMovie m = api.GetMovieInfo(movieNode.id);

            movie.Identifier = m.id.ToString();
            movie.ImdbId = m.imdb_id;
            movie.Name = m.original_title;
            movie.TranslatedTitle = m.title;
            movie.AlternativeTitle = m.original_title;
            DateTime date;
            if (DateTime.TryParse(m.release_date, out date))
              movie.Year = date.Year;
            movie.DetailsUrl = m.homepage;
            movie.Summary = m.overview;
            movie.Score = (float)Math.Round(m.vote_average, 1);
            // movie.Certification = "";
            foreach (SpokenLanguage spokenLanguage in m.spoken_languages)
            {
              movie.Languages.Add(spokenLanguage.name);
            }
            movie.Runtime = m.runtime;

            TmdbMovieCast p = api.GetMovieCast(movieNode.id);

            foreach (Cast cast in p.cast)
            {
              string name = cast.name;
              string character = cast.character;
              DbPersonInfo personToAdd = new DbPersonInfo { Id = cast.id.ToString(), Name = cast.name, DetailsUrl = cast.profile_path };
              movie.Persons.Add(personToAdd);

              if (character.Length > 0) name = name + " (" + character + ")";
              movie.Actors.Add(name);
            }

            foreach (Crew crew in p.crew)
            {
              DbPersonInfo personToAdd = new DbPersonInfo { Id = crew.id.ToString(), Name = crew.name, DetailsUrl = crew.profile_path };
              movie.Persons.Add(personToAdd);
              switch (crew.department)
              {
            case "Production":
              movie.Producers.Add(crew.name);
              break;
            case "Directing":
              movie.Directors.Add(crew.name);
              break;
            case "Writing":
              movie.Writers.Add(crew.name);
              break;
            case "Sound":
            case "Camera":
              break;
              }
            }

            foreach (Cast cast in p.cast)
            {
              string name = cast.name;
              string character = cast.character;
              string thumb = cast.profile_path;
              string job = cast.character;
              string id = cast.id.ToString();
              string url = cast.profile_path;
              var personToAdd = new DbPersonInfo { Id = id, Name = name, DetailsUrl = url, Job = job };
              movie.Persons.Add(personToAdd);
              switch (job)
              {
            case "Producer":
              movie.Producers.Add(name);
              break;
            case "Director":
              movie.Directors.Add(name);
              break;
            case "Actor":
              if (character.Length > 0)
                name = name + " (" + character + ")";
              movie.Actors.Add(name);
              break;
            case "Screenplay":
              movie.Writers.Add(name);
              break;
              }
            }
            foreach (ProductionCountry country in m.production_countries)
            {
              movie.Country.Add(country.name);
            }
            foreach (MovieGenre genre in m.genres)
            {
              movie.Country.Add(genre.name);
            }

            TmdbConfiguration tmdbConf = api.GetConfiguration();

            // load posters
            TmdbMovieImages movieImages = api.GetMovieImages(movieNode.id, language);
            LogMyFilms.Debug("GetMovieInformation() - language = '" + (language ?? "") + "', Posters: '" + movieImages.posters.Count + "', Backdrops: '" + movieImages.backdrops.Count + "'");

            foreach (Poster poster in movieImages.posters)
            {
              movie.Posters.Add(tmdbConf.images.base_url + "w500" + poster.file_path);
            }
            foreach (Backdrop backdrop in movieImages.backdrops)
            {
              movie.Backdrops.Add(tmdbConf.images.base_url + "original" + backdrop.file_path);
            }

            // english posters and backdrops
            movieImages = api.GetMovieImages(movieNode.id, "en"); // fallback to en language images
            LogMyFilms.Debug("GetMovieInformation() - language = 'en', Posters: '" + movieImages.posters.Count + "', Backdrops: '" + movieImages.backdrops.Count + "'");
            if (movie.Posters.Count < 5)
            {
              foreach (Poster poster in movieImages.posters)
              {
            movie.Posters.Add(tmdbConf.images.base_url + "w500" + poster.file_path);
              }
            }
            foreach (Backdrop backdrop in movieImages.backdrops)
            {
              movie.Backdrops.Add(tmdbConf.images.base_url + "original" + backdrop.file_path);
            }

            // non language posters and backdrops
            movieImages = api.GetMovieImages(movieNode.id, null); // fallback to non language images
            LogMyFilms.Debug("GetMovieInformation() - language = 'null', Posters: '" + movieImages.posters.Count + "', Backdrops: '" + movieImages.backdrops.Count + "'");
            if (movie.Posters.Count < 11)
            {
              foreach (Poster poster in movieImages.posters)
              {
            movie.Posters.Add(tmdbConf.images.base_url + "w500" + poster.file_path);
              }
            }

            if (movie.Backdrops.Count < 11) // only load foreign backdrops, if not anough are availabole
            {
              foreach (Backdrop backdrop in movieImages.backdrops)
              {
            movie.Backdrops.Add(tmdbConf.images.base_url + "original" + backdrop.file_path);
              }
            }
            LogMyFilms.Debug("GetMovieInformation() - Totals added - Posters: '" + movie.Posters.Count + "', Backdrops: '" + movie.Backdrops.Count + "'");
              }
              catch (Exception ex)
              {
            LogMyFilms.Debug(ex.StackTrace);
              }
              return movie;
        }
Example #7
0
        private List<DbMovieInfo> GetMoviesByTitle(string title, int year, string director, string imdbid, string tmdbid, bool choose, string language)
        {
            LogMyFilms.Debug("GetMoviesByTitle - title = '" + title + "', year = '" + year + "', imdbid = '" + imdbid + "', tmdbid = '" + tmdbid + "', choose = '" + choose + "', language = '" + language + "'");

              //title = Grabber.GrabUtil.normalizeTitle(title);

              //string apiSearchLanguage = ApiSearchMovie;
              //string apiGetMovieInfoLanguage = ApiGetMovieInfo;
              //if (language.Length == 2)
              //{
              //  apiSearchLanguage = ApiSearchMovie.Replace("/en/", "/" + language + "/");
              //  apiGetMovieInfoLanguage = ApiGetMovieInfo.Replace("/en/", "/" + language + "/");
              //}
              //else
              //{
              //  apiSearchLanguage = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead
              //  apiGetMovieInfoLanguage = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead
              //  language = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead
              //}

              if (language.Length != 2)
            language = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead

              List<DbMovieInfo> results = new List<DbMovieInfo>();
              List<DbMovieInfo> resultsdet = new List<DbMovieInfo>();
              // XmlNodeList xml = null; // old API2.1 xml structure
              List<TmdbMovie> movies = new List<TmdbMovie>();

              //Tmdb api = new Tmdb(TmdbApiKey, CultureInfo.CurrentCulture.Name.Substring(0, 2)); // language is optional, default is "en"
              //TmdbConfiguration tmdbConf = api.GetConfiguration();
              //TmdbMovieSearch tmdbMovies = api.SearchMovie(searchname, 0, language, 2012);
              //TmdbPersonSearch tmdbPerson = api.SearchPerson(personname, 1);
              //List<MovieResult> persons = tmdbMovies.results;
              //if (persons != null && persons.Count > 0)
              //{
              //  PersonResult pinfo = persons[0];
              //  TmdbPerson singleperson = api.GetPersonInfo(pinfo.id);
              //  // TMDB.TmdbPersonImages images = api.GetPersonImages(pinfo.id);
              //  // TMDB.TmdbPersonCredits personFilmList = api.GetPersonCredits(pinfo.id);
              //}

              Tmdb api = new Tmdb(TmdbApiKey, language); // language is optional, default is "en"
              // TmdbConfiguration tmdbConf = api.GetConfiguration();

              try
              {
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Contains("tt"))
            {
              TmdbMovie movie = api.GetMovieByIMDB(imdbid);
              if (movie.id > 0)
              {
            results.Add(GetMovieInformation(api, movie, language));
            return results;
              }
            }

            TmdbMovieSearch moviesfound;
            if (year > 0)
            {
              moviesfound = api.SearchMovie(title, 1, "", null, year);
              if (moviesfound.results.Count == 0) moviesfound = api.SearchMovie(title, 1, language);
              movies.AddRange(moviesfound.results);
            }
            else
            {
              int ipage = 1;
              while (true)
              {
            moviesfound = api.SearchMovie(title, 1, null);
            movies.AddRange(moviesfound.results);
            ipage++;
            if (ipage > moviesfound.total_pages) break;
              }
              movies = movies.OrderBy(x => x.release_date).ToList(); // .AsEnumerable()
            }

            if (movies.Count == 1)
            {
              results.Add(GetMovieInformation(api, movies[0], language));
              return results;
            }
            else
            {
              foreach (TmdbMovie movieResult in movies)
              {
            DbMovieInfo movie = GetMovieInformation(api, movieResult, language);
            if (movie != null && Grabber.GrabUtil.normalizeTitle(movie.Name.ToLower()).Contains(Grabber.GrabUtil.normalizeTitle(title.ToLower())))
              if (year > 0 && movie.Year > 0 && !choose)
              {
                if ((year >= movie.Year - 2) && (year <= movie.Year + 2))
                  results.Add(movie);
              }
              else
                results.Add(movie);
              }
              return results;
            }

              }
              catch (Exception ex)
              {
            LogMyFilms.Debug(ex.StackTrace);
              }

              #region old TMDB APIv2.1 code
              //if (!string.IsNullOrEmpty(imdbid))
              //  xml = GetXml(ApiSearchMovieByImdb + imdbid);
              //if (xml == null) // if imdb search was unsuccessful use normal search...
              //  xml = GetXml(apiSearchLanguage + Grabber.GrabUtil.RemoveDiacritics(title.Trim().ToLower()).Replace(" ", "+"));

              //if (xml == null)
              //  return results;

              //XmlNodeList movieNodes = xml.Item(0).SelectNodes("//movie");
              //foreach (XmlNode node in movieNodes)
              //{
              //  DbMovieInfo movie = GetMovieInformation(node);
              //  if (movie != null && Grabber.GrabUtil.normalizeTitle(movie.Name.ToLower()).Contains(Grabber.GrabUtil.normalizeTitle(title.ToLower())))
              //    if (year > 0 && movie.Year > 0 && !choose)
              //    {
              //      if ((year >= movie.Year - 2) && (year <= movie.Year + 2))
              //        results.Add(movie);
              //    }
              //    else
              //      results.Add(movie);
              //}

              //if (results.Count > 0)
              //{
              //  // Replace non-descriptive characters with spaces
              //  director = System.Text.RegularExpressions.Regex.Replace(director, "( et | and | & | und )", ",");
              //  if (director.IndexOf(",", System.StringComparison.Ordinal) > 0)
              //    director = director.Substring(0, director.IndexOf(",", System.StringComparison.Ordinal));
              //  foreach (DbMovieInfo movie in results.Where(movie => movie.Identifier != null))
              //  {
              //    try { xml = GetXml(apiGetMovieInfoLanguage + movie.Identifier); }
              //    catch { xml = null; }
              //    if (xml != null)
              //    {
              //      movieNodes = xml.Item(0).SelectNodes("//movie");
              //      foreach (DbMovieInfo movie2 in from XmlNode node in movieNodes select GetMovieInformation(node))
              //      {
              //        if (movie2 != null && Grabber.GrabUtil.normalizeTitle(movie2.Name.ToLower()).Contains(Grabber.GrabUtil.normalizeTitle(title.ToLower())) && movie2.Directors.Contains(director))
              //          if (year > 0 && movie2.Year > 0 && !choose)
              //          {
              //            if ((year >= movie2.Year - 2) && (year <= movie2.Year + 2))
              //              resultsdet.Add(movie2);
              //          }
              //          else
              //            resultsdet.Add(movie2);
              //        else
              //          if (choose)
              //            resultsdet.Add(movie2);
              //      }
              //    }
              //  }
              //}
              #endregion

              return resultsdet.Count > 0 ? resultsdet : results;
        }
Example #8
0
        private static DbPersonInfo GetPersonInformation(Tmdb api, TmdbPerson personNode, string language)
        {
            LogMyFilms.Debug("GetPersonInformation()");

              if (personNode == null) return null;

              List<string> images = new List<string>();
              DbPersonInfo person = new DbPersonInfo();

              try
              {
            TmdbPerson m = api.GetPersonInfo(personNode.id);

            person.Id = m.id.ToString();
            person.Name = m.name;
            person.Biography = m.biography;
            person.Birthday = m.birthday;
            person.Birthplace = m.place_of_birth;
            person.DetailsUrl = m.homepage;

            TmdbPersonCredits p = api.GetPersonCredits(personNode.id);

            foreach (CastCredit cast in p.cast)
            {
            }

            foreach (CrewCredit crew in p.crew)
            {
            }

            TmdbConfiguration tmdbConf = api.GetConfiguration();

            TmdbPersonImages personImages = api.GetPersonImages(personNode.id);
            foreach (PersonImageProfile imageProfile in personImages.profiles)
            {
              person.Images.Add(tmdbConf.images.base_url + "w500" + imageProfile.file_path);
            }
              }
              catch (Exception ex)
              {
            LogMyFilms.Debug(ex.StackTrace);
              }
              return person;
        }
Example #9
0
    private static int SearchTmdbMovie(string searchexpression, string title, string title2, int year, string language, bool collectionsearch)
    {
      LogMyFilms.Debug("SearchTmdbMovie() - title '" + title + "', title2 '" + title2 + "', year '" + year.ToString() + "'");
      var api = new Tmdb(MyFilms.TmdbApiKey, language);
      var tmdbConf = api.GetConfiguration();
      var allMoviesFound = new List<TmdbMovie>();
      var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

      const int minChars = 2;
      const bool filter = true;

      if (dlg == null) return -1;
      dlg.Reset();
      dlg.SetHeading(GUILocalizeStrings.Get(10798646));  // Search Films
      dlg.Add("  *****  " + GUILocalizeStrings.Get(1079860) + "  *****  "); //manual selection
      allMoviesFound.Add(new TmdbMovie());

      foreach (TmdbMovie t in api.SearchMovie(searchexpression, 1, null).results)
      {
        LogMyFilms.Debug("TMDB - movie found '" + t.title + "'");
        var item = new GUIListItem();
        item.Label = t.title + "  (" + t.release_date + ")";
        item.IconImage = tmdbConf.images.base_url + "w500" + t.poster_path;
        item.ThumbnailImage = tmdbConf.images.base_url + "w500" + t.poster_path;
        if (collectionsearch)
        {
          TmdbMovie tmdbMovie = api.GetMovieInfo(t.id);
          TmdbCollection collection = api.GetCollectionInfo(tmdbMovie.belongs_to_collection.id);

          LogMyFilms.Debug("TMDB - Value found - movie   = '" + (tmdbMovie.title ?? "") + "'");
          LogMyFilms.Debug("TMDB - Value found - belongs to collection   = '" + (collection.name ?? "") + "'");

          item.Label += " - " + (collection.name ?? "<no collection>");
          item.IconImage = tmdbConf.images.base_url + "w500" + collection.poster_path;
        }
        dlg.Add(item);
        allMoviesFound.Add(t);
      }

      #region title2 search (disabled)
      //if (title2.Length > 0)
      //{
      //  foreach (MovieResult t in api.SearchMovie(title2, 1, null).results)
      //  {
      //    LogMyFilms.Debug("TMDB - movie found '" + t.title + "'");

      //    var item = new GUIListItem();
      //    item.Label = t.title + "  (" + t.release_date + ")";
      //    item.IconImage = tmdbConf.images.base_url + "w500" + t.poster_path;
      //    item.ThumbnailImage = tmdbConf.images.base_url + "w500" + t.poster_path;
      //    if (collectionsearch)
      //    {
      //      TmdbMovie tmdbMovie = api.GetMovieInfo(t.id);
      //      TmdbCollection collection = api.GetCollectionInfo(tmdbMovie.belongs_to_collection.id);

      //      LogMyFilms.Debug("TMDB - Value found - movie   = '" + (tmdbMovie.title ?? "") + "'");
      //      LogMyFilms.Debug("TMDB - Value found - belongs to collection   = '" + (collection.name ?? "") + "'");

      //      item.Label += " - " + (collection.name ?? "<no collection>");
      //      item.IconImage = tmdbConf.images.base_url + "w500" + collection.poster_path;
      //    }
      //    dlg.Add(item);
      //    allMoviesFound.Add(t);
      //  }
      //}
      #endregion

      if (allMoviesFound.Count > 0)
      {
        dlg.DoModal(wGetID);
      }
      else
      {
        dlg.SelectedLabel = 0;
      }
      if (dlg.SelectedLabel == -1) return -1;

      if (dlg.SelectedLabel == 0)
      {
        //First Show Dialog to choose Otitle, Ttitle or substrings - or Keyboard to manually enter searchstring!!!
        var dlgSearchFilm = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
        if (dlgSearchFilm == null) return -1;
        dlgSearchFilm.Reset();
        dlgSearchFilm.SetHeading(GUILocalizeStrings.Get(1079859)); // choose search expression
        dlgSearchFilm.Add("  *****  " + GUILocalizeStrings.Get(1079858) + "  *****  ");
        dlgSearchFilm.Add(title);
        dlgSearchFilm.Add(title2);
        foreach (object t in from object t in MyFilms.SubTitleGrabbing(title) where t.ToString().Length > 1 select t) dlgSearchFilm.Add(t.ToString());
        foreach (object t in from object t in MyFilms.SubTitleGrabbing(title2) where t.ToString().Length > 1 select t) dlgSearchFilm.Add(t.ToString());
        foreach (object t in from object t in MyFilms.SubWordGrabbing(title, minChars, filter) where t.ToString().Length > 1 select t) dlgSearchFilm.Add(t.ToString()); // Min 3 Chars, Filter true (no der die das)
        foreach (object t in from object t in MyFilms.SubWordGrabbing(title2, minChars, filter) where t.ToString().Length > 1 select t) dlgSearchFilm.Add(t.ToString());
        dlgSearchFilm.DoModal(wGetID);

        if (dlgSearchFilm.SelectedLabel == 0) // enter manual searchstring via VK
        {
          var keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
          if (null == keyboard) return -1;
          keyboard.Reset();
          keyboard.SetLabelAsInitialText(false); // set to false, otherwise our intial text is cleared
          keyboard.Text = title;
          keyboard.DoModal(wGetID);
          if (keyboard.IsConfirmed && keyboard.Text.Length > 0) return SearchTmdbMovie(keyboard.Text, title, title2, year, language, collectionsearch);
        }
        if (dlgSearchFilm.SelectedLabel > 0) return SearchTmdbMovie(dlgSearchFilm.SelectedLabelText, title, title2, year, language, collectionsearch);
      }

      if (dlg.SelectedLabel > 0) return allMoviesFound[dlg.SelectedLabel].id;

      return 0; // return 0 if no movie found or -1 if search was cancelled
    }
Example #10
0
    //-------------------------------------------------------------------------------------------
    //  Search and Download Trailerfiles via TMDB (mostly YouTube)
    //-------------------------------------------------------------------------------------------        
    internal static void SearchAndDownloadTrailerOnlineTMDB(DataRow[] r1, int index, bool loadAllTrailers, bool interactive, string overridestoragepath)
    {
      //LogMyFilms.Debug("(SearchAndDownloadTrailerOnlineTMDB) - mastertitle      : '" + MyFilms.r[index][MyFilms.conf.StrTitle1] + "'");
      //if (Helper.FieldIsSet(MyFilms.conf.StrTitle2)) LogMyFilms.Debug("(SearchAndDownloadTrailerOnlineTMDB) - secondary title  : '" + MyFilms.r[index][MyFilms.conf.StrTitle2] + "'");
      //LogMyFilms.Debug("(SearchAndDownloadTrailerOnlineTMDB) - Cleaned Title    : '" + MediaPortal.Util.Utils.FilterFileName(MyFilms.r[index][MyFilms.conf.StrTitle1].ToString().ToLower()) + "'");

      string titlename = Helper.TitleWithoutGroupName(r1[index][MyFilms.conf.StrTitle1].ToString());
      string titlename2 = (Helper.FieldIsSet(MyFilms.conf.StrTitle2)) ? Helper.TitleWithoutGroupName(r1[index][MyFilms.conf.StrTitle2].ToString()) : "";
      string collectionname = Helper.TitleFirstGroupName(r1[index][MyFilms.conf.StrTitle1].ToString());

      string path;
      #region Retrieve original directory of mediafiles
      try
      {
        path = r1[index][MyFilms.conf.StrStorage].ToString();
        if (path.Contains(";")) path = path.Substring(0, path.IndexOf(";", StringComparison.Ordinal));
        //path = Path.GetDirectoryName(path);
        //if (path == null || !Directory.Exists(path))
        //{
        //  LogMyFilms.Warn("Directory of movie '" + titlename + "' doesn't exist anymore - check your DB");
        //  return;
        //}
        if (path.Contains("\\")) path = path.Substring(0, path.LastIndexOf("\\", StringComparison.Ordinal));
        
        // LogMyFilms.Debug("(SearchAndDownloadTrailerOnlineTMDB) get media directory name: '" + path + "'");
      }
      catch (Exception)
      {
        LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() error with directory of movie '" + titlename + "' - check your DB");
        return;
      }
      #endregion

      string imdb = "";
      #region get imdb number sor better search match
      if (!string.IsNullOrEmpty(r1[index]["IMDB_Id"].ToString()))
        imdb = r1[index]["IMDB_Id"].ToString();
      else if (!string.IsNullOrEmpty(r1[index]["URL"].ToString()))
      {
        string urLstring = r1[index]["URL"].ToString();
        var cutText = new Regex("" + @"tt\d{7}" + "");
        var m = cutText.Match(urLstring);
        if (m.Success) imdb = m.Value;
      }
      #endregion

      int year;

      #region get local language
      string language = CultureInfo.CurrentCulture.Name.Substring(0, 2);
      // LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB - detected language = '" + language + "'");
      #endregion

      LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - movie '" + titlename + "', media directory '" + path + "', language '" + language + "'");
      
      var api = new Tmdb(MyFilms.TmdbApiKey, language);
      // var tmdbConf = api.GetConfiguration();

      int selectedMovieId = 0;

      #region search matching TMDB movie id
      if (imdb.Contains("tt"))
      {
        TmdbMovie movie = api.GetMovieByIMDB(imdb);
        if (movie.id > 0)
        {
          selectedMovieId = movie.id;
        }
      }

      if (selectedMovieId == 0) // no movie found by imdb search
      {
        TmdbMovieSearch moviesfound;
        if (int.TryParse(r1[index]["Year"].ToString(), out year))
        {
          moviesfound = api.SearchMovie(titlename, 1, "", null, year);
          if (moviesfound.results.Count == 0) moviesfound = api.SearchMovie(titlename, 1, null);
        }
        else
        {
          moviesfound = api.SearchMovie(r1[index][MyFilms.conf.StrTitle1].ToString(), 1, null);
          if (moviesfound.results.Count == 0 && titlename2.Length > 0)
          {
            if (int.TryParse(r1[index]["Year"].ToString(), out year))
            {
              moviesfound = api.SearchMovie(titlename2, 1, "", null, year);
              if (moviesfound.results.Count == 0) moviesfound = api.SearchMovie(titlename2, 1, null);
            }
          }
        }

        if (moviesfound.results.Count == 1)
        {
          selectedMovieId = moviesfound.results[0].id;
        }
        else
        {
          LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - Movie Search Results: '" + moviesfound.total_results.ToString() + "' for movie '" + titlename + "'");
          if (!interactive) return;
          else
          {
            if (moviesfound.results.Count == 0)
            {
              while(selectedMovieId == 0)
              {
                selectedMovieId = SearchTmdbMovie(titlename, titlename, titlename2, year, language, false);
                if (selectedMovieId == -1) return; // cancel search
              }
            }
            else
            {
              var choiceMovies = new List<TmdbMovie>();
              var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
              if (dlg == null) return;
              dlg.Reset();
              dlg.SetHeading(GUILocalizeStrings.Get(10798992)); // Select movie ...

              foreach (TmdbMovie movieResult in moviesfound.results)
              {
                dlg.Add(movieResult.title + " (" + movieResult.release_date + ")");
                choiceMovies.Add(movieResult);
              }
              dlg.DoModal(GUIWindowManager.ActiveWindow);
              if (dlg.SelectedLabel == -1) return;
              selectedMovieId = choiceMovies[dlg.SelectedLabel].id;
            }
          }
        }
      }
      #endregion

      if (selectedMovieId == 0)
      {
        LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB - no movie found - no trailers added to DL queue - returning");
        if (interactive) GUIUtils.ShowNotifyDialog(GUILocalizeStrings.Get(10798995)); // No matching movie found !
        return;
      }

      #region search trailers for movie
      var trailersfound = new List<Youtube>();

      TmdbMovieTrailers trailers = api.GetMovieTrailers(selectedMovieId, language); // trailers in local language
      if (trailers.youtube.Count > 0) trailersfound.AddRange(trailers.youtube);
      LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - '" + trailers.youtube.Count + "' trailers found in local language ('" + language + "')");

      if (language != "en")
      {
        trailers = api.GetMovieTrailers(selectedMovieId, "en"); // engish trailers
        if (trailers.youtube.Count > 0) trailersfound.AddRange(trailers.youtube);
        LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - '" + trailers.youtube.Count + "' trailers found in language 'en'");
      }

      if (trailersfound.Count == 0)
      {
        LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - no trailers found - returning");
        if (interactive) GUIUtils.ShowNotifyDialog(GUILocalizeStrings.Get(10798996)); // no trailers found !
      }
      else
      {
        LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - '" + trailersfound.Count + "' trailers found");
        var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
        if (dlg == null) return;

        Youtube selectedTrailer = null;
        string selectedTrailerUrl = "";
        string selectedQuality = "";

        if (interactive)
        {
          #region build menu with available trailers
          var choiceView = new List<Youtube>();
          dlg.Reset();
          dlg.SetHeading(GUILocalizeStrings.Get(10798993)); // Select trailer ...

          dlg.Add("<" + GUILocalizeStrings.Get(10798997) + ">"); // load all 
          choiceView.Add(new Youtube());

          foreach (Youtube trailer in trailersfound)
          {
            dlg.Add(trailer.name + " (" + trailer.size + ")");
            choiceView.Add(trailer);
          }

          //dlg.Add(GUILocalizeStrings.Get(10798711)); //search youtube trailer with onlinevideos
          //choiceView.Add("youtube");

          dlg.DoModal(GUIWindowManager.ActiveWindow);
          if (dlg.SelectedLabel == -1) return;
          if (dlg.SelectedLabel >  0)
          {
            selectedTrailer = choiceView[dlg.SelectedLabel];
            LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - selectedTrailer = '" + selectedTrailer.name + " (" + selectedTrailer.size + ")'");
          }
          #endregion
        }

        #region select trailer format and quality in OV player factory
        if (selectedTrailer != null)
        {
          Dictionary<string, string> availableTrailerFiles = MyFilmsPlugin.Utils.OVplayer.GetYoutubeDownloadUrls("http://www.youtube.com/watch?v=" + selectedTrailer.source);
          var choiceView = new List<string>();
          dlg.Reset();
          dlg.SetHeading(GUILocalizeStrings.Get(10798994)); // Select quality ...
          foreach (KeyValuePair<string, string> availableTrailerFile in availableTrailerFiles)
          {
            dlg.Add(availableTrailerFile.Key);
            choiceView.Add(availableTrailerFile.Value); // this is the download URL
          }
          dlg.DoModal(GUIWindowManager.ActiveWindow);
          if (dlg.SelectedLabel == -1) return;
          selectedTrailerUrl = choiceView[dlg.SelectedLabel];
          selectedQuality = dlg.SelectedLabelText;
        }
        #endregion

        #region download trailer

        string destinationDirectory;
        if (overridestoragepath != null)
        {
          string newpath = Path.Combine(overridestoragepath + @"MyFilms\", path.Substring(path.LastIndexOf("\\") + 1));
          newpath = Path.Combine(newpath, "Trailer");
          destinationDirectory = newpath;
        }
        else
        {
          destinationDirectory = Path.Combine(path, "Trailer");
        }

        if (selectedTrailerUrl.Length > 0 && selectedTrailer != null)
        {
          var trailer = new Trailer();
          trailer.MovieTitle = titlename;
          trailer.Trailername = selectedTrailer.name;
          trailer.OriginalUrl = "http://www.youtube.com/watch?v=" + selectedTrailer.source;
          trailer.SourceUrl = selectedTrailerUrl;
          trailer.Quality = selectedQuality;
          trailer.DestinationDirectory = destinationDirectory; // Path.Combine(Path.Combine(path, "Trailer"), (MediaPortal.Util.Utils.FilterFileName(titlename + " (trailer) " + selectedTrailer.name + " (" + dlg.SelectedLabelText.Replace(" ", "") + ")" + extension)));
          MyFilms.AddTrailerToDownloadQueue(trailer);
          LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - start loading single trailer '" + selectedTrailer.name + "' from URL: '" + selectedTrailerUrl + "'");
          if (interactive) GUIUtils.ShowNotifyDialog(GUILocalizeStrings.Get(1079703)); //  trailer addd to DL queue
        }
        else
        {
          for (int i = 0; i < trailersfound.Count; i++)
          {
            if (i < 2 || loadAllTrailers)
            {
              Dictionary<string, string> availableTrailerFiles = MyFilmsPlugin.Utils.OVplayer.GetYoutubeDownloadUrls("http://www.youtube.com/watch?v=" + trailersfound[i].source);
              string url = null;
              string quality = null;
              if (availableTrailerFiles != null && availableTrailerFiles.Count > 0)
              {
                //url = availableTrailerFiles.Last().Value;
                //quality = availableTrailerFiles.Last().Key;
                KeyValuePair<string, string> highestQualitySelection = MyFilmsPlugin.Utils.OVplayer.GetPreferredQualityOption(availableTrailerFiles, "FHD");
                url = highestQualitySelection.Value;
                quality = highestQualitySelection.Key;
                LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - selected trailer with quality = '" + quality ?? "" + "', url = '" + url ?? "" + "'");
              }
              else
              {
                LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - no download Url found - adding trailer without DL links for later processing from queue");
              }
              var trailer = new Trailer();
              trailer.MovieTitle = titlename;
              trailer.Trailername = trailersfound[i].name;
              trailer.OriginalUrl = "http://www.youtube.com/watch?v=" + trailersfound[i].source;
              trailer.SourceUrl = url;
              trailer.Quality = quality;
              trailer.DestinationDirectory = destinationDirectory;
              // filename: (MediaPortal.Util.Utils.FilterFileName(titlename + " (trailer) " + trailersfound[i].name + " (" + quality.Replace(" ", "") + ")" + extension))
              LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() - add trailer '#" + i + "'");
              MyFilms.AddTrailerToDownloadQueue(trailer);
            }
          }
        }
        #endregion
      }
      #endregion
    }
Example #11
0
    internal static void Load_Detailed_TMDB(GUIListItem item)
    {
      var stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start();
      string language = CultureInfo.CurrentCulture.Name.Substring(0, 2);
      LogMyFilms.Debug("GetImagesForTMDB - detected language = '" + language + "'");
      Tmdb api = new Tmdb(MyFilms.TmdbApiKey, language); // language is optional, default is "en"
      // TmdbConfiguration tmdbConf = api.GetConfiguration();
      string wstring = "";
      OnlineMovie movie = item.TVTag as OnlineMovie;

      if (movie == null)
      {
        LogMyFilms.Warn("Load_Detailed_TMDB() - Failed loading details ... now clearing properties ...");
        Init_Detailed_DB(false);
        return;
      }

      #region always clear person properties in film details ...
      clearGUIProperty("person.name.value");
      clearGUIProperty("person.dateofbirth.value");
      clearGUIProperty("person.placeofbirth.value");
      clearGUIProperty("person.biography.value");
      //clearGUIProperty("person.dateofdeath.value");
      //clearGUIProperty("person.placeofdeath.value");
      //clearGUIProperty("person.movies.value");
      //clearGUIProperty("person.lastupdate.value");
      #endregion

      movie.Movie = api.GetMovieInfo(movie.MovieSearchResult.id, language);
      if (string.IsNullOrEmpty(movie.Movie.overview))
        movie.Movie = api.GetMovieInfo(movie.MovieSearchResult.id, null);
      movie.MovieCast = api.GetMovieCast(movie.MovieSearchResult.id);

      setGUIProperty("user.mastertitle.value", movie.Movie.title);
      setGUIProperty("user.secondarytitle.value", movie.Movie.original_title);
      setGUIProperty("db.description.value", movie.Movie.overview);
      setGUIProperty("db.year.value", movie.Movie.release_date);
      setGUIProperty("db.length.value", movie.Movie.runtime.ToString());
      setGUIProperty("user.source.isonline", item.IsRemote ? "unavailable" : "available");
      
      //int trailers = 0;
      //try
      //{
      //  trailers = movie.Trailers.youtube.Count;
      //}
      //catch (Exception) {}
      //setGUIProperty("user.sourcetrailer.isonline", (trailers > 0) ? "available" : "unavailable");

      string trailerstatus = "unknown";
      switch (movie.MovieSearchResult.TrailerStatus)
      {
        case TmdbMovieSearchResult.TrailerState.Unknown:
          trailerstatus = "unknown";
          break;
        case TmdbMovieSearchResult.TrailerState.Local:
        case TmdbMovieSearchResult.TrailerState.LocalAndRemote:
          trailerstatus = "available";
          break;
        case TmdbMovieSearchResult.TrailerState.Remote:
          trailerstatus = "offline";
          break;
        case TmdbMovieSearchResult.TrailerState.None:
          trailerstatus = "unavailable";
          break;
      }
      setGUIProperty("user.sourcetrailer.isonline", trailerstatus);

      wstring = "";
      foreach (MovieGenre genre in movie.Movie.genres)
      {
        if (wstring.Length > 0) wstring += ", ";
        wstring += genre.name;
      }
      SetTmdbProperties("Category", wstring);

      wstring = "";
      foreach (ProductionCountry country in movie.Movie.production_countries)
      {
        if (wstring.Length > 0) wstring += ", ";
        wstring += country.name;
      }
      SetTmdbProperties("Country", wstring);

      wstring = "";
      foreach (Cast cast in movie.MovieCast.cast)
      {
        if (wstring.Length > 0) wstring += ", ";
        wstring += cast.name + " (" + cast.character + ")";
      }
      SetTmdbProperties("Actors", wstring);

      string producer = "";
      string director = "";
      string writer = "";
      foreach (Crew crew in movie.MovieCast.crew)
      {
        switch (crew.department)
        {
          case "Production":
            if (producer.Length > 0) producer += ", ";
            producer += crew.name + " (" + crew.job + ")";
            break;
          case "Directing":
            if (director.Length > 0) director += ", ";
            director += crew.name + " (" + crew.job + ")";
            break;
          case "Writing":
            if (writer.Length > 0) writer += ", ";
            writer += crew.name + " (" + crew.job + ")";
            break;
          case "Sound":
          case "Camera":
            break;
        }
      }
      SetTmdbProperties("Director", director);
      SetTmdbProperties("Producer", producer);
      SetTmdbProperties("Writer", writer);

      wstring = "";
      foreach (Cast cast in movie.MovieCast.cast)
      {
        if (wstring.Length > 0) wstring += ", ";
        wstring += cast.name + " (" + cast.character + ")";
      }
      SetTmdbProperties("Actors", wstring);

      SetTmdbProperties("Rating", Math.Round(movie.Movie.vote_average, 1).ToString("0.0"));

      stopwatch.Stop();
      LogMyFilms.Debug("Load_Detailed_TMDB() - load details finished (" + stopwatch.ElapsedMilliseconds + " ms).");
    }
Example #12
0
    internal static void LoadCollectionImages(DataRow[] r1, int index, bool interactive, GUIAnimation animation)
    {
      if (!File.Exists(GUIGraphicsContext.Skin + @"\MyFilmsDialogImageSelect.xml"))
      {
        if (interactive) GUIUtils.ShowNotifyDialog("Missing Skin File");
        return;
      }
      // var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
      var dlgMenuOrg = (GUIWindow)GUIWindowManager.GetWindow(2012);
      var dlg = new GUIDialogImageSelect();
      if (dlg == null) return;
      dlg.Init();
      GUIWindowManager.Replace(2009, dlg);

      //var dlgOk = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
      //var dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
      //var dlgPrgrs = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

      new Thread(delegate(object o)
      {
        try
        {
          SetProcessAnimationStatus(true, animation);
          #region select and load collection image
          string titlename = Helper.TitleWithoutGroupName(r1[index][MyFilms.conf.StrTitle1].ToString());
          string titlename2 = (Helper.FieldIsSet(MyFilms.conf.StrTitle2)) ? Helper.TitleWithoutGroupName(r1[index][MyFilms.conf.StrTitle2].ToString()) : "";
          string collectionname = Helper.TitleFirstGroupName(r1[index][MyFilms.conf.StrTitle1].ToString());
          string collectionSafeName = GrabUtil.CreateFilename(collectionname);

          string path;
          #region Retrieve original directory of mediafiles
          try
          {
            path = r1[index][MyFilms.conf.StrStorage].ToString();
            if (path.Contains(";")) path = path.Substring(0, path.IndexOf(";", StringComparison.Ordinal));
            //path = Path.GetDirectoryName(path);
            //if (path == null || !Directory.Exists(path))
            //{
            //  LogMyFilms.Warn("Directory of movie '" + titlename + "' doesn't exist anymore - check your DB");
            //  return;
            //}
            if (path.Contains("\\")) path = path.Substring(0, path.LastIndexOf("\\", StringComparison.Ordinal));

            // LogMyFilms.Debug("(SearchAndDownloadTrailerOnlineTMDB) get media directory name: '" + path + "'");
          }
          catch (Exception)
          {
            LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB() error with directory of movie '" + titlename + "' - check your DB");
            return;
          }
          #endregion

          string imdb = "";
          #region get imdb number for better search match
          if (!string.IsNullOrEmpty(r1[index]["IMDB_Id"].ToString()))
            imdb = r1[index]["IMDB_Id"].ToString();
          else if (!string.IsNullOrEmpty(r1[index]["URL"].ToString()))
          {
            string urLstring = r1[index]["URL"].ToString();
            var cutText = new Regex("" + @"tt\d{7}" + "");
            var m = cutText.Match(urLstring);
            if (m.Success) imdb = m.Value;
          }
          #endregion

          int year;

          LogMyFilms.Debug("LoadCollectionImages() - movietitle = '" + titlename + "', collectionname = '" + collectionSafeName + "', collectionSafeName = '" + collectionSafeName + "', interactive = '" + interactive + "'");

          string language = CultureInfo.CurrentCulture.Name.Substring(0, 2);
          var api = new Tmdb(MyFilms.TmdbApiKey, language); // language is optional, default is "en"
          TmdbConfiguration tmdbConf = api.GetConfiguration();
          foreach (string size in tmdbConf.images.poster_sizes) LogMyFilms.Debug("Available TMDB Poster Size: '" + size + "'");
          // foreach (string size in tmdbConf.images.backdrop_sizes) LogMyFilms.Debug("Available TMDB Backdrop Size: '" + size + "'");
          try
          {
            int selectedMovieId = 0;

            #region search matching TMDB movie id
            if (imdb.Contains("tt"))
            {
              TmdbMovie movie = api.GetMovieByIMDB(imdb);
              if (movie.id > 0)
              {
                selectedMovieId = movie.id;
              }
            }

            if (selectedMovieId == 0) // no movie found by tmdb search
            {
              TmdbMovieSearch moviesfound;
              if (int.TryParse(r1[index]["Year"].ToString(), out year))
              {
                moviesfound = api.SearchMovie(titlename, 1, "", null, year);
                if (moviesfound.results.Count == 0) moviesfound = api.SearchMovie(titlename, 1, null);
              }
              else
              {
                moviesfound = api.SearchMovie(r1[index][MyFilms.conf.StrTitle1].ToString(), 1, null);
                if (moviesfound.results.Count == 0 && titlename2.Length > 0)
                {
                  if (int.TryParse(r1[index]["Year"].ToString(), out year))
                  {
                    moviesfound = api.SearchMovie(titlename2, 1, "", null, year);
                    if (moviesfound.results.Count == 0) moviesfound = api.SearchMovie(titlename2, 1, null);
                  }
                }
              }
              SetProcessAnimationStatus(false, animation);

              if (moviesfound.results.Count == 1 && !interactive)
              {
                selectedMovieId = moviesfound.results[0].id;
              }
              else
              {
                LogMyFilms.Debug("LoadCollectionImages() - Movie Search Results: '" + moviesfound.total_results.ToString() + "' for movie '" + titlename + "'");
                if (!interactive) return;
                else
                {
                  if (moviesfound.results.Count == 0)
                  {
                    while (selectedMovieId == 0)
                    {
                      selectedMovieId = SearchTmdbMovie(titlename, titlename, titlename2, year, language, true);
                      if (selectedMovieId == -1) return; // cancel search
                    }
                  }
                  else
                  {
                    var choiceMovies = new List<TmdbMovie>();
                    if (dlg == null) return;
                    dlg.Reset();
                    dlg.SetHeading(GUILocalizeStrings.Get(10798992)); // Select movie ...

                    foreach (TmdbMovie movieResult in moviesfound.results)
                    {
                      dlg.Add(movieResult.title + " (" + movieResult.release_date + ")");
                      choiceMovies.Add(movieResult);
                    }
                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                    if (dlg.SelectedLabel == -1) return;
                    selectedMovieId = choiceMovies[dlg.SelectedLabel].id;
                  }
                }
              }

              // now load the artwork
            }
            #endregion

            if (selectedMovieId == 0)
            {
              LogMyFilms.Debug("SearchAndDownloadTrailerOnlineTMDB - no movie found - no trailers added to DL queue - returning");
              if (interactive) GUIUtils.ShowNotifyDialog(GUILocalizeStrings.Get(10798995)); // No matching movie found !
              return;
            }

            SetProcessAnimationStatus(true, animation);
            #region now load the details and collection images info
            TmdbMovie tmdbMovie = api.GetMovieInfo(selectedMovieId);
            TmdbCollection collection = api.GetCollectionInfo(tmdbMovie.belongs_to_collection.id);
            var collectionPosters = new List<CollectionPoster>();
            var backdrops = new List<CollectionBackdrop>();

            LogMyFilms.Debug("TMDB - Value found - movie   = '" + (tmdbMovie.title ?? "") + "'" + " (" + tmdbMovie.release_date + ")");
            LogMyFilms.Debug("TMDB - Value found - belongs to collection id = '" + collection.id.ToString() + "', name  = '" + (collection.name ?? "") + "'");

            TmdbCollectionImages collectionImages = api.GetCollectionImages(collection.id, language);
            LogMyFilms.Debug("TMDB - Collection Posters found for language = '" + language + "' : '" + collectionImages.posters.Count + "'");
            collectionPosters.AddRange(collectionImages.posters);
            backdrops.AddRange(collectionImages.backdrops);
            collectionImages = api.GetCollectionImages(collection.id, null);
            LogMyFilms.Debug("TMDB - Collection Posters found: '" + collectionImages.posters.Count + "'");
            collectionPosters.AddRange(collectionImages.posters);
            backdrops.AddRange(collectionImages.backdrops);

            collectionPosters.Distinct();
            backdrops.Distinct();

            //foreach (CollectionBackdrop backdrop in backdrops)
            //{
            //  string fanartUrl = tmdbConf.images.base_url + "original" + backdrop.file_path;
            //  LogMyFilms.Debug("TMDB - Backdrop found = '" + fanartUrl + "'");
            //}
            #endregion

            if (collectionPosters.Count == 0)
            {
              SetProcessAnimationStatus(false, animation);
              GUIUtils.ShowNotifyDialog(GUILocalizeStrings.Get(10798760), GUILocalizeStrings.Get(10798625)); // load group covers, no result found
              return;
            }

            #region load collection images into selection menu
            var choicePosters = new List<CollectionPoster>();
            if (dlg == null) return;
            dlg.Reset();
            dlg.SetHeading(GUILocalizeStrings.Get(10798760)); // Load collection cover (Tmdb)
            foreach (CollectionPoster poster in collectionPosters)
            {
              string posterUrlSmall = tmdbConf.images.base_url + "w154" + poster.file_path;
              string posterUrl = tmdbConf.images.base_url + "w500" + poster.file_path;
              LogMyFilms.Debug("TMDB - Collection Poster found = '" + posterUrl + "'");
              var item = new GUIListItem();
              item.Label = poster.width + " x " + poster.height;
              item.IconImage = posterUrlSmall;
              item.ThumbnailImage = posterUrl;
              dlg.Add(item);
              choicePosters.Add(poster);
            }
            #endregion
            SetProcessAnimationStatus(false, animation);

            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedLabel == -1) return;
            CollectionPoster selectedPoster = choicePosters[dlg.SelectedLabel];

            #region load collection cover images and fanart
            SetProcessAnimationStatus(true, animation);
            try
            {
              #region Poster

              string localThumb = MyFilms.conf.StrPicturePrefix.Length > 0
                             ? MyFilms.conf.StrPathImg + "\\" + MyFilms.conf.StrPicturePrefix + collectionSafeName + ".jpg"
                             : Path.Combine(MyFilms.conf.StrPathImg, collectionSafeName + ".jpg");
              string remoteThumb = tmdbConf.images.base_url + "w500" + selectedPoster.file_path;
              LogMyFilms.Debug("GetImagesTMDB() - localThumb = '" + localThumb + "'");
              LogMyFilms.Debug("GetImagesTMDB() - remoteThumb = '" + remoteThumb + "'");

              if (!string.IsNullOrEmpty(remoteThumb) && !string.IsNullOrEmpty(localThumb))
              {
                if (File.Exists(localThumb)) try { File.Delete(localThumb); }
                  catch (Exception) { }
                Thread.Sleep(10);
                if (GrabUtil.DownloadImage(remoteThumb, localThumb))
                {
                  string coverThumbDir = MyFilmsSettings.GetPath(MyFilmsSettings.Path.ThumbsCache) + @"\MyFilms_Movies";
                  string strThumb = MediaPortal.Util.Utils.GetCoverArtName(coverThumbDir, collectionSafeName); // cached cover
                  if (!string.IsNullOrEmpty(strThumb) && strThumb.Contains("."))
                  {
                    string strThumbSmall = strThumb.Substring(0, strThumb.LastIndexOf(".", StringComparison.Ordinal)) + "_s" + Path.GetExtension(strThumb);  // cached cover for Icons - small resolution
                    if (!string.IsNullOrEmpty(localThumb) && localThumb != MyFilms.conf.DefaultCover)
                    {
                      Picture.CreateThumbnail(localThumb, strThumbSmall, 100, 150, 0, Thumbs.SpeedThumbsSmall);
                      Picture.CreateThumbnail(localThumb, strThumb, MyFilms.cacheThumbWith, MyFilms.cacheThumbHeight, 0, Thumbs.SpeedThumbsLarge);
                      LogMyFilms.Debug("Creating thumbimage for collection: '" + collection + "'");
                    }
                  }
                  //// notify that image has been downloaded
                  //item.NotifyPropertyChanged("PosterImageFilename");
                  SetProcessAnimationStatus(false, animation);
                  if (interactive) GUIUtils.ShowNotifyDialog(GUILocalizeStrings.Get(1079846)); // Done !
                }
              }
              #endregion

              #region Fanart
              if (MyFilms.conf.StrFanart)
              {
                //string fanartUrl = tmdbConf.images.base_url + "original" + movie.MovieSearchResult.backdrop_path;
                //string filename;
                //string filename1 = GrabUtil.DownloadBacdropArt(MyFilms.conf.StrPathFanart, fanartUrl, item.Label, true, true, out filename);
                //// LogMyFilms.Debug("Fanart " + filename1.Substring(filename1.LastIndexOf("\\") + 1) + " downloaded for " + item.Label);

                ////movie.MovieImages = api.GetMovieImages(movie.MovieSearchResult.id, language);
                ////if (movie.MovieImages.posters.Count == 0)
                ////{
                ////  movie.MovieImages = api.GetMovieImages(movie.MovieSearchResult.id, null);
                ////  LogMyFilms.Debug("GetImagesTMDB() - no '" + language + "' posters found - used default and found '" + movie.MovieImages.posters.Count + "'");
                ////}
                ////int ii = 0;
                ////foreach (Backdrop fanart in movie.MovieImages.backdrops)
                ////{
                ////  if (ii == 0)
                ////  {
                ////    string fanartUrl = tmdbConf.images.base_url + "original" + fanart.file_path;
                ////    string filename;
                ////    string filename1 = GrabUtil.DownloadBacdropArt(MyFilms.conf.StrPathFanart, fanartUrl, item.Label, true, (i == 0), out filename);
                ////    LogMyFilms.Debug("Fanart " + filename1.Substring(filename1.LastIndexOf("\\") + 1) + " downloaded for " + item.Label);
                ////  }
                ////  ii++;
                ////}
              }
              #endregion

            }
            catch (Exception ex)
            {
              LogMyFilms.Debug("GetImagesForTmdbCollection() - Error: '" + ex.Message + "'");
              LogMyFilms.Debug("GetImagesForTmdbCollection() - Exception: '" + ex.StackTrace + "'");
              SetProcessAnimationStatus(false, animation);
            }
            #endregion
          #endregion
          }
          catch (Exception tex)
          {
            LogMyFilms.DebugException("CollectionArtwork() - error in TMDB grabbing movie '" + titlename + "': " + tex.Message, tex);
            SetProcessAnimationStatus(false, animation);
          }
        }
        catch (Exception ex)
        {
          LogMyFilms.DebugException("Thread 'LoadCollectionImages' - exception! - ", ex);
        }
        finally
        {
          GUIWindowManager.Replace(2009, dlgMenuOrg);
          SetProcessAnimationStatus(false, animation);
        }
        GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) =>
        {
          // after background thread has finished !
          return 0;
        }, 0, 0, null);
      }) { Name = "LoadCollectionImages", IsBackground = true }.Start();
    }
Example #13
0
    internal static bool UpdatePersonDetails(string personname, GUIListItem item, bool forceupdate, bool stopLoadingViewDetails)
    {
      if (!forceupdate && !Helper.PersonUpdateAllowed(MyFilms.conf.StrPathArtist, personname)) return false;

      string item1LabelOrg = (item != null) ? item.Label : "";
      string item3LabelOrg = (item != null) ? item.Label3 : "";
      string filename = MyFilms.conf.StrPathArtist + "\\" + personname + ".jpg";  // string filename = Path.Combine(MyFilms.conf.StrPathArtist, personname); //File.Exists(MyFilms.conf.StrPathArtist + "\\" + personsname + ".jpg")))

      IMDBActor person = null;
      bool vdBexists = false;

      if (item != null) item.Label = item1LabelOrg + " " + GUILocalizeStrings.Get(10799205); // (updating...)

      #region get person info from VDB
      if (item != null) item.Label3 = "Loading details from VDB ...";
      var actorList = new ArrayList();
      VideoDatabase.GetActorByName(personname, actorList);
      LogMyFilms.Debug("VDB - found '" + actorList.Count + "' local results for '" + personname + "'");
      if (actorList.Count > 0 && actorList.Count < 5)
      {
        LogMyFilms.Debug("VDB first search result: '" + actorList[0] + "'");
        string[] strActor = actorList[0].ToString().Split(new char[] { '|' });
        // int actorID = (strActor[0].Length > 0 && strActor.Count() > 1) ? Convert.ToInt32(strActor[0]) : 0; // string actorname = strActor[1];
        int actorId;
        int.TryParse(strActor[0], out actorId);
        if (actorId > 0)
        {
          person = VideoDatabase.GetActorInfo(actorId);
        }
        if (person != null)
        {
          if (item != null) item.Label3 = "ID = " + actorId + ", URL = " + person.ThumbnailUrl;
          vdBexists = true;
        }
        else
        {
          if (item != null) item.Label3 = "ID = " + actorId;
        }
      }
      #endregion

      if (person != null && File.Exists(filename) && !forceupdate && !person.Biography.ToLower().StartsWith("unknown") && !(person.Biography.Length > 8))
      {
        LogMyFilms.Debug("Skip update for '" + personname + "' - VDB entry and image already present !");
        if (item != null)
        {
          item.MusicTag = person;
          item.Label = item1LabelOrg;
          item.Label3 = item3LabelOrg;
        }
        if (stopLoadingViewDetails && item != null) return false; // stop download if we have exited window
        return true; // nothing to do
      }

      // region update person detail infos or load new ones ...
      if (person == null || person.DateOfBirth.Length < 1 || person.DateOfBirth.ToLower().StartsWith("unknown") || !File.Exists(filename) || forceupdate)
      {
        if (person == null) person = new IMDBActor();

        #region IMDB internet search
        if (item != null) item.Label3 = "Searching IMDB ...";

        string grabberscript = MyFilmsSettings.GetPath(MyFilmsSettings.Path.GrabberScripts) + @"\IMDB-Person.xml";
        if (File.Exists(grabberscript))
        {
          ArrayList personUrls = FindActor(personname, grabberscript);
          LogMyFilms.Debug("IMDB - " + personUrls.Count + " person(s) found for '" + personname + "' with person grabber script '" + grabberscript + "'"); 
          if (personUrls.Count > 0)
          {
            var wurl = (Grabber_URLClass.IMDBUrl)personUrls[0];
            if (wurl.URL.Length != 0)
            {
              if (item != null) item.Label3 = "Loading IMDB details ...";
              GrabActorDetails(wurl.URL, grabberscript, out person);
              LogMyFilms.Debug("IMDB - Value found - name       = '" + (person.Name ?? "") + "'");
              LogMyFilms.Debug("IMDB - Value found - birthday   = '" + (person.DateOfBirth ?? "") + "'");
              LogMyFilms.Debug("IMDB - Value found - birthplace = '" + (person.PlaceOfBirth ?? "") + "'");
              LogMyFilms.Debug("IMDB - Value found - biography  = '" + (person.Biography.Substring(0, Math.Min(person.Biography.Length, 100)) ?? "") + "'");
              LogMyFilms.Debug("IMDB - Value found - thumb url  = '" + (person.ThumbnailUrl ?? "") + "'");
            }
          }
        }
        else
        {
          LogMyFilms.Debug("IMDB - Default person grabber script not found (" + grabberscript + ")");
        }
        
        //var imdb = new IMDB();
        //imdb.FindActor(personname);
        //LogMyFilms.Debug("IMDB - " + imdb.Count + " person(s) found for '" + personname + "' with IMDB API");
        //if (imdb.Count > 0)
        //{
        //  if (imdb[0].URL.Length != 0)
        //  {
        //    if (item != null) item.Label3 = "Loading IMDB details ...";
        //    //#if MP1X
        //    // _imdb.GetActorDetails(_imdb[0], out person);
        //    //#else
        //    // _imdb.GetActorDetails(_imdb[0], false, out person);
        //    //#endif
        //    GUIUtils.GetActorDetails(imdb, imdb[0], false, out person);
        //    LogMyFilms.Debug("IMDB - Value found - name       = '" + (person.Name ?? "") + "'");
        //    LogMyFilms.Debug("IMDB - Value found - birthday   = '" + (person.DateOfBirth ?? "") + "'");
        //    LogMyFilms.Debug("IMDB - Value found - birthplace = '" + (person.PlaceOfBirth ?? "") + "'");
        //    LogMyFilms.Debug("IMDB - Value found - biography  = '" + (person.Biography.Substring(0, Math.Min(person.Biography.Length, 100)) ?? "") + "'");
        //  }
        //}

        if (stopLoadingViewDetails && item != null && !forceupdate) return false; // stop download if we have exited window

        #endregion

        #region TMDB V3 API description
        // Search
        //TmdbMovieSearch SearchMovie(string query, int page)
        //TmdbPersonSearch SearchPerson(string query, int page)
        //TmdbCompanySearch SearchCompany(string query, int page);             

        // Person Info
        //TmdbPerson GetPersonInfo(int PersonID)
        //TmdbPersonCredits GetPersonCredits(int PersonID)
        //TmdbPersonImages GetPersonImages(int PersonID)
        //Movie Info
        //TmdbMovie GetMovieInfo(int MovieID)
        //TmdbMovie GetMovieByIMDB(string IMDB_ID)
        //TmdbMovieAlternateTitles GetMovieAlternateTitles(int MovieID, string Country)
        //TmdbMovieCast GetMovieCast(int MovieID)
        //TmdbMovieImages GetMovieImages(int MovieID)
        //TmdbMovieKeywords GetMovieKeywords(int MovieID)
        //TmdbMovieReleases GetMovieReleases(int MovieID)
        //TmdbMovieTrailers GetMovieTrailers(int MovieID)
        //TmdbSimilarMovies GetSimilarMovies(int MovieID, int page)
        //TmdbTranslations GetMovieTranslations(int MovieID)

        // Social Movie Info
        //TmdbNowPlaying GetNowPlayingMovies(int page)
        //TmdbPopular GetPopularMovies(int page)
        //TmdbTopRated GetTopRatedMovies(int page)
        //TmdbUpcoming GetUpcomingMovies(int page)
        #endregion

        #region TMDB v3 infos ...
        try
        {
          if (item != null) item.Label3 = "Searching TMDB ...";

          // grabber.TheMoviedb tmdbapi = new grabber.TheMoviedb(); // we're using new v3 api here
          var api = new Tmdb(MyFilms.TmdbApiKey, CultureInfo.CurrentCulture.Name.Substring(0, 2)); // language is optional, default is "en"
          TmdbConfiguration tmdbConf = api.GetConfiguration();
          TmdbPersonSearch tmdbPerson = api.SearchPerson(personname, 1);
          List<PersonResult> persons = tmdbPerson.results;
          LogMyFilms.Debug("TMDB - " + persons.Count + " person(s) found for '" + personname + "' with TMDB API");
          if (persons != null && persons.Count > 0)
          {
            PersonResult pinfo = persons[0];
            if (item != null) item.Label3 = "Loading TMDB details ...";
            TmdbPerson singleperson = api.GetPersonInfo(pinfo.id);
            
            // TMDB.TmdbPersonImages images = api.GetPersonImages(pinfo.id);
            // TMDB.TmdbPersonCredits personFilmList = api.GetPersonCredits(pinfo.id);

            LogMyFilms.Debug("TMDB - Value found - birthday   = '" + (singleperson.birthday ?? "") + "'");
            LogMyFilms.Debug("TMDB - Value found - birthplace = '" + (singleperson.place_of_birth ?? "") + "'");
            LogMyFilms.Debug("TMDB - Value found - biography  = '" + ((!string.IsNullOrEmpty(singleperson.biography)) ? singleperson.biography.Substring(0, Math.Min(singleperson.biography.Length, 100)) : "") + "'");

            SetActorDetailsFromTmdb(singleperson, tmdbConf, ref person);

            if (!string.IsNullOrEmpty(singleperson.profile_path) && !File.Exists(filename))
            {
              if (item != null) item.Label3 = "Loading TMDB image ...";
              string filename1person = GrabUtil.DownloadPersonArtwork(MyFilms.conf.StrPathArtist, person.ThumbnailUrl, personname, false, true, out filename);
              LogMyFilms.Debug("Person Image (TMDB) '" + filename1person.Substring(filename1person.LastIndexOf("\\") + 1) + "' downloaded for '" + personname + "', path = '" + filename1person + "', filename = '" + filename + "'");
              if (item != null)
              {
                item.IconImage = filename;
                item.IconImageBig = filename;
                item.ThumbnailImage = filename;
                item.Label3 = "TMDB ID = " + singleperson.id + ", URL = " + singleperson.profile_path;
              }
            }
          }
        }
        catch (Exception tex)
        {
          LogMyFilms.DebugException("UpdatePersonDetails() - error in TMDB grabbing person '" + personname + "': " + tex.Message, tex);
        }
        if (stopLoadingViewDetails && item != null && !forceupdate) return false; // stop download if we have exited window
        #endregion

        #region Add actor to database to get infos in person facades later...
        if (item != null) item.Label3 = "Save detail info to VDB ...";
        try
        {
          //#if MP1X
          //                  int actorId = VideoDatabase.AddActor(person.Name);
          //#else
          //                  int actorId = VideoDatabase.AddActor(null, person.Name);
          //#endif
          int actorId = GUIUtils.AddActor(null, person.Name);
          if (actorId > 0)
          {
            if (!string.IsNullOrEmpty(person.Biography)) // clean up before saving ...
            {
              if (person.Biography.Contains("Wikipedia"))
              {
                string startwiki = "From Wikipedia, the free encyclopedia";
                string endwiki = "Description above from the Wikipedia article";
                person.Biography = person.Biography.TrimStart('?', '.', ' ', '\r', '\n').TrimStart();
                if (person.Biography.Contains(startwiki)) person.Biography = person.Biography.Substring(person.Biography.IndexOf(startwiki) + startwiki.Length + 1);
                if (person.Biography.Contains(endwiki)) person.Biography = person.Biography.Substring(0, person.Biography.LastIndexOf(endwiki));
                person.Biography = person.Biography.Trim().TrimStart('?', '.', ' ', '\r', '\n').TrimEnd('\r', '\n', ' ').Trim(new char[] { ' ', '\r', '\n' }).Trim();
                LogMyFilms.Debug("Biography - cleaned value = '" + person.Biography + "'");
              }
            }
            VideoDatabase.SetActorInfo(actorId, person);
            //VideoDatabase.AddActorToMovie(_movieDetails.ID, actorId);
            if (item != null) item.Label3 = (vdBexists) ? ("Updated ID" + actorId + ", URL = " + person.ThumbnailUrl) : ("Added ID" + actorId + ", URL = " + person.ThumbnailUrl);
          }
        }
        catch (Exception ex)
        {
          if (item != null) item.Label = item1LabelOrg;
          LogMyFilms.Debug("Error adding person to VDB: " + ex.Message, ex.StackTrace);
        }
        if (stopLoadingViewDetails && item != null && !forceupdate) return false; // stop download if we have exited window
        #endregion

        #region load missing images ...
        if ((person.ThumbnailUrl.Contains("http:") && !File.Exists(filename)) || forceupdate)
        {
          #region MP Thumb download deactivated, as downloading not yet working !!!
          //if (person.ThumbnailUrl != string.Empty) // to update MP person thumb dir
          //{
          //  string largeCoverArt = Utils.GetLargeCoverArtName(Thumbs.MovieActors, person.Name);
          //  string coverArt = Utils.GetCoverArtName(Thumbs.MovieActors, person.Name);
          //  Utils.FileDelete(largeCoverArt);
          //  Utils.FileDelete(coverArt);
          //  IMDBFetcher.DownloadCoverArt(Thumbs.MovieActors, person.ThumbnailUrl, person.Name);
          //  //DownloadCoverArt(Thumbs.MovieActors, imdbActor.ThumbnailUrl, imdbActor.Name);
          //}
          #endregion
          if (item != null) item.Label3 = "Loading image ...";
          LogMyFilms.Debug(" Image found for person '" + personname + "', URL = '" + person.ThumbnailUrl + "'");
          string filename1person = GrabUtil.DownloadPersonArtwork(MyFilms.conf.StrPathArtist, person.ThumbnailUrl, personname, false, true, out filename);
          LogMyFilms.Debug("Person Image '" + filename1person.Substring(filename1person.LastIndexOf("\\") + 1) + "' downloaded for '" + personname + "', path = '" + filename1person + "', filename = '" + filename + "'");

          string strThumbDirectory = MyFilmsSettings.GetPath(MyFilmsSettings.Path.ThumbsCache) + @"\MyFilms_Persons\";
          string strThumb = strThumbDirectory + personname + ".png";
          string strThumbSmall = strThumbDirectory + personname + "_s.png";
          if (File.Exists(filename) && (forceupdate || !File.Exists(strThumbSmall)))
          {
            if (item != null) item.Label3 = "Creating cache image ...";
            //Picture.CreateThumbnail(strThumbSource, strThumbDirectory + itemlabel + "_s.png", 100, 150, 0, Thumbs.SpeedThumbsSmall);
            MyFilms.CreateCacheThumb(filename, strThumbSmall, 100, 150, "small");
            //Picture.CreateThumbnail(strThumbSource, strThumb, cacheThumbWith, cacheThumbHeight, 0, Thumbs.SpeedThumbsLarge);
            MyFilms.CreateCacheThumb(filename, strThumb, MyFilms.cacheThumbWith, MyFilms.cacheThumbHeight, "large");
          }

          if (item != null)
          {
            if (File.Exists(strThumb)) // (re)check if thumbs exist...
            {
              item.IconImage = strThumbSmall;
              item.IconImageBig = strThumb;
              item.ThumbnailImage = strThumb;
            }
            else if (File.Exists(filename))
            {
              item.IconImage = filename;
              item.IconImageBig = filename;
              item.ThumbnailImage = filename;
            }
            else
            {
              {
                item.IconImage = MyFilms.conf.DefaultCoverArtist;
                item.IconImageBig = MyFilms.conf.DefaultCoverArtist;
                item.ThumbnailImage = MyFilms.conf.DefaultCoverArtist;
              }
            }

            item.Label3 = "URL = " + person.ThumbnailUrl;
            // item.NotifyPropertyChanged("ThumbnailImage");
          }
        }
        #endregion

        if (item != null)
        {
          item.MusicTag = person;
        }

        #region old stuff deactivated
        //string[] strActiveFacadeImages = SetViewThumbs(wStrSort, item.Label, strThumbDirectory, isperson, currentCustomView, defaultViewImage, reversenames);
        ////string texture = "[MyFilms:" + strActiveFacadeImages[0].GetHashCode() + "]";
        ////if (GUITextureManager.LoadFromMemory(ImageFast.FastFromFile(strActiveFacadeImages[0]), texture, 0, 0, 0) > 0)
        ////{
        ////  item.ThumbnailImage = texture;
        ////  item.IconImage = texture;
        ////  item.IconImageBig = texture;
        ////}

        //item.IconImage = strActiveFacadeImages[1];
        //item.IconImageBig = strActiveFacadeImages[0];
        //item.ThumbnailImage = strActiveFacadeImages[0];

        //// if selected force an update of thumbnail
        ////GUIListItem selectedItem = GUIControl.GetSelectedListItem(ID_MyFilms, 50);
        ////if (selectedItem == item) GUIWindowManager.SendThreadMessage(new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_SELECT, GUIWindowManager.ActiveWindow, 0, 50, selectedItem.ItemId, 0, null));
        #endregion
      }

      if (item != null) // reset to original values
      {
        item.Label = item1LabelOrg;
        item.Label3 = item3LabelOrg;
      }
      return true;
    }
 public TheMovieDbService()
 {
     _tmdbService = new Tmdb("b2f505a89784ca773dae669293fa024f", "en");
 }
Example #15
0
 public void Setup()
 {
     api = new Tmdb("e7ea08e0ed9aba51ea90d5ffe68fa672");
 }
Example #16
0
        private List<DbMovieInfo> GetMoviesByTitle(string title, int year, string director, string imdbid, string tmdbid, bool choose, string language)
        {
            LogMyFilms.Debug("GetMoviesByTitle - title = '" + title + "', year = '" + year + "', imdbid = '" + imdbid + "', tmdbid = '" + tmdbid + "', choose = '" + choose + "', language = '" + language + "'");

              //title = Grabber.GrabUtil.NormalizeTitle(title);

              //string apiSearchLanguage = ApiSearchMovie;
              //string apiGetMovieInfoLanguage = ApiGetMovieInfo;
              //if (language.Length == 2)
              //{
              //  apiSearchLanguage = ApiSearchMovie.Replace("/en/", "/" + language + "/");
              //  apiGetMovieInfoLanguage = ApiGetMovieInfo.Replace("/en/", "/" + language + "/");
              //}
              //else
              //{
              //  apiSearchLanguage = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead
              //  apiGetMovieInfoLanguage = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead
              //  language = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead
              //}

              if (language.Length != 2) language = CultureInfo.CurrentCulture.Name.Substring(0, 2); // use local language instead

              List<DbMovieInfo> results = new List<DbMovieInfo>();
              List<DbMovieInfo> resultsdet = new List<DbMovieInfo>();
              // XmlNodeList xml = null; // old API2.1 xml structure
              List<TmdbMovie> movies = new List<TmdbMovie>();

              //Tmdb api = new Tmdb(TmdbApiKey, CultureInfo.CurrentCulture.Name.Substring(0, 2)); // language is optional, default is "en"
              //TmdbConfiguration tmdbConf = api.GetConfiguration();
              //TmdbMovieSearch tmdbMovies = api.SearchMovie(searchname, 0, language, 2012);
              //TmdbPersonSearch tmdbPerson = api.SearchPerson(personname, 1);
              //List<MovieResult> persons = tmdbMovies.results;
              //if (persons != null && persons.Count > 0)
              //{
              //  PersonResult pinfo = persons[0];
              //  TmdbPerson singleperson = api.GetPersonInfo(pinfo.id);
              //  // TMDB.TmdbPersonImages images = api.GetPersonImages(pinfo.id);
              //  // TMDB.TmdbPersonCredits personFilmList = api.GetPersonCredits(pinfo.id);
              //}

              Tmdb api = new Tmdb(TmdbApiKey, language); // language is optional, default is "en"
              // TmdbConfiguration tmdbConf = api.GetConfiguration();

              try
              {
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Contains("tt"))
            {
              TmdbMovie movie = api.GetMovieByIMDB(imdbid);
              if (movie.id > 0)
              {
            results.Add(GetMovieInformation(api, movie, language));
            return results;
              }
            }

            TmdbMovieSearch moviesfound;
            if (year > 0)
            {
              moviesfound = api.SearchMovie(title, 1, "", null, year);
              if (moviesfound.results.Count == 0) moviesfound = api.SearchMovie(title, 1, language);
              movies.AddRange(moviesfound.results);
            }
            else
            {
              int ipage = 1;
              while (true)
              {
            moviesfound = api.SearchMovie(title, 1, null);
            movies.AddRange(moviesfound.results);
            ipage++;
            if (ipage > moviesfound.total_pages) break;
              }
              movies = movies.OrderBy(x => x.release_date).ToList(); // .AsEnumerable()
            }

            if (movies.Count == 1)
            {
              results.Add(GetMovieInformation(api, movies[0], language));
              return results;
            }
            else
            {
              foreach (TmdbMovie movieResult in movies)
              {
            DbMovieInfo movie = GetMovieInformation(api, movieResult, language);
            if (movie != null && GrabUtil.NormalizeTitle(movie.Name.ToLower()).Contains(GrabUtil.NormalizeTitle(title.ToLower())))
              if (year > 0 && movie.Year > 0 && !choose)
              {
                if ((year >= movie.Year - 2) && (year <= movie.Year + 2))
                  results.Add(movie);
              }
              else
                results.Add(movie);
              }
              return results;
            }

              }
              catch (Exception ex)
              {
            LogMyFilms.Debug(ex.StackTrace);
              }
              return resultsdet.Count > 0 ? resultsdet : results;
        }