From 7aa59ab7f88b4d873f6bd4d252cbea5263cd35f4 Mon Sep 17 00:00:00 2001 From: MBR-0001 <55142207+MBR-0001@users.noreply.github.com> Date: Fri, 5 Apr 2024 21:14:27 +0200 Subject: [PATCH] Add more subtitle metadata (fps, hi/sdh, forced etc) (#133) --- .../OpenSubtitleDownloader.cs | 22 +++++++++++--- .../Models/Responses/Attributes.cs | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs b/Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs index 770bea9..5a56c4c 100644 --- a/Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs +++ b/Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs @@ -198,10 +198,15 @@ bool MediaFilter(ResponseData x) => Format = "srt", ProviderName = Name, ThreeLetterISOLanguageName = request.Language, - Id = $"srt-{request.Language}-{i.Attributes?.Files[0].FileId}", + Id = $"srt-{request.Language}-{i.Attributes?.Files[0].FileId}{((i.Attributes?.HearingImpaired ?? false) ? "-sdh" : string.Empty)}{((i.Attributes?.ForeignPartsOnly ?? false) ? "-forced" : string.Empty)}", Name = i.Attributes?.Release, DateCreated = i.Attributes?.UploadDate, - IsHashMatch = i.Attributes?.MovieHashMatch + IsHashMatch = i.Attributes?.MovieHashMatch, + HearingImpaired = i.Attributes?.HearingImpaired, + MachineTranslated = i.Attributes?.MachineTranslated, + AiTranslated = i.Attributes?.AiTranslated, + FrameRate = i.Attributes?.Fps, + Forced = i.Attributes?.ForeignPartsOnly }); } @@ -241,7 +246,7 @@ private async Task GetSubtitlesInternal(string id, Cancellatio } var idParts = id.Split('-'); - if (idParts.Length != 3) + if (idParts.Length < 3) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Invalid subtitle id format: {0}", id)); } @@ -249,6 +254,8 @@ private async Task GetSubtitlesInternal(string id, Cancellatio var format = idParts[0]; var language = idParts[1]; var fileId = int.Parse(idParts[2], CultureInfo.InvariantCulture); + var isHearingImpaired = id.Contains("-sdh", StringComparison.OrdinalIgnoreCase); + var isForced = id.Contains("-forced", StringComparison.OrdinalIgnoreCase); var info = await OpenSubtitlesApi .GetSubtitleLinkAsync(fileId, format, _login, cancellationToken) @@ -323,7 +330,14 @@ private async Task GetSubtitlesInternal(string id, Cancellatio throw new HttpRequestException(msg); } - return new SubtitleResponse { Format = format, Language = language, Stream = new MemoryStream(Encoding.UTF8.GetBytes(res.Body)) }; + return new SubtitleResponse + { + Format = format, + Language = language, + Stream = new MemoryStream(Encoding.UTF8.GetBytes(res.Body)), + IsForced = isForced, + IsHearingImpaired = isHearingImpaired + }; } private async Task Login(CancellationToken cancellationToken) diff --git a/Jellyfin.Plugin.OpenSubtitles/OpenSubtitlesHandler/Models/Responses/Attributes.cs b/Jellyfin.Plugin.OpenSubtitles/OpenSubtitlesHandler/Models/Responses/Attributes.cs index 03a4224..b2f98f7 100644 --- a/Jellyfin.Plugin.OpenSubtitles/OpenSubtitlesHandler/Models/Responses/Attributes.cs +++ b/Jellyfin.Plugin.OpenSubtitles/OpenSubtitlesHandler/Models/Responses/Attributes.cs @@ -21,6 +21,12 @@ public class Attributes [JsonPropertyName("ratings")] public float Ratings { get; set; } + /// + /// Gets or sets the subtitle framerate. + /// + [JsonPropertyName("fps")] + public float Fps { get; set; } + /// /// Gets or sets a value indicating whether this subtitle was from a trusted uploader. /// @@ -68,4 +74,28 @@ public class Attributes /// [JsonPropertyName("moviehash_match")] public bool? MovieHashMatch { get; set; } + + /// + /// Gets or sets a value indicating whether the subtitle is for hearing impaired. + /// + [JsonPropertyName("hearing_impaired")] + public bool? HearingImpaired { get; set; } + + /// + /// Gets or sets a value indicating whether the subtitle is ai translated. + /// + [JsonPropertyName("ai_translated")] + public bool? AiTranslated { get; set; } + + /// + /// Gets or sets a value indicating whether the subtitle is machine translated. + /// + [JsonPropertyName("machine_translated")] + public bool? MachineTranslated { get; set; } + + /// + /// Gets or sets a value indicating whether the subtitle is forced. + /// + [JsonPropertyName("foreign_parts_only")] + public bool? ForeignPartsOnly { get; set; } }