aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThongrapee Panyapatiphan <[email protected]>2021-10-01 20:48:32 +0700
committerThongrapee Panyapatiphan <[email protected]>2021-10-01 20:48:32 +0700
commit96dcc4a5364d934b413b247e7b69ff31606c6183 (patch)
tree7d9be813ea28bd84560a1cd408ddf34fdb90268a /src
parent296a0a8178fb3c670c924b230a042cc1e6241719 (diff)
downloadmuse-96dcc4a5364d934b413b247e7b69ff31606c6183.tar.xz
muse-96dcc4a5364d934b413b247e7b69ff31606c6183.zip
Revert "Add config for song limit per playlist"
This reverts commit 296a0a8178fb3c670c924b230a042cc1e6241719.
Diffstat (limited to 'src')
-rw-r--r--src/commands/play.ts15
-rw-r--r--src/services/config.ts11
-rw-r--r--src/services/get-songs.ts16
3 files changed, 11 insertions, 31 deletions
diff --git a/src/commands/play.ts b/src/commands/play.ts
index 81a4ae1..a907a40 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -10,7 +10,6 @@ import LoadingMessage from '../utils/loading-message.js';
import errorMsg from '../utils/error-msg.js';
import Command from '.';
import GetSongs from '../services/get-songs.js';
-import Config from '../services/config.js';
@injectable()
export default class implements Command {
@@ -32,16 +31,10 @@ export default class implements Command {
private readonly playerManager: PlayerManager;
private readonly getSongs: GetSongs;
- private readonly playlistLimit: number;
- constructor(
- @inject(TYPES.Managers.Player) playerManager: PlayerManager,
- @inject(TYPES.Services.GetSongs) getSongs: GetSongs,
- @inject(TYPES.Config) config: Config,
- ) {
+ constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager, @inject(TYPES.Services.GetSongs) getSongs: GetSongs) {
this.playerManager = playerManager;
this.getSongs = getSongs;
- this.playlistLimit = config.getPlaylistLimit();
}
public async execute(msg: Message, args: string[]): Promise<void> {
@@ -110,11 +103,11 @@ export default class implements Command {
} else if (url.protocol === 'spotify:' || url.host === 'open.spotify.com') {
const [convertedSongs, nSongsNotFound, totalSongs] = await this.getSongs.spotifySource(args[0]);
- if (totalSongs > this.playlistLimit) {
- extraMsg = `a random sample of ${this.playlistLimit} songs was taken`;
+ if (totalSongs > 50) {
+ extraMsg = 'a random sample of 50 songs was taken';
}
- if (totalSongs > this.playlistLimit && nSongsNotFound !== 0) {
+ if (totalSongs > 50 && nSongsNotFound !== 0) {
extraMsg += ' and ';
}
diff --git a/src/services/config.ts b/src/services/config.ts
index 087ea0b..759a27a3 100644
--- a/src/services/config.ts
+++ b/src/services/config.ts
@@ -4,7 +4,6 @@ import path from 'path';
dotenv.config();
export const DATA_DIR = path.resolve(process.env.DATA_DIR ? process.env.DATA_DIR : './data');
-const DEFAULT_PLAYLIST_LIMIT = 50;
const CONFIG_MAP = {
DISCORD_TOKEN: process.env.DISCORD_TOKEN,
@@ -13,7 +12,6 @@ const CONFIG_MAP = {
SPOTIFY_CLIENT_SECRET: process.env.SPOTIFY_CLIENT_SECRET,
DATA_DIR,
CACHE_DIR: path.join(DATA_DIR, 'cache'),
- PLAYLIST_LIMIT: process.env.PLAYLIST_LIMIT,
} as const;
@injectable()
@@ -24,7 +22,6 @@ export default class Config {
readonly SPOTIFY_CLIENT_SECRET!: string;
readonly DATA_DIR!: string;
readonly CACHE_DIR!: string;
- readonly PLAYLIST_LIMIT!: string;
constructor() {
for (const [key, value] of Object.entries(CONFIG_MAP)) {
@@ -36,12 +33,4 @@ export default class Config {
this[key as keyof typeof CONFIG_MAP] = value;
}
}
-
- getPlaylistLimit() {
- if (!this.PLAYLIST_LIMIT) {
- return DEFAULT_PLAYLIST_LIMIT;
- }
-
- return Number(this.PLAYLIST_LIMIT) || DEFAULT_PLAYLIST_LIMIT;
- }
}
diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts
index dcf6823..ba4401c 100644
--- a/src/services/get-songs.ts
+++ b/src/services/get-songs.ts
@@ -27,7 +27,6 @@ export default class {
private readonly youtubeKey: string;
private readonly spotify: Spotify;
private readonly cache: CacheProvider;
- private readonly playlistLimit: number;
private readonly ytsrQueue: PQueue;
@@ -39,7 +38,6 @@ export default class {
this.youtubeKey = config.YOUTUBE_API_KEY;
this.spotify = thirdParty.spotify;
this.cache = cache;
- this.playlistLimit = config.getPlaylistLimit();
this.ytsrQueue = new PQueue({concurrency: 4});
}
@@ -128,7 +126,7 @@ export default class {
const {items, nextPageToken} = await this.cache.wrap(
this.youtube.playlists.items,
listId,
- {maxResults: `${this.playlistLimit}`, pageToken: nextToken},
+ {maxResults: '50', pageToken: nextToken},
{
expiresIn: ONE_MINUTE_IN_SECONDS,
},
@@ -201,7 +199,7 @@ export default class {
case 'album': {
const uri = parsed as spotifyURI.Album;
- const [{body: album}, {body: {items}}] = await Promise.all([this.spotify.getAlbum(uri.id), this.spotify.getAlbumTracks(uri.id, {limit: this.playlistLimit})]);
+ const [{body: album}, {body: {items}}] = await Promise.all([this.spotify.getAlbum(uri.id), this.spotify.getAlbumTracks(uri.id, {limit: 50})]);
tracks.push(...items);
@@ -212,7 +210,7 @@ export default class {
case 'playlist': {
const uri = parsed as spotifyURI.Playlist;
- let [{body: playlistResponse}, {body: tracksResponse}] = await Promise.all([this.spotify.getPlaylist(uri.id), this.spotify.getPlaylistTracks(uri.id, {limit: this.playlistLimit})]);
+ let [{body: playlistResponse}, {body: tracksResponse}] = await Promise.all([this.spotify.getPlaylist(uri.id), this.spotify.getPlaylistTracks(uri.id, {limit: 50})]);
playlist = {title: playlistResponse.name, source: playlistResponse.href};
@@ -221,7 +219,7 @@ export default class {
while (tracksResponse.next) {
// eslint-disable-next-line no-await-in-loop
({body: tracksResponse} = await this.spotify.getPlaylistTracks(uri.id, {
- limit: parseInt(new URL(tracksResponse.next).searchParams.get('limit') ?? `${this.playlistLimit}`, 10),
+ limit: parseInt(new URL(tracksResponse.next).searchParams.get('limit') ?? '50', 10),
offset: parseInt(new URL(tracksResponse.next).searchParams.get('offset') ?? '0', 10),
}));
@@ -254,13 +252,13 @@ export default class {
}
}
- // Get random songs if many then limit to playlistLimit (defaults to 50)
+ // Get 50 random songs if many
const originalNSongs = tracks.length;
- if (tracks.length > this.playlistLimit) {
+ if (tracks.length > 50) {
const shuffled = shuffle(tracks);
- tracks = shuffled.slice(0, this.playlistLimit);
+ tracks = shuffled.slice(0, 50);
}
let songs = await Promise.all(tracks.map(async track => this.spotifyToYouTube(track, playlist)));