From ae74bb2f7328be3aa929698b732991c496f7eeac Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Sat, 13 Jul 2024 02:14:21 +0200 Subject: [PATCH] feat: expose media info chapter language if available --- Shoko.Server/API/v3/Models/Shoko/MediaInfo.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Shoko.Server/API/v3/Models/Shoko/MediaInfo.cs b/Shoko.Server/API/v3/Models/Shoko/MediaInfo.cs index c2d6f90e1..012d3b301 100644 --- a/Shoko.Server/API/v3/Models/Shoko/MediaInfo.cs +++ b/Shoko.Server/API/v3/Models/Shoko/MediaInfo.cs @@ -111,11 +111,13 @@ public MediaInfo(SVR_VideoLocal file, MediaContainer mediaContainer) { if (string.IsNullOrEmpty(key)) continue; - var (hours, minutes, seconds, milliseconds, _rest) = key.Substring(1).Split('_'); + var (hours, minutes, seconds, milliseconds, _rest) = key[1..].Split('_'); if (!TimeSpan.TryParse($"{hours}:{minutes}:{seconds}.{milliseconds}", out var timestamp)) continue; - var title = string.IsNullOrEmpty(value) ? "" : value[0] == ':' ? value.Substring(1).Trim() : value.Trim(); - var chapterInfo = new ChapterInfo(title, timestamp); + var index = value.IndexOf(':'); + var title = string.IsNullOrEmpty(value) ? string.Empty : index != -1 ? value[(index + 1)..].Trim() : value.Trim(); + var language = index == -1 || index == 0 ? TitleLanguage.Unknown : value[..index].GetTitleLanguage(); + var chapterInfo = new ChapterInfo(title, language, timestamp); Chapters.Add(chapterInfo); } } @@ -516,14 +518,21 @@ public class ChapterInfo /// public string Title { get; } + /// + /// Chapter title language, if specified. + /// + [JsonConverter(typeof(StringEnumConverter))] + public TitleLanguage Language { get; } + /// /// Chapter timestamp. /// public TimeSpan Timestamp { get; } - public ChapterInfo (string title, TimeSpan timestamp) + public ChapterInfo(string title, TitleLanguage language, TimeSpan timestamp) { Title = title; + Language = language; Timestamp = timestamp; } }