From 4ab7307ba76534051d847825fec71165d1e56e30 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 15 Sep 2021 21:45:55 -0600 Subject: [PATCH] music: no logic yet just soundcloud client id grabbing --- src/modules/music.js | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/modules/music.js diff --git a/src/modules/music.js b/src/modules/music.js new file mode 100644 index 0000000..90e0a29 --- /dev/null +++ b/src/modules/music.js @@ -0,0 +1,46 @@ +const fetch = require("node-fetch"); +const ytdl = require("ytdl-core"); +const Eris = require("eris"); + +const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/; +const REGEX_YOUTUBE_PLAYLIST = + /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/playlist\?list=(.+)$/; +const REGEX_YOUTUBE_PLAYLIST_SHORT = /^PL[a-zA-Z0-9-_]{1,32}$/; +const REGEX_SOUNDCLOUD = + /^((https?:\/\/)?(www\.|m\.)?soundcloud\.com\/|sc:).+\/.+$/; +const REGEX_SOUNDCLOUD_PLAYLIST = + /^((https?:\/\/)?(www\.|m\.)?soundcloud\.com\/|sc:).+\/(sets\/.+|likes|tracks)$/; +const REGEX_FILE = + /^(https?:\/\/)?.*\..*\/.+\.(mp3|ogg|flac|wav|webm|mp4|mov|mkv)$/; + +let SOUNDCLOUD_CLIENTID; + +hf.voiceStorage = hf.voiceStorage || new Eris.Collection(); + +// https://stackoverflow.com/a/12646864 ยง "Updating to ES6 / ECMAScript 2015" +function shuffleArray(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } +} + +async function getSoundcloudClientID() { + if (SOUNDCLOUD_CLIENTID != null) { + return SOUNDCLOUD_CLIENTID; + } + const page = await fetch("https://soundcloud.com").then((res) => res.text()); + const scripts = page + .match(/