Added caption support for Piped backend (#867)

Co-authored-by: Ivan <ivanferrari@porch.com>
This commit is contained in:
Ivan0xFF 2025-06-17 07:03:18 -07:00 committed by GitHub
parent 06c0eaa920
commit 8609ef7709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -591,7 +591,8 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
dislikes: details["dislikes"]?.int,
streams: extractStreams(from: content),
related: extractRelated(from: content),
chapters: extractChapters(from: content)
chapters: extractChapters(from: content),
captions: extractCaptions(from: content)
)
}
@ -819,6 +820,24 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
}
}
private func extractCaptions(from content: JSON) -> [Captions] {
content["subtitles"].arrayValue.compactMap { details in
guard let url = details["url"].url,
let code = details["code"].string,
let label = details["name"].string,
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
else { return nil }
components.queryItems = components.queryItems?.map { item in
item.name == "fmt" ? URLQueryItem(name: "fmt", value: "srt") : item
}
guard let newUrl = components.url else { return nil }
return Captions(label: label, code: code, url: newUrl)
}
}
private func contentItemsDictionary(from content: JSON) -> JSON {
if let key = Self.contentItemsKeys.first(where: { content.dictionaryValue.keys.contains($0) }),
let items = content.dictionaryValue[key]