|
|
|
@ -15,12 +15,14 @@ struct KBrowserView: View { |
|
|
|
@State var showVideoView = false |
|
|
|
@State var message = "" |
|
|
|
@State var webTitle = "" |
|
|
|
@State var serverMessage = "On Server" |
|
|
|
@State var dlUrls = [String]() |
|
|
|
|
|
|
|
var item: String |
|
|
|
var completionHandler: (() -> Void)? |
|
|
|
|
|
|
|
@State var videoModel: SVideoModel? |
|
|
|
@State private var showingAlert = false |
|
|
|
|
|
|
|
// For WebView's forward and backward navigation |
|
|
|
var webViewNavigationBar: some View { |
|
|
|
@ -79,22 +81,29 @@ struct KBrowserView: View { |
|
|
|
}) |
|
|
|
.buttonStyle(BorderlessButtonStyle()) |
|
|
|
Spacer() |
|
|
|
Text (serverMessage).foregroundColor(Color.blue) |
|
|
|
Button(action: { |
|
|
|
NetworkManager.sharedInstance.dlserverlen { c in |
|
|
|
serverMessage = "On Server: \(c)"; |
|
|
|
} |
|
|
|
self.viewModel.valuePublisher.send("") |
|
|
|
}, label: { |
|
|
|
Text("download") |
|
|
|
}) |
|
|
|
.buttonStyle(BorderlessButtonStyle()).confirmationDialog("Open", isPresented: $downloadOptions) { |
|
|
|
let dlcount = dlUrls.count |
|
|
|
|
|
|
|
ForEach(0..<dlcount) { index in |
|
|
|
let name = makeLabel(url: dlUrls[index]) |
|
|
|
ForEach(dlUrls, id: \.self) { ur in |
|
|
|
let name = makeLabel(url: ur) |
|
|
|
HStack { |
|
|
|
Button(name) { |
|
|
|
self.preview(url: dlUrls[index], dl: false) |
|
|
|
Task { |
|
|
|
await self.preview(url: ur, dl: false) |
|
|
|
} |
|
|
|
} |
|
|
|
Button("download") { |
|
|
|
self.preview(url: dlUrls[index], dl: true) |
|
|
|
Button("download \(name)") { |
|
|
|
Task { |
|
|
|
await self.preview(url: ur, dl: true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -106,6 +115,8 @@ struct KBrowserView: View { |
|
|
|
print(value) |
|
|
|
downloadOptions = true |
|
|
|
dlUrls = value |
|
|
|
}.alert("File exists", isPresented: $showingAlert) { |
|
|
|
Button("OK", role: .cancel) { } |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@ -137,11 +148,11 @@ struct KBrowserView: View { |
|
|
|
if showLoader { |
|
|
|
// Loader() |
|
|
|
} |
|
|
|
}.fullScreenCover(isPresented: $showVideoView) { |
|
|
|
}.fullScreenCover(isPresented: $showVideoView, content: { |
|
|
|
SVideoPlayer(completionHandler: { saved in |
|
|
|
showVideoView = false |
|
|
|
}, model: videoModel!) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -162,7 +173,9 @@ struct KBrowserView: View { |
|
|
|
return name |
|
|
|
} |
|
|
|
|
|
|
|
func preview(url: String, dl: Bool) { |
|
|
|
func preview(url: String, dl: Bool) async { |
|
|
|
showVideoView = false |
|
|
|
|
|
|
|
let url2 = URL(string: url)! |
|
|
|
|
|
|
|
if (url2.pathExtension == "zip") { |
|
|
|
@ -192,21 +205,16 @@ struct KBrowserView: View { |
|
|
|
if hostcomp.count > 2 { |
|
|
|
let hostEnd = String(hostcomp[1] + "." + hostcomp[2]) |
|
|
|
|
|
|
|
getCookieHeader(for: hostEnd) { dictionary in |
|
|
|
print(dictionary) |
|
|
|
|
|
|
|
item.cookies = dictionary |
|
|
|
self.showVideo(selectedItem: item) |
|
|
|
} |
|
|
|
item.cookies = await getCookieHeader(for: hostEnd) |
|
|
|
} |
|
|
|
|
|
|
|
if ((url2.pathExtension == "mp4" || url2.pathExtension == "m3u8") && dl) { |
|
|
|
NetworkManager.sharedInstance.downloadToServer(path: site, url: url2, cookies: item.cookies, result: { |
|
|
|
NetworkManager.sharedInstance.downloadToServer(path: site, url: URL(string: item.externalURL!)!, cookies: item.cookies, result: { |
|
|
|
(r) in |
|
|
|
print(r) |
|
|
|
// self.showAlert(title: "download ready", message: r) |
|
|
|
if (r == "exists") { |
|
|
|
|
|
|
|
showingAlert = true |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
@ -215,21 +223,20 @@ struct KBrowserView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func getCookieHeader(for domain: String? = nil, completion: @escaping (String)->()) { |
|
|
|
func getCookieHeader(for domain: String? = nil) async -> String { |
|
|
|
let httpCookieStore = viewModel.httpCookieStore! |
|
|
|
var cookieDict = [HTTPCookie]() |
|
|
|
httpCookieStore.getAllCookies { cookies in |
|
|
|
for cookie in cookies { |
|
|
|
if let domain = domain { |
|
|
|
if cookie.domain.contains(domain) { |
|
|
|
cookieDict.append(cookie) |
|
|
|
} |
|
|
|
let cookies = await httpCookieStore.allCookies() |
|
|
|
for cookie in cookies { |
|
|
|
if let domain = domain { |
|
|
|
if cookie.domain.contains(domain) { |
|
|
|
cookieDict.append(cookie) |
|
|
|
} |
|
|
|
} |
|
|
|
let values = HTTPCookie.requestHeaderFields(with: cookieDict) |
|
|
|
|
|
|
|
completion(values["Cookie"]!) |
|
|
|
} |
|
|
|
let values = HTTPCookie.requestHeaderFields(with: cookieDict) |
|
|
|
|
|
|
|
return values["Cookie"]! |
|
|
|
} |
|
|
|
|
|
|
|
func showVideo(selectedItem: MediaItem) { |
|
|
|
|