mirror of
https://github.com/yattee/yattee.git
synced 2025-01-09 14:27:11 +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
|
preservingTime: Bool = false
|
||||||
) {
|
) {
|
||||||
resetSegments()
|
resetSegments()
|
||||||
sponsorBlock.loadSegments(videoID: video.videoID)
|
sponsorBlock.loadSegments(videoID: video.videoID, categories: Defaults[.sponsorBlockCategories])
|
||||||
|
|
||||||
if let url = stream.singleAssetURL {
|
if let url = stream.singleAssetURL {
|
||||||
logger.info("playing stream with one asset\(stream.kind == .hls ? " (HLS)" : ""): \(url)")
|
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 {
|
guard !skipSegmentsURL.isNil, self.videoID != videoID else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.videoID = videoID
|
self.videoID = videoID
|
||||||
|
|
||||||
requestSegments()
|
requestSegments(categories: categories)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func requestSegments() {
|
private func requestSegments(categories: Set<String>) {
|
||||||
guard let url = skipSegmentsURL else {
|
guard let url = skipSegmentsURL, !categories.isEmpty else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
AF.request(url, parameters: parameters).responseJSON { response in
|
AF.request(url, parameters: parameters(categories: categories)).responseJSON { response in
|
||||||
switch response.result {
|
switch response.result {
|
||||||
case let .success(value):
|
case let .success(value):
|
||||||
self.segments = JSON(value).arrayValue.map(SponsorBlockSegment.init).sorted { $0.end < $1.end }
|
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"
|
return url.isEmpty ? nil : "\(url)/api/skipSegments"
|
||||||
}
|
}
|
||||||
|
|
||||||
private var parameters: [String: String] {
|
private func parameters(categories: Set<String>) -> [String: String] {
|
||||||
[
|
[
|
||||||
"videoID": videoID!,
|
"videoID": videoID!,
|
||||||
"categories": JSON(SponsorBlockAPI.categories).rawString(String.Encoding.utf8)!
|
"categories": JSON(Array(categories)).rawString(String.Encoding.utf8)!
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user