CC support with Invidious and MPV

This commit is contained in:
Arkadiusz Fal
2022-07-05 19:20:25 +02:00
parent 3718311a93
commit e56ab3804e
11 changed files with 163 additions and 25 deletions

View File

@@ -428,7 +428,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
keywords: json["keywords"].arrayValue.compactMap { $0.string },
streams: extractStreams(from: json),
related: extractRelated(from: json),
chapters: extractChapters(from: description)
chapters: extractChapters(from: description),
captions: extractCaptions(from: json)
)
}
@@ -566,4 +567,17 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
channel: Channel(id: channelId, name: author)
)
}
private func extractCaptions(from content: JSON) -> [Captions] {
content["captions"].arrayValue.compactMap { details in
guard let baseURL = account.url,
let url = URL(string: baseURL + details["url"].stringValue) else { return nil }
return Captions(
label: details["label"].stringValue,
code: details["language_code"].stringValue,
url: url
)
}
}
}