private async Task<QueryResult<ServerItem>> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) { var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Series && i.ContainsPerson(person.Name)) .ToList(); var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery { ContentTypes = new[] { ChannelMediaContentType.MovieExtra }, ExtraTypes = new[] { ExtraType.Trailer }, UserId = user.Id.ToString("N") }, CancellationToken.None).ConfigureAwait(false); var currentIds = items.Select(i => i.GetProviderId(MetadataProviders.Imdb)) .ToList(); var trailersToAdd = trailerResult.Items .Where(i => i.ContainsPerson(person.Name)) .Where(i => { // Try to filter out dupes using imdb id var imdb = i.GetProviderId(MetadataProviders.Imdb); if (!string.IsNullOrWhiteSpace(imdb) && currentIds.Contains(imdb, StringComparer.OrdinalIgnoreCase)) { return false; } return true; }); items.AddRange(trailersToAdd); items = _libraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending) .Skip(startIndex ?? 0) .Take(limit ?? int.MaxValue) .ToList(); var serverItems = items.Select(i => new ServerItem { Item = i, StubType = null }) .ToArray(); return new QueryResult<ServerItem> { TotalRecordCount = serverItems.Length, Items = serverItems }; }
/// <summary> /// Processes the info. /// </summary> /// <param name="person">The person.</param> /// <param name="searchResult">The search result.</param> protected void ProcessInfo(Person person, PersonResult searchResult) { person.Overview = searchResult.biography; DateTime date; if (DateTime.TryParseExact(searchResult.birthday, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out date)) { person.PremiereDate = date.ToUniversalTime(); } if (DateTime.TryParseExact(searchResult.deathday, "yyyy-MM-dd", new CultureInfo("en-US"), DateTimeStyles.None, out date)) { person.EndDate = date.ToUniversalTime(); } if (!string.IsNullOrEmpty(searchResult.homepage)) { person.HomePageUrl = searchResult.homepage; } if (!person.LockedFields.Contains(MetadataFields.ProductionLocations)) { if (!string.IsNullOrEmpty(searchResult.place_of_birth)) { person.ProductionLocations = new List<string> { searchResult.place_of_birth }; } } person.SetProviderId(MetadataProviders.Tmdb, searchResult.id.ToString(UsCulture)); }
/// <summary> /// Fetches the images. /// </summary> /// <param name="person">The person.</param> /// <param name="searchResult">The search result.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> private async Task FetchImages(Person person, Images searchResult, CancellationToken cancellationToken) { if (searchResult != null && searchResult.profiles.Count > 0) { //get our language var profile = searchResult.profiles.FirstOrDefault( p => !string.IsNullOrEmpty(GetIso639(p)) && GetIso639(p).Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); if (profile == null) { //didn't find our language - try first null one profile = searchResult.profiles.FirstOrDefault( p => !string.IsNullOrEmpty(GetIso639(p)) && GetIso639(p).Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); } if (profile == null) { //still nothing - just get first one profile = searchResult.profiles[0]; } if (profile != null && !person.HasImage(ImageType.Primary)) { var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); await DownloadAndSaveImage(person, tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedProfileSize + profile.file_path, MimeTypes.GetMimeType(profile.file_path), cancellationToken).ConfigureAwait(false); } } }
/// <summary> /// Fetches the info. /// </summary> /// <param name="person">The person.</param> /// <param name="id">The id.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> private async Task FetchInfo(Person person, string id, CancellationToken cancellationToken) { string url = string.Format(@"http://api.themoviedb.org/3/person/{1}?api_key={0}&append_to_response=credits,images", MovieDbProvider.ApiKey, id); PersonResult searchResult = null; using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbProvider.AcceptHeader }).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream<PersonResult>(json); } cancellationToken.ThrowIfCancellationRequested(); if (searchResult != null) { ProcessInfo(person, searchResult); Logger.Debug("TmdbPersonProvider downloaded and saved information for {0}", person.Name); await FetchImages(person, searchResult.images, cancellationToken).ConfigureAwait(false); } }
private QueryResult<ServerItem> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) { var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user) { Person = person.Name, IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name, typeof(Trailer).Name }, SortBy = new[] { ItemSortBy.SortName }, Limit = limit, StartIndex = startIndex }); var serverItems = itemsResult.Items.Select(i => new ServerItem { Item = i, StubType = null }) .ToArray(); return new QueryResult<ServerItem> { TotalRecordCount = itemsResult.TotalRecordCount, Items = serverItems }; }
private QueryResult<ServerItem> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) { var itemsWithPerson = _libraryManager.GetItems(new InternalItemsQuery { Person = person.Name }).Items; var items = itemsWithPerson .Where(i => i is Movie || i is Series || i is IChannelItem) .Where(i => i.IsVisibleStandalone(user)) .ToList(); items = _libraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending) .Skip(startIndex ?? 0) .Take(limit ?? int.MaxValue) .ToList(); var serverItems = items.Select(i => new ServerItem { Item = i, StubType = null }) .ToArray(); return new QueryResult<ServerItem> { TotalRecordCount = serverItems.Length, Items = serverItems }; }
/// <summary> /// Fetches the info. /// </summary> /// <param name="person">The person.</param> /// <param name="id">The id.</param> /// <param name="isForcedRefresh">if set to <c>true</c> [is forced refresh].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> private async Task FetchInfo(Person person, string id, bool isForcedRefresh, CancellationToken cancellationToken) { var dataFilePath = GetPersonDataFilePath(ConfigurationManager.ApplicationPaths, id); // Only download if not already there // The prescan task will take care of updates so we don't need to re-download here if (!File.Exists(dataFilePath)) { await DownloadPersonInfo(id, cancellationToken).ConfigureAwait(false); } if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(person)) { var info = JsonSerializer.DeserializeFromFile<PersonResult>(dataFilePath); cancellationToken.ThrowIfCancellationRequested(); ProcessInfo(person, info); } }
/// <summary> /// Fetches the info. /// </summary> /// <param name="person">The person.</param> /// <param name="id">The id.</param> /// <param name="isForcedRefresh">if set to <c>true</c> [is forced refresh].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> private async Task FetchInfo(Person person, string id, bool isForcedRefresh, CancellationToken cancellationToken) { await EnsurePersonInfo(id, cancellationToken).ConfigureAwait(false); if (isForcedRefresh || !HasAltMeta(person)) { var dataFilePath = GetPersonDataFilePath(ConfigurationManager.ApplicationPaths, id); var info = JsonSerializer.DeserializeFromFile<PersonResult>(dataFilePath); cancellationToken.ThrowIfCancellationRequested(); ProcessInfo(person, info); } }