Add more subtitle metadata (fps, hi/sdh, forced etc) (#133)

This commit is contained in:
MBR-0001 2024-04-05 21:14:27 +02:00 committed by GitHub
parent d3b9e11ed9
commit 7aa59ab7f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 4 deletions

View File

@ -198,10 +198,15 @@ public class OpenSubtitleDownloader : ISubtitleProvider
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 @@ public class OpenSubtitleDownloader : ISubtitleProvider
}
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 @@ public class OpenSubtitleDownloader : ISubtitleProvider
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 @@ public class OpenSubtitleDownloader : ISubtitleProvider
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)

View File

@ -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>
@ -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; }
}