Skip to content

Commit

Permalink
Update play.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Colonel-Ltd authored Mar 7, 2021
1 parent ab7ae64 commit 6c9c0ed
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions commands/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ytdlDiscord = require("ytdl-core-discord");
const yts = require("yt-search");
const fs = require("fs");
const sendError = require("../util/error");

const scdl = require("soundcloud-downloader").default;
module.exports = {
info: {
name: "play",
Expand Down Expand Up @@ -46,6 +46,24 @@ module.exports = {
console.error(error);
return message.reply(error.message).catch(console.error);
}
} else if (url.match(/^https?:\/\/(soundcloud\.com)\/(.*)$/gi)) {
try {
songInfo = await scdl.getInfo(url);
if (!songInfo) return sendError("Looks like i was unable to find the song on soundcloud", message.channel);
song = {
id: songInfo.permalink,
title: songInfo.title,
url: songInfo.permalink_url,
img: songInfo.artwork_url,
ago: songInfo.last_modified,
views: String(songInfo.playback_count).padStart(10, " "),
duration: Math.ceil(songInfo.duration / 1000),
req: message.author,
};
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
} else {
try {
var searched = await yts.search(searchString);
Expand Down Expand Up @@ -104,22 +122,38 @@ module.exports = {
message.client.queue.delete(message.guild.id);
return;
}
let stream = null;
if (song.url.includes("youtube.com")) {
stream = await ytdl(song.url);
stream.on("error", function (er) {
if (er) {
if (queue) {
queue.songs.shift();
play(queue.songs[0]);
return sendError(`An unexpected error has occurred.\nPossible type \`${er}\``, message.channel);
}
let stream;
let streamType;

try {
if (song.url.includes("soundcloud.com")) {
try {
stream = await scdl.downloadFormat(song.url, scdl.FORMATS.OPUS, client.config.SOUNDCLOUD);
} catch (error) {
stream = await scdl.downloadFormat(song.url, scdl.FORMATS.MP3, client.config.SOUNDCLOUD);
streamType = "unknown";
}
});
} else if (song.url.includes("youtube.com")) {
stream = await ytdl(song.url, { quality: "highestaudio", highWaterMark: 1 << 25, type: "opus" });
stream.on("error", function (er) {
if (er) {
if (queue) {
queue.songs.shift();
play(queue.songs[0]);
return sendError(`An unexpected error has occurred.\nPossible type \`${er}\``, message.channel);
}
}
});
}
} catch (error) {
console.log();
if (queue) {
queue.songs.shift();
play(queue.songs[0]);
}
}
queue.connection.on("disconnect", () => message.client.queue.delete(message.guild.id));

const dispatcher = queue.connection.play(ytdl(song.url, { quality: "highestaudio", highWaterMark: 1 << 25, type: "opus" })).on("finish", () => {
const dispatcher = queue.connection.play(stream).on("finish", () => {
const shiffed = queue.songs.shift();
if (queue.loop === true) {
queue.songs.push(shiffed);
Expand Down

0 comments on commit 6c9c0ed

Please sign in to comment.