From c0eafa1c742a40fcbe6b784c5672e04dd2d9bb74 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Sat, 25 Jan 2025 15:50:08 +0100 Subject: [PATCH] little thing --- Sora/Views/MediaInfoView/MediaInfoView.swift | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 94e3407..7373c3a 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -247,28 +247,39 @@ struct MediaInfoView: View { do { let jsContent = try moduleManager.getModuleContent(module) jsController.loadScript(jsContent) + if module.metadata.asyncJS == true { jsController.fetchStreamUrlJS(episodeUrl: href) { streamUrl in - if let url = streamUrl { - playStream(url: url, fullURL: href) + guard let url = streamUrl, url != "null" else { + handleStreamFailure() + return } + playStream(url: url, fullURL: href) } } else { jsController.fetchStreamUrl(episodeUrl: href) { streamUrl in - if let url = streamUrl { - playStream(url: url, fullURL: href) + guard let url = streamUrl, url != "null" else { + handleStreamFailure() + return } + playStream(url: url, fullURL: href) } } } catch { - Logger.shared.log("Error loading module: \(error)", type: "Error") - DropManager.shared.showDrop(title: "Stream not Found", subtitle: "", duration: 1.0, icon: UIImage(systemName: "xmark")) - self.isLoading = false + handleStreamFailure(error: error) } } } } + func handleStreamFailure(error: Error? = nil) { + if let error = error { + Logger.shared.log("Error loading module: \(error)", type: "Error") + } + DropManager.shared.showDrop(title: "Stream not Found", subtitle: "", duration: 1.0, icon: UIImage(systemName: "xmark")) + self.isLoading = false + } + func playStream(url: String, fullURL: String) { DispatchQueue.main.async { let videoPlayerViewController = VideoPlayerViewController(module: module)