diff --git a/Shoko.Server/Services/GeneratedPlaylistService.cs b/Shoko.Server/Services/GeneratedPlaylistService.cs index 7e4be2495..75a11ca48 100644 --- a/Shoko.Server/Services/GeneratedPlaylistService.cs +++ b/Shoko.Server/Services/GeneratedPlaylistService.cs @@ -6,8 +6,8 @@ using System.Web; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Shoko.Commons.Extensions; using Shoko.Plugin.Abstractions.DataModels; +using Shoko.Plugin.Abstractions.DataModels.Shoko; using Shoko.Plugin.Abstractions.Enums; using Shoko.Server.Utilities; @@ -25,9 +25,7 @@ public GeneratedPlaylistService(IHttpContextAccessor contentAccessor) public FileStreamResult GeneratePlaylistForVideo(IVideo video) { - var episode = video.CrossReferences - .Select(xref => xref.AnidbEpisode) - .WhereNotNull() + var episode = video.Episodes .OrderBy(episode => episode.Type) .ThenBy(episode => episode.EpisodeNumber) .FirstOrDefault(); @@ -35,7 +33,7 @@ public FileStreamResult GeneratePlaylistForVideo(IVideo video) } private FileStreamResult GeneratePlaylistForEpisodeList( - IEnumerable<(IEpisode ep, IReadOnlyList videos)> episodeList, + IEnumerable<(IShokoEpisode ep, IReadOnlyList videos)> episodeList, string name = "Playlist" ) { @@ -50,13 +48,13 @@ private FileStreamResult GeneratePlaylistForEpisodeList( ); foreach (var (episode, videos) in episodeList) { - var anime = episode.Series; - if (anime is null) + var series = episode.Series; + if (series is null) continue; var index = 0; foreach (var video in videos) - m3U8.Append(GetEpisodeEntry(new UriBuilder(uri.ToString()), anime, episode, video, ++index, videos.Count)); + m3U8.Append(GetEpisodeEntry(new UriBuilder(uri.ToString()), series, episode, video, ++index, videos.Count)); } var bytes = Encoding.UTF8.GetBytes(m3U8.ToString()); @@ -67,9 +65,9 @@ private FileStreamResult GeneratePlaylistForEpisodeList( }; } - private static string GetEpisodeEntry(UriBuilder uri, ISeries anime, IEpisode episode, IVideo video, int part, int totalParts) + private static string GetEpisodeEntry(UriBuilder uri, IShokoSeries series, IShokoEpisode episode, IVideo video, int part, int totalParts) { - var poster = anime.GetPreferredImageForType(ImageEntityType.Poster) ?? anime.DefaultPoster; + var poster = series.GetPreferredImageForType(ImageEntityType.Poster) ?? series.DefaultPoster; var parts = totalParts > 1 ? $" ({part}/{totalParts})" : string.Empty; var episodeNumber = episode.Type is EpisodeType.Episode ? episode.EpisodeNumber.ToString() @@ -81,16 +79,16 @@ private static string GetEpisodeEntry(UriBuilder uri, ISeries anime, IEpisode ep if (poster is not null && !string.IsNullOrEmpty(poster.RemoteURL)) queryString.Add("posterUrl", poster.RemoteURL); queryString.Add("appId", "07a58b50-5109-5aa3-abbc-782fed0df04f"); // plugin id - queryString.Add("animeId", anime.ID.ToString()); - queryString.Add("animeName", anime.PreferredTitle); - queryString.Add("epId", episode.ID.ToString()); + queryString.Add("animeId", series.AnidbAnimeID.ToString()); + queryString.Add("animeName", series.PreferredTitle); + queryString.Add("epId", episode.AnidbEpisodeID.ToString()); queryString.Add("episodeName", episode.PreferredTitle); queryString.Add("epNo", episodeNumber); - queryString.Add("epCount", anime.EpisodeCounts.Episodes.ToString()); - queryString.Add("restricted", anime.Restricted ? "true" : "false"); + queryString.Add("epCount", series.EpisodeCounts.Episodes.ToString()); + queryString.Add("restricted", series.Restricted ? "true" : "false"); uri.Path = $"{(uri.Path.Length > 1 ? uri.Path + "/" : "/")}api/v3/File/{video.ID}/Stream"; uri.Query = queryString.ToString(); - return $"#EXTINF:-1,{episode.PreferredTitle} — {episodeNumber}{parts}\n{uri}\n"; + return $"#EXTINF:-1,{series.PreferredTitle} - {episodeNumber} - {episode.PreferredTitle}{parts}\n{uri}\n"; } }