public void TestNameMatches() { var name = string.Empty; int?year = null; MovieDbProvider.ParseName("My Movie (2013)", out name, out year); Assert.AreEqual("My Movie", name); Assert.AreEqual(2013, year); name = string.Empty; year = null; MovieDbProvider.ParseName("My Movie 2 (2013)", out name, out year); Assert.AreEqual("My Movie 2", name); Assert.AreEqual(2013, year); name = string.Empty; year = null; MovieDbProvider.ParseName("My Movie 2001 (2013)", out name, out year); Assert.AreEqual("My Movie 2001", name); Assert.AreEqual(2013, year); name = string.Empty; year = null; MovieDbProvider.ParseName("My Movie - 2 (2013)", out name, out year); Assert.AreEqual("My Movie - 2", name); Assert.AreEqual(2013, year); name = string.Empty; year = null; MovieDbProvider.ParseName("curse.of.chucky.2013.stv.unrated.multi.1080p.bluray.x264-rough", out name, out year); Assert.AreEqual("curse.of.chucky", name); Assert.AreEqual(2013, year); }
internal async Task <RootObject> FetchMainResult(string urlPattern, string id, int seasonNumber, int episodeNumber, string language, CancellationToken cancellationToken) { var url = string.Format(urlPattern, id, seasonNumber.ToString(CultureInfo.InvariantCulture), episodeNumber, MovieDbProvider.ApiKey); if (!string.IsNullOrEmpty(language)) { url += string.Format("&language={0}", language); } var includeImageLanguageParam = MovieDbProvider.GetImageLanguagesParam(language); // Get images in english and with no language url += "&include_image_language=" + includeImageLanguageParam; cancellationToken.ThrowIfCancellationRequested(); using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbProvider.AcceptHeader }).ConfigureAwait(false)) { return(_jsonSerializer.DeserializeFromStream <RootObject>(json)); } }
private void Compare(string str1, string str2) { var title1 = MovieDbProvider.GetComparableName(str1); var title2 = MovieDbProvider.GetComparableName(str2); Assert.AreEqual(title1, title2); }
private async Task <RootObject> FetchMainResult(string id, string language, CancellationToken cancellationToken) { var url = string.Format(GetCollectionInfo3, id, MovieDbProvider.ApiKey); if (!string.IsNullOrEmpty(language)) { url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language)); // Get images in english and with no language url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language); } cancellationToken.ThrowIfCancellationRequested(); RootObject mainResult = null; using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbSearch.AcceptHeader }).ConfigureAwait(false)) { using (var json = response.Content) { mainResult = await _json.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false); } } cancellationToken.ThrowIfCancellationRequested(); if (mainResult != null && string.IsNullOrEmpty(mainResult.name)) { if (!string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) { url = string.Format(GetCollectionInfo3, id, MovieDbSearch.ApiKey) + "&language=en"; if (!string.IsNullOrEmpty(language)) { // Get images in english and with no language url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language); } using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbSearch.AcceptHeader }).ConfigureAwait(false)) { using (var json = response.Content) { mainResult = await _json.DeserializeFromStreamAsync <RootObject>(json).ConfigureAwait(false); } } } } return(mainResult); }
internal async Task <RootObject> FetchMainResult(string id, string language, CancellationToken cancellationToken) { var url = string.Format(GetTvInfo3, id, MovieDbProvider.ApiKey); if (!string.IsNullOrEmpty(language)) { url += string.Format("&language={0}", MovieDbProvider.NormalizeLanguage(language)); // Get images in english and with no language url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language); } cancellationToken.ThrowIfCancellationRequested(); RootObject mainResult; using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbProvider.AcceptHeader }).ConfigureAwait(false)) { mainResult = _jsonSerializer.DeserializeFromStream <RootObject>(json); } cancellationToken.ThrowIfCancellationRequested(); // If the language preference isn't english, then have the overview fallback to english if it's blank if (mainResult != null && string.IsNullOrEmpty(mainResult.overview) && !string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) { _logger.Info("MovieDbSeriesProvider couldn't find meta for language " + language + ". Trying English..."); url = string.Format(GetTvInfo3, id, MovieDbProvider.ApiKey) + "&language=en"; if (!string.IsNullOrEmpty(language)) { // Get images in english and with no language url += "&include_image_language=" + MovieDbProvider.GetImageLanguagesParam(language); } using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbProvider.AcceptHeader }).ConfigureAwait(false)) { var englishResult = _jsonSerializer.DeserializeFromStream <RootObject>(json); mainResult.overview = englishResult.overview; } } return(mainResult); }
public void TestCorrectMovieTitleIsFetched() { string matchedName; string[] possibles; MovieDbProvider.AttemptFindId("City Of Men", "", out matchedName, out possibles); Assert.AreEqual("City Of Men".ToLower(), matchedName.ToLower()); }
public void TestThatTheYearIsRespected() { string matchedName; string[] possibles; var id = MovieDbProvider.AttemptFindId("Star Wars", "1922", out matchedName, out possibles); Assert.AreEqual(id, null); }
public void TestIgnoreBracketsForMovieMatch() { string name = "Rocky [The awesome movie]"; string match; string[] possibles; MovieDbProvider.FindId(name, null, out match, out possibles); Assert.IsNotNull(match); }
public void TestSpecificMovieMatch() { string name = "Flight of the Phoenix (2004)"; string match; string[] possibles; MovieDbProvider.FindId(name, null, out match, out possibles); Assert.IsNotNull(match); }
private IEnumerable <RemoteImageInfo> GetImages(MovieDbBoxSetProvider.RootObject obj, string language, string baseUrl) { var list = new List <RemoteImageInfo>(); var images = obj.images ?? new MovieDbBoxSetProvider.Images(); list.AddRange(GetPosters(images).Select(i => new RemoteImageInfo { Url = baseUrl + i.file_path, CommunityRating = i.vote_average, VoteCount = i.vote_count, Width = i.width, Height = i.height, Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language), ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score })); list.AddRange(GetBackdrops(images).Select(i => new RemoteImageInfo { Url = baseUrl + i.file_path, CommunityRating = i.vote_average, VoteCount = i.vote_count, Width = i.width, Height = i.height, ProviderName = Name, Type = ImageType.Backdrop, RatingType = RatingType.Score })); var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase); return(list.OrderByDescending(i => { if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase)) { return 3; } if (!isLanguageEn) { if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase)) { return 2; } } if (string.IsNullOrEmpty(i.Language)) { return isLanguageEn ? 3 : 2; } return 0; }) .ThenByDescending(i => i.CommunityRating ?? 0) .ThenByDescending(i => i.VoteCount ?? 0) .ToList()); }
public void TestSpecificMovieMatchFails() { string name = "Flight of the Phoenix"; string match; string[] possibles; var id = MovieDbProvider.FindId(name, 1977, out match, out possibles); Assert.IsNull(match); Assert.IsNull(id); }
public void TestFetching() { int count = 0; int matched = 0; List <string> nonmatches = new List <string>(); using (StreamReader sr = File.OpenText(@"..\..\..\TestMediaBrowser\movies.txt")) { string line = sr.ReadLine(); while (line != null) { string match; string name = Helper.RemoveCommentsFromName(Path.GetFileName(line)); string[] possibles; string id = MovieDbProvider.FindId(name, out match, out possibles); count++; if (match == null) { nonmatches.Add(name); Debug.WriteLine(name + " not matched"); if (possibles != null) { Debug.WriteLine("\t" + string.Join("\n\t", possibles)); } else { Debug.WriteLine("\tNo possible matches"); } } else { matched++; Debug.WriteLine(name + " matched with " + match); Debug.WriteLine(string.Format("http://api.themoviedb.org/2.0/Movie.getInfo?id={0}&api_key={1}", id, "f6bd687ffa63cd282b6ff2c6877f2669")); } line = sr.ReadLine(); } } Debug.WriteLine(string.Format("Fetching matched {0}/{1}", matched, count)); Debug.WriteLine("The following were not matched: "); Debug.WriteLine(string.Join("\n", nonmatches.ToArray())); }
public void TestSpecificMovieMatch() { string name = "Flight of the Phoenix (2004)"; string match; string[] possibles; MovieDbProvider.FindId(name, out match, out possibles); if (match == null) { Debug.WriteLine(name + " not matched"); if (possibles != null) { Debug.WriteLine("\t" + string.Join("\n\t", possibles)); } else { Debug.WriteLine("\tNo possible matches"); } } else { Debug.WriteLine(name + " matched with " + match); } }
public async Task <IEnumerable <RemoteImageInfo> > GetImages(IHasMetadata item, CancellationToken cancellationToken) { var episode = (Controller.Entities.TV.Episode)item; var series = episode.Series; var seriesId = series != null?series.GetProviderId(MetadataProviders.Tmdb) : null; var list = new List <RemoteImageInfo>(); if (string.IsNullOrEmpty(seriesId)) { return(list); } var seasonNumber = episode.ParentIndexNumber; var episodeNumber = episode.IndexNumber; if (!seasonNumber.HasValue || !episodeNumber.HasValue) { return(list); } var language = item.GetPreferredMetadataLanguage(); var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value, language, cancellationToken).ConfigureAwait(false); var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.secure_base_url + "original"; list.AddRange(GetPosters(response.images).Select(i => new RemoteImageInfo { Url = tmdbImageUrl + i.file_path, CommunityRating = i.vote_average, VoteCount = i.vote_count, Width = i.width, Height = i.height, Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language), ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score })); var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase); return(list.OrderByDescending(i => { if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase)) { return 3; } if (!isLanguageEn) { if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase)) { return 2; } } if (string.IsNullOrEmpty(i.Language)) { return isLanguageEn ? 3 : 2; } return 0; }) .ThenByDescending(i => i.CommunityRating ?? 0) .ThenByDescending(i => i.VoteCount ?? 0)); }
public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { var list = new List <RemoteImageInfo>(); var results = await FetchImages(item, null, _jsonSerializer, cancellationToken).ConfigureAwait(false); if (results == null) { return(list); } var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original"); var language = item.GetPreferredMetadataLanguage(); list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo { Url = tmdbImageUrl + i.file_path, CommunityRating = i.vote_average, VoteCount = i.vote_count, Width = i.width, Height = i.height, Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language), ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score })); list.AddRange(GetBackdrops(results).Select(i => new RemoteImageInfo { Url = tmdbImageUrl + i.file_path, CommunityRating = i.vote_average, VoteCount = i.vote_count, Width = i.width, Height = i.height, ProviderName = Name, Type = ImageType.Backdrop, RatingType = RatingType.Score })); var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase); return(list.OrderByDescending(i => { if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase)) { return 3; } if (!isLanguageEn) { if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase)) { return 2; } } if (string.IsNullOrEmpty(i.Language)) { return isLanguageEn ? 3 : 2; } return 0; }) .ThenByDescending(i => i.CommunityRating ?? 0) .ThenByDescending(i => i.VoteCount ?? 0)); }
public MoviesController(MovieDbProvider movieDbProvider, TmdbRequestUtility tmdbRequestUtility) { this.movieDbProvider = movieDbProvider; this.tmdbRequestUtility = tmdbRequestUtility; }