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);
|
let linkData = DiscordMusicPlayer.parseSpotifyLink(query);
|
||||||
|
|
||||||
if (linkData.type === 'playlist' || linkData.type === 'album') {
|
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();
|
const songs = await playlist.all_tracks();
|
||||||
|
|
||||||
for (const song of songs) {
|
for (const song of songs) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import { EventEmitter } from 'stream';
|
|||||||
|
|
||||||
import DiscordProvider from './Discord';
|
import DiscordProvider from './Discord';
|
||||||
import Environment from './Environment';
|
import Environment from './Environment';
|
||||||
|
import Logger from '../libs/Logger';
|
||||||
|
|
||||||
export type ValidTracks = YouTubeVideo | SpotifyTrack;
|
export type ValidTracks = YouTubeVideo | SpotifyTrack;
|
||||||
declare class YouTubeThumbnail {
|
declare class YouTubeThumbnail {
|
||||||
@@ -45,7 +46,8 @@ interface SpotifyThumbnail {
|
|||||||
url: string;
|
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({
|
playdl.setToken({
|
||||||
youtube: {
|
youtube: {
|
||||||
cookie: Buffer.from(Environment.get().YOUTUBE_COOKIE_BASE64, 'base64').toString()
|
cookie: Buffer.from(Environment.get().YOUTUBE_COOKIE_BASE64, 'base64').toString()
|
||||||
@@ -443,18 +445,16 @@ class DiscordMusicPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async searchSpotifyBySpotifyLink(spotifyLink: SpotifyLink) {
|
public async searchSpotifyBySpotifyLink(spotifyLink: SpotifyLink) {
|
||||||
if(playdl.is_expired())
|
|
||||||
await playdl.refreshToken();
|
|
||||||
|
|
||||||
if(spotifyLink.type != 'track') return;
|
|
||||||
|
|
||||||
if(playdl.is_expired())
|
if(playdl.is_expired())
|
||||||
await playdl.refreshToken();
|
await playdl.refreshToken();
|
||||||
|
|
||||||
if(spotifyLink.type != 'track') return;
|
if(spotifyLink.type != 'track') return;
|
||||||
|
|
||||||
// Fetch data from spotify
|
// 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 instanceof SpotifyTrack)) return;
|
||||||
|
|
||||||
if (!searched) return null;
|
if (!searched) return null;
|
||||||
@@ -525,7 +525,13 @@ class DiscordMusicPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getSpotifySongsInPlayList(spotifyLink: string) {
|
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'))
|
if(!(result.type == 'playlist' || result.type == 'album'))
|
||||||
throw new Error("Not a spotify playlist");
|
throw new Error("Not a spotify playlist");
|
||||||
|
|||||||
Reference in New Issue
Block a user