From 7a2dcc3cf1d1d427168647c84bd222c37c4bfb5d Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 4 Dec 2022 00:35:07 +0100 Subject: [PATCH] Reset sponsorblock segments for local videos --- Model/Player/PlayerModel.swift | 8 +++++++- Model/SponsorBlock/SponsorBlockAPI.swift | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 54625577..a03b28a0 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -388,6 +388,10 @@ final class PlayerModel: ObservableObject { } } + if video.isLocal { + resetSegments() + } + (withBackend ?? backend).playStream( stream, of: video, @@ -436,7 +440,9 @@ final class PlayerModel: ObservableObject { changeActiveBackend(from: activeBackend, to: backend) } - guard let stream = (((availableStreams.count == 1 && availableStreams.first!.isLocal) ? availableStreams.first : nil) ?? streamByQualityProfile), + let localStream = (availableStreams.count == 1 && availableStreams.first!.isLocal) ? availableStreams.first : nil + + guard let stream = localStream ?? streamByQualityProfile, let currentVideo else { return diff --git a/Model/SponsorBlock/SponsorBlockAPI.swift b/Model/SponsorBlock/SponsorBlockAPI.swift index d3a7c45d..29685450 100644 --- a/Model/SponsorBlock/SponsorBlockAPI.swift +++ b/Model/SponsorBlock/SponsorBlockAPI.swift @@ -80,6 +80,11 @@ final class SponsorBlockAPI: ObservableObject { } } + func reset() { + videoID = nil + segments = [] + } + private func requestSegments(categories: Set, completionHandler: @escaping () -> Void = {}) { guard let url = skipSegmentsURL, !categories.isEmpty else { return