talmobi / yt-search

93 stars 31 forks source link

TypeError: Cannot read properties of undefined (reading 'match') #78

Open LingleDev opened 1 week ago

LingleDev commented 1 week ago

So I am attempting to use the yt-search npm library for my Discord music bot, as ytdl has stopped working for getting video info.

Every time I attempt to search using a video's ID, I get this error:

/root/project/node_modules/yt-search/dist/yt-search.js:931
                while (timestamp[timestamp.length - 1].match(/\D/)) {
                                                       ^

TypeError: Cannot read properties of undefined (reading 'match')
    at _parseDuration (/root/project/node_modules/yt-search/dist/yt-search.js:931:42)
    at _parseVideoInitialData (/root/project/node_modules/yt-search/dist/yt-search.js:683:18)
    at /root/project/node_modules/yt-search/dist/yt-search.js:640:9
    at i (/root/project/node_modules/dasu/dist/dasu.min.js:1:4250)
    at Gunzip.<anonymous> (/root/project/node_modules/dasu/dist/dasu.min.js:1:2645)
    at Gunzip.emit (node:events:519:28)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v21.5.0

I was able to stop this error by adding a ? after the array index on line 931.

Like so:

while (timestamp[timestamp.length - 1]?.match(/\D/)) {
LingleDev commented 1 week ago

I was able to find a fix for this issue by playing around with the library code; I submitted a pull request to see if it can be fixed

talmobi commented 1 week ago

@LingleDev thanks~ does it happen on all videos or only some? and if so do you have an example video ID where it fails? thanks~ 🙏