amishshah / ytdl-core-discord

A ytdl-core wrapper focused on efficiency for use in Discord music bots
Apache License 2.0
67 stars 26 forks source link

youtu.be URLs not working #393

Closed EasyXploit closed 3 years ago

EasyXploit commented 3 years ago

I think that this library should be able to interpret URLs of the domain youtu.be, which are the URLs obtained through the Share button of the YouTube app.

When you try to use one of those URLs, you get the following error:

Error: not a known youtube link
    at AsyncFunction.main.getPlaylistID (/home/user/bot/node_modules/ytpl/lib/main.js:207:46)
    at module.exports (/home/user/bot/node_modules/ytpl/lib/main.js:13:30)
    at addPlaylist (/home/user/bot/commands/music/play.js:254:40)
    at Object.exports.run (/home/user/bot/commands/music/play.js:349:21)
    at Object.exports.run (/home/user/bot/events/message.js:169:23)
    at Client.<anonymous> (/home/user/bot/index.js:82:31)
    at Client.emit (node:events:394:28)
    at MessageCreateAction.handle (/home/user/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/user/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/user/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)

EDIT: It would be a good idea to use regular expressions to solve the problem:

link.replace(/^https?:\/\/youtu\.be\/([a-z\d]+)$/i, 'http://www.youtube.com/watch?v=$1');
EasyXploit commented 3 years ago

It was not a problem with the library. It is perfectly capable of interpreting addresses from the youtu.be domain.