|
@@ -127,31 +127,31 @@ request = async (method, url, data = null, headers = {}, requestId, platform) =>
|
|
}
|
|
}
|
|
|
|
|
|
isLiveContent = video => {
|
|
isLiveContent = video => {
|
|
- const badgets = video["badges"]
|
|
|
|
- if (badgets && badgets.length > 0) {
|
|
|
|
- for (const badge of badgets) {
|
|
|
|
- if (badge["metadataBadgeRenderer"] && badge["metadataBadgeRenderer"]["style"] === "BADGE_STYLE_TYPE_LIVE_NOW") {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- const publishText = video["publishedTimeText"]?.["simpleText"];
|
|
|
|
- if (!publishText) {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- const livePublishTexts = [
|
|
|
|
- "直播", // 中文
|
|
|
|
- "Stream", // 英语
|
|
|
|
- "Diffusé", // 法语
|
|
|
|
- "gestreamt", // 德语
|
|
|
|
- "Emitido hace", // 西班牙语
|
|
|
|
- "Transmitido há"// 西班牙
|
|
|
|
- ]
|
|
|
|
- for (const liveItem of livePublishTexts) {
|
|
|
|
- if (publishText.indexOf(liveItem) >= 0) {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // const badgets = video["badges"]
|
|
|
|
+ // if (badgets && badgets.length > 0) {
|
|
|
|
+ // for (const badge of badgets) {
|
|
|
|
+ // if (badge["metadataBadgeRenderer"] && badge["metadataBadgeRenderer"]["style"] === "BADGE_STYLE_TYPE_LIVE_NOW") {
|
|
|
|
+ // return true
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // const publishText = video["publishedTimeText"]?.["simpleText"];
|
|
|
|
+ // if (!publishText) {
|
|
|
|
+ // return true
|
|
|
|
+ // }
|
|
|
|
+ // const livePublishTexts = [
|
|
|
|
+ // "直播", // 中文
|
|
|
|
+ // "Stream", // 英语
|
|
|
|
+ // "Diffusé", // 法语
|
|
|
|
+ // "gestreamt", // 德语
|
|
|
|
+ // "Emitido hace", // 西班牙语
|
|
|
|
+ // "Transmitido há"// 西班牙
|
|
|
|
+ // ]
|
|
|
|
+ // for (const liveItem of livePublishTexts) {
|
|
|
|
+ // if (publishText.indexOf(liveItem) >= 0) {
|
|
|
|
+ // return true
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
@@ -460,23 +460,42 @@ search = async (keyword, next, requestId, platform) => {
|
|
|
|
|
|
let regex = /var ytInitialData\s*=\s*({.*?});/;
|
|
let regex = /var ytInitialData\s*=\s*({.*?});/;
|
|
let match = html.match(regex);
|
|
let match = html.match(regex);
|
|
|
|
+ let json_str = "";
|
|
if (!match || !match.length) {
|
|
if (!match || !match.length) {
|
|
- console.log("can not found ytInitialData");
|
|
|
|
- throw new Error('JSON not found: ytInitialData');
|
|
|
|
|
|
+ let reg = /var ytInitialData = '(.*?)';/;
|
|
|
|
+ match = html.match(reg);
|
|
|
|
+ if (!match) {
|
|
|
|
+ throw new Error('JSON not found: ytInitialData');
|
|
|
|
+ }
|
|
|
|
+ json_str = match[1].replace(/\\x([0-9a-fA-F]{2})/g, (_, hex) => {
|
|
|
|
+ return String.fromCharCode(parseInt(hex, 16));
|
|
|
|
+ })
|
|
|
|
+ .replace(/\\"/g, '"')
|
|
|
|
+ // json_str = match[1].replace(/\\x22/g, '"')
|
|
|
|
+ // .replace(/\\x5b/g, '[')
|
|
|
|
+ // .replace(/\\x5d/g, ']')
|
|
|
|
+ // .replace(/\\x7b/g, '{')
|
|
|
|
+ // .replace(/\\x7d/g, '}')
|
|
|
|
+ // .replace(/\\x27/g, "'")
|
|
|
|
+ // .replace(/\\\x3d/g, "=")
|
|
|
|
+ // .replace(/\\"/g, '"')
|
|
|
|
+ // .replace(/\\\//g, '/')
|
|
|
|
+ } else {
|
|
|
|
+ json_str = match[1]
|
|
}
|
|
}
|
|
|
|
|
|
- const ytInitialDataResp = JSON.parse(match[1]);
|
|
|
|
|
|
+ const ytInitialDataResp = JSON.parse(json_str);
|
|
if (printable(platform)) {
|
|
if (printable(platform)) {
|
|
console.log(ytInitialDataResp);
|
|
console.log(ytInitialDataResp);
|
|
}
|
|
}
|
|
const videos = [];
|
|
const videos = [];
|
|
- const contents = ytInitialDataResp["contents"]?.["twoColumnSearchResultsRenderer"]?.["primaryContents"]?.["sectionListRenderer"]?.["contents"] || []
|
|
|
|
|
|
+ const contents = ytInitialDataResp["contents"]?.["sectionListRenderer"]?.["contents"] || []
|
|
for (const content of contents) {
|
|
for (const content of contents) {
|
|
const currentContents = content["itemSectionRenderer"]?.["contents"]
|
|
const currentContents = content["itemSectionRenderer"]?.["contents"]
|
|
if (Array.isArray(currentContents)) {
|
|
if (Array.isArray(currentContents)) {
|
|
for (const currentContent of currentContents) {
|
|
for (const currentContent of currentContents) {
|
|
- if (currentContent["videoRenderer"]) {
|
|
|
|
- const video = currentContent["videoRenderer"];
|
|
|
|
|
|
+ if (currentContent["videoWithContextRenderer"]) {
|
|
|
|
+ const video = currentContent["videoWithContextRenderer"];
|
|
if (printable(platform)) {
|
|
if (printable(platform)) {
|
|
console.log(video);
|
|
console.log(video);
|
|
}
|
|
}
|
|
@@ -485,13 +504,13 @@ search = async (keyword, next, requestId, platform) => {
|
|
"type": "videoWithContextRenderer",
|
|
"type": "videoWithContextRenderer",
|
|
"data": {
|
|
"data": {
|
|
"videoId": video["videoId"],
|
|
"videoId": video["videoId"],
|
|
- "title": video["title"]?.["runs"]?.[0]?.["text"],
|
|
|
|
|
|
+ "title": video["headline"]?.["runs"]?.[0]?.["text"],
|
|
"thumbnails": video["thumbnail"]?.["thumbnails"],
|
|
"thumbnails": video["thumbnail"]?.["thumbnails"],
|
|
- "channelName": video["longBylineText"]?.["runs"]?.[0]?.["text"],
|
|
|
|
- "publishedTimeText": video["publishedTimeText"]?.["simpleText"],
|
|
|
|
- "viewCountText": video["viewCountText"]?.["simpleText"],
|
|
|
|
- "shortViewCountText": video["shortViewCountText"]?.["simpleText"],
|
|
|
|
- "lengthText": video["lengthText"]?.["simpleText"]
|
|
|
|
|
|
+ "channelName": video["shortBylineText"]?.["runs"]?.[0]?.["text"],
|
|
|
|
+ "publishedTimeText": video["publishedTimeText"]?.["runs"]?.[0]?.["text"],
|
|
|
|
+ "viewCountText": video["shortViewCountText"]?.["runs"]?.[0]?.["text"],
|
|
|
|
+ "shortViewCountText": video["shortViewCountText"]?.["runs"]?.[0]?.["text"],
|
|
|
|
+ "lengthText": video["lengthText"]?.["accessibility"]?.["accessibilityData"]?.["label"],
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|