Browse Source

add: requestId

Ben 8 months ago
parent
commit
507c97b778
5 changed files with 46 additions and 63 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. 46 63
      js/youtube/youtubev1.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


+ 46 - 63
js/youtube/youtubev1.js

@@ -124,6 +124,8 @@ request = async (method, url, data = null, headers = {}, requestId, platform) =>
 
 detail = async (url, requestId, platform) => {
     try {
+        // fetch recommend
+        const recommendInfo = [];
         const htmlResp = await request('GET', `${url}&bpctr=9999999999&has_verified=1`, null, {
             'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
             'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
@@ -133,30 +135,42 @@ detail = async (url, requestId, platform) => {
             'Cookie': 'PREF=hl=en&tz=UTC; SOCS=CAI'
         }, requestId, platform);
         let {data: html, headers: htmlHeaders} = htmlResp;
-
         let regex = /var ytInitialPlayerResponse\s*=\s*({.*?});/;
         let match = html.match(regex);
-        if (!match || !match.length) {
-            console.log('can not found JSON: ytInitialPlayerResponse');
-            throw new Error('JSON not found: ytInitialPlayerResponse');
-        }
-        const ytInitialPlayerResponse = JSON.parse(match[1]);
-        if (printable(platform)) {
+        if (match) {
+            const ytInitialPlayerResponse = JSON.parse(match[1]);
             console.log(ytInitialPlayerResponse);
-        }
-        const originVideoDetails = ytInitialPlayerResponse['videoDetails'];
-        const thumbnails = []
-        for (const item of originVideoDetails['thumbnail']['thumbnails']) {
-            thumbnails.push({
-                'url': item['url'],
-                'width': item['width'] + "",
-                'height': item['height'] + ""
-            })
+            const originVideoDetails = ytInitialPlayerResponse['videoDetails'];
+            const ytInitialDataMatch = html.match(/var ytInitialData\s*=\s*({.*?});/);
+            if (ytInitialDataMatch && ytInitialDataMatch.length === 2) {
+                const ytInitialData = JSON.parse(ytInitialDataMatch[1]);
+                console.log(ytInitialData);
+                for (const item of ytInitialData["contents"]?.["twoColumnWatchNextResults"]?.["secondaryResults"]?.["secondaryResults"]?.["results"] || []) {
+                    if (item["compactVideoRenderer"]) {
+                        const recommendVideo = item["compactVideoRenderer"];
+                        console.log(`recommend video: ${JSON.stringify(recommendVideo)}`);
+                        if (recommendVideo["videoId"]) {
+                            recommendInfo.push({
+                                "type": "gridVideoRenderer",
+                                "videoId": recommendVideo["videoId"],
+                                "title": recommendVideo["title"]?.["simpleText"],
+                                "thumbnails": recommendVideo["thumbnail"]?.["thumbnails"],
+                                "channelName": recommendVideo["longBylineText"]?.["runs"]?.[0]?.["text"],
+                                "publishedTimeText": recommendVideo["publishedTimeText"]?.["simpleText"],
+                                "viewCountText": recommendVideo["viewCountText"]?.["simpleText"],
+                                "shortViewCountText": recommendVideo["shortViewCountText"]?.["simpleText"],
+                                "lengthText": recommendVideo["lengthText"]?.["simpleText"]
+                            })
+                        }
+                    }
+                }
+            }
         }
 
-        let originFormats = [];
-
         // android
+        let thumbnails = [];
+        let originFormats = [];
+        let originVideoDetails = undefined;
         try {
             const apiUrl = `https://music.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8`;
             const apiResp = await request('POST', apiUrl, JSON.stringify({
@@ -182,6 +196,7 @@ detail = async (url, requestId, platform) => {
             console.log(`android api result: ${JSON.stringify(apiResp)}`);
             const res = JSON.parse(apiData);
             const currentFormats = [];
+            originVideoDetails = res["videoDetails"];
             for (const format of [].concat(res["streamingData"]["formats"] || []).concat(res["streamingData"]["adaptiveFormats"] || [])) {
                 if (format) {
                     format["from"] = "android"
@@ -191,26 +206,16 @@ detail = async (url, requestId, platform) => {
             originFormats = originFormats.concat(currentFormats);
         } catch (e) {
             console.log(`can not found format android api error: ${e}`);
-            console.log(`detail2 result error: ${JSON.stringify(ret)}`);
             const ret = {
                 "code": -1,
-                "msg": e.toString()
+                "msg": e.toString(),
+                "requestId": requestId
             }
+            console.log(`detail2 result error: ${JSON.stringify(ret)}`);
             return ret;
         }
         console.log(`after android api, format size:${originFormats.length}`);
 
-        // web
-        // const currentFormats = [];
-        // for (const format of ytInitialPlayerResponse["streamingData"]["formats"].concat(ytInitialPlayerResponse["streamingData"]["adaptiveFormats"])) {
-        //     if (format) {
-        //         format["from"] = "web"
-        //         currentFormats.push(format);
-        //     }
-        // }
-        // originFormats = originFormats.concat(currentFormats);
-        // console.log(`after html, format size:${originFormats.length}`);
-
         let qualities = [];
         const formats = [];
         for (let format of originFormats) {
@@ -246,33 +251,6 @@ detail = async (url, requestId, platform) => {
             }
         }
 
-        const ytInitialDataMatch = html.match(/var ytInitialData\s*=\s*({.*?});/);
-        const recommendInfo = [];
-        if (ytInitialDataMatch && ytInitialDataMatch.length === 2) {
-            const ytInitialData = JSON.parse(ytInitialDataMatch[1]);
-            if (printable(platform)) {
-                console.log(ytInitialData);
-            }
-            for (const item of ytInitialData["contents"]?.["twoColumnWatchNextResults"]?.["secondaryResults"]?.["secondaryResults"]?.["results"] || []) {
-                if (item["compactVideoRenderer"]) {
-                    const recommendVideo = item["compactVideoRenderer"];
-                    console.log(`recommend video: ${JSON.stringify(recommendVideo)}`);
-                    if (recommendVideo["videoId"]) {
-                        recommendInfo.push({
-                            "type": "gridVideoRenderer",
-                            "videoId": recommendVideo["videoId"],
-                            "title": recommendVideo["title"]?.["simpleText"],
-                            "thumbnails": recommendVideo["thumbnail"]?.["thumbnails"],
-                            "channelName": recommendVideo["longBylineText"]?.["runs"]?.[0]?.["text"],
-                            "publishedTimeText": recommendVideo["publishedTimeText"]?.["simpleText"],
-                            "viewCountText": recommendVideo["viewCountText"]?.["simpleText"],
-                            "shortViewCountText": recommendVideo["shortViewCountText"]?.["simpleText"],
-                            "lengthText": recommendVideo["lengthText"]?.["simpleText"]
-                        })
-                    }
-                }
-            }
-        }
 
         formats.sort((a, b) => parseInt(a["height"]) - parseInt(b["height"]));
 
@@ -299,14 +277,16 @@ detail = async (url, requestId, platform) => {
                     "formats": formats
                 }
             },
-            "id": "MusicDetailViewModel_detail_url"
+            "id": "MusicDetailViewModel_detail_url",
+            "requestId": requestId
         }
         console.log(`detail result: ${JSON.stringify(ret)}`);
         return ret;
     } catch (e) {
         const ret = {
             "code": -1,
-            "msg": e.toString()
+            "msg": e.toString(),
+            "requestId": requestId
         }
         console.log(`detail2 result error: ${JSON.stringify(ret)}`);
         console.log(e);
@@ -365,7 +345,8 @@ search = async (keyword, next, requestId, platform) => {
                         "continuation": res["onResponseReceivedCommands"]?.[0]?.["appendContinuationItemsAction"]?.["continuationItems"]?.[1]?.["continuationItemRenderer"]?.["continuationEndpoint"]?.["continuationCommand"]?.["token"],
                     }),
                 },
-                "id": "MusicSearchResultViewModel_search_result"
+                "id": "MusicSearchResultViewModel_search_result",
+                "requestId": requestId
             }
             console.log(`[next] search result: ${JSON.stringify(ret)}`);
             return ret;
@@ -434,7 +415,8 @@ search = async (keyword, next, requestId, platform) => {
                     "data": videos,
                     "next": JSON.stringify(next),
                 },
-                "id": "MusicSearchResultViewModel_search_result"
+                "id": "MusicSearchResultViewModel_search_result",
+                "requestId": requestId
             }
             console.log(`unnext search result: ${JSON.stringify(ret)}`);
             return ret;
@@ -442,7 +424,8 @@ search = async (keyword, next, requestId, platform) => {
     } catch (e) {
         const ret = {
             "code": -1,
-            "msg": e.toString()
+            "msg": e.toString(),
+            "requestId": requestId
         }
         console.log(`search result error: ${JSON.stringify(ret)}`);
         return ret;

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