From 5014b7e55f6c19d227b0669e7591a60124e722c9 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Sat, 5 Jun 2021 10:02:32 +0200 Subject: unescape html characters --- htmlChars | 22 ++++++++++++++++++++++ yta | 9 ++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 htmlChars diff --git a/htmlChars b/htmlChars new file mode 100644 index 0000000..3114945 --- /dev/null +++ b/htmlChars @@ -0,0 +1,22 @@ +module.exports = { + '"': '\"', + '"': '\"', + ''': '\\', + ''': '\\', + '&': '&', + '&': '&', + '>': '>', + '>': '>', + '<': '<', + '<': '<', + '¢': '¢', + '¢': '¢', + '©': '©', + '©': '©', + '€': '€', + '€': '€', + '£': '£', + '£': '£', + '®': '®', + '®': '®' +}; diff --git a/yta b/yta index bdee11e..c572662 100755 --- a/yta +++ b/yta @@ -3,6 +3,7 @@ const spawn = require('child_process').spawn; const colors = require('colors'); const prompt = require('prompt'); const fetch = require('node-fetch'); +const htmlChars = require('./htmlChars'); const { YTKEY } = require('./config'); let data = {ids: [], titles: [], descriptions: [], channels: [], durations: []}; @@ -131,9 +132,9 @@ const getDurations = (ids) => getJson(detailsUrl(ids)).then(json => json.items.m const presentResults = (results) => { const items = results.items.filter(i => i.snippet); - data.titles = items.map(i => i.snippet.title); - data.descriptions = items.map(i => i.snippet.description); - data.channels = items.map(i => i.snippet.channelTitle); + data.titles = items.map(i => decode(i.snippet.title)); + data.descriptions = items.map(i => decode(i.snippet.description)); + data.channels = items.map(i => decode(i.snippet.channelTitle)); data.ids = items.map(i => i.id.videoId); getDurations(data.ids).then(durations => { data.durations = durations; @@ -143,6 +144,8 @@ const presentResults = (results) => { }); }; +const decode = t => t.replace(new RegExp(`/${Object.keys(htmlChars).join('|')}/gi`), (m) => htmlChars[m]); + const handlePrompt = (err, { query }) => { if (err) { console.log(err); -- cgit v1.2.3