mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
Fixed Spotify crash
This commit is contained in:
@@ -386,7 +386,12 @@ export default class Play extends DiscordModule {
|
||||
let linkData = DiscordMusicPlayer.parseSpotifyLink(query);
|
||||
|
||||
if (linkData.type === 'playlist' || linkData.type === 'album') {
|
||||
let playlist = await DiscordMusicPlayer.getSpotifySongsInPlayList(query);
|
||||
let playlist = await DiscordMusicPlayer.getSpotifySongsInPlayList(query).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] }, true);
|
||||
return null;
|
||||
});
|
||||
|
||||
if(!playlist) return;
|
||||
const songs = await playlist.all_tracks();
|
||||
|
||||
for (const song of songs) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import { EventEmitter } from 'stream';
|
||||
|
||||
import DiscordProvider from './Discord';
|
||||
import Environment from './Environment';
|
||||
import Logger from '../libs/Logger';
|
||||
|
||||
export type ValidTracks = YouTubeVideo | SpotifyTrack;
|
||||
declare class YouTubeThumbnail {
|
||||
@@ -45,7 +46,8 @@ interface SpotifyThumbnail {
|
||||
url: string;
|
||||
}
|
||||
|
||||
if (Environment.get().YOUTUBE_COOKIE_BASE64) {
|
||||
// TODO: Make proper check later
|
||||
if (Environment.get().YOUTUBE_COOKIE_BASE64 && Environment.get().SPOTIFY_CLIENT_ID) {
|
||||
playdl.setToken({
|
||||
youtube: {
|
||||
cookie: Buffer.from(Environment.get().YOUTUBE_COOKIE_BASE64, 'base64').toString()
|
||||
@@ -443,18 +445,16 @@ class DiscordMusicPlayer {
|
||||
}
|
||||
|
||||
public async searchSpotifyBySpotifyLink(spotifyLink: SpotifyLink) {
|
||||
if(playdl.is_expired())
|
||||
await playdl.refreshToken();
|
||||
|
||||
if(spotifyLink.type != 'track') return;
|
||||
|
||||
if(playdl.is_expired())
|
||||
await playdl.refreshToken();
|
||||
|
||||
if(spotifyLink.type != 'track') return;
|
||||
|
||||
// Fetch data from spotify
|
||||
const searched: Spotify = await playdl.spotify("https://open.spotify.com/track/" + spotifyLink.id);
|
||||
const searched: Spotify = await playdl.spotify("https://open.spotify.com/track/" + spotifyLink.id).catch((err) => {
|
||||
Logger.error(err.message);
|
||||
throw new Error('Error while searching on Spotify');
|
||||
});
|
||||
if(!(searched instanceof SpotifyTrack)) return;
|
||||
|
||||
if (!searched) return null;
|
||||
@@ -525,7 +525,13 @@ class DiscordMusicPlayer {
|
||||
}
|
||||
|
||||
public async getSpotifySongsInPlayList(spotifyLink: string) {
|
||||
const result = await playdl.spotify(spotifyLink);
|
||||
if(playdl.is_expired())
|
||||
await playdl.refreshToken();
|
||||
|
||||
const result = await playdl.spotify(spotifyLink).catch((err) => {
|
||||
Logger.error(err.message);
|
||||
throw new Error('Error while searching on Spotify');
|
||||
});
|
||||
|
||||
if(!(result.type == 'playlist' || result.type == 'album'))
|
||||
throw new Error("Not a spotify playlist");
|
||||
|
||||
Reference in New Issue
Block a user