From eb12d0965285e195e9a3d1442662ee1b2b3959d0 Mon Sep 17 00:00:00 2001 From: marcoschmickler Date: Sun, 17 Apr 2022 16:51:19 +0200 Subject: [PATCH] Webview --- download.js | 25 ++++++++++++- kplayer.xcodeproj/project.pbxproj | 4 -- kplayer/video/SVideoPlayer.swift | 36 +++++++++--------- kplayer/web/KBrowserView.swift | 61 +++++++++++++++++-------------- 4 files changed, 75 insertions(+), 51 deletions(-) diff --git a/download.js b/download.js index 0a09d1e..6980ba0 100644 --- a/download.js +++ b/download.js @@ -12,13 +12,34 @@ linkname = "href" } else if (window.location.hostname.endsWith("chaturbate.com")) { - var src = JSON.parse(window.initialRoomDossier).hls_source - window.kplayerUrls.push(src) + var u = JSON.parse(window.initialRoomDossier).hls_source + if (u.indexOf(".m3u8")>0) { + var base = u.split('/').slice(0,-1).join('/') + window.webkit.messageHandlers.jsError.postMessage('base: ' + base) + window.webkit.messageHandlers.jsError.postMessage('url: ' + u) + var r = await fetch(u) + var data = await r.text() + + // Do something with your data + var lines = data.split('\n') + + for (let l of lines) { + if (!l.startsWith("#")) { + window.webkit.messageHandlers.jsError.postMessage('l: ' + base + l) + + window.kplayerUrls.push(base + "/" + l) + } + } + } } else if (window.location.hostname.endsWith("hegre.com")) { links = document.querySelectorAll('a[class="members-only"], a[class="image-download"]') linkname = "href" } + else if (window.location.hostname.endsWith("dickdrainers.com")) { + links = document.querySelectorAll('a[title="Right click the link below and select save as to download:"]') + linkname = "href" + } else if (window.location.hostname == "www.kink.com") { links = document.querySelectorAll('span[data-resolution="720"], span[data-resolution="1080"]') linkname = "data-url" diff --git a/kplayer.xcodeproj/project.pbxproj b/kplayer.xcodeproj/project.pbxproj index 8fe351f..6541b3f 100644 --- a/kplayer.xcodeproj/project.pbxproj +++ b/kplayer.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 1C73600CB93F16F4F28C116F /* KSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736A6E8396EE306B1AD3A8 /* KSettingsView.swift */; }; 1C736048BFA120F5C7D36874 /* readme.md in Sources */ = {isa = PBXBuildFile; fileRef = 1C73685B4BBFDAFBF08C032C /* readme.md */; }; 1C7360C0F2A4F0214FE353BD /* FileHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7367ECBD369A2A0C94C499 /* FileHelper.swift */; }; - 1C736110BE0903CEFE5C18A4 /* download.js in Sources */ = {isa = PBXBuildFile; fileRef = 1C7363A2B3338DAF752D8CE9 /* download.js */; }; 1C73613562EB375F53A0BD03 /* ServerDownloadDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736595533B56039C417E0D /* ServerDownloadDelegate.swift */; }; 1C7361B3AF46CEB30D3F4FA0 /* KSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736AE5021E3D985FE3402D /* KSettings.swift */; }; 1C73631EACF56BABD3B2BCFB /* LayoutTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736BC4450890C45F8FBC63 /* LayoutTools.swift */; }; @@ -111,7 +110,6 @@ 1C736260E748CF136FF37EA7 /* UploadOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadOperation.swift; sourceTree = ""; }; 1C7362DE1D6BE634D7C2ACBF /* KPersistentContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KPersistentContainer.swift; sourceTree = ""; }; 1C73631C96E6C860833052CA /* ItemType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemType.swift; sourceTree = ""; }; - 1C7363A2B3338DAF752D8CE9 /* download.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = download.js; sourceTree = ""; }; 1C73645DBD6499A726D34973 /* links.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = links.html; sourceTree = ""; }; 1C73647019E6C2E822127BA3 /* DatabaseManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = ""; }; 1C7364709899FF62774B0199 /* VideoHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoHelper.swift; sourceTree = ""; }; @@ -211,7 +209,6 @@ 1C73625012D50E457D18A785 /* kplayer.js */, 1C73615FFA2AA98BD1C56CD4 /* links.html */, 1C73645DBD6499A726D34973 /* links.html */, - 1C7363A2B3338DAF752D8CE9 /* download.js */, ); path = server; sourceTree = ""; @@ -621,7 +618,6 @@ 1C7366FF0651A802F09936D6 /* WebViewModel.swift in Sources */, 1C736776CF759CA3DB136F33 /* KBrowserView.swift in Sources */, 1C7369C0A66A8F8CB0E54460 /* WebView.swift in Sources */, - 1C736110BE0903CEFE5C18A4 /* download.js in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/kplayer/video/SVideoPlayer.swift b/kplayer/video/SVideoPlayer.swift index a3a5cf4..1ecc96c 100644 --- a/kplayer/video/SVideoPlayer.swift +++ b/kplayer/video/SVideoPlayer.swift @@ -348,7 +348,7 @@ struct SVideoPlayer: View, EditItemDelegate { } } - player.automaticallyWaitsToMinimizeStalling = false + player.automaticallyWaitsToMinimizeStalling = true let item = model.currentPlayerItem() @@ -421,21 +421,6 @@ struct SVideoPlayer: View, EditItemDelegate { } private func move(_ dragged: CGSize, start: CGPoint) -> Bool { - if dragged.height > 100 { - if timeCounter == 0 { - if let i = model.allItems.index(where: { m in m === model.currentSnapshot }) { - if i + 1 < model.allItems.count { - gotoSnapshot(model.allItems[i + 1]) - } else { - gotoSnapshot(model.allItems[0]) - } - timeCounter = 50 - print("jump") - } - } - return false - } - if model.paused { if let time = getCurrentTime() { if smoothTime < 0 { @@ -443,8 +428,8 @@ struct SVideoPlayer: View, EditItemDelegate { } if (start.y < 130) { - let delta = dragged.width / 500.0 - // print(delta) + let delta = (dragged.width + dragged.height) / 400.0 + print(start.y) seekTimeSmoothly(smoothTime + delta) return false @@ -466,6 +451,21 @@ struct SVideoPlayer: View, EditItemDelegate { } } + if dragged.height > 100 { + if timeCounter == 0 { + if let i = model.allItems.index(where: { m in m === model.currentSnapshot }) { + if i + 1 < model.allItems.count { + gotoSnapshot(model.allItems[i + 1]) + } else { + gotoSnapshot(model.allItems[0]) + } + timeCounter = 50 + print("jump") + } + } + return false + } + if let time = getCurrentTime() { let dragWidth = 20.0 if !model.seeking { diff --git a/kplayer/web/KBrowserView.swift b/kplayer/web/KBrowserView.swift index ca5c652..4fdd039 100644 --- a/kplayer/web/KBrowserView.swift +++ b/kplayer/web/KBrowserView.swift @@ -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.. 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) {