private string GetLanguageTitle(Movie movie, string isoCodes) { if (isoCodes.IsNotNullOrWhiteSpace()) { foreach (var isoCode in isoCodes.Split('|')) { var language = IsoLanguages.Find(isoCode.ToLower())?.Language; if (language == null) { continue; } var titles = movie.Translations.Where(t => t.Language == language).ToList(); if (!movie.Translations.Any()) { titles = _movieTranslationService.GetAllTranslationsForMovie(movie.Id).Where(t => t.Language == language).ToList(); } return(titles.FirstOrDefault()?.Title ?? movie.Title); } } return(movie.Title); }
private static MovieTranslation MapTranslation(TranslationResource arg) { var newAlternativeTitle = new MovieTranslation { Title = arg.Title, Overview = arg.Overview, CleanTitle = arg.Title.CleanMovieTitle(), Language = IsoLanguages.Find(arg.Language.ToLower())?.Language }; return(newAlternativeTitle); }
private static AlternativeTitle MapAlternativeTitle(AlternativeTitleResource arg) { var newAlternativeTitle = new AlternativeTitle { Title = arg.Title, SourceType = SourceType.TMDB, CleanTitle = arg.Title.CleanMovieTitle(), Language = IsoLanguages.Find(arg.Language.ToLower())?.Language ?? Language.English }; return(newAlternativeTitle); }
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem) { if (localMovie.MediaInfo == null) { return(null); } var audioLanguages = localMovie.MediaInfo.AudioLanguages.Distinct().ToList(); var languages = new List <Languages.Language>(); foreach (var audioLanguage in audioLanguages) { var language = IsoLanguages.Find(audioLanguage)?.Language; languages.AddIfNotNull(language); } if (languages.Count == 0) { return(null); } return(new AugmentLanguageResult(languages, Confidence.MediaInfo)); }
public Movie GetMovieInfo(int TmdbId, Profile profile = null, bool hasPreDBEntry = false) { var langCode = profile != null?IsoLanguages.Get(profile.Language)?.TwoLetterCode ?? "en" : "en"; var request = _movieBuilder.Create() .SetSegment("route", "movie") .SetSegment("id", TmdbId.ToString()) .SetSegment("secondaryRoute", "") .AddQueryParam("append_to_response", "alternative_titles,release_dates,videos") .AddQueryParam("language", langCode.ToUpper()) // .AddQueryParam("country", "US") .Build(); request.AllowAutoRedirect = true; request.SuppressHttpError = true; var response = _httpClient.Get <MovieResourceRoot>(request); if (response.StatusCode == HttpStatusCode.NotFound) { throw new MovieNotFoundException("Movie not found."); } if (response.StatusCode != HttpStatusCode.OK) { throw new HttpException(request, response); } if (response.Headers.ContentType != HttpAccept.JsonCharset.Value) { throw new HttpException(request, response); } // The dude abides, so should us, Lets be nice to TMDb // var allowed = int.Parse(response.Headers.GetValues("X-RateLimit-Limit").First()); // get allowed // var reset = long.Parse(response.Headers.GetValues("X-RateLimit-Reset").First()); // get time when it resets if (response.Headers.ContainsKey("X-RateLimit-Remaining")) { var remaining = int.Parse(response.Headers.GetValues("X-RateLimit-Remaining").First()); if (remaining <= 5) { _logger.Trace("Waiting 5 seconds to get information for the next 35 movies"); Thread.Sleep(5000); } } var resource = response.Resource; if (resource.status_message != null) { if (resource.status_code == 34) { _logger.Warn("Movie with TmdbId {0} could not be found. This is probably the case when the movie was deleted from TMDB.", TmdbId); return(null); } _logger.Warn(resource.status_message); return(null); } var movie = new Movie(); var altTitles = new List <AlternativeTitle>(); if (langCode != "en") { var iso = IsoLanguages.Find(resource.original_language); if (iso != null) { altTitles.Add(new AlternativeTitle(resource.original_title, SourceType.TMDB, TmdbId, iso.Language)); } //movie.AlternativeTitles.Add(resource.original_title); } foreach (var alternativeTitle in resource.alternative_titles.titles) { if (alternativeTitle.iso_3166_1.ToLower() == langCode) { altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, TmdbId, IsoLanguages.Find(alternativeTitle.iso_3166_1.ToLower())?.Language ?? Language.English)); } else if (alternativeTitle.iso_3166_1.ToLower() == "us") { altTitles.Add(new AlternativeTitle(alternativeTitle.title, SourceType.TMDB, TmdbId, Language.English)); } } movie.TmdbId = TmdbId; movie.ImdbId = resource.imdb_id; movie.Title = resource.title; movie.TitleSlug = Parser.Parser.ToUrlSlug(resource.title); movie.CleanTitle = resource.title.CleanSeriesTitle(); movie.SortTitle = Parser.Parser.NormalizeTitle(resource.title); movie.Overview = resource.overview; movie.Website = resource.homepage; if (resource.release_date.IsNotNullOrWhiteSpace()) { movie.InCinemas = DateTime.Parse(resource.release_date); // get the lowest year in all release date var lowestYear = new List <int>(); foreach (ReleaseDates releaseDates in resource.release_dates.results) { foreach (ReleaseDate releaseDate in releaseDates.release_dates) { lowestYear.Add(DateTime.Parse(releaseDate.release_date).Year); } } movie.Year = lowestYear.Min(); } movie.TitleSlug += "-" + movie.TmdbId.ToString(); movie.Images.AddIfNotNull(MapImage(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page! movie.Images.AddIfNotNull(MapImage(resource.backdrop_path, MediaCoverTypes.Fanart)); movie.Runtime = resource.runtime; //foreach(Title title in resource.alternative_titles.titles) //{ // movie.AlternativeTitles.Add(title.title); //} foreach (ReleaseDates releaseDates in resource.release_dates.results) { foreach (ReleaseDate releaseDate in releaseDates.release_dates) { if (releaseDate.type == 5 || releaseDate.type == 4) { if (movie.PhysicalRelease.HasValue) { if (movie.PhysicalRelease.Value.After(DateTime.Parse(releaseDate.release_date))) { movie.PhysicalRelease = DateTime.Parse(releaseDate.release_date); //Use oldest release date available. movie.PhysicalReleaseNote = releaseDate.note; } } else { movie.PhysicalRelease = DateTime.Parse(releaseDate.release_date); movie.PhysicalReleaseNote = releaseDate.note; } } } } movie.Ratings = new Ratings(); movie.Ratings.Votes = resource.vote_count; movie.Ratings.Value = (decimal)resource.vote_average; foreach (Genre genre in resource.genres) { movie.Genres.Add(genre.name); } //this is the way it should be handled //but unfortunately it seems //tmdb lacks alot of release date info //omdbapi is actually quite good for this info //except omdbapi has been having problems recently //so i will just leave this in as a comment //and use the 3 month logic that we were using before /*var now = DateTime.Now; * if (now < movie.InCinemas) * movie.Status = MovieStatusType.Announced; * if (now >= movie.InCinemas) * movie.Status = MovieStatusType.InCinemas; * if (now >= movie.PhysicalRelease) * movie.Status = MovieStatusType.Released; */ var now = DateTime.Now; //handle the case when we have both theatrical and physical release dates if (movie.InCinemas.HasValue && movie.PhysicalRelease.HasValue) { if (now < movie.InCinemas) { movie.Status = MovieStatusType.Announced; } else if (now >= movie.InCinemas) { movie.Status = MovieStatusType.InCinemas; } if (now >= movie.PhysicalRelease) { movie.Status = MovieStatusType.Released; } } //handle the case when we have theatrical release dates but we dont know the physical release date else if (movie.InCinemas.HasValue && (now >= movie.InCinemas)) { movie.Status = MovieStatusType.InCinemas; } //handle the case where we only have a physical release date else if (movie.PhysicalRelease.HasValue && (now >= movie.PhysicalRelease)) { movie.Status = MovieStatusType.Released; } //otherwise the title has only been announced else { movie.Status = MovieStatusType.Announced; } //since TMDB lacks alot of information lets assume that stuff is released if its been in cinemas for longer than 3 months. if (!movie.PhysicalRelease.HasValue && (movie.Status == MovieStatusType.InCinemas) && (((DateTime.Now).Subtract(movie.InCinemas.Value)).TotalSeconds > 60 * 60 * 24 * 30 * 3)) { movie.Status = MovieStatusType.Released; } if (!hasPreDBEntry) { if (_predbService.HasReleases(movie)) { movie.HasPreDBEntry = true; } else { movie.HasPreDBEntry = false; } } //this matches with the old behavior before the creation of the MovieStatusType.InCinemas /*if (resource.status == "Released") * { * if (movie.InCinemas.HasValue && (((DateTime.Now).Subtract(movie.InCinemas.Value)).TotalSeconds <= 60 * 60 * 24 * 30 * 3)) * { * movie.Status = MovieStatusType.InCinemas; * } * else * { * movie.Status = MovieStatusType.Released; * } * } * else * { * movie.Status = MovieStatusType.Announced; * }*/ if (resource.videos != null) { foreach (Video video in resource.videos.results) { if (video.type == "Trailer" && video.site == "YouTube") { if (video.key != null) { movie.YouTubeTrailerId = video.key; break; } } } } if (resource.production_companies != null) { if (resource.production_companies.Any()) { movie.Studio = resource.production_companies[0].name; } } movie.AlternativeTitles.AddRange(altTitles); return(movie); }
public Movie MapMovie(MovieResource resource) { var movie = new Movie(); var altTitles = new List <AlternativeTitle>(); movie.TmdbId = resource.TmdbId; movie.ImdbId = resource.ImdbId; movie.Title = resource.Title; movie.OriginalTitle = resource.OriginalTitle; movie.TitleSlug = resource.TitleSlug; movie.CleanTitle = resource.Title.CleanMovieTitle(); movie.SortTitle = Parser.Parser.NormalizeTitle(resource.Title); movie.Overview = resource.Overview; movie.AlternativeTitles.AddRange(resource.AlternativeTitles.Select(MapAlternativeTitle)); movie.Translations.AddRange(resource.Translations.Select(MapTranslation)); movie.OriginalLanguage = IsoLanguages.Find(resource.OriginalLanguage.ToLower())?.Language ?? Language.English; movie.Website = resource.Homepage; movie.InCinemas = resource.InCinema; movie.PhysicalRelease = resource.PhysicalRelease; movie.DigitalRelease = resource.DigitalRelease; movie.Year = resource.Year; //If the premier differs from the TMDB year, use it as a secondary year. if (resource.Premier.HasValue && resource.Premier?.Year != movie.Year) { movie.SecondaryYear = resource.Premier?.Year; } movie.Images = resource.Images.Select(MapImage).ToList(); if (resource.Runtime != null) { movie.Runtime = resource.Runtime.Value; } var certificationCountry = _configService.CertificationCountry.ToString(); movie.Certification = resource.Certifications.FirstOrDefault(m => m.Country == certificationCountry)?.Certification; movie.Ratings = resource.Ratings.Select(MapRatings).FirstOrDefault() ?? new Ratings(); movie.Genres = resource.Genres; movie.Recommendations = resource.Recommendations?.Select(r => r.TmdbId).ToList() ?? new List <int>(); var now = DateTime.Now; movie.Status = MovieStatusType.Announced; if (resource.InCinema.HasValue && now > resource.InCinema) { movie.Status = MovieStatusType.InCinemas; if (!resource.PhysicalRelease.HasValue && !resource.DigitalRelease.HasValue && now > resource.InCinema.Value.AddDays(90)) { movie.Status = MovieStatusType.Released; } } if (resource.PhysicalRelease.HasValue && now >= resource.PhysicalRelease) { movie.Status = MovieStatusType.Released; } if (resource.DigitalRelease.HasValue && now >= resource.DigitalRelease) { movie.Status = MovieStatusType.Released; } movie.YouTubeTrailerId = resource.YoutubeTrailerId; movie.Studio = resource.Studio; if (resource.Collection != null) { movie.Collection = new MovieCollection { Name = resource.Collection.Name, TmdbId = resource.Collection.TmdbId }; } return(movie); }
public void should_not_return_portuguese(string isoCode) { var result = IsoLanguages.Find(isoCode); result.Should().Be(null); }
public void should_return_portuguese(string isoCode) { var result = IsoLanguages.Find(isoCode); result.Language.Should().Be(Language.Portuguese); }
public void unknown_or_invalid_code_should_return_null(string isoCode) { var result = IsoLanguages.Find(isoCode); result.Should().Be(null); }
public void should_return_iso_language_for_English(string isoCode) { var result = IsoLanguages.Find(isoCode); result.Language.Should().Be(Language.English); }