public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updateMovieList = false) { if (other is MovieCollectionInfo collection) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, collection.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomIds, collection.CustomIds); HasChanged |= MetadataUpdater.SetOrUpdateString(ref CollectionName, collection.CollectionName, overwriteShorterStrings); if (TotalMovies < collection.TotalMovies) { HasChanged = true; TotalMovies = collection.TotalMovies; } if (updateMovieList) //Comparing all movies can be quite time consuming { MetadataUpdater.SetOrUpdateList(Movies, collection.Movies.Distinct().ToList(), true, overwriteShorterStrings); } MergeDataProviders(collection); return(true); } return(false); }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is PersonInfo person) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, person.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, person.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, person.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvMazeId, person.TvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvRageId, person.TvRageId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicBrainzId, person.MusicBrainzId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AudioDbId, person.AudioDbId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Name, person.Name, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref AlternateName, person.AlternateName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Biography, person.Biography, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Orign, person.Orign, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Occupation, person.Occupation, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref DateOfBirth, person.DateOfBirth); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref DateOfDeath, person.DateOfDeath); return(true); } return(false); }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is SeasonInfo season) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, season.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, season.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, season.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvMazeId, season.TvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvRageId, season.TvRageId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomIds, season.CustomIds); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesImdbId, season.SeriesImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesMovieDbId, season.SeriesMovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesTvdbId, season.SeriesTvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesTvMazeId, season.SeriesTvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesTvRageId, season.SeriesTvRageId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomSeriesIds, season.CustomSeriesIds); HasChanged |= MetadataUpdater.SetOrUpdateString(ref SeriesName, season.SeriesName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Description, season.Description, overwriteShorterStrings); if (TotalEpisodes < season.TotalEpisodes) { HasChanged = true; TotalEpisodes = season.TotalEpisodes; } HasChanged |= MetadataUpdater.SetOrUpdateValue(ref FirstAired, season.FirstAired); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref SeasonNumber, season.SeasonNumber); MergeDataProviders(season); return(true); } return(false); }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is SubtitleInfo sub) { SubtitleId = $"{SubtitleId};{sub.SubtitleId}"; Name = $"{Name};{sub.Name}"; if (MatchPercentage.HasValue && sub.MatchPercentage.HasValue) { MatchPercentage = Math.Max(MatchPercentage.Value, sub.MatchPercentage.Value); } else if (sub.MatchPercentage.HasValue) { MatchPercentage = sub.MatchPercentage; } HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, sub.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, sub.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, sub.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomIds, sub.CustomIds); Categories = Categories.Except(sub.Categories).Concat(sub.Categories).ToList(); MergeDataProviders(sub); return(true); } return(false); }
public override bool MergeWith(object other, bool overwriteShorterStrings = false, bool updateDiscInfo = false) { if (other is TrackInfo track) { //Only update album related info if they are equal bool albumMatch = this.CloneBasicInstance <AlbumInfo>().Equals(track.CloneBasicInstance <AlbumInfo>()); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AudioDbId, track.AudioDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicBrainzId, track.MusicBrainzId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref IsrcId, track.IsrcId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref LyricId, track.LyricId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicIpId, track.MusicIpId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MvDbId, track.MvDbId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref TrackName, track.TrackName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref TrackLyrics, track.TrackLyrics, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref ReleaseDate, track.ReleaseDate); HasChanged |= MetadataUpdater.SetOrUpdateRatings(ref Rating, track.Rating); if (Genres.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(Genres, track.Genres.Distinct().ToList(), true); } if (albumMatch) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumAudioDbId, track.AlbumAudioDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumCdDdId, track.AlbumCdDdId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumMusicBrainzDiscId, track.AlbumMusicBrainzDiscId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumMusicBrainzGroupId, track.AlbumMusicBrainzGroupId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumMusicBrainzId, track.AlbumMusicBrainzId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumAmazonId, track.AlbumAmazonId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumItunesId, track.AlbumItunesId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AlbumUpcEanId, track.AlbumUpcEanId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Album, track.Album, overwriteShorterStrings); if (updateDiscInfo) { HasChanged |= MetadataUpdater.SetOrUpdateValue(ref DiscNum, track.DiscNum); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref TotalDiscs, track.TotalDiscs); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref TotalTracks, track.TotalTracks); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref TrackNum, track.TrackNum); } } //These lists contain Ids and other properties that are not persisted, so they will always appear changed. //So changes to these lists will only be stored if something else has changed. MetadataUpdater.SetOrUpdateList(Artists, track.Artists.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Artists.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Composers, track.Composers.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Composers.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Conductors, track.Conductors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Conductors.Count == 0, overwriteShorterStrings); if (albumMatch) { MetadataUpdater.SetOrUpdateList(MusicLabels, track.MusicLabels.Where(c => !string.IsNullOrEmpty(c.Name)).Distinct().ToList(), MusicLabels.Count == 0, overwriteShorterStrings); //In some cases the album artists can be "Various Artist" and/or "Multiple Artists" or track variations MetadataUpdater.SetOrUpdateList(AlbumArtists, track.AlbumArtists.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), AlbumArtists.Count == 0, overwriteShorterStrings); } return(true); } return(false); }
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 override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is EpisodeInfo episode) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, episode.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, episode.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, episode.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvMazeId, episode.TvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvRageId, episode.TvRageId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesImdbId, episode.SeriesImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesMovieDbId, episode.SeriesMovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesTvdbId, episode.SeriesTvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesTvMazeId, episode.SeriesTvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref SeriesTvRageId, episode.SeriesTvRageId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref EpisodeName, episode.EpisodeName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Summary, episode.Summary, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref SeriesName, episode.SeriesName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref FirstAired, episode.FirstAired); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref SeasonNumber, episode.SeasonNumber); MetadataUpdater.SetOrUpdateValue(ref SeriesFirstAired, episode.SeriesFirstAired); HasChanged |= MetadataUpdater.SetOrUpdateRatings(ref Rating, episode.Rating); if (EpisodeNumbers.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(EpisodeNumbers, episode.EpisodeNumbers.Distinct().ToList(), true); } if (DvdEpisodeNumbers.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(DvdEpisodeNumbers, episode.DvdEpisodeNumbers.Distinct().ToList(), true); } if (Genres.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(Genres, episode.Genres.Distinct().ToList(), true); } if (!HasThumbnail && episode.HasThumbnail) { Thumbnail = episode.Thumbnail; HasChanged = true; } //These lists contain Ids and other properties that are not persisted, so they will always appear changed. //So changes to these lists will only be stored if something else has changed. MetadataUpdater.SetOrUpdateList(Actors, episode.Actors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Actors.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Characters, episode.Characters.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Characters.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Directors, episode.Directors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Directors.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Writers, episode.Writers.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Writers.Count == 0, overwriteShorterStrings); return(true); } return(false); }
public void DeleteMetadataIfValueIsEmptyOrNull() { var updates = new Dictionary <string, string> { { "MerlinGuess", null }, { "NumFailedMissions", "" } }; MetadataUpdater.Update(_metadata, updates); CollectionAssert.IsEmpty(_metadata); }
public void Update() { using (var client = new HttpClient()) { var requestor = new WebRequestor(client); var updater = new MetadataUpdater(requestor, config.MarketsFeedUrl, config.SymbolsFeedUrl); var markets = updater.LoadMarkets().Result; var symbols = updater.LoadSymbols().Result; this.persister.SaveMarkets(markets); this.persister.SaveSymbols(symbols); } }
public void UpdateMetadataIfValueIsNotEmptyOrNull() { var updates = new Dictionary <string, string> { { "NumFailedMissions", "1" }, { "PercivalGuess", "Andrea" } }; MetadataUpdater.Update(_metadata, updates); CollectionAssert.AreEquivalent(new Dictionary <string, string> { { "MerlinGuess", "Michael" }, { "NumFailedMissions", "1" }, { "PercivalGuess", "Andrea" }, }, _metadata); }
public static bool MatchTrack(string filename, TrackInfo trackInfo) { foreach (Regex regex in REGEXP_TRACK) { Match match = regex.Match(string.IsNullOrEmpty(trackInfo.TrackName) ? filename : trackInfo.TrackName); if (match.Groups[GROUP_ARTIST].Length > 0 && match.Groups[GROUP_ALBUM].Length > 0 && match.Groups[GROUP_TRACK].Length > 0) { trackInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref trackInfo.TrackName, match.Groups[GROUP_TRACK].Value.Trim(new[] { ' ', '-' })); trackInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref trackInfo.Album, match.Groups[GROUP_ALBUM].Value.Trim(new[] { ' ', '-' })); List <PersonInfo> artists = new List <PersonInfo>() { new PersonInfo() { Name = match.Groups[GROUP_ARTIST].Value.Trim(new[] { ' ', '-' }), Occupation = PersonAspect.OCCUPATION_ARTIST, ParentMediaName = trackInfo.Album, MediaName = trackInfo.TrackName } }; trackInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(trackInfo.Artists, artists, true); List <PersonInfo> albumArtists = new List <PersonInfo>() { new PersonInfo() { Name = match.Groups[GROUP_ARTIST].Value.Trim(new[] { ' ', '-' }), Occupation = PersonAspect.OCCUPATION_ARTIST, ParentMediaName = trackInfo.Album, MediaName = trackInfo.TrackName } }; trackInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(trackInfo.AlbumArtists, albumArtists, true); if (match.Groups[GROUP_TRACK_NUM].Length > 0) { trackInfo.HasChanged |= MetadataUpdater.SetOrUpdateValue(ref trackInfo.TrackNum, Convert.ToInt32(match.Groups[GROUP_TRACK_NUM].Value)); } if (match.Groups[GROUP_DISC_NUM].Length > 0) { trackInfo.HasChanged |= MetadataUpdater.SetOrUpdateValue(ref trackInfo.DiscNum, Convert.ToInt32(match.Groups[GROUP_DISC_NUM].Value)); } return(true); } } return(false); }
public static bool ExtractFromTags(ILocalFsResourceAccessor folderOrFileLfsra, MovieInfo movieInfo) { // Calling EnsureLocalFileSystemAccess not necessary; only string operation string extensionUpper = StringUtils.TrimToEmpty(Path.GetExtension(folderOrFileLfsra.LocalFileSystemPath)).ToUpper(); // Try to get extended information out of MP4 files) if (extensionUpper != ".MP4") { return(false); } using (folderOrFileLfsra.EnsureLocalFileSystemAccess()) { TagLib.File mp4File = TagLib.File.Create(folderOrFileLfsra.LocalFileSystemPath); if (ReferenceEquals(mp4File, null) || ReferenceEquals(mp4File.Tag, null)) { return(false); } TagLib.Tag tag = mp4File.Tag; if (!ReferenceEquals(tag.Genres, null) && tag.Genres.Length > 0) { List <GenreInfo> genreList = tag.Genres.Select(s => new GenreInfo { Name = s }).ToList(); OnlineMatcherService.Instance.AssignMissingMovieGenreIds(genreList); movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(movieInfo.Genres, genreList, movieInfo.Genres.Count == 0); } if (!ReferenceEquals(tag.Performers, null) && tag.Performers.Length > 0) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(movieInfo.Actors, tag.Performers.Select(t => new PersonInfo() { Name = t, Occupation = PersonAspect.OCCUPATION_ACTOR, MediaName = movieInfo.MovieName.Text }).ToList(), false); } //Clean up memory mp4File.Dispose(); return(true); } }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is CompanyInfo company) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, company.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, company.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, company.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvMazeId, company.TvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicBrainzId, company.MusicBrainzId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AudioDbId, company.AudioDbId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Name, company.Name, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Description, company.Description, overwriteShorterStrings); return(true); } return(false); }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is CharacterInfo character) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, character.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, character.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvMazeId, character.TvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ActorTvdbId, character.ActorTvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ActorMovieDbId, character.ActorMovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ActorTvMazeId, character.ActorTvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ActorTvRageId, character.ActorTvRageId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Name, character.Name, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref ActorName, character.ActorName, overwriteShorterStrings); return(true); } return(false); }
public static bool MatchTitleYear(string path, MovieInfo movieInfo) { try { if (string.IsNullOrEmpty(path)) { return(false); } if (!string.IsNullOrEmpty(movieInfo.ImdbId)) { //Remove IMDB id from file name because it can lead to wrong detection of year if (path.Contains("[" + movieInfo.ImdbId + "]")) { path = path.Replace("[" + movieInfo.ImdbId + "]", ""); } else { path = path.Replace(movieInfo.ImdbId, ""); } } var settings = ServiceRegistration.Get <ISettingsManager>().Load <MovieMetadataExtractorSettings>(); foreach (SerializableRegex regex in settings.MovieYearPatterns) { Match match = regex.Regex.Match(path); if (match.Groups[GROUP_TITLE].Length > 0 || match.Groups[GROUP_YEAR].Length > 0) { ServiceRegistration.Get <ILogger>().Info("MovieNameMatcher: Found title '{0}' and year {1}", match.Groups[GROUP_TITLE].Value, match.Groups[GROUP_YEAR].Value); string title = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(match.Groups[GROUP_TITLE].Value.Trim(new[] { ' ', '-' })); movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref movieInfo.MovieName, title, true); movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateValue(ref movieInfo.ReleaseDate, new DateTime(int.Parse(match.Groups[GROUP_YEAR].Value), 1, 1)); return(true); } } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Error("MovieNameMatcher: Exception matching title year for title '{0}'", e, movieInfo.MovieName); } return(false); }
public override bool UpdateFromOnlineSeriesEpisode(EpisodeInfo episode, string language, bool cacheOnly) { try { List <EpisodeInfo> episodeDetails = new List <EpisodeInfo>(); OmDbEpisode episodeDetail = null; if (!string.IsNullOrEmpty(episode.SeriesImdbId) && episode.SeasonNumber.HasValue && episode.EpisodeNumbers.Count > 0) { OmDbSeason seasonDetail = _omDbHandler.GetSeriesSeason(episode.SeriesImdbId, 1, cacheOnly); foreach (int episodeNumber in episode.EpisodeNumbers) { episodeDetail = _omDbHandler.GetSeriesEpisode(episode.SeriesImdbId, episode.SeasonNumber.Value, episodeNumber, cacheOnly); if (episodeDetail == null) { continue; } if (episodeDetail.EpisodeNumber <= 0) { continue; } EpisodeInfo info = new EpisodeInfo() { ImdbId = episodeDetail.ImdbID, SeriesImdbId = episodeDetail.ImdbSeriesID, SeriesName = new SimpleTitle(seasonDetail.Title, true), SeriesFirstAired = seasonDetail != null && seasonDetail.Episodes != null && seasonDetail.Episodes.Count > 0 ? seasonDetail.Episodes[0].Released : default(DateTime?), SeasonNumber = episodeDetail.SeasonNumber, EpisodeNumbers = episodeDetail.EpisodeNumber.HasValue ? new List <int>(new int[] { episodeDetail.EpisodeNumber.Value }) : null, FirstAired = episodeDetail.Released, EpisodeName = new SimpleTitle(episodeDetail.Title, true), Summary = new SimpleTitle(episodeDetail.Plot, true), Genres = episodeDetail.Genres.Select(s => new GenreInfo { Name = s }).ToList(), }; if (episodeDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref info.Rating, new SimpleRating(episodeDetail.ImdbRating, episodeDetail.ImdbVotes)); } if (episodeDetail.TomatoRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref info.Rating, new SimpleRating(episodeDetail.TomatoRating, episodeDetail.TomatoTotalReviews)); } if (episodeDetail.TomatoUserRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref info.Rating, new SimpleRating(episodeDetail.TomatoUserRating, episodeDetail.TomatoUserTotalReviews)); } //Only use these if absolutely necessary because there is no way to ID them if (episode.Actors == null || episode.Actors.Count == 0) { info.Actors = ConvertToPersons(episodeDetail.Actors, PersonAspect.OCCUPATION_ARTIST, episodeDetail.Title, seasonDetail.Title); } if (episode.Directors == null || episode.Directors.Count == 0) { info.Directors = ConvertToPersons(episodeDetail.Writers, PersonAspect.OCCUPATION_DIRECTOR, episodeDetail.Title, seasonDetail.Title); } if (episode.Writers == null || episode.Writers.Count == 0) { info.Writers = ConvertToPersons(episodeDetail.Directors, PersonAspect.OCCUPATION_WRITER, episodeDetail.Title, seasonDetail.Title); } episodeDetails.Add(info); } } if (episodeDetails.Count > 1) { SetMultiEpisodeDetails(episode, episodeDetails); return(true); } else if (episodeDetails.Count > 0) { SetEpisodeDetails(episode, episodeDetails[0]); return(true); } return(false); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing episode {0}", ex, episode.ToString()); return(false); } }
public static async Task <bool> ExtractFromTagsAsync(ILocalFsResourceAccessor folderOrFileLfsra, MovieInfo movieInfo) { // Calling EnsureLocalFileSystemAccess not necessary; only string operation string extensionLower = StringUtils.TrimToEmpty(Path.GetExtension(folderOrFileLfsra.LocalFileSystemPath)).ToLower(); if (!MatroskaConsts.MATROSKA_VIDEO_EXTENSIONS.Contains(extensionLower)) { return(false); } // Try to get extended information out of matroska files) MatroskaBinaryReader mkvReader = new MatroskaBinaryReader(folderOrFileLfsra); // Add keys to be extracted to tags dictionary, matching results will returned as value Dictionary <string, IList <string> > tagsToExtract = MatroskaConsts.DefaultVideoTags; await mkvReader.ReadTagsAsync(tagsToExtract).ConfigureAwait(false); // Read plot IList <string> tags = tagsToExtract[MatroskaConsts.TAG_EPISODE_SUMMARY]; string plot = tags != null?tags.FirstOrDefault() : string.Empty; if (!string.IsNullOrEmpty(plot)) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref movieInfo.Summary, plot, true); } // Read genre tags = tagsToExtract[MatroskaConsts.TAG_SERIES_GENRE]; if (tags != null) { List <GenreInfo> genreList = tags.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(); movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(movieInfo.Genres, genreList, movieInfo.Genres.Count == 0); } // Read actors tags = tagsToExtract[MatroskaConsts.TAG_ACTORS]; if (tags != null) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(movieInfo.Actors, tags.Select(t => new PersonInfo() { Name = t, Occupation = PersonAspect.OCCUPATION_ACTOR, MediaName = movieInfo.MovieName.Text }).ToList(), false); } tags = tagsToExtract[MatroskaConsts.TAG_DIRECTORS]; if (tags != null) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(movieInfo.Directors, tags.Select(t => new PersonInfo() { Name = t, Occupation = PersonAspect.OCCUPATION_DIRECTOR, MediaName = movieInfo.MovieName.Text }).ToList(), false); } tags = tagsToExtract[MatroskaConsts.TAG_WRITTEN_BY]; if (tags != null) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(movieInfo.Writers, tags.Select(t => new PersonInfo() { Name = t, Occupation = PersonAspect.OCCUPATION_WRITER, MediaName = movieInfo.MovieName.Text }).ToList(), false); } if (tagsToExtract[MatroskaConsts.TAG_MOVIE_IMDB_ID] != null) { string imdbId; foreach (string candidate in tagsToExtract[MatroskaConsts.TAG_MOVIE_IMDB_ID]) { if (ImdbIdMatcher.TryMatchImdbId(candidate, out imdbId)) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateId(ref movieInfo.ImdbId, imdbId); break; } } } if (tagsToExtract[MatroskaConsts.TAG_MOVIE_TMDB_ID] != null) { int tmp; foreach (string candidate in tagsToExtract[MatroskaConsts.TAG_MOVIE_TMDB_ID]) { if (int.TryParse(candidate, out tmp) == true) { movieInfo.HasChanged |= MetadataUpdater.SetOrUpdateId(ref movieInfo.MovieDbId, tmp); break; } } } return(true); }
public override bool MergeWith(object other, bool overwriteShorterStrings = false, bool updateTrackList = false) { if (other is AlbumInfo album) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref AudioDbId, album.AudioDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CdDdId, album.CdDdId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicBrainzDiscId, album.MusicBrainzDiscId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicBrainzGroupId, album.MusicBrainzGroupId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MusicBrainzId, album.MusicBrainzId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AmazonId, album.AmazonId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ItunesId, album.ItunesId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref UpcEanId, album.UpcEanId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomIds, album.CustomIds); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Album, album.Album, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Description, album.Description, overwriteShorterStrings); if (TotalTracks < album.TotalTracks) { HasChanged = true; TotalTracks = album.TotalTracks; } HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Compilation, album.Compilation); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref DiscNum, album.DiscNum); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref ReleaseDate, album.ReleaseDate); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Sales, album.Sales); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref TotalDiscs, album.TotalDiscs); HasChanged |= MetadataUpdater.SetOrUpdateRatings(ref Rating, album.Rating); if (Genres.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(Genres, album.Genres.Distinct().ToList(), true); } HasChanged |= MetadataUpdater.SetOrUpdateList(Awards, album.Awards.Distinct().ToList(), true); //These lists contain Ids and other properties that are not persisted, so they will always appear changed. //So changes to these lists will only be stored if something else has changed. MetadataUpdater.SetOrUpdateList(Artists, album.Artists.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Artists.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(MusicLabels, album.MusicLabels.Where(c => !string.IsNullOrEmpty(c.Name)).Distinct().ToList(), MusicLabels.Count == 0, overwriteShorterStrings); if (updateTrackList) //Comparing all tracks can be quite time consuming { MetadataUpdater.SetOrUpdateList(Tracks, album.Tracks.Distinct().ToList(), true, overwriteShorterStrings); List <string> artists = new List <string>(); foreach (TrackInfo track in album.Tracks) { if (track.Artists.Count > 0) { if (!artists.Contains(track.Artists[0].Name)) { artists.Add(track.Artists[0].Name); } } } if (album.Tracks.Count > 5 && (float)artists.Count > (float)album.Tracks.Count * 0.6 && !Compilation) { Compilation = true; HasChanged = true; } } if (Artists.Count > 0 && !Compilation && (Artists[0].Name.IndexOf("Various", StringComparison.InvariantCultureIgnoreCase) >= 0 || Artists[0].Name.Equals("VA", StringComparison.InvariantCultureIgnoreCase))) { Compilation = true; HasChanged = true; } MergeDataProviders(album); return(true); } 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 match series by reading matroska tags from <paramref name="folderOrFileLfsra"/>. /// </summary> /// <param name="folderOrFileLfsra"><see cref="ILocalFsResourceAccessor"/> to file or folder</param> /// <param name="episodeInfo">Returns the parsed EpisodeInfo</param> /// <param name="extractedAspectData">Dictionary containing a mapping of media item aspect ids to /// already present media item aspects, this metadata extractor should edit. If a media item aspect is not present /// in this dictionary but found by this metadata extractor, it will add it to the dictionary.</param> /// <returns><c>true</c> if successful.</returns> public bool MatchSeries(ILocalFsResourceAccessor folderOrFileLfsra, EpisodeInfo episodeInfo) { // Calling EnsureLocalFileSystemAccess not necessary; only string operation string extensionLower = StringUtils.TrimToEmpty(Path.GetExtension(folderOrFileLfsra.LocalFileSystemPath)).ToLower(); if (!MatroskaConsts.MATROSKA_VIDEO_EXTENSIONS.Contains(extensionLower)) { return(false); } MatroskaInfoReader mkvReader = new MatroskaInfoReader(folderOrFileLfsra); // Add keys to be extracted to tags dictionary, matching results will returned as value Dictionary <string, IList <string> > tagsToExtract = MatroskaConsts.DefaultTags; mkvReader.ReadTags(tagsToExtract); IList <string> tags = tagsToExtract[MatroskaConsts.TAG_EPISODE_SUMMARY]; string plot = tags != null?tags.FirstOrDefault() : string.Empty; if (!string.IsNullOrEmpty(plot)) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref episodeInfo.Summary, plot, true); } // Series and episode handling. Prefer information from tags. if (tagsToExtract[MatroskaConsts.TAG_EPISODE_TITLE] != null) { string title = tagsToExtract[MatroskaConsts.TAG_EPISODE_TITLE].FirstOrDefault(); if (!string.IsNullOrEmpty(title)) { title = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(title); episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref episodeInfo.EpisodeName, title, true); } } if (tagsToExtract[MatroskaConsts.TAG_SERIES_TITLE] != null) { string title = tagsToExtract[MatroskaConsts.TAG_SERIES_TITLE].FirstOrDefault(); if (!string.IsNullOrEmpty(title)) { title = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(title); episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref episodeInfo.SeriesName, title, true); } } if (tagsToExtract[MatroskaConsts.TAG_SERIES_IMDB_ID] != null) { string imdbId; foreach (string candidate in tagsToExtract[MatroskaConsts.TAG_SERIES_IMDB_ID]) { if (ImdbIdMatcher.TryMatchImdbId(candidate, out imdbId)) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateId(ref episodeInfo.SeriesImdbId, imdbId); break; } } } if (tagsToExtract[MatroskaConsts.TAG_SERIES_ACTORS] != null) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateList(episodeInfo.Actors, tagsToExtract[MatroskaConsts.TAG_SERIES_ACTORS].Select(t => new PersonInfo() { Name = t, Occupation = PersonAspect.OCCUPATION_ACTOR, MediaName = episodeInfo.EpisodeName.Text, ParentMediaName = episodeInfo.SeriesName.Text }).ToList(), false); } // On Series, the counting tag is "TVDB" if (tagsToExtract[MatroskaConsts.TAG_SERIES_TVDB_ID] != null) { int tmp; foreach (string candidate in tagsToExtract[MatroskaConsts.TAG_SERIES_TVDB_ID]) { if (int.TryParse(candidate, out tmp) == true) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateId(ref episodeInfo.SeriesTvdbId, tmp); break; } } } int tmpInt; if (tagsToExtract[MatroskaConsts.TAG_SEASON_NUMBER] != null && int.TryParse(tagsToExtract[MatroskaConsts.TAG_SEASON_NUMBER].FirstOrDefault(), out tmpInt)) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateValue(ref episodeInfo.SeasonNumber, tmpInt); } if (tagsToExtract[MatroskaConsts.TAG_EPISODE_NUMBER] != null) { int episodeNum; foreach (string s in tagsToExtract[MatroskaConsts.TAG_EPISODE_NUMBER]) { if (int.TryParse(s, out episodeNum)) { if (!episodeInfo.EpisodeNumbers.Contains(episodeNum)) { episodeInfo.EpisodeNumbers.Add(episodeNum); } } } } return(true); }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updateEpisodeList = false) { if (other is SeriesInfo series) { //Reset next episode data because it was already aired if (NextEpisodeAirDate.HasValue && NextEpisodeAirDate.Value < DateTime.Now) { NextEpisodeAirDate = null; NextEpisodeNumber = null; NextEpisodeSeasonNumber = null; NextEpisodeName = null; HasChanged = true; } HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvdbId, series.TvdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, series.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, series.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvMazeId, series.TvMazeId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref TvRageId, series.TvRageId); HasChanged |= MetadataUpdater.SetOrUpdateString(ref SeriesName, series.SeriesName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref OriginalName, series.OriginalName); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Description, series.Description, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Certification, series.Certification); HasChanged |= MetadataUpdater.SetOrUpdateString(ref NextEpisodeName, series.NextEpisodeName); if (TotalSeasons < series.TotalSeasons) { HasChanged = true; TotalSeasons = series.TotalSeasons; } if (TotalEpisodes < series.TotalEpisodes) { HasChanged = true; TotalEpisodes = series.TotalEpisodes; } HasChanged |= MetadataUpdater.SetOrUpdateValue(ref FirstAired, series.FirstAired); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Popularity, series.Popularity); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref IsEnded, series.IsEnded); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref NextEpisodeAirDate, series.NextEpisodeAirDate); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref NextEpisodeNumber, series.NextEpisodeNumber); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref NextEpisodeSeasonNumber, series.NextEpisodeSeasonNumber); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Score, series.Score); HasChanged |= MetadataUpdater.SetOrUpdateRatings(ref Rating, series.Rating); if (Genres.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(Genres, series.Genres.Distinct().ToList(), true); } HasChanged |= MetadataUpdater.SetOrUpdateList(Awards, series.Awards.Distinct().ToList(), true); //These lists contain Ids and other properties that are not persisted, so they will always appear changed. //So changes to these lists will only be stored if something else has changed. MetadataUpdater.SetOrUpdateList(Networks, series.Networks.Where(c => !string.IsNullOrEmpty(c.Name)).Distinct().ToList(), Networks.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(ProductionCompanies, series.ProductionCompanies.Where(c => !string.IsNullOrEmpty(c.Name)).Distinct().ToList(), ProductionCompanies.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Actors, series.Actors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Actors.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Characters, series.Characters.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Characters.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Seasons, series.Seasons, true, overwriteShorterStrings); if (updateEpisodeList) //Comparing all episodes can be quite time consuming { //Only allow new episodes if empty. Online sources might have different names for same series so season name would look strange. bool allowAdd = Episodes.Count == 0; for (int matchIndex = 0; matchIndex < series.Episodes.Count; matchIndex++) { int existing = Episodes.IndexOf(series.Episodes[matchIndex]); if (existing >= 0) { //Don't merge with existing specials. They seem to be different on various online sources. if ((Episodes[existing].SeasonNumber.HasValue && Episodes[existing].SeasonNumber.Value > 0) && (series.Episodes[matchIndex].SeasonNumber.HasValue && series.Episodes[matchIndex].SeasonNumber.Value > 0)) { Episodes[existing].MergeWith(series.Episodes[matchIndex], overwriteShorterStrings); } } else if (allowAdd) { Episodes.Add(series.Episodes[matchIndex]); } } Episodes.Sort(); } return(true); } return(false); }
public void Setup() { this.updater = new MetadataUpdater(this.requestor, CONST_MarketsFeedUrl, CONST_SymbolsFeedUrl); }
public override bool MergeWith(object other, bool overwriteShorterStrings = true, bool updatePrimaryChildList = false) { if (other is MovieInfo movie) { HasChanged |= MetadataUpdater.SetOrUpdateId(ref ImdbId, movie.ImdbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref MovieDbId, movie.MovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CollectionMovieDbId, movie.CollectionMovieDbId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref AllocinebId, movie.AllocinebId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CinePassionId, movie.CinePassionId); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomIds, movie.CustomIds); HasChanged |= MetadataUpdater.SetOrUpdateId(ref CustomCollectionIds, movie.CustomCollectionIds); HasChanged |= MetadataUpdater.SetOrUpdateString(ref MovieName, movie.MovieName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref OriginalName, movie.OriginalName); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Summary, movie.Summary, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Certification, movie.Certification, false); HasChanged |= MetadataUpdater.SetOrUpdateString(ref CollectionName, movie.CollectionName, overwriteShorterStrings); HasChanged |= MetadataUpdater.SetOrUpdateString(ref Tagline, movie.Tagline); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Budget, movie.Budget); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Revenue, movie.Revenue); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Runtime, movie.Runtime); if (movie.ReleaseDate.HasValue && movie.ReleaseDate.Value.Year > 1800) { if (!ReleaseDate.HasValue || ReleaseDate > movie.ReleaseDate) { ReleaseDate = movie.ReleaseDate; HasChanged = true; } } HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Popularity, movie.Popularity); HasChanged |= MetadataUpdater.SetOrUpdateValue(ref Score, movie.Score); HasChanged |= MetadataUpdater.SetOrUpdateRatings(ref Rating, movie.Rating); if (Genres.Count == 0) { HasChanged |= MetadataUpdater.SetOrUpdateList(Genres, movie.Genres.Distinct().ToList(), true); } HasChanged |= MetadataUpdater.SetOrUpdateList(Awards, movie.Awards.Distinct().ToList(), true); //Limit the number of persons if (Actors.Count == 0 && movie.Actors.Count > MAX_PERSONS) { movie.Actors.RemoveRange(MAX_PERSONS, movie.Actors.Count - MAX_PERSONS); } if (Characters.Count == 0 && movie.Characters.Count > MAX_PERSONS) { movie.Characters.RemoveRange(MAX_PERSONS, movie.Characters.Count - MAX_PERSONS); } if (Directors.Count == 0 && movie.Directors.Count > MAX_PERSONS) { movie.Directors.RemoveRange(MAX_PERSONS, movie.Directors.Count - MAX_PERSONS); } if (Writers.Count == 0 && movie.Writers.Count > MAX_PERSONS) { movie.Writers.RemoveRange(MAX_PERSONS, movie.Writers.Count - MAX_PERSONS); } //These lists contain Ids and other properties that are not persisted, so they will always appear changed. //So changes to these lists will only be stored if something else has changed. MetadataUpdater.SetOrUpdateList(Actors, movie.Actors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Actors.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Characters, movie.Characters.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Characters.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Directors, movie.Directors.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Directors.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(ProductionCompanies, movie.ProductionCompanies.Where(c => !string.IsNullOrEmpty(c.Name)).Distinct().ToList(), ProductionCompanies.Count == 0, overwriteShorterStrings); MetadataUpdater.SetOrUpdateList(Writers, movie.Writers.Where(p => !string.IsNullOrEmpty(p.Name)).Distinct().ToList(), Writers.Count == 0, overwriteShorterStrings); MergeDataProviders(movie); return(true); } return(false); }
static bool ParseSeries(Match ma, EpisodeInfo episodeInfo) { if (!ma.Success) { return(false); } Group group = ma.Groups[GROUP_SERIES]; if (group.Length > 0) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref episodeInfo.SeriesName, EpisodeInfo.CleanupWhiteSpaces(group.Value), true); } group = ma.Groups[GROUP_EPISODE]; if (group.Length > 0) { episodeInfo.HasChanged |= MetadataUpdater.SetOrUpdateString(ref episodeInfo.EpisodeName, EpisodeInfo.CleanupWhiteSpaces(group.Value), true); } group = ma.Groups[GROUP_SEASONNUM]; int tmpInt; if (group.Length > 0 && int.TryParse(group.Value, out tmpInt)) { episodeInfo.SeasonNumber = tmpInt; } // There can be multiple episode numbers in one file group = ma.Groups[GROUP_EPISODENUM]; if (group.Length > 0) { List <int> episodeNums = new List <int>(); if (group.Captures.Count > 1) { foreach (Capture capture in group.Captures) { int episodeNum; if (int.TryParse(capture.Value, out episodeNum)) { episodeNums.Add(episodeNum); } } } else if (ma.Groups[GROUP_ENDEPISODENUM].Length > 0) { int start; if (int.TryParse(group.Value, out start)) { int end; group = ma.Groups[GROUP_ENDEPISODENUM]; if (group.Length > 0 && int.TryParse(group.Value, out end)) { for (int episode = start; episode <= end; episode++) { episodeNums.Add(episode); } } } } else { foreach (Capture capture in group.Captures) { int episodeNum; if (int.TryParse(capture.Value, out episodeNum)) { episodeNums.Add(episodeNum); } } } if (episodeNums.Count > 0 && !episodeInfo.EpisodeNumbers.SequenceEqual(episodeNums)) { episodeInfo.HasChanged = true; episodeInfo.EpisodeNumbers = new List <int>(episodeNums); } } return(true); }
public override bool UpdateFromOnlineSeries(SeriesInfo series, string language, bool cacheOnly) { try { OmDbSeries seriesDetail = null; if (!string.IsNullOrEmpty(series.ImdbId)) { seriesDetail = _omDbHandler.GetSeries(series.ImdbId, cacheOnly); } if (seriesDetail == null) { return(false); } series.ImdbId = seriesDetail.ImdbID; series.SeriesName = new SimpleTitle(seriesDetail.Title, true); series.FirstAired = seriesDetail.Released; series.Description = new SimpleTitle(seriesDetail.Plot, true); if (seriesDetail.EndYear.HasValue) { series.IsEnded = true; } series.Certification = seriesDetail.Rated; List <string> awards = new List <string>(); if (!string.IsNullOrEmpty(seriesDetail.Awards)) { if (seriesDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || seriesDetail.Awards.IndexOf(" Oscar", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Oscar"); } if (seriesDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || seriesDetail.Awards.IndexOf(" Golden Globe", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Golden Globe"); } series.Awards = awards; } if (seriesDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.ImdbRating, seriesDetail.ImdbVotes)); } if (seriesDetail.TomatoRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.TomatoRating, seriesDetail.TomatoTotalReviews)); } if (seriesDetail.TomatoUserRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.TomatoUserRating, seriesDetail.TomatoUserTotalReviews)); } series.Genres = seriesDetail.Genres.Select(s => new GenreInfo { Name = s }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (seriesDetail.Actors == null || seriesDetail.Actors.Count == 0) { series.Actors = ConvertToPersons(seriesDetail.Actors, PersonAspect.OCCUPATION_ACTOR, null, seriesDetail.Title); } //Episode listing is currently not optimal //OmDbSeason seasonDetails = null; //OmDbSeasonEpisode nextEpisode = null; //int seasonNumber = 1; //while (true) //{ // seasonDetails = _omDbHandler.GetSeriesSeason(series.ImdbId, seasonNumber, cacheOnly); // if (seasonDetails != null) // { // SeasonInfo seasonInfo = new SeasonInfo() // { // SeriesImdbId = seriesDetail.ImdbID, // SeriesName = new SimpleTitle(seriesDetail.Title, true), // SeasonNumber = seasonDetails.SeasonNumber, // FirstAired = seasonDetails.Episodes.First().Released, // TotalEpisodes = seasonDetails.Episodes.Count // }; // if (!series.Seasons.Contains(seasonInfo)) // series.Seasons.Add(seasonInfo); // foreach (OmDbSeasonEpisode episodeDetail in seasonDetails.Episodes) // { // if (episodeDetail.EpisodeNumber <= 0) continue; // EpisodeInfo info = new EpisodeInfo() // { // ImdbId = episodeDetail.ImdbID, // SeriesImdbId = seriesDetail.ImdbID, // SeriesName = new SimpleTitle(seriesDetail.Title, true), // SeriesFirstAired = series.FirstAired, // SeasonNumber = seasonNumber, // EpisodeNumbers = new List<int>(new int[] { episodeDetail.EpisodeNumber }), // FirstAired = episodeDetail.Released, // EpisodeName = new SimpleTitle(episodeDetail.Title, true), // }; // series.Episodes.Add(info); // if (nextEpisode == null && episodeDetail.Released > DateTime.Now) // { // series.NextEpisodeName = new SimpleTitle(episodeDetail.Title, true); // series.NextEpisodeAirDate = episodeDetail.Released; // series.NextEpisodeSeasonNumber = seasonDetails.SeasonNumber; // series.NextEpisodeNumber = episodeDetail.EpisodeNumber; // } // } // seasonNumber++; // } // else // { // break; // } //} series.TotalSeasons = series.Seasons.Count; series.TotalEpisodes = series.Episodes.Count; return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing series {0}", ex, series.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); } }
/// <summary> /// Tries to match series by checking the <paramref name="folderOrFileName"/> for known patterns. The match is only successful, /// if the <see cref="EpisodeInfo.IsBaseInfoPresent"/> is <c>true</c>. /// </summary> /// <param name="folderOrFileName">Full path to file</param> /// <param name="episodeInfo">Returns the parsed EpisodeInfo</param> /// <returns><c>true</c> if successful.</returns> public bool MatchSeries(string folderOrFileName, EpisodeInfo episodeInfo) { var settings = ServiceRegistration.Get <ISettingsManager>().Load <SeriesMetadataExtractorSettings>(); // General cleanup for remote mounted resources (will be a local path) string remoteResourcePattern = @".*\\RemoteResources\\[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\\"; Regex re = new Regex(remoteResourcePattern, RegexOptions.IgnoreCase | RegexOptions.Multiline); folderOrFileName = re.Replace(folderOrFileName, ""); // First do replacements before match foreach (var replacement in settings.Replacements.Where(r => r.BeforeMatch)) { replacement.Replace(ref folderOrFileName); } foreach (var pattern in settings.SeriesPatterns) { // Calling EnsureLocalFileSystemAccess not necessary; only string operation Regex matcher; if (pattern.GetRegex(out matcher)) { Match ma = matcher.Match(folderOrFileName); ParseSeries(ma, episodeInfo); if (episodeInfo.IsBaseInfoPresent) { // Do replacements after successful match foreach (var replacement in settings.Replacements.Where(r => !r.BeforeMatch)) { string tmp; if (!episodeInfo.SeriesName.IsEmpty) { tmp = episodeInfo.SeriesName.Text; replacement.Replace(ref tmp); episodeInfo.SeriesName.Text = tmp; } if (!episodeInfo.EpisodeName.IsEmpty) { tmp = episodeInfo.EpisodeName.Text; replacement.Replace(ref tmp); episodeInfo.EpisodeName.Text = tmp; } } if (!episodeInfo.SeriesName.IsEmpty) { Match yearMa = settings.SeriesYearPattern.Regex.Match(episodeInfo.SeriesName.Text); if (yearMa.Success) { //episodeInfo.SeriesName = new SimpleTitle(EpisodeInfo.CleanupWhiteSpaces(yearMa.Groups[GROUP_SERIES].Value), episodeInfo.SeriesName.DefaultLanguage); MetadataUpdater.SetOrUpdateValue(ref episodeInfo.SeriesFirstAired, new DateTime(Convert.ToInt32(yearMa.Groups[GROUP_YEAR].Value), 1, 1)); } yearMa = settings.SeriesYearPattern.Regex.Match(folderOrFileName); if (yearMa.Success) { MetadataUpdater.SetOrUpdateValue(ref episodeInfo.SeriesFirstAired, new DateTime(Convert.ToInt32(yearMa.Groups[GROUP_YEAR].Value), 1, 1)); } } return(true); } } } return(false); }