I\'m using youtube-search 1.1.4 to find videos. The problem is that i get the results titles encoded with &
or '
instead of just
You can use the the DOM Parser
var parser = new DOMParser;
let finalResult = parser.parseFromString(results, "text/html")
console.log(finalResult.body.innerHtml); // will turn & to &
After finding a related ticket on google's issue tracker: issuetracker.google.com/u/1/issues/128673539 and got a response from google that this is the expected behaviour and they won't fix it, i just used user 3limin4t0r suggestion and decoded the return value title using he.js library, it's the idle way to solve this but i had no intention to wait for google to come around from their decision...
so, my solution goes like that:
var youtubeSearch = require("youtube-search")
let he = require('he');
var opts = {
maxResults : 15,
key : 'MY_API_KEY',
part : 'snippet',
type : 'video',
};
youtubeSearch('post malone', opts, function(err, results) {
if(err) return console.log(err);
results = results.map(item => {
item.snippet.title = he.decode(item.snippet.title);
return item;
});
console.dir(results);
});