diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 2175d7b4..eed2a5fa 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -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)") diff --git a/Model/SponsorBlock/SponsorBlockAPI.swift b/Model/SponsorBlock/SponsorBlockAPI.swift index 7269b5e3..ef1019af 100644 --- a/Model/SponsorBlock/SponsorBlockAPI.swift +++ b/Model/SponsorBlock/SponsorBlockAPI.swift @@ -27,22 +27,22 @@ final class SponsorBlockAPI: ObservableObject { } } - func loadSegments(videoID: String) { + func loadSegments(videoID: String, categories: Set) { 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) { + 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] { [ "videoID": videoID!, - "categories": JSON(SponsorBlockAPI.categories).rawString(String.Encoding.utf8)! + "categories": JSON(Array(categories)).rawString(String.Encoding.utf8)! ] } } diff --git a/Shared/Player/PlayerViewController.swift b/Shared/Player/PlayerViewController.swift index 93676c6d..792077c7 100644 --- a/Shared/Player/PlayerViewController.swift +++ b/Shared/Player/PlayerViewController.swift @@ -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) }