twlite / youtube-sr

A dead-simple youtube metadata scraper
https://npmjs.com/package/youtube-sr
MIT License
113 stars 16 forks source link

fix(Util): Video likes count is not guaranteed #41

Closed TDWilkinson99 closed 2 years ago

TDWilkinson99 commented 2 years ago

YouTube.getVideo("Some_Video_URL") returns an error: Error: Cannot read properties of undefined (reading 'accessibilityData') for videos that don't have their ratings visible. An example of a video that doesn't show it's ratings is https://www.youtube.com/watch?v=LL998ajnjN4 and has been used in the testing of this fix. An additional video that doesn't have ratings enabled (currently at least) is https://www.youtube.com/watch?v=aKSxbt-O6TA and can also be used for testing.

This fix makes the accessibility property in getInfoLikesCount() optional for when a video has their number of likes hidden and there is no accessibility property available.

Additionally, this adds an || OR operator to a video's like ratings that returns 0 if getInfoLikesCount(info) returns NaN after being unable to return the likes count of a video.