Skip to content

Commit

Permalink
Add more subtitle metadata (fps, hi/sdh, forced etc) (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBR-0001 authored Apr 5, 2024
1 parent d3b9e11 commit 7aa59ab
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down Expand Up @@ -241,14 +246,16 @@ private async Task<SubtitleResponse> 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));
}

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)
Expand Down Expand Up @@ -323,7 +330,14 @@ private async Task<SubtitleResponse> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class Attributes
[JsonPropertyName("ratings")]
public float Ratings { get; set; }

/// <summary>
/// Gets or sets the subtitle framerate.
/// </summary>
[JsonPropertyName("fps")]
public float Fps { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this subtitle was from a trusted uploader.
/// </summary>
Expand Down Expand Up @@ -68,4 +74,28 @@ public class Attributes
/// </summary>
[JsonPropertyName("moviehash_match")]
public bool? MovieHashMatch { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the subtitle is for hearing impaired.
/// </summary>
[JsonPropertyName("hearing_impaired")]
public bool? HearingImpaired { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the subtitle is ai translated.
/// </summary>
[JsonPropertyName("ai_translated")]
public bool? AiTranslated { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the subtitle is machine translated.
/// </summary>
[JsonPropertyName("machine_translated")]
public bool? MachineTranslated { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the subtitle is forced.
/// </summary>
[JsonPropertyName("foreign_parts_only")]
public bool? ForeignPartsOnly { get; set; }
}

0 comments on commit 7aa59ab

Please sign in to comment.