This commit is contained in:
Francesco 2025-05-25 08:56:35 +02:00
parent 653e714955
commit 34334f8e6e
2 changed files with 38 additions and 9 deletions

View file

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

View file

@ -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,