TimeForANinja / node-ytsr

Do anonymous YouTube search requests.
MIT License
286 stars 66 forks source link

fix: address filterWrapper is not iterable error #210

Closed reply2za closed 1 year ago

reply2za commented 1 year ago

Addresses issue#206

A quick and technically not ideal fix. This change adds a safety check so that if wrapper.subMenu returns undefined, then the method returns an empty filter map, instead of throwing an error. This will likely always be the case now and this code does not address the root issue.

The fact of the matter is that YouTube likely updated their payload data (thus breaking the filter feature). The main fix would be updating the path to searchFilterGroupRenderer, which still exists. The point of this PR, at the very least, is to add a safety check to allow for YTSR to return search data, which is much better than not returning anything at all whenever YouTube updates their response.

Furthermore, I did take a look into the new payload and found that filter data could maybe be retrieved like this:

exports.parseFilters = json => {
  const pc = json.header.searchHeaderRenderer.searchFilterButton.buttonRenderer.command.openPopupAction.popup;
  const filterWrapper = pc.searchFilterOptionsDialogRenderer.groups || [];
  const parsedGroups = new Map();
...

I did not make a PR with this code (yet) for a few reasons. Firstly because all the tests that rely on local HTML data fail, because this code only expects the new payload format. Also the typings have to be updated.

Update: I updated the code to support both the old and new payload formats.

Thanks, Reply2za

Domjan1911 commented 1 year ago

Hi, where is this utils.js , I can't find it, I tried searching for Freetube on whereis Freetube but on my terminal it shows nothing, I'm a Linux newbie.

SergioAcostaTer commented 1 year ago

pls fix it

reply2za commented 1 year ago

@Domjan1911 The utils.js file is within node modules. node modules -> ytsr -> lib -> utils.js

The utils.js code I am using is this.

TimeForANinja commented 1 year ago

closing in favor of #203