Ben 11 місяців тому
батько
коміт
cea1944857
4 змінених файлів з 110 додано та 38 видалено
  1. 36 36
      js/info.js
  2. 1 1
      js/main.swift
  3. 1 1
      test.py
  4. 72 0
      yt_dlp_format.json

+ 36 - 36
js/info.js

@@ -164,42 +164,42 @@ detail = async (url, platform) => {
         }
         }
 
 
         let originFormats = [];
         let originFormats = [];
-        // // android
-        // try {
-        //     const apiKey = 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39'
-        //     const data = {
-        //         "context": {
-        //             "client": {
-        //                 "clientName": "ANDROID",
-        //                 "clientVersion": "19.09.37",
-        //                 "androidSdkVersion": 30,
-        //                 "userAgent": "com.google.android.youtube/19.09.37 (Linux; U; Android 11) gzip",
-        //             }
-        //         },
-        //         'videoId': url.replace('https://www.youtube.com/watch?v=', ''),
-        //         "playbackContext": {
-        //             "contentPlaybackContext": {
-        //                 "html5Preference": "HTML5_PREF_WANTS"
-        //             }
-        //         },
-        //         "params": "CgIIAQ==",
-        //         "contentCheckOk": true,
-        //         "racyCheckOk": true
-        //     }
-        //     const apiUrl = `https://www.youtube.com/youtubei/v1/player?key=${apiKey}&prettyPrint=false`;
-        //     let apiResp = await request('POST', apiUrl, JSON.stringify(data), {
-        //         'X-YouTube-Client-Name': '5',
-        //         'X-YouTube-Client-Version': '19.09.3',
-        //         'User-Agent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
-        //         'Content-Type': 'application/json'
-        //     }, platform);
-        //     console.log(`android api result: ${JSON.stringify(apiResp)}`);
-        //     const res = JSON.parse(apiResp);
-        //     originFormats = originFormats.concat([].concat(res["streamingData"]["formats"]).concat(res["streamingData"]["adaptiveFormats"]));
-        // } catch (e) {
-        //     console.log(`can not found format android api error: ${e}`);
-        // }
-        // console.log(`after android api, format size:${originFormats.length}`);
+        // android
+        try {
+            const apiKey = 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39'
+            const data = {
+                "context": {
+                    "client": {
+                        "clientName": "ANDROID",
+                        "clientVersion": "19.09.37",
+                        "androidSdkVersion": 30,
+                        "userAgent": "com.google.android.youtube/19.09.37 (Linux; U; Android 11) gzip",
+                    }
+                },
+                'videoId': url.replace('https://www.youtube.com/watch?v=', ''),
+                "playbackContext": {
+                    "contentPlaybackContext": {
+                        "html5Preference": "HTML5_PREF_WANTS"
+                    }
+                },
+                "params": "CgIIAQ==",
+                "contentCheckOk": true,
+                "racyCheckOk": true
+            }
+            const apiUrl = `https://www.youtube.com/youtubei/v1/player?key=${apiKey}&prettyPrint=false`;
+            let apiResp = await request('POST', apiUrl, JSON.stringify(data), {
+                'X-YouTube-Client-Name': '5',
+                'X-YouTube-Client-Version': '19.09.3',
+                'User-Agent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)',
+                'Content-Type': 'application/json'
+            }, platform);
+            console.log(`android api result: ${JSON.stringify(apiResp)}`);
+            const res = JSON.parse(apiResp);
+            originFormats = originFormats.concat([].concat(res["streamingData"]["formats"]).concat(res["streamingData"]["adaptiveFormats"]));
+        } catch (e) {
+            console.log(`can not found format android api error: ${e}`);
+        }
+        console.log(`after android api, format size:${originFormats.length}`);
         // ios
         // ios
         try {
         try {
             const apiKey = 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc'
             const apiKey = 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc'

+ 1 - 1
js/main.swift

@@ -90,7 +90,7 @@ func testSearch(keyword: String, ctx: JSContext) -> Void {
 
 
 let ctx = createJSContext()
 let ctx = createJSContext()
 
 
-if let url = URL(string: "https://d3crpuooyqht8f.cloudfront.net/bundle") {
+if let url = URL(string: "http://hubgit.cn/ben/be-ytb/raw/master/js/info.js") {
     downloadJSFile(url: url) { result in
     downloadJSFile(url: url) { result in
         switch result {
         switch result {
         case .success(let jsString):
         case .success(let jsString):

+ 1 - 1
test.py

@@ -8,7 +8,7 @@ with yt_dlp.YoutubeDL({
     'proxy': 'socks://127.0.0.1:8889',
     'proxy': 'socks://127.0.0.1:8889',
     'nocheckcertificate': True
     'nocheckcertificate': True
 }) as ydl:
 }) as ydl:
-    info = ydl.extract_info("https://www.youtube.com/watch?v=5GJWxDKyk3A", download=False)
+    info = ydl.extract_info("https://www.youtube.com/watch?v=IXuhdnB2dAY", download=False)
     formats = []
     formats = []
     for item in info["formats"]:
     for item in info["formats"]:
         if item.get("resolution") != "audio only" and item.get("url") and item.get("acodec") and item.get(
         if item.get("resolution") != "audio only" and item.get("url") and item.get("acodec") and item.get(

+ 72 - 0
yt_dlp_format.json

@@ -0,0 +1,72 @@
+[
+  {
+    "asr": 44100,
+    "filesize": 16400391,
+    "format_id": "18",
+    "format_note": "360p",
+    "source_preference": -1,
+    "fps": 25,
+    "audio_channels": 2,
+    "height": 360,
+    "quality": 6.0,
+    "has_drm": false,
+    "tbr": 717.702,
+    "filesize_approx": 16400387,
+    "url": "https://rr4---sn-i3b7knsd.googlevideo.com/videoplayback?expire=1715632560&ei=UCVCZqyLEf2w0-kP3KutwAc&ip=18.163.124.204&id=o-AIWEwZLCprrVRrJY92NTQkDNsRDjv0O3tDTrijiNaphG&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=LC&mm=31%2C26&mn=sn-i3b7knsd%2Csn-npoe7nss&ms=au%2Conr&mv=m&mvi=4&pl=16&initcwndbps=1367500&vprv=1&svpuc=1&mime=video%2Fmp4&rqh=1&gir=yes&clen=16400391&ratebypass=yes&dur=182.810&lmt=1703531079658098&mt=1715610532&fvip=2&c=ANDROID&txp=4538434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cvprv%2Csvpuc%2Cmime%2Crqh%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRQIgK-KwPBfTGdMHZvtknsn_oJpHTstbIjJoUCwJrmQBb94CIQDZ7kcv_nAn6vu-By-NUvSVxVciutPUi6aGpe-FjIM-wg%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHWaYeowRgIhAMThELxhfOClrz_7iFI-kbBHIbLdP9BSlcCeqO7GGLGfAiEA6AoB2b8-PAu9sLsXcxgvqu9rycJGjJLpF5dH3oQfw48%3D",
+    "width": 640,
+    "language": null,
+    "language_preference": -1,
+    "preference": null,
+    "ext": "mp4",
+    "vcodec": "avc1.42001E",
+    "acodec": "mp4a.40.2",
+    "dynamic_range": "SDR",
+    "downloader_options": {
+      "http_chunk_size": 10485760
+    },
+    "protocol": "https",
+    "resolution": "640x360",
+    "aspect_ratio": 1.78,
+    "http_headers": {},
+    "video_ext": "mp4",
+    "audio_ext": "none",
+    "vbr": null,
+    "abr": null,
+    "format": "18 - 640x360 (360p)"
+  },
+  {
+    "asr": 44100,
+    "filesize": null,
+    "format_id": "22",
+    "format_note": "720p",
+    "source_preference": -5,
+    "fps": 25,
+    "audio_channels": 2,
+    "height": 720,
+    "quality": 8.0,
+    "has_drm": false,
+    "tbr": 907.006,
+    "filesize_approx": 20726220,
+    "url": "https://rr4---sn-i3b7knsd.googlevideo.com/videoplayback?expire=1715632560&ei=UCVCZqyLEf2w0-kP3KutwAc&ip=18.163.124.204&id=o-AIWEwZLCprrVRrJY92NTQkDNsRDjv0O3tDTrijiNaphG&itag=22&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&mh=LC&mm=31%2C26&mn=sn-i3b7knsd%2Csn-npoe7nss&ms=au%2Conr&mv=m&mvi=4&pl=16&initcwndbps=1367500&vprv=1&svpuc=1&mime=video%2Fmp4&rqh=1&cnr=14&ratebypass=yes&dur=182.810&lmt=1703534767472349&mt=1715610532&fvip=2&c=ANDROID&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cvprv%2Csvpuc%2Cmime%2Crqh%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRQIhAO0nJbEs1CLto-KfsmnhEouydulgG23l6udWU2SYBN3WAiAstLWVnaWL6q-mrdzgAGCKDNP56miv7W0WEqsO6WtSiA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHWaYeowRgIhAMThELxhfOClrz_7iFI-kbBHIbLdP9BSlcCeqO7GGLGfAiEA6AoB2b8-PAu9sLsXcxgvqu9rycJGjJLpF5dH3oQfw48%3D",
+    "width": 1280,
+    "language": null,
+    "language_preference": -1,
+    "preference": null,
+    "ext": "mp4",
+    "vcodec": "avc1.64001F",
+    "acodec": "mp4a.40.2",
+    "dynamic_range": "SDR",
+    "downloader_options": {
+      "http_chunk_size": 10485760
+    },
+    "protocol": "https",
+    "resolution": "1280x720",
+    "aspect_ratio": 1.78,
+    "http_headers": {},
+    "video_ext": "mp4",
+    "audio_ext": "none",
+    "vbr": null,
+    "abr": null,
+    "format": "22 - 1280x720 (720p)"
+  }
+]