mirror of
https://github.com/yattee/yattee.git
synced 2025-07-07 04:00:05 +00:00
Added caption support for Piped backend (#867)
Co-authored-by: Ivan <ivanferrari@porch.com>
This commit is contained in:
parent
06c0eaa920
commit
8609ef7709
@ -591,7 +591,8 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
|||||||
dislikes: details["dislikes"]?.int,
|
dislikes: details["dislikes"]?.int,
|
||||||
streams: extractStreams(from: content),
|
streams: extractStreams(from: content),
|
||||||
related: extractRelated(from: content),
|
related: extractRelated(from: content),
|
||||||
chapters: extractChapters(from: content)
|
chapters: extractChapters(from: content),
|
||||||
|
captions: extractCaptions(from: content)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,6 +819,24 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
|||||||
return Chapter(title: title, image: image, start: start)
|
return Chapter(title: title, image: image, start: start)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
private func contentItemsDictionary(from content: JSON) -> JSON {
|
||||||
if let key = Self.contentItemsKeys.first(where: { content.dictionaryValue.keys.contains($0) }),
|
if let key = Self.contentItemsKeys.first(where: { content.dictionaryValue.keys.contains($0) }),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user