mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Merge pull request #810 from yattee/auto-retry-video-loading
Retry loading video before presenting error
This commit is contained in:
commit
ed11e593ff
@ -5,6 +5,7 @@ final class AdvancedSettingsGroupExporter: SettingsGroupExporter {
|
|||||||
override var globalJSON: JSON {
|
override var globalJSON: JSON {
|
||||||
[
|
[
|
||||||
"showPlayNowInBackendContextMenu": Defaults[.showPlayNowInBackendContextMenu],
|
"showPlayNowInBackendContextMenu": Defaults[.showPlayNowInBackendContextMenu],
|
||||||
|
"videoLoadingRetryCount": Defaults[.videoLoadingRetryCount],
|
||||||
"showMPVPlaybackStats": Defaults[.showMPVPlaybackStats],
|
"showMPVPlaybackStats": Defaults[.showMPVPlaybackStats],
|
||||||
"mpvEnableLogging": Defaults[.mpvEnableLogging],
|
"mpvEnableLogging": Defaults[.mpvEnableLogging],
|
||||||
"mpvCacheSecs": Defaults[.mpvCacheSecs],
|
"mpvCacheSecs": Defaults[.mpvCacheSecs],
|
||||||
|
@ -9,6 +9,10 @@ struct AdvancedSettingsGroupImporter {
|
|||||||
Defaults[.showPlayNowInBackendContextMenu] = showPlayNowInBackendContextMenu
|
Defaults[.showPlayNowInBackendContextMenu] = showPlayNowInBackendContextMenu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let videoLoadingRetryCount = json["videoLoadingRetryCount"].int {
|
||||||
|
Defaults[.videoLoadingRetryCount] = videoLoadingRetryCount
|
||||||
|
}
|
||||||
|
|
||||||
if let showMPVPlaybackStats = json["showMPVPlaybackStats"].bool {
|
if let showMPVPlaybackStats = json["showMPVPlaybackStats"].bool {
|
||||||
Defaults[.showMPVPlaybackStats] = showMPVPlaybackStats
|
Defaults[.showMPVPlaybackStats] = showMPVPlaybackStats
|
||||||
}
|
}
|
||||||
|
@ -203,6 +203,9 @@ final class PlayerModel: ObservableObject {
|
|||||||
var rateToRestore: Float?
|
var rateToRestore: Float?
|
||||||
private var remoteCommandCenterConfigured = false
|
private var remoteCommandCenterConfigured = false
|
||||||
|
|
||||||
|
// Used in the PlayerModel extension in PlayerQueue
|
||||||
|
var retryAttempts = [String: Int]()
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
var keyPressMonitor: Any?
|
var keyPressMonitor: Any?
|
||||||
#endif
|
#endif
|
||||||
|
@ -359,6 +359,31 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func videoLoadFailureHandler(_ error: RequestError, video: Video? = nil) {
|
private func videoLoadFailureHandler(_ error: RequestError, video: Video? = nil) {
|
||||||
|
guard let video else {
|
||||||
|
presentErrorAlert(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let videoID = video.videoID
|
||||||
|
let currentRetry = retryAttempts[videoID] ?? 0
|
||||||
|
|
||||||
|
if currentRetry < Defaults[.videoLoadingRetryCount] {
|
||||||
|
retryAttempts[videoID] = currentRetry + 1
|
||||||
|
|
||||||
|
logger.info("Retry attempt \(currentRetry + 1) for video \(videoID) due to error: \(error)")
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.enqueueVideo(video, play: true, prepending: true, loadDetails: true)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
retryAttempts[videoID] = 0
|
||||||
|
presentErrorAlert(error, video: video)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func presentErrorAlert(_ error: RequestError, video: Video? = nil) {
|
||||||
var message = error.userMessage
|
var message = error.userMessage
|
||||||
if let errorDictionary = error.json.dictionaryObject,
|
if let errorDictionary = error.json.dictionaryObject,
|
||||||
let errorMessage = errorDictionary["message"] ?? errorDictionary["error"],
|
let errorMessage = errorDictionary["message"] ?? errorDictionary["error"],
|
||||||
|
@ -358,6 +358,7 @@ extension Defaults.Keys {
|
|||||||
// MARK: Group - Advanced
|
// MARK: Group - Advanced
|
||||||
|
|
||||||
static let showPlayNowInBackendContextMenu = Key<Bool>("showPlayNowInBackendContextMenu", default: false)
|
static let showPlayNowInBackendContextMenu = Key<Bool>("showPlayNowInBackendContextMenu", default: false)
|
||||||
|
static let videoLoadingRetryCount = Key<Int>("videoLoadingRetryCount", default: 10)
|
||||||
|
|
||||||
static let showMPVPlaybackStats = Key<Bool>("showMPVPlaybackStats", default: false)
|
static let showMPVPlaybackStats = Key<Bool>("showMPVPlaybackStats", default: false)
|
||||||
static let mpvEnableLogging = Key<Bool>("mpvEnableLogging", default: false)
|
static let mpvEnableLogging = Key<Bool>("mpvEnableLogging", default: false)
|
||||||
|
@ -15,6 +15,7 @@ struct AdvancedSettings: View {
|
|||||||
@Default(.showCacheStatus) private var showCacheStatus
|
@Default(.showCacheStatus) private var showCacheStatus
|
||||||
@Default(.feedCacheSize) private var feedCacheSize
|
@Default(.feedCacheSize) private var feedCacheSize
|
||||||
@Default(.showPlayNowInBackendContextMenu) private var showPlayNowInBackendContextMenu
|
@Default(.showPlayNowInBackendContextMenu) private var showPlayNowInBackendContextMenu
|
||||||
|
@Default(.videoLoadingRetryCount) private var videoLoadingRetryCount
|
||||||
|
|
||||||
@State private var filesToShare = [MPVClient.logFile]
|
@State private var filesToShare = [MPVClient.logFile]
|
||||||
@State private var presentingShareSheet = false
|
@State private var presentingShareSheet = false
|
||||||
@ -65,6 +66,7 @@ struct AdvancedSettings: View {
|
|||||||
@ViewBuilder var advancedSettings: some View {
|
@ViewBuilder var advancedSettings: some View {
|
||||||
Section(header: SettingsHeader(text: "Advanced")) {
|
Section(header: SettingsHeader(text: "Advanced")) {
|
||||||
showPlayNowInBackendButtonsToggle
|
showPlayNowInBackendButtonsToggle
|
||||||
|
videoLoadingRetryCountField
|
||||||
}
|
}
|
||||||
|
|
||||||
Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) {
|
Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) {
|
||||||
@ -288,6 +290,19 @@ struct AdvancedSettings: View {
|
|||||||
Toggle("Show video context menu options to force selected backend", isOn: $showPlayNowInBackendContextMenu)
|
Toggle("Show video context menu options to force selected backend", isOn: $showPlayNowInBackendContextMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var videoLoadingRetryCountField: some View {
|
||||||
|
HStack {
|
||||||
|
Text("Maximum retries for video loading")
|
||||||
|
.frame(minWidth: 200, alignment: .leading)
|
||||||
|
.multilineTextAlignment(.leading)
|
||||||
|
TextField("Limit", value: $videoLoadingRetryCount, formatter: NumberFormatter())
|
||||||
|
.multilineTextAlignment(.trailing)
|
||||||
|
#if !os(macOS)
|
||||||
|
.keyboardType(.numberPad)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var showMPVPlaybackStatsToggle: some View {
|
var showMPVPlaybackStatsToggle: some View {
|
||||||
Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
|
Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user