Browse Source

Webview

master
marcoschmickler 4 years ago
parent
commit
eb12d09652
  1. 25
      download.js
  2. 4
      kplayer.xcodeproj/project.pbxproj
  3. 36
      kplayer/video/SVideoPlayer.swift
  4. 61
      kplayer/web/KBrowserView.swift

25
download.js

@ -12,13 +12,34 @@
linkname = "href" linkname = "href"
} }
else if (window.location.hostname.endsWith("chaturbate.com")) { 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")) { else if (window.location.hostname.endsWith("hegre.com")) {
links = document.querySelectorAll('a[class="members-only"], a[class="image-download"]') links = document.querySelectorAll('a[class="members-only"], a[class="image-download"]')
linkname = "href" 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") { else if (window.location.hostname == "www.kink.com") {
links = document.querySelectorAll('span[data-resolution="720"], span[data-resolution="1080"]') links = document.querySelectorAll('span[data-resolution="720"], span[data-resolution="1080"]')
linkname = "data-url" linkname = "data-url"

4
kplayer.xcodeproj/project.pbxproj

@ -10,7 +10,6 @@
1C73600CB93F16F4F28C116F /* KSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736A6E8396EE306B1AD3A8 /* KSettingsView.swift */; }; 1C73600CB93F16F4F28C116F /* KSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736A6E8396EE306B1AD3A8 /* KSettingsView.swift */; };
1C736048BFA120F5C7D36874 /* readme.md in Sources */ = {isa = PBXBuildFile; fileRef = 1C73685B4BBFDAFBF08C032C /* readme.md */; }; 1C736048BFA120F5C7D36874 /* readme.md in Sources */ = {isa = PBXBuildFile; fileRef = 1C73685B4BBFDAFBF08C032C /* readme.md */; };
1C7360C0F2A4F0214FE353BD /* FileHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7367ECBD369A2A0C94C499 /* FileHelper.swift */; }; 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 */; }; 1C73613562EB375F53A0BD03 /* ServerDownloadDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736595533B56039C417E0D /* ServerDownloadDelegate.swift */; };
1C7361B3AF46CEB30D3F4FA0 /* KSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736AE5021E3D985FE3402D /* KSettings.swift */; }; 1C7361B3AF46CEB30D3F4FA0 /* KSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736AE5021E3D985FE3402D /* KSettings.swift */; };
1C73631EACF56BABD3B2BCFB /* LayoutTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736BC4450890C45F8FBC63 /* LayoutTools.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 = "<group>"; }; 1C736260E748CF136FF37EA7 /* UploadOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadOperation.swift; sourceTree = "<group>"; };
1C7362DE1D6BE634D7C2ACBF /* KPersistentContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KPersistentContainer.swift; sourceTree = "<group>"; }; 1C7362DE1D6BE634D7C2ACBF /* KPersistentContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KPersistentContainer.swift; sourceTree = "<group>"; };
1C73631C96E6C860833052CA /* ItemType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemType.swift; sourceTree = "<group>"; }; 1C73631C96E6C860833052CA /* ItemType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemType.swift; sourceTree = "<group>"; };
1C7363A2B3338DAF752D8CE9 /* download.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = download.js; sourceTree = "<group>"; };
1C73645DBD6499A726D34973 /* links.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = links.html; sourceTree = "<group>"; }; 1C73645DBD6499A726D34973 /* links.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = links.html; sourceTree = "<group>"; };
1C73647019E6C2E822127BA3 /* DatabaseManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; }; 1C73647019E6C2E822127BA3 /* DatabaseManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; };
1C7364709899FF62774B0199 /* VideoHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoHelper.swift; sourceTree = "<group>"; }; 1C7364709899FF62774B0199 /* VideoHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoHelper.swift; sourceTree = "<group>"; };
@ -211,7 +209,6 @@
1C73625012D50E457D18A785 /* kplayer.js */, 1C73625012D50E457D18A785 /* kplayer.js */,
1C73615FFA2AA98BD1C56CD4 /* links.html */, 1C73615FFA2AA98BD1C56CD4 /* links.html */,
1C73645DBD6499A726D34973 /* links.html */, 1C73645DBD6499A726D34973 /* links.html */,
1C7363A2B3338DAF752D8CE9 /* download.js */,
); );
path = server; path = server;
sourceTree = "<group>"; sourceTree = "<group>";
@ -621,7 +618,6 @@
1C7366FF0651A802F09936D6 /* WebViewModel.swift in Sources */, 1C7366FF0651A802F09936D6 /* WebViewModel.swift in Sources */,
1C736776CF759CA3DB136F33 /* KBrowserView.swift in Sources */, 1C736776CF759CA3DB136F33 /* KBrowserView.swift in Sources */,
1C7369C0A66A8F8CB0E54460 /* WebView.swift in Sources */, 1C7369C0A66A8F8CB0E54460 /* WebView.swift in Sources */,
1C736110BE0903CEFE5C18A4 /* download.js in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

36
kplayer/video/SVideoPlayer.swift

@ -348,7 +348,7 @@ struct SVideoPlayer: View, EditItemDelegate {
} }
} }
player.automaticallyWaitsToMinimizeStalling = false
player.automaticallyWaitsToMinimizeStalling = true
let item = model.currentPlayerItem() let item = model.currentPlayerItem()
@ -421,21 +421,6 @@ struct SVideoPlayer: View, EditItemDelegate {
} }
private func move(_ dragged: CGSize, start: CGPoint) -> Bool { 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 model.paused {
if let time = getCurrentTime() { if let time = getCurrentTime() {
if smoothTime < 0 { if smoothTime < 0 {
@ -443,8 +428,8 @@ struct SVideoPlayer: View, EditItemDelegate {
} }
if (start.y < 130) { 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) seekTimeSmoothly(smoothTime + delta)
return false 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() { if let time = getCurrentTime() {
let dragWidth = 20.0 let dragWidth = 20.0
if !model.seeking { if !model.seeking {

61
kplayer/web/KBrowserView.swift

@ -15,12 +15,14 @@ struct KBrowserView: View {
@State var showVideoView = false @State var showVideoView = false
@State var message = "" @State var message = ""
@State var webTitle = "" @State var webTitle = ""
@State var serverMessage = "On Server"
@State var dlUrls = [String]() @State var dlUrls = [String]()
var item: String var item: String
var completionHandler: (() -> Void)? var completionHandler: (() -> Void)?
@State var videoModel: SVideoModel? @State var videoModel: SVideoModel?
@State private var showingAlert = false
// For WebView's forward and backward navigation // For WebView's forward and backward navigation
var webViewNavigationBar: some View { var webViewNavigationBar: some View {
@ -79,22 +81,29 @@ struct KBrowserView: View {
}) })
.buttonStyle(BorderlessButtonStyle()) .buttonStyle(BorderlessButtonStyle())
Spacer() Spacer()
Text (serverMessage).foregroundColor(Color.blue)
Button(action: { Button(action: {
NetworkManager.sharedInstance.dlserverlen { c in
serverMessage = "On Server: \(c)";
}
self.viewModel.valuePublisher.send("") self.viewModel.valuePublisher.send("")
}, label: { }, label: {
Text("download") Text("download")
}) })
.buttonStyle(BorderlessButtonStyle()).confirmationDialog("Open", isPresented: $downloadOptions) { .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 { HStack {
Button(name) { 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) print(value)
downloadOptions = true downloadOptions = true
dlUrls = value dlUrls = value
}.alert("File exists", isPresented: $showingAlert) {
Button("OK", role: .cancel) { }
} }
} }
@ -137,11 +148,11 @@ struct KBrowserView: View {
if showLoader { if showLoader {
// Loader() // Loader()
} }
}.fullScreenCover(isPresented: $showVideoView) {
}.fullScreenCover(isPresented: $showVideoView, content: {
SVideoPlayer(completionHandler: { saved in SVideoPlayer(completionHandler: { saved in
showVideoView = false showVideoView = false
}, model: videoModel!) }, model: videoModel!)
}
})
} }
@ -162,7 +173,9 @@ struct KBrowserView: View {
return name return name
} }
func preview(url: String, dl: Bool) {
func preview(url: String, dl: Bool) async {
showVideoView = false
let url2 = URL(string: url)! let url2 = URL(string: url)!
if (url2.pathExtension == "zip") { if (url2.pathExtension == "zip") {
@ -192,21 +205,16 @@ struct KBrowserView: View {
if hostcomp.count > 2 { if hostcomp.count > 2 {
let hostEnd = String(hostcomp[1] + "." + hostcomp[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) { 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 (r) in
print(r) print(r)
// self.showAlert(title: "download ready", message: r) // self.showAlert(title: "download ready", message: r)
if (r == "exists") { 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! let httpCookieStore = viewModel.httpCookieStore!
var cookieDict = [HTTPCookie]() 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) { func showVideo(selectedItem: MediaItem) {

Loading…
Cancel
Save