mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Load only user selected SponsorBlock categories
This commit is contained in:
parent
24f7c566bf
commit
710f1f3630
@ -121,7 +121,7 @@ final class PlayerModel: ObservableObject {
|
||||
preservingTime: Bool = false
|
||||
) {
|
||||
resetSegments()
|
||||
sponsorBlock.loadSegments(videoID: video.videoID)
|
||||
sponsorBlock.loadSegments(videoID: video.videoID, categories: Defaults[.sponsorBlockCategories])
|
||||
|
||||
if let url = stream.singleAssetURL {
|
||||
logger.info("playing stream with one asset\(stream.kind == .hls ? " (HLS)" : ""): \(url)")
|
||||
|
@ -27,22 +27,22 @@ final class SponsorBlockAPI: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func loadSegments(videoID: String) {
|
||||
func loadSegments(videoID: String, categories: Set<String>) {
|
||||
guard !skipSegmentsURL.isNil, self.videoID != videoID else {
|
||||
return
|
||||
}
|
||||
|
||||
self.videoID = videoID
|
||||
|
||||
requestSegments()
|
||||
requestSegments(categories: categories)
|
||||
}
|
||||
|
||||
private func requestSegments() {
|
||||
guard let url = skipSegmentsURL else {
|
||||
private func requestSegments(categories: Set<String>) {
|
||||
guard let url = skipSegmentsURL, !categories.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
AF.request(url, parameters: parameters).responseJSON { response in
|
||||
AF.request(url, parameters: parameters(categories: categories)).responseJSON { response in
|
||||
switch response.result {
|
||||
case let .success(value):
|
||||
self.segments = JSON(value).arrayValue.map(SponsorBlockSegment.init).sorted { $0.end < $1.end }
|
||||
@ -64,10 +64,10 @@ final class SponsorBlockAPI: ObservableObject {
|
||||
return url.isEmpty ? nil : "\(url)/api/skipSegments"
|
||||
}
|
||||
|
||||
private var parameters: [String: String] {
|
||||
private func parameters(categories: Set<String>) -> [String: String] {
|
||||
[
|
||||
"videoID": videoID!,
|
||||
"categories": JSON(SponsorBlockAPI.categories).rawString(String.Encoding.utf8)!
|
||||
"categories": JSON(Array(categories)).rawString(String.Encoding.utf8)!
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ extension PlayerViewController: AVPlayerViewControllerDelegate {
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
if self.playerModel.playingInPictureInPicture {
|
||||
if self.playerModel.playingInPictureInPicture {
|
||||
self.present(playerViewController, animated: false) {
|
||||
completionHandler(true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user