/// <summary> /// Load the Connex data of the Metadata in the background /// </summary> ///<param name="max">Max number of Persons which can be retrieved (downloaded/saved)</param> public void LoadAsync(int max = int.MaxValue) { if (TagLibFile != null && TagLibFile.Tag != null) { //LimeMsg.Debug("LimeMetadata LoadAsync: {0}", TagLibFile.Name); bool isVideo = Type == MediaType.Video; LimePerson.Cancel(); var list = new List <LimePerson>(10); var cond = Get(isVideo ? "Director" : "Conductor"); if (cond != null && cond.Content is string person) { if (!string.IsNullOrWhiteSpace(person)) { list.Add(new LimePerson(person, new string[] { cond.Name })); } } var perf = Get(isVideo ? "Actors" : "Artists"); if (perf != null && perf.Content is StringComposite <LimePerson> persons && persons.Collection != null) { foreach (var pers in persons.Collection) { list.Add(pers); } Persons = persons.Collection; } else { Persons = null; } // Start with the end as this is a LIFO stack for (int i = list.Count - 1; i >= 0; i--) { var pers = list[i]; if (!pers.IsLoaded) { pers.LoadAsync(i < max); } } } }
/// <summary> /// Update a Person data from TMDb /// </summary> /// <param name="person">Person to be updated</param> /// <returns>true if updated</returns> public async Task <bool> GetPersonAsync(LimePerson person) { Connect(); // Retrieve person-ID by name if (person.TmdbId == 0) { var search = await TmdbClient.SearchPersonAsync(person.Name, 0, Adult); if (search.Results != null && search.Results.Count > 0 && string.Equals(search.Results[0].Name, person.Name, StringComparison.InvariantCultureIgnoreCase)) { person.TmdbId = search.Results[0].Id; } } // Retrieve person by ID if (person.TmdbId != 0) { var db = await TmdbClient.GetPersonAsync( person.TmdbId, TMDbLib.Objects.People.PersonMethods.Images | TMDbLib.Objects.People.PersonMethods.MovieCredits ); if (db == null) { return(false); } var pics = new List <LimePicture>(10); foreach (var img in db.Images.Profiles) { DownloadPic(ref pics, img.FilePath, PictureType.Artist); } person.Pictures = pics.ToArray(); person.ImdbId = db.ImdbId; person.TmdbPage = db.ProfilePath; person.Name = db.Name; person.Alias = db.AlsoKnownAs?.ToArray(); person.Gender = (LimePerson.PersonGender)db.Gender; person.Adult = db.Adult; person.Birthday = db.Birthday; person.Deathday = db.Deathday; person.Biography = CleanupDescription.Replace(db.Biography).Trim(); person.Homepage = db.Homepage; // Build Opus var opus = new List <LimeOpus>(); if (db.MovieCredits?.Cast != null) { foreach (var cast in db.MovieCredits.Cast) { // Avoid duplicates var op = opus.Find(o => o.TmdbId == cast.Id); if (op != null) { if (!op.Roles.Contains(cast.Character)) { op.Roles.Add(cast.Character); } } else { op = new LimeOpus(LimeOpusType.Movie, cast.Id, cast.Title, cast.Character) { OriginalTitle = cast.OriginalTitle, Adult = cast.Adult, Released = cast.ReleaseDate != null ? (uint)cast.ReleaseDate.Value.Year : 0 }; if (cast.PosterPath != null) { op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri; } opus.Add(op); } } } if (db.TvCredits?.Cast != null) { foreach (var cast in db.TvCredits.Cast) { // Avoid duplicates var op = opus.Find(o => o.TmdbId == cast.Id); if (op != null) { if (!op.Roles.Contains(cast.Character)) { op.Roles.Add(cast.Character); } } else { op = new LimeOpus(LimeOpusType.TvShow, cast.Id, cast.Name, cast.Character) { OriginalTitle = cast.OriginalName, Released = cast.FirstAirDate != null ? (uint)cast.FirstAirDate.Value.Year : 0 }; if (cast.PosterPath != null) { op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri; } opus.Add(op); } } } if (db.MovieCredits?.Crew != null) { foreach (var cast in db.MovieCredits.Crew) { // Avoid duplicates var op = opus.Find(o => o.TmdbId == cast.Id); if (op != null) { if (!op.Roles.Contains(cast.Department)) { op.Roles.Add(cast.Department); } } else { op = new LimeOpus(LimeOpusType.Movie, cast.Id, cast.Title, cast.Department) { OriginalTitle = cast.OriginalTitle, Adult = cast.Adult, Released = cast.ReleaseDate != null ? (uint)cast.ReleaseDate.Value.Year : 0 }; if (cast.PosterPath != null) { op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri; } opus.Add(op); } } } if (db.TvCredits?.Crew != null) { foreach (var cast in db.TvCredits.Crew) { // Avoid duplicates var op = opus.Find(o => o.TmdbId == cast.Id); if (op != null) { if (!op.Roles.Contains(cast.Department)) { op.Roles.Add(cast.Department); } } else { op = new LimeOpus(LimeOpusType.TvShow, cast.Id, cast.Name, cast.Department) { OriginalTitle = cast.OriginalName, Released = cast.FirstAirDate != null ? (uint)cast.FirstAirDate.Value.Year : 0 }; if (cast.PosterPath != null) { op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri; } opus.Add(op); } } } // Set genres foreach (var op in opus) { if (op.Adult) { op.Genres = new string[] { LimeLanguage.Translate(IniLanguageSection, "GenreAdult", "GenreAdult") } } ; op.BuildToolTip(); } person.Opus = opus.ToArray(); return(true); } return(false); }
/// <summary> /// Build the Property collection /// </summary> private void BuildProperties() { bool isVideo = Type == MediaType.Video; Add("Title", TagLibFile.Tag, "Title"); if (Type == MediaType.Image) { var ptag = TagLibFile.Tag as TagLib.Image.CombinedImageTag; if (ptag != null) { Add("Date", ptag, "DateTime", allowEmpty: true); Add("Model", ptag, "Model"); Add("ISO", ptag, "ISOSpeedRatings"); } } else if ((Type & (MediaType.Video | MediaType.Audio)) != 0) { Add("Tagline", TagLibFile.Tag, "Subtitle", multiline: true); Add("Description", TagLibFile.Tag, "Description", multiline: true); Add("Comment", TagLibFile.Tag, "Comment", multiline: true); Add("DateTagged", TagLibFile.Tag, "DateTagged", readOnly: true, allowEmpty: true); if (TagLibFile.Properties != null && TagLibFile.Properties.Duration > TimeSpan.Zero) { string val = FormatValue("DurationHMS", TagLibFile.Properties.Duration.Hours, TagLibFile.Properties.Duration.Minutes, TagLibFile.Properties.Duration.Seconds); Add("Duration", val, true, allowEmpty: true); } Add("Genres", new StringComposite <string>(TagLibFile.Tag.Genres)); Add("Released", TagLibFile.Tag, "Year", allowEmpty: true); Add(isVideo ? "Collection" : "Album", TagLibFile.Tag, "Album"); Add(isVideo ? "Season" : "Disc", TagLibFile.Tag, "Disc", allowEmpty: true); Add(isVideo ? "SeasonCount" : "DiscCount", TagLibFile.Tag, "DiscCount", allowEmpty: true); Add(isVideo ? "Episode" : "Track", TagLibFile.Tag, "Track", allowEmpty: true); Add(isVideo ? "EpisodeCount" : "TrackCount", TagLibFile.Tag, "TrackCount", allowEmpty: true); // retrieve the conductor Add(isVideo ? "Director" : "Conductor", TagLibFile.Tag, "Conductor"); // Retrieve the persons/characters LimePerson[] persons; if (TagLibFile.Tag.Performers != null) { persons = new LimePerson[TagLibFile.Tag.Performers.Length]; for (int i = 0; i < persons.Length; i++) { var name = TagLibFile.Tag.Performers[i]; string[] roles = null; if (TagLibFile.Tag.PerformersRole != null && i < TagLibFile.Tag.PerformersRole.Length) { roles = TagLibFile.Tag.PerformersRole[i]?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (roles != null) { for (int j = 0; j < roles.Length; j++) { roles[j] = roles[j].Trim(); } } } persons[i] = new LimePerson(name, roles); } } else { persons = new LimePerson[0]; // enforce type } Add(isVideo ? "Actors" : "Artists", new StringComposite <LimePerson>(persons, ";", Environment.NewLine), null, multiline: true); Add("Pictures", TagLibFile.Tag, "Pictures", visible: false); } }
/// <summary> /// Download the metadata on a movie from TMDB by its TMDB identifier /// </summary> /// <param name="id">TMDB movie identifier</param> /// <returns>Metadata object representing the movie</returns> public async Task <LimeMetadata> GetVideoAsync(int id) { LimeMetadata meta = null; Connect(); Movie movie = await TmdbClient.GetMovieAsync(id, MovieMethods.Images | MovieMethods.Videos | MovieMethods.Reviews | MovieMethods.Credits); // Create Metadata object representing the movie meta = new LimeMetadata(MediaType.Video); // Copy metadata from Web to Tag meta.Add("TMDB_ID", movie.Id, readOnly: true, visible: false); meta.Add("Title", movie.Title); meta.Add("Tagline", movie?.Tagline); meta.Add("Description", CleanupDescription.Replace(movie?.Overview).Trim()); //if (movie.OriginalLanguage != null) meta.Add("OriginalLanguage", movie.OriginalLanguage); meta.Add("Score", movie.VoteAverage != 0 ? movie.VoteAverage / 2.0 : 0.0); meta.Add("Released", movie.ReleaseDate != null ? (uint)movie.ReleaseDate.Value.Year : 0); // Genres var genres = new string[movie.Genres.Count]; for (int i = 0; i < genres.Length; i++) { genres[i] = movie.Genres[i].Name; } meta.Add("Genres", new StringComposite <string>(genres)); // Actors var actors = new List <LimePerson>(); foreach (var cast in movie.Credits.Cast) { var person = new LimePerson(cast.Id, cast.Name, new string[] { cast.Character }); actors.Add(person); } meta.Add("Actors", new StringComposite <LimePerson>(actors, ";", Environment.NewLine)); // Director string director = null; foreach (var crew in movie.Credits.Crew) { switch (crew.Department) { case "Directing": if (director == null) { director = crew.Name; } break; case "Writing": // do nothing so far break; default: // do nothing so far break; } } meta.Add("Director", director); var pics = new List <Picture>(1); DownloadPic(ref pics, movie.PosterPath, PictureType.OtherFileIcon); // Store more images foreach (var img in movie.Images.Posters) { DownloadPic(ref pics, img.FilePath, PictureType.OtherFileIcon); } foreach (var img in movie.Images.Backdrops) { DownloadPic(ref pics, img.FilePath, PictureType.Illustration); } // Collections string collection = null; uint season = 0; uint seasonCount = 0; if (movie.BelongsToCollection != null) { var collec = await TmdbClient.GetCollectionAsync(movie.BelongsToCollection.Id); if (collec != null && collec.Parts != null) { collection = collec.Name; seasonCount = (uint)collec.Parts.Count; for (int i = 0; i < collec.Parts.Count; i++) { if (collec.Parts[i].Id == movie.Id) { season = (uint)i + 1; break; } } DownloadPic(ref pics, collec.PosterPath, PictureType.FrontCover); DownloadPic(ref pics, collec.BackdropPath, PictureType.BackCover); } } meta.Add("Collection", collection); meta.Add("SeasonCount", seasonCount); meta.Add("Season", season); // Finalize images meta.Add("Pictures", pics.ToArray(), false, false); // Finalize meta.BuildToolTip(); return(meta); }