Browse Source

mod: android api

Ben 8 months ago
parent
commit
9cbecb29ff
2 changed files with 26 additions and 13 deletions
  1. 1 1
      js/youtube/test.js
  2. 25 12
      js/youtube/youtubev1.js

+ 1 - 1
js/youtube/test.js

@@ -6,7 +6,7 @@
 //         console.log(e);
 //     })
 
-detail(`https://www.youtube.com/watch?v=S9bCLPwzSC0`, '123', 'WEB')
+detail(`https://www.youtube.com/watch?v=S9bCLPwzSC0`, '123', 'LOCAL')
     .then(res => {
         console.log(res);
     })

+ 25 - 12
js/youtube/youtubev1.js

@@ -89,11 +89,15 @@ request = async (method, url, data = null, headers = {}, requestId, platform) =>
         url = url.replace("https://www.youtube.com/", "http://16.162.163.175:80/");
         url = url.replace("https://music.youtube.com/", "http://16.162.163.175:80/");
     }
+    if (platform === "LOCAL") {
+        url = url.replace("https://www.youtube.com/", "http://127.0.0.1:80/");
+        url = url.replace("https://music.youtube.com/", "http://127.0.0.1:80/");
+    }
     console.log(`request url:${url}`)
     console.log(`request data:${data}`)
     console.log(`request method:${method}`)
     console.log(`request headers:${JSON.stringify((headers))}`)
-    if (platform === "WEB") {
+    if (platform === "WEB" || platform === "LOCAL") {
         const res = await fetch(url, {
             'mode': 'cors',
             'method': method,
@@ -172,25 +176,34 @@ detail = async (url, requestId, platform) => {
         let originFormats = [];
         let originVideoDetails = undefined;
         try {
-            const apiUrl = `https://music.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8`;
+            const apiUrl = `https://music.youtube.com/youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w`;
             const apiResp = await request('POST', apiUrl, JSON.stringify({
                 "context": {
                     "client": {
                         "clientName": "ANDROID",
+                        "clientVersion": "19.09.37",
+                        "androidSdkVersion": 30,
+                        "userAgent": "com.google.android.youtube/19.09.37 (Linux; U; Android 11) gzip",
                         "hl": "en",
-                        "clientVersion": "18.49.37",
-                        "gl": "US"
+                        "timeZone": "UTC",
+                        "utcOffsetMinutes": 0
+                    }
+                },
+                "params": "CgIIAQ==",
+                "playbackContext": {
+                    "contentPlaybackContext": {
+                        "html5Preference": "HTML5_PREF_WANTS"
                     }
                 },
-                "videoId": url.replace('https://www.youtube.com/watch?v=', ''),
-                "params": "CgIQBg"
+                "contentCheckOk": true,
+                "videoId": url.replace('https://www.youtube.com/watch?v=', '')
             }), {
-                'Host': 'www.youtube.com',
-                'Connection': 'keep-alive',
-                'User-Agent': 'com.google.android.apps.youtube.music/17.31.35 (Linux; U; Android 11) gzip',
-                'Accept-Language': 'en-US,en',
-                'Cookie': parseSetCookie(htmlHeaders),
-                'Content-Type': 'application/json'
+                // 'Host': 'www.youtube.com',
+                // 'Connection': 'keep-alive',
+                // 'User-Agent': 'com.google.android.apps.youtube.music/17.31.35 (Linux; U; Android 11) gzip',
+                // 'Accept-Language': 'en-US,en',
+                // 'Cookie': parseSetCookie(htmlHeaders),
+                // 'Content-Type': 'application/json'
             }, requestId, platform);
             let {data: apiData, _} = apiResp;
             console.log(`android api result: ${JSON.stringify(apiResp)}`);