Load only user selected SponsorBlock categories

This commit is contained in:
Arkadiusz Fal 2021-10-28 21:32:03 +02:00
parent 24f7c566bf
commit 710f1f3630
3 changed files with 9 additions and 9 deletions

View File

@ -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)")

View File

@ -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)!
]
}
}

View File

@ -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)
}