|
@@ -110,6 +110,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',
|
|
@@ -119,25 +121,41 @@ 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]);
|
|
|
- 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'] + ""
|
|
|
- })
|
|
|
+ if (match) {
|
|
|
+ const ytInitialPlayerResponse = JSON.parse(match[1]);
|
|
|
+ console.log(ytInitialPlayerResponse);
|
|
|
+ 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 thumbnails = [];
|
|
|
let originFormats = [];
|
|
|
-
|
|
|
+ let originVideoDetails = undefined;
|
|
|
// android
|
|
|
try {
|
|
|
const apiUrl = `https://music.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8`;
|
|
@@ -159,6 +177,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"
|
|
@@ -250,30 +269,10 @@ 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]);
|
|
|
- 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"]
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ for (const item of originVideoDetails['thumbnail']['thumbnails']) {
|
|
|
+ thumbnails.push({
|
|
|
+ 'url': item['url'], 'width': item['width'] + "", 'height': item['height'] + ""
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
formats.sort((a, b) => parseInt(a["height"]) - parseInt(b["height"]));
|