/// <summary> /// Tries to lookup the Movie online and downloads images. /// </summary> /// <param name="movieInfo">Movie to check</param> /// <returns><c>true</c> if successful</returns> public virtual async Task <IEnumerable <MovieInfo> > FindMatchingMoviesAsync(MovieInfo movieInfo) { List <MovieInfo> matches = new List <MovieInfo>(); try { // Try online lookup if (!await InitAsync().ConfigureAwait(false)) { return(matches); } MovieInfo movieSearch = movieInfo.Clone(); TLang language = FindBestMatchingLanguage(movieInfo.Languages); IEnumerable <MovieInfo> onlineMatches = null; if (GetMovieId(movieInfo, out string movieId)) { Logger.Debug(_id + ": Get movie from id {0} online", movieId); if (await _wrapper.UpdateFromOnlineMovieAsync(movieSearch, language, false)) { onlineMatches = new MovieInfo[] { movieSearch } } ; } if (onlineMatches == null) { Logger.Debug(_id + ": Search for movie {0} online", movieInfo.ToString()); onlineMatches = await _wrapper.SearchMovieMatchesAsync(movieSearch, language).ConfigureAwait(false); } if (onlineMatches?.Count() > 0) { matches.AddRange(onlineMatches.Where(m => m.IsBaseInfoPresent)); } return(matches); } catch (Exception ex) { Logger.Debug(_id + ": Exception while matching movie {0}", ex, movieInfo.ToString()); return(matches); } }
private void ExtractFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { if (aspects.ContainsKey(VideoAspect.ASPECT_ID)) { if (BaseInfo.IsVirtualResource(aspects)) { return; } MovieInfo movieInfo = new MovieInfo(); movieInfo.FromMetadata(aspects); bool forceFanart = !movieInfo.IsRefreshed; ExtractLocalImages(aspects, mediaItemId, movieInfo.ToString()); } }
public override async Task CollectFanArtAsync(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { //Virtual resources won't have local fanart if (BaseInfo.IsVirtualResource(aspects)) { return; } //Don't process the same item again if (!AddToCache(mediaItemId)) { return; } IResourceLocator mediaItemLocator = GetResourceLocator(aspects); if (mediaItemLocator == null) { return; } //Only needed for the name used in the fanart cache MovieInfo movieInfo = new MovieInfo(); movieInfo.FromMetadata(aspects); string title = movieInfo.ToString(); //Fanart files in the local directory if (ShouldCacheLocalFanArt(mediaItemLocator.NativeResourcePath, VideoMetadataExtractor.CacheLocalFanArt, VideoMetadataExtractor.CacheOfflineFanArt)) { await ExtractFolderFanArt(mediaItemLocator, mediaItemId, title).ConfigureAwait(false); } //Fanart in MKV tags if (MKV_EXTENSIONS.Contains(ResourcePathHelper.GetExtension(mediaItemLocator.NativeResourcePath.FileName))) { await ExtractMkvFanArt(mediaItemLocator, mediaItemId, title).ConfigureAwait(false); } }
private void ExtractFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects, Guid?collectionMediaItemId, IDictionary <Guid, string> actorMediaItems) { if (aspects.ContainsKey(MovieAspect.ASPECT_ID)) { if (BaseInfo.IsVirtualResource(aspects)) { return; } MovieInfo movieInfo = new MovieInfo(); movieInfo.FromMetadata(aspects); bool forceFanart = !movieInfo.IsRefreshed; MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>(); ExtractLocalImages(aspects, mediaItemId, collectionMediaItemId, movieInfo.ToString(), collectionInfo.ToString(), actorMediaItems); if (!MovieMetadataExtractor.SkipFanArtDownload) { OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, movieInfo, forceFanart); } //Take advantage of the movie language being known and download collection too if (collectionMediaItemId.HasValue && !_checkCache.Contains(collectionMediaItemId.Value)) { if (!MovieMetadataExtractor.SkipFanArtDownload) { OnlineMatcherService.Instance.DownloadMovieFanArt(collectionMediaItemId.Value, collectionInfo, forceFanart); } _checkCache.Add(collectionMediaItemId.Value); } } else if (aspects.ContainsKey(PersonAspect.ASPECT_ID)) { PersonInfo personInfo = new PersonInfo(); personInfo.FromMetadata(aspects); if (personInfo.Occupation == PersonAspect.OCCUPATION_ACTOR || personInfo.Occupation == PersonAspect.OCCUPATION_DIRECTOR || personInfo.Occupation == PersonAspect.OCCUPATION_WRITER) { if (!MovieMetadataExtractor.SkipFanArtDownload) { OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, personInfo, !personInfo.IsRefreshed); } } } else if (aspects.ContainsKey(CharacterAspect.ASPECT_ID)) { CharacterInfo characterInfo = new CharacterInfo(); characterInfo.FromMetadata(aspects); if (!MovieMetadataExtractor.SkipFanArtDownload) { OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, characterInfo, !characterInfo.IsRefreshed); } } else if (aspects.ContainsKey(CompanyAspect.ASPECT_ID)) { CompanyInfo companyInfo = new CompanyInfo(); companyInfo.FromMetadata(aspects); if (companyInfo.Type == CompanyAspect.COMPANY_PRODUCTION) { if (!MovieMetadataExtractor.SkipFanArtDownload) { OnlineMatcherService.Instance.DownloadMovieFanArt(mediaItemId, companyInfo, !companyInfo.IsRefreshed); } } } }
public override async Task <bool> UpdateFromOnlineMovieAsync(MovieInfo movie, string language, bool cacheOnly) { try { SimApiMovie movieDetail = null; if (!string.IsNullOrEmpty(movie.ImdbId)) { movieDetail = await _simApiHandler.GetMovieAsync(movie.ImdbId, cacheOnly).ConfigureAwait(false); } if (movieDetail == null) { return(false); } movie.ImdbId = movieDetail.ImdbID; movie.MovieName = new SimpleTitle(movieDetail.Title, true); movie.Summary = new SimpleTitle(movieDetail.Plot, true); CertificationMapping cert = null; if (CertificationMapper.TryFindMovieCertification(movieDetail.Rated, out cert)) { movie.Certification = cert.CertificationId; } movie.Runtime = movieDetail.Duration.HasValue ? movieDetail.Duration.Value : 0; movie.ReleaseDate = movieDetail.Year.HasValue ? (DateTime?)new DateTime(movieDetail.Year.Value, 1, 1) : null; if (movieDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.ImdbRating, 1)); } movie.Genres = movieDetail.Genres.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (movie.Actors.Count == 0) { movie.Actors = ConvertToPersons(movieDetail.Actors, PersonAspect.OCCUPATION_ACTOR, movieDetail.Title); } if (movie.Writers.Count == 0) { movie.Writers = ConvertToPersons(movieDetail.Writers, PersonAspect.OCCUPATION_WRITER, movieDetail.Title); } //if (movie.Directors.Count == 0) // movie.Directors = ConvertToPersons(movieDetail.Directors, PersonAspect.OCCUPATION_DIRECTOR, movieDetail.Title); return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("SimApiWrapper: Exception while processing movie {0}", ex, movie.ToString()); return(false); } }
public virtual async Task <bool> UpdateCompaniesAsync(MovieInfo movieInfo, string companyType) { try { // Try online lookup if (!await InitAsync().ConfigureAwait(false)) { return(false); } TLang language = FindBestMatchingLanguage(movieInfo.Languages); bool updated = false; MovieInfo movieMatch = movieInfo.Clone(); List <CompanyInfo> companies = new List <CompanyInfo>(); if (companyType == CompanyAspect.COMPANY_PRODUCTION) { foreach (CompanyInfo company in movieMatch.ProductionCompanies) { string id; if (_companyMatcher.GetNameMatch(company.Name, out id)) { if (SetCompanyId(company, id)) { //Only add if Id valid if not then it is to avoid a retry //and the company should be ignored companies.Add(company); updated = true; } } else { companies.Add(company); } } } if (companies.Count == 0) { return(true); } foreach (CompanyInfo company in companies) { //Try updating from cache if (!await _wrapper.UpdateFromOnlineMovieCompanyAsync(movieMatch, company, language, true).ConfigureAwait(false)) { Logger.Debug(_id + ": Search for company {0} online", company.ToString()); //Try to update company information from online source if online Ids are present if (!await _wrapper.UpdateFromOnlineMovieCompanyAsync(movieMatch, company, language, false).ConfigureAwait(false)) { //Search for the company online and update the Ids if a match is found if (await _wrapper.SearchCompanyUniqueAndUpdateAsync(company, language).ConfigureAwait(false)) { //Ids were updated now try to fetch the online company info if (await _wrapper.UpdateFromOnlineMovieCompanyAsync(movieMatch, company, language, false).ConfigureAwait(false)) { //Set as changed because cache has changed and might contain new/updated data movieInfo.HasChanged = true; updated = true; } } } else { updated = true; } } else { Logger.Debug(_id + ": Found company {0} in cache", company.ToString()); updated = true; } } if (updated) { //These lists contain Ids and other properties that are not loaded, so they will always appear changed. //So these changes will be ignored and only stored if there is any other reason for it to have changed. if (companyType == CompanyAspect.COMPANY_PRODUCTION) { MetadataUpdater.SetOrUpdateList(movieInfo.ProductionCompanies, movieMatch.ProductionCompanies.Where(c => !string.IsNullOrEmpty(c.Name)).Distinct().ToList(), false); } } List <string> thumbs = new List <string>(); if (companyType == CompanyAspect.COMPANY_PRODUCTION) { foreach (CompanyInfo company in movieInfo.ProductionCompanies) { string id; if (GetCompanyId(company, out id)) { _companyMatcher.StoreNameMatch(id, company.Name, company.Name); } else { //Store empty match so it is not retried _companyMatcher.StoreNameMatch("", company.Name, company.Name); } } } return(updated); } catch (Exception ex) { Logger.Debug(_id + ": Exception while processing companies {0}", ex, movieInfo.ToString()); return(false); } }
public virtual async Task <bool> UpdateCharactersAsync(MovieInfo movieInfo) { try { // Try online lookup if (!await InitAsync().ConfigureAwait(false)) { return(false); } TLang language = FindBestMatchingLanguage(movieInfo.Languages); bool updated = false; MovieInfo movieMatch = movieInfo.Clone(); foreach (CharacterInfo character in movieMatch.Characters) { string id; if (_characterMatcher.GetNameMatch(character.Name, out id)) { if (SetCharacterId(character, id)) { updated = true; } else { continue; } } //Try updating from cache if (!await _wrapper.UpdateFromOnlineMovieCharacterAsync(movieMatch, character, language, true).ConfigureAwait(false)) { Logger.Debug(_id + ": Search for character {0} online", character.ToString()); //Try to update character information from online source if online Ids are present if (!await _wrapper.UpdateFromOnlineMovieCharacterAsync(movieMatch, character, language, false).ConfigureAwait(false)) { //Search for the character online and update the Ids if a match is found if (await _wrapper.SearchCharacterUniqueAndUpdateAsync(character, language).ConfigureAwait(false)) { //Ids were updated now try to fetch the online character info if (await _wrapper.UpdateFromOnlineMovieCharacterAsync(movieMatch, character, language, false).ConfigureAwait(false)) { //Set as changed because cache has changed and might contain new/updated data movieInfo.HasChanged = true; updated = true; } } } else { updated = true; } } else { Logger.Debug(_id + ": Found character {0} in cache", character.ToString()); updated = true; } } if (updated) { //These lists contain Ids and other properties that are not loaded, so they will always appear changed. //So these changes will be ignored and only stored if there is any other reason for it to have changed. MetadataUpdater.SetOrUpdateList(movieInfo.Characters, movieMatch.Characters.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), false); } List <string> thumbs = new List <string>(); foreach (CharacterInfo character in movieInfo.Characters) { string id; if (GetCharacterId(character, out id)) { _characterMatcher.StoreNameMatch(id, character.Name, character.Name); } else { //Store empty match so he/she is not retried _characterMatcher.StoreNameMatch("", character.Name, character.Name); } } return(updated); } catch (Exception ex) { Logger.Debug(_id + ": Exception while processing characters {0}", ex, movieInfo.ToString()); return(false); } }
public virtual async Task <bool> UpdatePersonsAsync(MovieInfo movieInfo, string occupation) { try { // Try online lookup if (!await InitAsync().ConfigureAwait(false)) { return(false); } TLang language = FindBestMatchingLanguage(movieInfo.Languages); bool updated = false; MovieInfo movieMatch = movieInfo.Clone(); List <PersonInfo> persons = new List <PersonInfo>(); if (occupation == PersonAspect.OCCUPATION_ACTOR) { foreach (PersonInfo person in movieMatch.Actors) { string id; if (_actorMatcher.GetNameMatch(person.Name, out id)) { if (SetPersonId(person, id)) { //Only add if Id valid if not then it is to avoid a retry //and the person should be ignored persons.Add(person); updated = true; } } else { persons.Add(person); } } } else if (occupation == PersonAspect.OCCUPATION_DIRECTOR) { foreach (PersonInfo person in movieMatch.Directors) { string id; if (_directorMatcher.GetNameMatch(person.Name, out id)) { if (SetPersonId(person, id)) { //Only add if Id valid if not then it is to avoid a retry //and the person should be ignored persons.Add(person); updated = true; } } else { persons.Add(person); } } } else if (occupation == PersonAspect.OCCUPATION_WRITER) { foreach (PersonInfo person in movieMatch.Writers) { string id; if (_writerMatcher.GetNameMatch(person.Name, out id)) { if (SetPersonId(person, id)) { //Only add if Id valid if not then it is to avoid a retry //and the person should be ignored persons.Add(person); updated = true; } } else { persons.Add(person); } } } if (persons.Count == 0) { return(true); } foreach (PersonInfo person in persons) { //Try updating from cache if (!await _wrapper.UpdateFromOnlineMoviePersonAsync(movieMatch, person, language, true).ConfigureAwait(false)) { Logger.Debug(_id + ": Search for person {0} online", person.ToString()); //Try to update person information from online source if online Ids are present if (!await _wrapper.UpdateFromOnlineMoviePersonAsync(movieMatch, person, language, false).ConfigureAwait(false)) { //Search for the person online and update the Ids if a match is found if (await _wrapper.SearchPersonUniqueAndUpdateAsync(person, language).ConfigureAwait(false)) { //Ids were updated now try to fetch the online person info if (await _wrapper.UpdateFromOnlineMoviePersonAsync(movieMatch, person, language, false).ConfigureAwait(false)) { //Set as changed because cache has changed and might contain new/updated data movieInfo.HasChanged = true; updated = true; } } } else { updated = true; } } else { Logger.Debug(_id + ": Found person {0} in cache", person.ToString()); updated = true; } } if (updated) { //These lists contain Ids and other properties that are not loaded, so they will always appear changed. //So these changes will be ignored and only stored if there is any other reason for it to have changed. if (occupation == PersonAspect.OCCUPATION_ACTOR) { MetadataUpdater.SetOrUpdateList(movieInfo.Actors, movieMatch.Actors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), false); } else if (occupation == PersonAspect.OCCUPATION_DIRECTOR) { MetadataUpdater.SetOrUpdateList(movieInfo.Directors, movieMatch.Directors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), false); } else if (occupation == PersonAspect.OCCUPATION_WRITER) { MetadataUpdater.SetOrUpdateList(movieInfo.Writers, movieMatch.Writers.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), false); } } List <string> thumbs = new List <string>(); if (occupation == PersonAspect.OCCUPATION_ACTOR) { foreach (PersonInfo person in movieInfo.Actors) { string id; if (GetPersonId(person, out id)) { _actorMatcher.StoreNameMatch(id, person.Name, person.Name); } else { //Store empty match so he/she is not retried _actorMatcher.StoreNameMatch("", person.Name, person.Name); } } } else if (occupation == PersonAspect.OCCUPATION_DIRECTOR) { foreach (PersonInfo person in movieInfo.Directors) { string id; if (GetPersonId(person, out id)) { _directorMatcher.StoreNameMatch(id, person.Name, person.Name); } else { //Store empty match so he/she is not retried _directorMatcher.StoreNameMatch("", person.Name, person.Name); } } } else if (occupation == PersonAspect.OCCUPATION_WRITER) { foreach (PersonInfo person in movieInfo.Writers) { string id; if (GetPersonId(person, out id)) { _writerMatcher.StoreNameMatch(id, person.Name, person.Name); } else { //Store empty match so he/she is not retried _writerMatcher.StoreNameMatch("", person.Name, person.Name); } } } return(updated); } catch (Exception ex) { Logger.Debug(_id + ": Exception while processing persons {0}", ex, movieInfo.ToString()); return(false); } }
/// <summary> /// Tries to lookup the Movie online and downloads images. /// </summary> /// <param name="movieInfo">Movie to check</param> /// <returns><c>true</c> if successful</returns> public virtual async Task <bool> FindAndUpdateMovieAsync(MovieInfo movieInfo) { try { // Try online lookup if (!await InitAsync().ConfigureAwait(false)) { return(false); } MovieInfo movieMatch = null; string movieId = null; bool matchFound = false; TLang language = FindBestMatchingLanguage(movieInfo.Languages); if (GetMovieId(movieInfo, out movieId)) { // Prefer memory cache CheckCacheAndRefresh(); if (_memoryCache.TryGetValue(movieId, out movieMatch)) { matchFound = true; } } if (!matchFound) { MovieMatch match = GetStroredMatch(movieInfo); movieMatch = movieInfo.Clone(); if (string.IsNullOrEmpty(movieId)) { Logger.Debug(_id + ": Try to lookup movie \"{0}\" from cache: {1}", movieInfo, match != null && !string.IsNullOrEmpty(match.Id)); if (match != null) { if (SetMovieId(movieMatch, match.Id)) { //If Id was found in cache the online movie info is probably also in the cache if (await _wrapper.UpdateFromOnlineMovieAsync(movieMatch, language, true).ConfigureAwait(false)) { Logger.Debug(_id + ": Found movie {0} in cache", movieInfo.ToString()); matchFound = true; } } else if (string.IsNullOrEmpty(movieId)) { //Match was found but with invalid Id probably to avoid a retry //No Id is available so online search will probably fail again return(false); } } } else { if (match != null && movieId != match.Id) { //Id was changed so remove it so it can be updated _storage.TryRemoveMatch(match); } } if (!matchFound) { Logger.Debug(_id + ": Search for movie {0} online", movieInfo.ToString()); //Try to update movie information from online source if online Ids are present if (!await _wrapper.UpdateFromOnlineMovieAsync(movieMatch, language, false).ConfigureAwait(false)) { //Search for the movie online and update the Ids if a match is found if (await _wrapper.SearchMovieUniqueAndUpdateAsync(movieMatch, language).ConfigureAwait(false)) { //Ids were updated now try to update movie information from online source if (await _wrapper.UpdateFromOnlineMovieAsync(movieMatch, language, false).ConfigureAwait(false)) { matchFound = true; } } } else { matchFound = true; } } } //Always save match even if none to avoid retries StoreMovieMatch(movieInfo, movieMatch); if (matchFound) { movieInfo.MergeWith(movieMatch, true); //Store person matches foreach (PersonInfo person in movieInfo.Actors) { string id; if (GetPersonId(person, out id)) { _actorMatcher.StoreNameMatch(id, person.Name, person.Name); } } foreach (PersonInfo person in movieInfo.Directors) { string id; if (GetPersonId(person, out id)) { _directorMatcher.StoreNameMatch(id, person.Name, person.Name); } } foreach (PersonInfo person in movieInfo.Writers) { string id; if (GetPersonId(person, out id)) { _writerMatcher.StoreNameMatch(id, person.Name, person.Name); } } //Store character matches foreach (CharacterInfo character in movieInfo.Characters) { string id; if (GetCharacterId(character, out id)) { _characterMatcher.StoreNameMatch(id, character.Name, character.Name); } } //Store company matches foreach (CompanyInfo company in movieInfo.ProductionCompanies) { string id; if (GetCompanyId(company, out id)) { _companyMatcher.StoreNameMatch(id, company.Name, company.Name); } } if (GetMovieId(movieInfo, out movieId)) { _memoryCache.TryAdd(movieId, movieInfo); } return(true); } return(false); } catch (Exception ex) { Logger.Debug(_id + ": Exception while processing movie {0}", ex, movieInfo.ToString()); return(false); } }
public override bool UpdateFromOnlineMovie(MovieInfo movie, string language, bool cacheOnly) { try { OmDbMovie movieDetail = null; if (!string.IsNullOrEmpty(movie.ImdbId)) { movieDetail = _omDbHandler.GetMovie(movie.ImdbId, cacheOnly); } if (movieDetail == null) { return(false); } movie.ImdbId = movieDetail.ImdbID; movie.MovieName = new SimpleTitle(movieDetail.Title, true); movie.Summary = new SimpleTitle(movieDetail.Plot, true); movie.Certification = movieDetail.Rated; movie.Revenue = movieDetail.Revenue.HasValue ? movieDetail.Revenue.Value : 0; movie.Runtime = movieDetail.Runtime.HasValue ? movieDetail.Runtime.Value : 0; movie.ReleaseDate = movieDetail.Released; List <string> awards = new List <string>(); if (!string.IsNullOrEmpty(movieDetail.Awards)) { if (movieDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || movieDetail.Awards.IndexOf(" Oscar", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Oscar"); } if (movieDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || movieDetail.Awards.IndexOf(" Golden Globe", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Golden Globe"); } movie.Awards = awards; } if (movieDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.ImdbVotes, movieDetail.ImdbVotes)); } if (movieDetail.TomatoRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.TomatoRating, movieDetail.TomatoTotalReviews)); } if (movieDetail.TomatoUserRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.TomatoUserRating, movieDetail.TomatoUserTotalReviews)); } movie.Genres = movieDetail.Genres.Select(s => new GenreInfo { Name = s }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (movie.Actors.Count == 0) { movie.Actors = ConvertToPersons(movieDetail.Actors, PersonAspect.OCCUPATION_ACTOR, movieDetail.Title); } if (movie.Writers.Count == 0) { movie.Writers = ConvertToPersons(movieDetail.Writers, PersonAspect.OCCUPATION_WRITER, movieDetail.Title); } if (movie.Directors.Count == 0) { movie.Directors = ConvertToPersons(movieDetail.Directors, PersonAspect.OCCUPATION_DIRECTOR, movieDetail.Title); } return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing movie {0}", ex, movie.ToString()); return(false); } }
public override Task <bool> UpdateFromOnlineMovieAsync(MovieInfo movie, string language, bool cacheOnly) { try { language = language ?? PreferredLanguage; if (_language != null && !_language.Equals(language, StringComparison.InvariantCultureIgnoreCase)) { return(Task.FromResult(false)); } if (cacheOnly) { return(Task.FromResult(false)); } if (!_script.UpdateMovie(movie)) { return(Task.FromResult(false)); } if (!movie.DataProviders.Contains(_name)) { movie.DataProviders.Add(_name); } return(Task.FromResult(true)); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug(_name + ": Exception in while processing movie {0}", ex, movie.ToString()); return(Task.FromResult(false)); } }
protected async Task ExtractMovieFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { bool shouldCacheLocal = false; IResourceLocator mediaItemLocator = null; if (!BaseInfo.IsVirtualResource(aspects)) { mediaItemLocator = GetResourceLocator(aspects); if (mediaItemLocator == null) { return; } //Whether local fanart should be stored in the fanart cache shouldCacheLocal = ShouldCacheLocalFanArt(mediaItemLocator.NativeResourcePath, MovieMetadataExtractor.CacheLocalFanArt, MovieMetadataExtractor.CacheOfflineFanArt); } if (!shouldCacheLocal && MovieMetadataExtractor.SkipFanArtDownload) { return; //Nothing to do } MovieInfo movieInfo = new MovieInfo(); movieInfo.FromMetadata(aspects); //Movie fanart if (AddToCache(mediaItemId)) { //Actor fanart may be stored in the movie directory, so get the actors now IList <Tuple <Guid, string> > actors = null; if (MediaItemAspect.TryGetAspect(aspects, VideoAspect.Metadata, out SingleMediaItemAspect videoAspect)) { var actorNames = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS); if (actorNames != null) { RelationshipExtractorUtils.TryGetMappedLinkedIds(PersonAspect.ROLE_ACTOR, aspects, actorNames.ToList(), out actors); } } if (shouldCacheLocal) { await ExtractMovieFolderFanArt(mediaItemLocator, mediaItemId, movieInfo.ToString(), actors).ConfigureAwait(false); } if (!MovieMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(mediaItemId, movieInfo).ConfigureAwait(false); } } //Collection fanart if (RelationshipExtractorUtils.TryGetLinkedId(MovieCollectionAspect.ROLE_MOVIE_COLLECTION, aspects, out Guid collectionMediaItemId) && AddToCache(collectionMediaItemId)) { MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>(); if (shouldCacheLocal) { await ExtractCollectionFolderFanArt(mediaItemLocator, collectionMediaItemId, collectionInfo.ToString()).ConfigureAwait(false); } if (!MovieMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(collectionMediaItemId, collectionInfo).ConfigureAwait(false); } } }
protected async Task ExtractMovieFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { bool shouldCacheLocal = false; IResourceLocator mediaItemLocator = null; if (!BaseInfo.IsVirtualResource(aspects)) { mediaItemLocator = GetResourceLocator(aspects); //Whether local fanart should be stored in the fanart cache shouldCacheLocal = ShouldCacheLocalFanArt(mediaItemLocator.NativeResourcePath, MovieMetadataExtractor.CacheLocalFanArt, MovieMetadataExtractor.CacheOfflineFanArt); } if (mediaItemLocator == null) { return; } if (!shouldCacheLocal && MovieMetadataExtractor.SkipFanArtDownload) { return; //Nothing to do } MovieInfo movieInfo = new MovieInfo(); movieInfo.FromMetadata(aspects); //Movie fanart if (AddToCache(mediaItemId)) { //Actor fanart may be stored in the movie directory, so get the actors now IList <Tuple <Guid, string> > actors = null; if (MediaItemAspect.TryGetAspect(aspects, VideoAspect.Metadata, out SingleMediaItemAspect videoAspect)) { var actorNames = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS); if (actorNames != null) { RelationshipExtractorUtils.TryGetMappedLinkedIds(PersonAspect.ROLE_ACTOR, aspects, actorNames.ToList(), out actors); } } if (shouldCacheLocal) { await ExtractMovieFolderFanArt(mediaItemLocator, mediaItemId, movieInfo.ToString(), actors).ConfigureAwait(false); } if (!MovieMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(mediaItemId, movieInfo).ConfigureAwait(false); } //Find central actor information folder var seriesDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../"); ResourcePath centralActorFolderPath = LocalFanartHelper.GetCentralPersonFolder(seriesDirectory, CentralPersonFolderType.MovieActors); if (shouldCacheLocal && centralActorFolderPath != null && actors != null) { foreach (var actor in actors) { // Check if we already processed this actor if (!AddToCache(actor.Item1)) { continue; } // First get the ResourcePath of the central directory var artistFolderPath = ResourcePathHelper.Combine(centralActorFolderPath, $"{LocalFanartHelper.GetSafePersonFolderName(actor.Item2)}/"); using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, artistFolderPath).CreateAccessor()) { if (accessor is IFileSystemResourceAccessor directoryAccessor) { FanArtPathCollection paths = new FanArtPathCollection(); List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryAccessor); ExtractAllFanArtImages(potentialFanArtFiles, paths); await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, actor.Item1, actor.Item2).ConfigureAwait(false); } } } } } //Collection fanart if (RelationshipExtractorUtils.TryGetLinkedId(MovieCollectionAspect.ROLE_MOVIE_COLLECTION, aspects, out Guid collectionMediaItemId) && AddToCache(collectionMediaItemId)) { MovieCollectionInfo collectionInfo = movieInfo.CloneBasicInstance <MovieCollectionInfo>(); if (shouldCacheLocal) { await ExtractCollectionFolderFanArt(mediaItemLocator, collectionMediaItemId, collectionInfo.ToString()).ConfigureAwait(false); } if (!MovieMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadMovieFanArtAsync(collectionMediaItemId, collectionInfo).ConfigureAwait(false); } } }
private void ChangeMovieDetailInfo(MovieInfo movieInfo, Texture texture) { posterRawImage.texture = texture; moveDetailText.text = movieInfo.ToString(); searchManager.GetMovieInfoAndTexture(movieInfo); }