From 34334f8e6e96cfd83bf749465eda671b231f1806 Mon Sep 17 00:00:00 2001 From: Francesco <100066266+cranci1@users.noreply.github.com> Date: Sun, 25 May 2025 08:56:35 +0200 Subject: [PATCH] test fix --- .../EpisodeCell/EpisodeCell.swift | 2 +- Sora/Views/MediaInfoView/MediaInfoView.swift | 45 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift index 53207c4..e7f71b1 100644 --- a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift +++ b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift @@ -110,7 +110,7 @@ struct EpisodeCell: View { Spacer() CircularProgressBar(progress: currentProgress) .frame(width: 40, height: 40) - .padding(.trailing, 8) + .padding(.trailing, 4) } .contentShape(Rectangle()) .background(isMultiSelectMode && isSelected ? Color.accentColor.opacity(0.1) : Color.clear) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index a77a1c7..6535427 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -755,22 +755,28 @@ struct MediaInfoView: View { showLoadingAlert = true isFetchingEpisode = true let completion: ((streams: [String]?, subtitles: [String]?, sources: [[String: Any]]?)) -> Void = { result in - guard self.activeFetchID == fetchID else { return } + guard self.activeFetchID == fetchID else { + return + } self.showLoadingAlert = false DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + guard self.activeFetchID == fetchID else { + return + } + if let streams = result.sources, !streams.isEmpty { if streams.count > 1 { - self.showStreamSelectionAlert(streams: streams, fullURL: href, subtitles: result.subtitles?.first) + self.showStreamSelectionAlert(streams: streams, fullURL: href, subtitles: result.subtitles?.first, fetchID: fetchID) } else { - self.playStream(url: streams[0]["streamUrl"] as? String ?? "", fullURL: href, subtitles: result.subtitles?.first, headers: streams[0]["headers"] as! [String : String]) + self.playStream(url: streams[0]["streamUrl"] as? String ?? "", fullURL: href, subtitles: result.subtitles?.first, headers: (streams[0]["headers"] as! [String : String]), fetchID: fetchID) } } else if let streams = result.streams, !streams.isEmpty { if streams.count > 1 { - self.showStreamSelectionAlert(streams: streams, fullURL: href, subtitles: result.subtitles?.first) + self.showStreamSelectionAlert(streams: streams, fullURL: href, subtitles: result.subtitles?.first, fetchID: fetchID) } else { - self.playStream(url: streams[0], fullURL: href, subtitles: result.subtitles?.first) + self.playStream(url: streams[0], fullURL: href, subtitles: result.subtitles?.first, fetchID: fetchID) } } else { self.handleStreamFailure(error: nil) @@ -816,11 +822,19 @@ struct MediaInfoView: View { self.isLoading = false } - func showStreamSelectionAlert(streams: [Any], fullURL: String, subtitles: String? = nil) { + func showStreamSelectionAlert(streams: [Any], fullURL: String, subtitles: String? = nil, fetchID: UUID) { + guard self.activeFetchID == fetchID else { + return + } + self.isFetchingEpisode = false self.showLoadingAlert = false DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + guard self.activeFetchID == fetchID else { + return + } + let alert = UIAlertController(title: "Select Server", message: "Choose a server to play from", preferredStyle: .actionSheet) var index = 0 @@ -866,7 +880,10 @@ struct MediaInfoView: View { alert.addAction(UIAlertAction(title: title, style: .default) { _ in - self.playStream(url: streamUrl, fullURL: fullURL, subtitles: subtitles,headers: headers) + guard self.activeFetchID == fetchID else { + return + } + self.playStream(url: streamUrl, fullURL: fullURL, subtitles: subtitles, headers: headers, fetchID: fetchID) }) streamIndex += 1 @@ -900,11 +917,19 @@ struct MediaInfoView: View { } } - func playStream(url: String, fullURL: String, subtitles: String? = nil, headers: [String:String]? = nil) { + func playStream(url: String, fullURL: String, subtitles: String? = nil, headers: [String:String]? = nil, fetchID: UUID) { + guard self.activeFetchID == fetchID else { + return + } + self.isFetchingEpisode = false self.showLoadingAlert = false DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + guard self.activeFetchID == fetchID else { + return + } + let externalPlayer = UserDefaults.standard.string(forKey: "externalPlayer") ?? "Sora" var scheme: String? @@ -952,6 +977,10 @@ struct MediaInfoView: View { return } + guard self.activeFetchID == fetchID else { + return + } + let customMediaPlayer = CustomMediaPlayerViewController( module: module, urlString: url.absoluteString,