private void GetMovieDBInfo(string searchMedia, string selectedLang, string fallbackLang, string selectedCertCountry, string fallbackCertCountry) { InitLists(); SearchContainer <SearchMovie> movieList = _tmDbClient.SearchMovie(searchMedia, selectedLang); if (movieList == null || movieList.TotalResults <= 0) { movieList = _tmDbClient.SearchMovie(searchMedia, fallbackLang); } if (movieList == null || movieList.TotalResults <= 0) { return; } SearchMovie resultMovie = new SearchMovie(); if (movieList.TotalResults > 1) { DBMultipleSelection selectWindow = new DBMultipleSelection { Owner = this, MovieDBSearchResults = movieList }; if (selectWindow.ShowDialog() == true) { resultMovie = selectWindow.MovieDBSelectionResult; } } else { resultMovie = movieList.Results.First(); } if (resultMovie.Id == 0) { return; } Movie searchResult = _tmDbClient.GetMovie(resultMovie.Id, selectedLang) ?? _tmDbClient.GetMovie(resultMovie.Id, fallbackLang); if (searchResult == null) { return; } ImagesWithId imageList = _tmDbClient.GetMovieImages(resultMovie.Id); Casts movieCasts = _tmDbClient.GetMovieCasts(resultMovie.Id); KeywordsContainer movieKeywords = _tmDbClient.GetMovieKeywords(resultMovie.Id); Trailers movieTrailers = _tmDbClient.GetMovieTrailers(resultMovie.Id); Releases movieReleases = _tmDbClient.GetMovieReleases(resultMovie.Id); MovieTitle.Text = searchResult.Title; MovieOriginalTitle.Text = searchResult.OriginalTitle; MovieGenre.Text = searchResult.Genres != null ? string.Join(" / ", searchResult.Genres.ConvertAll(input => input.Name)) : string.Empty; MovieRuntime.Text = searchResult.Runtime.ToString("g"); if (AppSettings.MovieDBRatingSource == 0) { MovieRating.Text = searchResult.VoteAverage.ToString("g"); MovieVotes.Text = searchResult.VoteCount.ToString("g"); } else { ImdbClient imdb = new ImdbClient(); ImdbMovieData movieData = imdb.GetMovieById(searchResult.ImdbId); MovieRating.Text = movieData.Rating.ToString("g"); MovieVotes.Text = movieData.RatingCount.ToString("g"); } MovieYear.Text = searchResult.ReleaseDate.Year.ToString("g"); MovieTagline.Text = searchResult.Tagline; MoviePlot.Text = searchResult.Overview; if (movieKeywords != null && movieKeywords.Keywords != null) { MovieKeywords.Text = string.Join(", ", movieKeywords.Keywords.ConvertAll(input => input.Name)); } else { MovieKeywords.Text = string.Empty; } MovieImdbId.Text = searchResult.ImdbId; MovieCountry.Text = searchResult.ProductionCountries != null ? string.Join(" / ", searchResult.ProductionCountries.ConvertAll(input => input.Name)) : string.Empty; if (movieCasts != null && movieCasts.Crew != null) { MovieDirector.Text = string.Join(" / ", movieCasts.Crew.Where(crew => crew.Job == "Director") .ToList() .ConvertAll(input => input.Name)); MovieWriters.Text = string.Join(" / ", movieCasts.Crew.Where( crew => crew.Job == "Writer" || crew.Job == "Screenplay") .ToList() .ConvertAll(input => input.Name)); } else { MovieDirector.Text = string.Empty; MovieWriters.Text = string.Empty; } MovieStudio.Text = searchResult.ProductionCompanies != null ? string.Join(" / ", searchResult.ProductionCompanies.ConvertAll(input => input.Name)) : string.Empty; MovieSetName.Text = searchResult.BelongsToCollection != null ? string.Join(" / ", searchResult.BelongsToCollection.ConvertAll(input => input.Name)) : string.Empty; if (movieTrailers != null && movieTrailers.Youtube != null && movieTrailers.Youtube.Count > 0) { MovieTrailer.Text = "plugin://plugin.video.youtube/?action=play_video&videoid=" + movieTrailers.Youtube.First().Source; } else { MovieTrailer.Text = string.Empty; } Country selCountry = movieReleases.Countries.SingleOrDefault(country => country.Iso_3166_1.ToLowerInvariant() == selectedCertCountry); string certPrefix = AppSettings.MovieDBPreferredCertPrefix; if (selCountry == null) { selCountry = movieReleases.Countries.SingleOrDefault( country => country.Iso_3166_1.ToLowerInvariant() == fallbackCertCountry); certPrefix = AppSettings.MovieDBFallbackCertPrefix; } if (selCountry == null) { selCountry = movieReleases.Countries.First(); certPrefix = string.Empty; } MovieMPAARating.Text = certPrefix + selCountry.Certification; // loading image sizes string posterOriginal = _tmDbClient.Config.Images.PosterSizes.Last(); string posterPreview = _tmDbClient.Config.Images.PosterSizes.Count >= 2 ? _tmDbClient.Config.Images.PosterSizes[_tmDbClient.Config.Images.PosterSizes.Count - 2] : _tmDbClient.Config.Images.PosterSizes.Last(); string backdropOriginal = _tmDbClient.Config.Images.BackdropSizes.Last(); string backdropPreview = _tmDbClient.Config.Images.BackdropSizes.Count >= 3 ? _tmDbClient.Config.Images.BackdropSizes[ _tmDbClient.Config.Images.BackdropSizes.Count - 3] : _tmDbClient.Config.Images.BackdropSizes.Last(); // remove duplicate entries imageList.Backdrops.RemoveAt(imageList.Backdrops.FindIndex(data => data.FilePath == searchResult.BackdropPath)); imageList.Posters.RemoveAt(imageList.Posters.FindIndex(data => data.FilePath == searchResult.PosterPath)); // create image lists _postersList.Add(new MovieDBPosterImage { Title = "Default", UrlOriginal = _tmDbClient.GetImageUrl(posterOriginal, searchResult.PosterPath).AbsoluteUri, UrlPreview = _tmDbClient.GetImageUrl(posterPreview, searchResult.PosterPath).AbsoluteUri }); _backdropsList.Add(new MovieDBImageInfo { Title = "Default", UrlOriginal = _tmDbClient.GetImageUrl(backdropOriginal, searchResult.BackdropPath).AbsoluteUri, UrlPreview = _tmDbClient.GetImageUrl(backdropPreview, searchResult.BackdropPath).AbsoluteUri }); int cnt = 1; foreach (ImageData poster in imageList.Posters) { _postersList.Add(new MovieDBPosterImage { Title = "Online image " + cnt, UrlOriginal = _tmDbClient.GetImageUrl(posterOriginal, poster.FilePath).AbsoluteUri, UrlPreview = _tmDbClient.GetImageUrl(posterPreview, poster.FilePath).AbsoluteUri }); cnt++; } MoviePosterList.ItemsSource = _postersList; MoviePosterList.SelectedIndex = 0; cnt = 1; foreach (ImageData backdrop in imageList.Backdrops) { _backdropsList.Add(new MovieDBImageInfo { Title = "Online image " + cnt, UrlOriginal = _tmDbClient.GetImageUrl(backdropOriginal, backdrop.FilePath).AbsoluteUri, UrlPreview = _tmDbClient.GetImageUrl(backdropPreview, backdrop.FilePath).AbsoluteUri }); cnt++; } MovieBackdropList.ItemsSource = _backdropsList; MovieBackdropList.SelectedIndex = 0; foreach (Cast cast in movieCasts.Cast) { _castList.Casts.Add(new MovieDBCast { Name = cast.Name, Role = cast.Character, Thumbnail = _tmDbClient.GetImageUrl("original", cast.ProfilePath).AbsoluteUri }); } MovieCastListView.ItemsSource = _castList.Casts; ResultTabControl.SelectedIndex = 1; }
private void GetTvDBInfo(string searchMedia, string selectedLang, string fallbackLang) { const string tvDBFanartPath = "http://thetvdb.com/banners/"; InitLists(); string regexSearch = AppSettings.TvDBParseString; regexSearch = regexSearch.Replace("%show%", @"(?<show>[\w\s]*)") .Replace("%season%", @"(?<season>[\d]*)") .Replace("%episode%", @"(?<episode>[\d]*)") .Replace("%episode_name%", @"(?<episodename>[\w\s]*)"); Regex searchObj = new Regex(regexSearch, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.ExplicitCapture); Match matchResult = searchObj.Match(searchMedia); // check first if we can use the search string if (!matchResult.Success) { regexSearch = regexSearch.Replace(@"(?<episodename>[\w\s]*)", "").Trim().TrimEnd(new [] { '-' }).Trim(); searchObj = new Regex(regexSearch, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.ExplicitCapture); matchResult = searchObj.Match(searchMedia); if (!matchResult.Success) { return; } } TvdbLanguage dbLang = _tvDbclient.Languages.Single(language => language.Abbriviation == selectedLang) ?? _tvDbclient.Languages.Single(language => language.Abbriviation == fallbackLang); List <TvdbSearchResult> searchResults = _tvDbclient.SearchSeries(matchResult.Groups["show"].Value, dbLang); if (searchResults == null) { return; } TvdbSearchResult resultShow = new TvdbSearchResult(); if (searchResults.Count > 1) { DBMultipleSelection selectWindow = new DBMultipleSelection { Owner = this, TvdbSearchResults = searchResults }; if (selectWindow.ShowDialog() == true) { resultShow = selectWindow.TvdbSelectionResult; } } else { resultShow = searchResults.Count > 0 ? searchResults.First() : null; } if (resultShow == null || resultShow.Id == 0) { return; } TvdbSeries series = _tvDbclient.GetSeries(resultShow.Id, dbLang, true, true, true, true); TvShowTitle.Text = series.SeriesName; TvShowGenre.Text = string.Join(" / ", series.Genre); TvShowRating.Text = series.Rating.ToString("g", AppSettings.CInfo); TvShowRuntime.Text = series.Runtime.ToString("g", AppSettings.CInfo); TvShowFirstAired.Text = series.FirstAired.ToString("yyyy-MM-dd"); TvShowPlot.Text = series.Overview; TvShowMpaaRating.Text = series.ContentRating; TvShowImdbId.Text = series.ImdbId; TvShowNetwork.Text = series.Network; foreach (TvdbEpisode episode in series.Episodes) { DBTvShowSeason season; try { season = _seasonList.First(showSeason => showSeason.SeasonNumber == episode.SeasonNumber); } catch (InvalidOperationException) { season = new DBTvShowSeason { SeasonNumber = episode.SeasonNumber, Title = episode.IsSpecial ? "Special" : "Season " + episode.SeasonNumber }; _seasonList.Add(season); } season.Episodes.Add(new DBTvShowEpisode { Directors = episode.Directors, Writers = episode.Writer, SeasonNumber = episode.SeasonNumber, Runtime = (int)series.Runtime, Rating = episode.Rating, Plot = episode.Overview, IsSpecial = episode.IsSpecial, ImdbId = episode.ImdbId, GuestStars = episode.GuestStars, FirstAired = episode.FirstAired, EpisodeTitle = episode.EpisodeName, EpisodeNumber = episode.EpisodeNumber, DvdEpisodeNumber = episode.DvdEpisodeNumber, CombinedEpisodeNumber = episode.CombinedEpisodeNumber, AbsoluteEpisodeNumber = episode.AbsoluteNumber, EpisodeImageUrl = tvDBFanartPath + episode.BannerPath, }); } TvShowSeason.ItemsSource = _seasonList; int tempInt; int.TryParse(matchResult.Groups["season"].Value, NumberStyles.Integer, AppSettings.CInfo, out tempInt); TvShowSeason.SelectedIndex = _seasonList.ToList().FindIndex(season => season.SeasonNumber == tempInt); int.TryParse(matchResult.Groups["episode"].Value, NumberStyles.Integer, AppSettings.CInfo, out tempInt); TvShowEpisodeNumber.SelectedIndex = ((List <DBTvShowEpisode>)TvShowEpisodeNumber.Items.SourceCollection).FindIndex( episode => episode.EpisodeNumber == tempInt); int imageCounter = 1; foreach (TvdbSeriesBanner banner in series.SeriesBanners) { _bannerList.Add(new MovieDBBannerImage { UrlOriginal = tvDBFanartPath + banner.BannerPath, UrlPreview = tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath) ? banner.ThumbPath : "_cache/" + banner.BannerPath), Title = "Online image " + imageCounter }); imageCounter++; } foreach (TvdbSeasonBanner banner in series.SeasonBanners) { _seasonBannerList.Add(new MovieDBSeasonBannerImage { UrlOriginal = tvDBFanartPath + banner.BannerPath, UrlPreview = tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath) ? banner.ThumbPath : "_cache/" + banner.BannerPath), Title = "Online image " + imageCounter, Season = banner.Season }); imageCounter++; } _bannerList.ToList().ForEach(image => _previewBannerList.Add(image)); _seasonBannerList.ToList().ForEach(image => _previewBannerList.Add(image)); imageCounter = 1; foreach (TvdbFanartBanner banner in series.FanartBanners) { _backdropsList.Add(new MovieDBImageInfo { Title = "Online image " + imageCounter, UrlOriginal = tvDBFanartPath + banner.BannerPath, UrlPreview = tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath) ? banner.ThumbPath : "_cache/" + banner.BannerPath) }); imageCounter++; } imageCounter = 1; foreach (TvdbPosterBanner banner in series.PosterBanners) { _postersList.Add(new MovieDBPosterImage { Title = "Online image " + imageCounter, UrlOriginal = tvDBFanartPath + banner.BannerPath, UrlPreview = tvDBFanartPath + (!string.IsNullOrEmpty(banner.ThumbPath) ? banner.ThumbPath : "_cache/" + banner.BannerPath) }); imageCounter++; } TvShowBannerList.ItemsSource = _previewBannerList; TvShowBannerList.SelectedValue = tvDBFanartPath + "_cache/" + series.BannerPath; TvShowFanartList.ItemsSource = _backdropsList; TvShowFanartList.SelectedValue = tvDBFanartPath + "_cache/" + series.FanartPath; TvShowPosterList.ItemsSource = _postersList; TvShowPosterList.SelectedValue = tvDBFanartPath + "_cache/" + series.PosterPath; foreach (TvdbActor actor in series.TvdbActors) { _castList.Casts.Add(new MovieDBCast { Name = actor.Name, Role = actor.Role, Thumbnail = actor.ActorImage != null && !string.IsNullOrEmpty(actor.ActorImage.BannerPath) ? tvDBFanartPath + actor.ActorImage.BannerPath : string.Empty }); } TvShowCastList.ItemsSource = _castList.Casts; ResultTabControl.SelectedIndex = 2; }