Ben há 11 meses atrás
pai
commit
bc3a538179
3 ficheiros alterados com 38 adições e 5 exclusões
  1. 6 2
      js/info.js
  2. 31 2
      js/main.swift
  3. 1 1
      js/test.js

+ 6 - 2
js/info.js

@@ -80,8 +80,12 @@ getStringBetween = (string, needleStart, needleEnd, offsetStart = 0, offsetEnd =
 
 getUrlFromSignature = (signatureCipher, baseContent) => {
     const decipher = getDecipherFunction(baseContent);
-    const searchParams = new URLSearchParams(signatureCipher);
-    const [url, signature, sp] = [searchParams.get("url"), searchParams.get("s"), searchParams.get("sp")];
+    const searchParams = {}
+    for (const item of signatureCipher.split("&")) {
+        const [key, value] = item.split('=');
+        searchParams[decodeURIComponent(key)] = decodeURIComponent(value);
+    }
+    const [url, signature, sp] = [searchParams["url"], searchParams["s"], searchParams["sp"]];
     console.log(signatureCipher, url, signature, sp);
     return `${url}&${sp}=${decipher(signature)}`;
 }

+ 31 - 2
js/main.swift

@@ -65,10 +65,38 @@ func createJSContext() -> JSContext {
     return ctx!
 }
 
+func testDetail(url: String, ctx: JSContext) -> Void {
+    if let detailFunction = ctx.objectForKeyedSubscript("detail") {
+        print(detailFunction)
+        let result = detailFunction.call(withArguments: [url])
+        print(result?.toString())
+        let resolveHandler: @convention(block) (JSValue?) -> Void = { resolvedValue in
+            if let value = resolvedValue {
+                print("解析成功: ", value)
+            }
+        }
+        let rejectHandler: @convention(block) (JSValue?) -> Void = { rejectedValue in
+            if let value = rejectedValue {
+                print("解析失败:", value)
+            }
+        }
+        if let thenFunction = result?.objectForKeyedSubscript("then") {
+            print("Then:", thenFunction.toString())
+            // 调用 then 函数,并传入回调函数
+            thenFunction.call(withArguments: [unsafeBitCast(resolveHandler, to: AnyObject.self)])
+        }
+        if let catchFunction = result?.objectForKeyedSubscript("catch") {
+            print("Catch:", catchFunction.toString())
+            // 调用 catch 函数,并传入回调函数
+            catchFunction.call(withArguments: [unsafeBitCast(rejectHandler, to: AnyObject.self)])
+        }
+    }
+}
+
 func testSearch(keyword: String, ctx: JSContext) -> Void {
     if let searchFunction = ctx.objectForKeyedSubscript("search") {
         print(searchFunction)
-        let result = searchFunction.call(withArguments: ["周杰伦", nil])
+        let result = searchFunction.call(withArguments: [keyword, nil])
         print(result?.toString())
         let resolveHandler: @convention(block) (JSValue?) -> Void = { resolvedValue in
             if let value = resolvedValue {
@@ -101,7 +129,8 @@ if let url = URL(string: "http://hubgit.cn/ben/be-ytb/raw/master/js/info.js") {
         case .success(let jsString):
             print("下载远程JS成功")
             ctx.evaluateScript(jsString)
-            testSearch(keyword: "周杰伦", ctx: ctx)
+            testDetail(url: "https://www.youtube.com/watch?v=7wNb0pHyGuI", ctx: ctx)
+//            testSearch(keyword: "周杰伦", ctx: ctx)
         case .failure(let error):
             print("Download Error: \(error)")
         }

+ 1 - 1
js/test.js

@@ -1,4 +1,4 @@
-const url = `https://www.youtube.com/watch?v=qrGRv0uMuag`
+const url = `https://www.youtube.com/watch?v=7wNb0pHyGuI`
 detail(url, true)
     .then(res => {
         console.log(res);