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; }
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; }
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(); }
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 }
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; }