diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..94f480d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/src/Player.ts b/src/Player.ts index 56279e7..bc4bfa5 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -187,7 +187,10 @@ export class Player extends EventEmitter { if (matchSpotifyURL) { const spotifyData = await spotify.getPreview(query).catch(() => {}); if (spotifyData) { - tracks = await Util.ytSearch(`${spotifyData.artist} - ${spotifyData.title}`, { + const searchString = this.options.disableArtistSearch + ? spotifyData.title + : `${spotifyData.artist} - ${spotifyData.title}`; + tracks = await Util.ytSearch(searchString, { user: message.author, player: this, limit: 1 @@ -208,8 +211,16 @@ export class Player extends EventEmitter { playlist.tracks.items.map(async (item: any) => { const sq = queryType === 'spotify_album' - ? `${item.artists[0].name} - ${item.name}` - : `${item.track.artists[0].name} - ${item.name}`; + ? `${ + this.options.disableArtistSearch + ? item.artists[0].name + : `${item.artists[0].name} - ` + }${item.name}` + : `${ + this.options.disableArtistSearch + ? item.track.artists[0].name + : `${item.track.artists[0].name} - ` + }${item.name}`; const data = await Util.ytSearch(sq, { limit: 1, @@ -1422,6 +1433,7 @@ export default Player; * @property {YTDLDownloadOptions} [ytdlDownloadOptions={}] The download options passed to `ytdl-core` * @property {Boolean} [useSafeSearch=false] If it should use `safe search` method for youtube searches * @property {Boolean} [disableAutoRegister=false] If it should disable auto-registeration of `@discord-player/extractor` + * @property {Boolean} [disableArtistSearch=false] If it should disable artist search for spotify */ /** diff --git a/src/types/types.ts b/src/types/types.ts index 9e57e90..629188d 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -13,6 +13,7 @@ export interface PlayerOptions { ytdlDownloadOptions?: downloadOptions; useSafeSearch?: boolean; disableAutoRegister?: boolean; + disableArtistSearch?: boolean; } export type FiltersName = keyof QueueFilters; diff --git a/src/utils/Util.ts b/src/utils/Util.ts index 7826f5d..c444c84 100644 --- a/src/utils/Util.ts +++ b/src/utils/Util.ts @@ -4,7 +4,7 @@ import YouTube from 'youtube-sr'; import { Track } from '../Structures/Track'; // @ts-ignore import { validateURL as SoundcloudValidateURL } from 'soundcloud-scraper'; -import { VoiceChannel } from 'discord.js'; +import { StageChannel, VoiceChannel } from 'discord.js'; const spotifySongRegex = /https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/; const spotifyPlaylistRegex = /https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:playlist\/|\?uri=spotify:playlist:)((\w|-){22})/; @@ -190,10 +190,10 @@ export class Util { /** * Checks if the given voice channel is empty - * @param {DiscordVoiceChannel} channel The voice channel + * @param {DiscordVoiceChannel|DiscordStageChannel} channel The voice channel * @returns {Boolean} */ - static isVoiceEmpty(channel: VoiceChannel): boolean { + static isVoiceEmpty(channel: VoiceChannel | StageChannel): boolean { return channel.members.filter((member) => !member.user.bot).size === 0; }