Skip to content

Commit

Permalink
fix: support for soundcloud mobile links (#428)
Browse files Browse the repository at this point in the history
* Fixed and made an actual branch
* fix: update SCDL
Co-authored-by: Erit Islami <eritislami@gmail.com>
  • Loading branch information
evrardco committed Dec 5, 2020
1 parent 5573079 commit b5a7561
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
20 changes: 19 additions & 1 deletion commands/play.js
@@ -1,7 +1,8 @@
const { play } = require("../include/play");
const ytdl = require("ytdl-core");
const YouTubeAPI = require("simple-youtube-api");
const scdl = require("soundcloud-downloader");
const scdl = require("soundcloud-downloader").default;
const https = require("https");
const { YOUTUBE_API_KEY, SOUNDCLOUD_CLIENT_ID, DEFAULT_VOLUME } = require("../util/EvobotUtil");
const youtube = new YouTubeAPI(YOUTUBE_API_KEY);

Expand Down Expand Up @@ -33,6 +34,7 @@ module.exports = {
const videoPattern = /^(https?:\/\/)?(www\.)?(m\.)?(youtube\.com|youtu\.?be)\/.+$/gi;
const playlistPattern = /^.*(list=)([^#\&\?]*).*/gi;
const scRegex = /^https?:\/\/(soundcloud\.com)\/(.*)$/;
const mobileScRegex = /^https?:\/\/(soundcloud\.app\.goo\.gl)\/(.*)$/;
const url = args[0];
const urlValid = videoPattern.test(args[0]);

Expand All @@ -43,6 +45,22 @@ module.exports = {
return message.client.commands.get("playlist").execute(message, args);
}

if (mobileScRegex.test(url)) {
try {
https.get(url, function (res) {
if (res.statusCode == "302") {
return message.client.commands.get("play").execute(message, [res.headers.location]);
} else {
return message.reply("No content could be found at that url.").catch(console.error);
}
});
} catch (error) {
console.error(error);
return message.reply(error.message).catch(console.error);
}
return message.reply("Following url redirection...").catch(console.error);
}

const queueConstruct = {
textChannel: message.channel,
channel,
Expand Down
2 changes: 1 addition & 1 deletion commands/playlist.js
@@ -1,7 +1,7 @@
const { MessageEmbed } = require("discord.js");
const { play } = require("../include/play");
const YouTubeAPI = require("simple-youtube-api");
const scdl = require("soundcloud-downloader");
const scdl = require("soundcloud-downloader").default;
const { YOUTUBE_API_KEY, SOUNDCLOUD_CLIENT_ID, MAX_PLAYLIST_SIZE } = require("../util/EvobotUtil");
const youtube = new YouTubeAPI(YOUTUBE_API_KEY);

Expand Down
2 changes: 1 addition & 1 deletion include/play.js
@@ -1,5 +1,5 @@
const ytdl = require("erit-ytdl");
const scdl = require("soundcloud-downloader");
const scdl = require("soundcloud-downloader").default;
const { canModifyQueue, STAY_TIME } = require("../util/EvobotUtil");

module.exports = {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -19,7 +19,7 @@
"ffmpeg-static": "^4.2.3",
"lyrics-finder": "^21.0.5",
"simple-youtube-api": "^5.1.1",
"soundcloud-downloader": "0.2.0",
"soundcloud-downloader": "^0.2.1",
"string-progressbar": "^1.0.1",
"ytdl-core": "^4.1.2"
},
Expand Down

0 comments on commit b5a7561

Please sign in to comment.