aboutsummaryrefslogtreecommitdiff
path: root/src/services/add-query-to-queue.ts
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-11-06 09:42:25 -0500
committerGitHub <[email protected]>2024-11-06 09:42:25 -0500
commitd92fd2a29796c9c5d6ddeb9718bf6fcd6ee5958a (patch)
tree81961cc995661448794669617f1ed439cbe84a3d /src/services/add-query-to-queue.ts
parentb605bf220859acd767533e0ab9436ced771bb8e2 (diff)
parent716d6d9f4f2cd1a6872e463e9877203a259478a3 (diff)
downloadmuse-d92fd2a29796c9c5d6ddeb9718bf6fcd6ee5958a.tar.xz
muse-d92fd2a29796c9c5d6ddeb9718bf6fcd6ee5958a.zip
Merge branch 'museofficial:master' into masterHEADmaster
Diffstat (limited to 'src/services/add-query-to-queue.ts')
-rw-r--r--src/services/add-query-to-queue.ts70
1 files changed, 1 insertions, 69 deletions
diff --git a/src/services/add-query-to-queue.ts b/src/services/add-query-to-queue.ts
index 401ad90..95e16ff 100644
--- a/src/services/add-query-to-queue.ts
+++ b/src/services/add-query-to-queue.ts
@@ -1,6 +1,5 @@
/* eslint-disable complexity */
import {ChatInputCommandInteraction, GuildMember} from 'discord.js';
-import {URL} from 'node:url';
import {inject, injectable} from 'inversify';
import shuffle from 'array-shuffle';
import {TYPES} from '../types.js';
@@ -60,74 +59,7 @@ export default class AddQueryToQueue {
await interaction.deferReply({ephemeral: queueAddResponseEphemeral});
- let newSongs: SongMetadata[] = [];
- let extraMsg = '';
-
- // Test if it's a complete URL
- try {
- const url = new URL(query);
-
- const YOUTUBE_HOSTS = [
- 'www.youtube.com',
- 'youtu.be',
- 'youtube.com',
- 'music.youtube.com',
- 'www.music.youtube.com',
- ];
-
- if (YOUTUBE_HOSTS.includes(url.host)) {
- // YouTube source
- if (url.searchParams.get('list')) {
- // YouTube playlist
- newSongs.push(...await this.getSongs.youtubePlaylist(url.searchParams.get('list')!, shouldSplitChapters));
- } else {
- const songs = await this.getSongs.youtubeVideo(url.href, shouldSplitChapters);
-
- if (songs) {
- newSongs.push(...songs);
- } else {
- throw new Error('that doesn\'t exist');
- }
- }
- } else if (url.protocol === 'spotify:' || url.host === 'open.spotify.com') {
- const [convertedSongs, nSongsNotFound, totalSongs] = await this.getSongs.spotifySource(query, playlistLimit, shouldSplitChapters);
-
- if (totalSongs > playlistLimit) {
- extraMsg = `a random sample of ${playlistLimit} songs was taken`;
- }
-
- if (totalSongs > playlistLimit && nSongsNotFound !== 0) {
- extraMsg += ' and ';
- }
-
- if (nSongsNotFound !== 0) {
- if (nSongsNotFound === 1) {
- extraMsg += '1 song was not found';
- } else {
- extraMsg += `${nSongsNotFound.toString()} songs were not found`;
- }
- }
-
- newSongs.push(...convertedSongs);
- } else {
- const song = await this.getSongs.httpLiveStream(query);
-
- if (song) {
- newSongs.push(song);
- } else {
- throw new Error('that doesn\'t exist');
- }
- }
- } catch (_: unknown) {
- // Not a URL, must search YouTube
- const songs = await this.getSongs.youtubeVideoSearch(query, shouldSplitChapters);
-
- if (songs) {
- newSongs.push(...songs);
- } else {
- throw new Error('that doesn\'t exist');
- }
- }
+ let [newSongs, extraMsg] = await this.getSongs.getSongs(query, playlistLimit, shouldSplitChapters);
if (newSongs.length === 0) {
throw new Error('no songs found');