mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-21 00:22:12 +00:00
im dumb asf
This commit is contained in:
parent
58c3642dc1
commit
2fbcbee45c
2 changed files with 55 additions and 4 deletions
|
|
@ -388,4 +388,46 @@ class JSController: ObservableObject {
|
||||||
completion(resultItems, episodeLinks)
|
completion(resultItems, episodeLinks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchStreamUrlJS(episodeUrl: String, completion: @escaping (String?) -> Void) {
|
||||||
|
if let exception = context.exception {
|
||||||
|
Logger.shared.log("JavaScript exception: \(exception)", type: "Error")
|
||||||
|
completion(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let extractStreamUrlFunction = context.objectForKeyedSubscript("extractStreamUrl") else {
|
||||||
|
Logger.shared.log("No JavaScript function extractStreamUrl found", type: "Error")
|
||||||
|
completion(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let promiseValue = extractStreamUrlFunction.call(withArguments: [episodeUrl])
|
||||||
|
guard let promise = promiseValue else {
|
||||||
|
Logger.shared.log("extractStreamUrl did not return a Promise", type: "Error")
|
||||||
|
completion(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let thenBlock: @convention(block) (JSValue) -> Void = { result in
|
||||||
|
let streamUrl = result.toString()
|
||||||
|
Logger.shared.log("Starting stream from: \(streamUrl ?? "nil")", type: "Stream")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
completion(streamUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let catchBlock: @convention(block) (JSValue) -> Void = { error in
|
||||||
|
Logger.shared.log("Promise rejected: \(String(describing: error.toString()))", type: "Error")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
completion(nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let thenFunction = JSValue(object: thenBlock, in: context)
|
||||||
|
let catchFunction = JSValue(object: catchBlock, in: context)
|
||||||
|
|
||||||
|
promise.invokeMethod("then", withArguments: [thenFunction as Any])
|
||||||
|
promise.invokeMethod("catch", withArguments: [catchFunction as Any])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,11 +235,20 @@ struct MediaInfoView: View {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
|
print(href)
|
||||||
let jsContent = try moduleManager.getModuleContent(module)
|
let jsContent = try moduleManager.getModuleContent(module)
|
||||||
jsController.loadScript(jsContent)
|
jsController.loadScript(jsContent)
|
||||||
jsController.fetchStreamUrl(episodeUrl: href) { streamUrl in
|
if module.metadata.asyncJS == true {
|
||||||
if let url = streamUrl {
|
jsController.fetchStreamUrlJS(episodeUrl: href) { streamUrl in
|
||||||
playStream(url: url, fullURL: href)
|
if let url = streamUrl {
|
||||||
|
playStream(url: url, fullURL: href)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jsController.fetchStreamUrl(episodeUrl: href) { streamUrl in
|
||||||
|
if let url = streamUrl {
|
||||||
|
playStream(url: url, fullURL: href)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -256,7 +265,7 @@ struct MediaInfoView: View {
|
||||||
videoPlayerViewController.streamUrl = url
|
videoPlayerViewController.streamUrl = url
|
||||||
videoPlayerViewController.fullUrl = fullURL
|
videoPlayerViewController.fullUrl = fullURL
|
||||||
videoPlayerViewController.modalPresentationStyle = .fullScreen
|
videoPlayerViewController.modalPresentationStyle = .fullScreen
|
||||||
|
print(url)
|
||||||
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||||
let rootVC = windowScene.windows.first?.rootViewController {
|
let rootVC = windowScene.windows.first?.rootViewController {
|
||||||
rootVC.present(videoPlayerViewController, animated: true, completion: nil)
|
rootVC.present(videoPlayerViewController, animated: true, completion: nil)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue