public async Task <MetadataResult <Movie> > GetMetadata(MovieInfo info, CancellationToken cancellationToken) { try { var result = new MetadataResult <Movie>(); var includeGroup = Plugin.Instance.Configuration.BoxSetGrouping == Ordering.GroupType.ShokoGroup; var config = Plugin.Instance.Configuration; Ordering.GroupFilterType?filterByType = config.SeriesGrouping == Ordering.GroupType.ShokoGroup ? config.FilterOnLibraryTypes ? Ordering.GroupFilterType.Movies : Ordering.GroupFilterType.Default : null; var(file, episode, series, group) = await ApiManager.GetFileInfoByPath(info.Path, filterByType); // if file is null then series and episode is also null. if (file == null) { Logger.LogWarning($"Unable to find file info for path {info.Path}"); return(result); } bool isMultiEntry = series.Shoko.Sizes.Total.Episodes > 1; var tags = await ApiManager.GetTags(series.Id); var(displayTitle, alternateTitle) = Text.GetMovieTitles(series.AniDB.Titles, episode.AniDB.Titles, series.Shoko.Name, episode.Shoko.Name, info.MetadataLanguage); var rating = isMultiEntry ? episode.AniDB.Rating.ToFloat(10) : series.AniDB.Rating.ToFloat(10); result.Item = new Movie { IndexNumber = Ordering.GetMovieIndexNumber(group, series, episode), Name = displayTitle, OriginalTitle = alternateTitle, PremiereDate = episode.AniDB.AirDate, // Use the file description if collection contains more than one movie, otherwise use the collection description. Overview = Text.SanitizeTextSummary((isMultiEntry ? episode.AniDB.Description ?? series.AniDB.Description : series.AniDB.Description) ?? ""), ProductionYear = episode.AniDB.AirDate?.Year, Tags = tags, CommunityRating = rating, }; result.Item.SetProviderId("Shoko File", file.Id); result.Item.SetProviderId("Shoko Episode", episode.Id); if (config.AddAniDBId) { result.Item.SetProviderId("AniDB", episode.AniDB.ID.ToString()); } result.HasMetadata = true; ApiManager.MarkSeriesAsFound(series.Id, group.Id); result.ResetPeople(); foreach (var person in await ApiManager.GetPeople(series.Id)) { result.AddPerson(person); } return(result); } catch (Exception e) { Logger.LogError(e, $"Threw unexpectedly; {e.Message}"); return(new MetadataResult <Movie>()); } }
private async Task <MetadataResult <Series> > GetDefaultMetadata(SeriesInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <Series>(); var series = await ApiManager.GetSeriesInfoByPath(info.Path); if (series == null) { Logger.LogWarning($"Unable to find series info for path {info.Path}"); return(result); } Logger.LogInformation($"Found series info for path {info.Path}"); var tags = await ApiManager.GetTags(series.Id); var(displayTitle, alternateTitle) = Text.GetSeriesTitles(series.AniDB.Titles, series.Shoko.Name, info.MetadataLanguage); result.Item = new Series { Name = displayTitle, OriginalTitle = alternateTitle, Overview = Text.SanitizeTextSummary(series.AniDB.Description), PremiereDate = series.AniDB.AirDate, EndDate = series.AniDB.EndDate, ProductionYear = series.AniDB.AirDate?.Year, Status = series.AniDB.EndDate == null ? SeriesStatus.Continuing : SeriesStatus.Ended, Tags = tags, CommunityRating = series.AniDB.Rating.ToFloat(10), }; result.Item.SetProviderId("Shoko Series", series.Id); if (Plugin.Instance.Configuration.AddAniDBId) { result.Item.SetProviderId("AniDB", series.AniDB.ID.ToString()); } result.HasMetadata = true; ApiManager.MarkSeriesAsFound(series.Id); result.ResetPeople(); foreach (var person in await ApiManager.GetPeople(series.Id)) { result.AddPerson(person); } return(result); }
private async Task <MetadataResult <BoxSet> > GetShokoGroupedMetadata(BoxSetInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <BoxSet>(); var config = Plugin.Instance.Configuration; Ordering.GroupFilterType filterByType = config.FilterOnLibraryTypes ? Ordering.GroupFilterType.Movies : Ordering.GroupFilterType.Default; var group = await ApiManager.GetGroupInfoByPath(info.Path, filterByType); if (group == null) { Logger.LogWarning($"Unable to find box-set info for path {info.Path}"); return(result); } var series = group.DefaultSeries; if (series.AniDB.Type != API.Models.SeriesType.Movie) { Logger.LogWarning($"File found, but not a movie! Skipping."); return(result); } var tags = await ApiManager.GetTags(series.Id); var(displayTitle, alternateTitle) = Text.GetSeriesTitles(series.AniDB.Titles, series.Shoko.Name, info.MetadataLanguage); result.Item = new BoxSet { Name = displayTitle, OriginalTitle = alternateTitle, Overview = Text.SanitizeTextSummary(series.AniDB.Description), PremiereDate = series.AniDB.AirDate, EndDate = series.AniDB.EndDate, ProductionYear = series.AniDB.AirDate?.Year, Tags = tags, CommunityRating = (float)((series.AniDB.Rating.Value * 10) / series.AniDB.Rating.MaxValue) }; result.Item.SetProviderId("Shoko Series", series.Id); result.Item.SetProviderId("Shoko Group", group.Id); if (config.AddAniDBId) { result.Item.SetProviderId("AniDB", series.AniDB.ID.ToString()); } result.HasMetadata = true; ApiManager.MarkSeriesAsFound(series.Id, group.Id); result.ResetPeople(); foreach (var person in await ApiManager.GetPeople(series.Id)) { result.AddPerson(person); } return(result); }
private async Task <MetadataResult <Season> > GetShokoGroupedMetadata(SeasonInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <Season>(); if (!info.SeriesProviderIds.ContainsKey("Shoko Group")) { Logger.LogWarning($"Shoko Group id not stored for series"); return(result); } var groupId = info.SeriesProviderIds["Shoko Group"]; var seasonNumber = info.IndexNumber ?? 1; var filterLibrary = Plugin.Instance.Configuration.FilterOnLibraryTypes; var series = await ApiManager.GetSeriesInfoFromGroup(groupId, seasonNumber, filterLibrary?Ordering.GroupFilterType.Others : Ordering.GroupFilterType.Default); if (series == null) { Logger.LogWarning($"Unable to find series info for G{groupId}:S{seasonNumber}"); return(result); } Logger.LogInformation($"Found series info for G{groupId}:S{seasonNumber}"); var tags = await ApiManager.GetTags(series.Id); var(displayTitle, alternateTitle) = Text.GetSeriesTitles(series.AniDB.Titles, series.Shoko.Name, info.MetadataLanguage); result.Item = new Season { Name = displayTitle, OriginalTitle = alternateTitle, IndexNumber = seasonNumber, Overview = Text.SanitizeTextSummary(series.AniDB.Description), PremiereDate = series.AniDB.AirDate, EndDate = series.AniDB.EndDate, ProductionYear = series.AniDB.AirDate?.Year, Tags = tags, CommunityRating = series.AniDB.Rating?.ToFloat(10), }; result.Item.ProviderIds.Add("Shoko Series", series.Id); if (Plugin.Instance.Configuration.AddAniDBId) { result.Item.ProviderIds.Add("AniDB", series.AniDB.ID.ToString()); } result.HasMetadata = true; ApiManager.MarkSeriesAsFound(series.Id, groupId); result.ResetPeople(); foreach (var person in await ApiManager.GetPeople(series.Id)) { result.AddPerson(person); } return(result); }