Browse Source

Add: fallback

yemingfeng 2 months ago
parent
commit
e5d2226b47
6 changed files with 94 additions and 2 deletions
  1. 0 0
      js/pornhub.bundle.js
  2. 0 0
      js/tiktok.bundle.js
  3. 0 0
      js/xvideos.bundle.js
  4. 0 0
      js/youtube.bundle.js
  5. 47 1
      js/youtube/youtubev1.js
  6. 47 1
      js/youtube/youtubev2.js

File diff suppressed because it is too large
+ 0 - 0
js/pornhub.bundle.js


File diff suppressed because it is too large
+ 0 - 0
js/tiktok.bundle.js


File diff suppressed because it is too large
+ 0 - 0
js/xvideos.bundle.js


File diff suppressed because it is too large
+ 0 - 0
js/youtube.bundle.js


+ 47 - 1
js/youtube/youtubev1.js

@@ -225,8 +225,54 @@ detail = async (url, requestId, platform) => {
         }
         console.log(`after android api, format size:${originFormats.length}`);
 
+        // fallback
+        let fallbackFormats = []
+        try {
+            const apiUrl = `https://www.youtube.com/youtubei/v1/player`;
+            const apiResp = await request('POST', apiUrl, JSON.stringify({
+                "contentCheckOk": true,
+                "context": {
+                    "client": {
+                        "clientName": "IOS",
+                        "clientVersion": "19.29.1",
+                        "deviceMake": "Apple",
+                        "deviceModel": "iPhone16,2",
+                        "hl": "en",
+                        "osName": "iPhone",
+                        "osVersion": "17.5.1.21F90",
+                        "timeZone": "UTC",
+                        "userAgent": "com.google.ios.youtube/19.29.1 (iPhone16,2; U; CPU iOS 17_5_1 like Mac OS X;)",
+                        "gl": "US",
+                        "utcOffsetMinutes": 0
+                    }
+                },
+                "videoId": url.replace('https://www.youtube.com/watch?v=', '')
+            }), {
+                'User-Agent': 'com.google.ios.youtube/19.29.1 (iPhone16,2; U; CPU iOS 17_5_1 like Mac OS X;)',
+                'Content-Type': 'application/json'
+            }, requestId, platform);
+            let {data: apiData, _} = apiResp;
+            console.log(`android api result: ${JSON.stringify(apiResp)}`);
+            const res = JSON.parse(apiData);
+            const currentFormats = [];
+            for (const format of [].concat(res["streamingData"]["formats"] || []).concat(res["streamingData"]["adaptiveFormats"] || [])) {
+                if (format) {
+                    format["from"] = "android"
+                    currentFormats.push(format);
+                }
+            }
+            fallbackFormats = fallbackFormats.concat(currentFormats);
+        } catch (e) {
+            console.log(`can not found format android fallback api error: ${e}`);
+            const ret = {
+                "code": -1, "msg": e.toString()
+            }
+            console.log(`detail2 fallback result error: ${JSON.stringify(ret)}`);
+            return ret;
+        }
+
         let audioUrl = ""
-        for (let format of [...originFormats].reverse()) {
+        for (let format of fallbackFormats) {
             if (format["url"]) {
                 const {vcodec, acodec} = parseCodecs(format)
                 if (!vcodec && acodec) {

+ 47 - 1
js/youtube/youtubev2.js

@@ -205,8 +205,54 @@ detail = async (url, requestId, platform) => {
         }
         console.log(`after android api, format size:${originFormats.length}`);
 
+        // fallback
+        let fallbackFormats = []
+        try {
+            const apiUrl = `https://www.youtube.com/youtubei/v1/player`;
+            const apiResp = await request('POST', apiUrl, JSON.stringify({
+                "contentCheckOk": true,
+                "context": {
+                    "client": {
+                        "clientName": "IOS",
+                        "clientVersion": "19.29.1",
+                        "deviceMake": "Apple",
+                        "deviceModel": "iPhone16,2",
+                        "hl": "en",
+                        "osName": "iPhone",
+                        "osVersion": "17.5.1.21F90",
+                        "timeZone": "UTC",
+                        "userAgent": "com.google.ios.youtube/19.29.1 (iPhone16,2; U; CPU iOS 17_5_1 like Mac OS X;)",
+                        "gl": "US",
+                        "utcOffsetMinutes": 0
+                    }
+                },
+                "videoId": url.replace('https://www.youtube.com/watch?v=', '')
+            }), {
+                'User-Agent': 'com.google.ios.youtube/19.29.1 (iPhone16,2; U; CPU iOS 17_5_1 like Mac OS X;)',
+                'Content-Type': 'application/json'
+            }, requestId, platform);
+            let {data: apiData, _} = apiResp;
+            console.log(`android api result: ${JSON.stringify(apiResp)}`);
+            const res = JSON.parse(apiData);
+            const currentFormats = [];
+            for (const format of [].concat(res["streamingData"]["formats"] || []).concat(res["streamingData"]["adaptiveFormats"] || [])) {
+                if (format) {
+                    format["from"] = "android"
+                    currentFormats.push(format);
+                }
+            }
+            fallbackFormats = fallbackFormats.concat(currentFormats);
+        } catch (e) {
+            console.log(`can not found format android fallback api error: ${e}`);
+            const ret = {
+                "code": -1, "msg": e.toString()
+            }
+            console.log(`detail2 fallback result error: ${JSON.stringify(ret)}`);
+            return ret;
+        }
+
         let audioUrl = ""
-        for (let format of originFormats) {
+        for (let format of fallbackFormats) {
             if (format["url"]) {
                 const {vcodec, acodec} = parseCodecs(format)
                 if (!vcodec && acodec) {

Some files were not shown because too many files changed in this diff