Closed 3chospirits closed 4 years ago
I can't reproduce this, what version are you using?
Ahh, sorry I missed this in the reproduce steps. Adding {type:"video"} to parameters breaks it. This code errors:
let {search} = require("scrape-yt")
search("helllo", {type:"video"}).then(r=>console.log(r));
(node:8684) UnhandledPromiseRejectionWarning: TypeError: Cannot read property
'videoId' of undefined
at Object.parseSearch (C:\Users\xxxxx\Projects\Music\node_modules\scrape-
yt\dist\common\parser.js:142:30)
If I run it without the type option it does not have any issues:
let {search} = require("scrape-yt")
search("helllo").then(r=>console.log(r));
[
{
id: 'YQHsXMglC9A',
title: 'Adele - Hello',
duration: 367,
thumbnail: 'https://i.ytimg.com/vi/YQHsXMglC9A/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLABnmZFMUz4mRFtZtiMekk8VLKZyw',
channel: {
id: 'UCsRM0YB_dabtEPGPTKo-gcw',
name: 'Adele',
url: 'https://www.youtube.com/channel/UCsRM0YB_dabtEPGPTKo-gcw'
},
uploadDate: '4 years ago',
viewCount: 2681828126,
type: 'video'
}
. . .
Also, I am using 1.4.0
Ah okay, it's indeed throwing an error with {type:"video"}
, I will look into this.
Thank you!! Please lmk if you find a fix!
Not sure if this is the proper way to resolve this issue, but i found that adding this in line 140 of parser.js removes the error:
if (data === undefined) continue;
if (searchType === "video") {
data = data.videoRenderer;
if (data === undefined) continue;
result = {
. . .
The issue itself was actually related to ads on youtube. Adding this:
if (searchType === "video") {
if (data.videoRenderer === undefined) console.log(data);
gave me this output:
{
searchPyvRenderer: {
ads: [ [Object] ],
trackingParams: 'CIsBEJMmGAAiEwjh3aWuxePqAhWVMAMKHQAgAvE='
}
}
its the annoying youtube ads lol
Try updating to 1.4.1, should fix it.
Describe the bug Search works for most keywords, but when the search terms trigger youtube's "showing results for xxxxxxx Search instead fo xxxxxxx", the search() function has a
To Reproduce Use search function with any "typoed" keywords as search query.
search(keywords)
Some example keyword combos that result in error:Expected behavior Should return normal search query results like normal without errors
Screenshots N/A
Additional context N/A