Skip to content

Commit

Permalink
feat: expose media info chapter language if available
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Jul 13, 2024
1 parent 2cd0a0f commit ae74bb2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Shoko.Server/API/v3/Models/Shoko/MediaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -516,14 +518,21 @@ public class ChapterInfo
/// </summary>
public string Title { get; }

/// <summary>
/// Chapter title language, if specified.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TitleLanguage Language { get; }

/// <summary>
/// Chapter timestamp.
/// </summary>
public TimeSpan Timestamp { get; }

public ChapterInfo (string title, TimeSpan timestamp)
public ChapterInfo(string title, TitleLanguage language, TimeSpan timestamp)
{
Title = title;
Language = language;
Timestamp = timestamp;
}
}
Expand Down

0 comments on commit ae74bb2

Please sign in to comment.