Giter Site home page Giter Site logo

Throws a "UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]" when trying to search for Chinese, Japanese, Hebrew, or Arabic lyrics about genius-lyrics-api HOT 8 CLOSED

farshed avatar farshed commented on May 27, 2024
Throws a "UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]" when trying to search for Chinese, Japanese, Hebrew, or Arabic lyrics

from genius-lyrics-api.

Comments (8)

farshed avatar farshed commented on May 27, 2024

@LittleWhole can you provide an example of the song you were trying to search?

from genius-lyrics-api.

LittleWhole avatar LittleWhole commented on May 27, 2024

@farshed Sure!

Chinese: https://genius.com/Pu-shu--lyrics

Japanese: https://genius.com/Mrs-green-apple-tenbyou-no-uta-lyrics

By the way, I should probably clarify that I am using the getLyrics() function, not the searchSong() function, sorry

from genius-lyrics-api.

farshed avatar farshed commented on May 27, 2024

@LittleWhole I cannot reproduce this. getLyrics method works fine with both URLs and returns the correct lyrics.

Can you share some more info like code samples and lib version?

from genius-lyrics-api.

LittleWhole avatar LittleWhole commented on May 27, 2024

@farshed

Lib version: 3.0.1

Code context: This is a lyrics command in a Discord bot.

const genius = require('genius-lyrics-api');
const Discord = require('discord.js')

exports.run = async (client, message, command, args, perms, config) => {
    let thisConnection = client.voice.connections.find(connection => connection.channel.guild === message.guild)
    let songInfo = thisConnection.dispatcher.songInfo();
    let options = {
        apiKey: config.apikeys.genius,
        title: songInfo.title,
        artist: "",
        optimizeQuery: true
    }
    genius.getLyrics(options).then((lyrics) => {
        let lyricsEmbed;
        for (let i = 0; i < lyrics.length; i += 2048) {
            const toSend = lyrics.substring(i, Math.min(lyrics.length, i + 2048));
            lyricsEmbed = new Discord.MessageEmbed()
            .setDescription(toSend)
            .setColor(config.colors.blue);
            message.channel.send({ embed: lyricsEmbed });
        }
    });
};

from genius-lyrics-api.

farshed avatar farshed commented on May 27, 2024

@LittleWhole what's the value of songInfo.title? Also can you attach a catch method with the getLyrics call and confirm that the error is being thrown by getLyrics and not something else in your code?

from genius-lyrics-api.

LittleWhole avatar LittleWhole commented on May 27, 2024

@farshed
In this test, songInfo.title should be 朴樹 - 平凡之路 [歌詞字幕][電影《後會無期》主題曲][完整高清音質] The Continent Theme Song - The Ordinary Road (Pu Shu).
Here's the catch output of the error:

2020-06-28T14:19:02.960979+00:00 app[worker.1]: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters

2020-06-28T14:19:02.960995+00:00 app[worker.1]:     at new ClientRequest (_http_client.js:151:13)

2020-06-28T14:19:02.960996+00:00 app[worker.1]:     at Object.request (https.js:310:10)

2020-06-28T14:19:02.960996+00:00 app[worker.1]:     at RedirectableRequest._performRequest (/app/node_modules/follow-redirects/index.js:169:24)

2020-06-28T14:19:02.960997+00:00 app[worker.1]:     at new RedirectableRequest (/app/node_modules/follow-redirects/index.js:66:8)

2020-06-28T14:19:02.960997+00:00 app[worker.1]:     at Object.wrappedProtocol.request (/app/node_modules/follow-redirects/index.js:307:14)

2020-06-28T14:19:02.960998+00:00 app[worker.1]:     at dispatchHttpRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:179:25)

2020-06-28T14:19:02.961000+00:00 app[worker.1]:     at new Promise (<anonymous>)

2020-06-28T14:19:02.961000+00:00 app[worker.1]:     at httpAdapter (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:21:10)

2020-06-28T14:19:02.961001+00:00 app[worker.1]:     at dispatchRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/core/dispatchRequest.js:52:10)

2020-06-28T14:19:02.961001+00:00 app[worker.1]:     at runMicrotasks (<anonymous>) {

2020-06-28T14:19:02.961002+00:00 app[worker.1]:   code: 'ERR_UNESCAPED_CHARACTERS'

2020-06-28T14:19:02.961003+00:00 app[worker.1]: }

from genius-lyrics-api.

farshed avatar farshed commented on May 27, 2024

The error is caused by the presence of special characters like [ and ] in the title. I've released a patch which encodes these special characters before making a request.

Do note that searching 朴樹 - 平凡之路 [歌詞字幕][電影《後會無期》主題曲][完整高清音質] The Continent Theme Song - The Ordinary Road (Pu Shu) on genius.com doesn't return any results so the lib will return null. See https://genius.com/search?q=%E6%9C%B4%E6%A8%B9%20-%20%E5%B9%B3%E5%87%A1%E4%B9%8B%E8%B7%AF%20%5B%E6%AD%8C%E8%A9%9E%E5%AD%97%E5%B9%95%5D%5B%E9%9B%BB%E5%BD%B1%E3%80%8A%E5%BE%8C%E6%9C%83%E7%84%A1%E6%9C%9F%E3%80%8B%E4%B8%BB%E9%A1%8C%E6%9B%B2%5D%5B%E5%AE%8C%E6%95%B4%E9%AB%98%E6%B8%85%E9%9F%B3%E8%B3%AA%5D%20The%20Continent%20Theme%20Song%20-%20The%20Ordinary%20Road%20

from genius-lyrics-api.

LittleWhole avatar LittleWhole commented on May 27, 2024

@farshed Thank you, I understand 😃

from genius-lyrics-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.