aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorThongrapee Panyapatiphan <[email protected]>2022-01-22 01:50:57 +0700
committerGitHub <[email protected]>2022-01-21 12:50:57 -0600
commit59cbc8b474425225f7f188ce54bc19d5f1193ecb (patch)
treee218db77455d935fed39e112dcd1807d53ea8352 /src/services
parentda72cd708bcfbba6e0a91da4878aaef10d2532e2 (diff)
downloadmuse-59cbc8b474425225f7f188ce54bc19d5f1193ecb.tar.xz
muse-59cbc8b474425225f7f188ce54bc19d5f1193ecb.zip
Announce current song (#470)
Co-authored-by: Max Isom <[email protected]>
Diffstat (limited to 'src/services')
-rw-r--r--src/services/get-songs.ts20
-rw-r--r--src/services/natural-language-commands.ts6
-rw-r--r--src/services/player.ts2
3 files changed, 19 insertions, 9 deletions
diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts
index 780f7ec..fb1b4ea 100644
--- a/src/services/get-songs.ts
+++ b/src/services/get-songs.ts
@@ -16,7 +16,7 @@ import ThirdParty from './third-party.js';
import Config from './config.js';
import KeyValueCacheProvider from './key-value-cache.js';
-type QueuedSongWithoutChannel = Except<QueuedSong, 'addedInChannelId'>;
+type SongMetadata = Except<QueuedSong, 'addedInChannelId' | 'requestedBy'>;
const ONE_HOUR_IN_SECONDS = 60 * 60;
const ONE_MINUTE_IN_SECONDS = 1 * 60;
@@ -42,7 +42,7 @@ export default class {
this.ytsrQueue = new PQueue({concurrency: 4});
}
- async youtubeVideoSearch(query: string): Promise<QueuedSongWithoutChannel> {
+ async youtubeVideoSearch(query: string): Promise<SongMetadata> {
const {items} = await this.ytsrQueue.add(async () => this.cache.wrap(
ytsr,
query,
@@ -70,7 +70,7 @@ export default class {
return this.youtubeVideo(firstVideo.id);
}
- async youtubeVideo(url: string): Promise<QueuedSongWithoutChannel> {
+ async youtubeVideo(url: string): Promise<SongMetadata> {
const videoDetails = await this.cache.wrap(
this.youtube.videos.get,
cleanUrl(url),
@@ -86,10 +86,11 @@ export default class {
url: videoDetails.id,
playlist: null,
isLive: videoDetails.snippet.liveBroadcastContent === 'live',
+ thumbnailUrl: videoDetails.snippet.thumbnails.medium.url,
};
}
- async youtubePlaylist(listId: string): Promise<QueuedSongWithoutChannel[]> {
+ async youtubePlaylist(listId: string): Promise<SongMetadata[]> {
// YouTube playlist
const playlist = await this.cache.wrap(
this.youtube.playlists.get,
@@ -158,7 +159,7 @@ export default class {
const queuedPlaylist = {title: playlist.snippet.title, source: playlist.id};
- const songsToReturn: QueuedSongWithoutChannel[] = [];
+ const songsToReturn: SongMetadata[] = [];
for (const video of playlistVideos) {
try {
@@ -171,6 +172,7 @@ export default class {
url: video.contentDetails.videoId,
playlist: queuedPlaylist,
isLive: false,
+ thumbnailUrl: video.snippet.thumbnails.medium.url,
});
} catch (_: unknown) {
// Private and deleted videos are sometimes in playlists, duration of these is not returned and they should not be added to the queue.
@@ -180,7 +182,7 @@ export default class {
return songsToReturn;
}
- async spotifySource(url: string, playlistLimit: number): Promise<[QueuedSongWithoutChannel[], number, number]> {
+ async spotifySource(url: string, playlistLimit: number): Promise<[SongMetadata[], number, number]> {
const parsed = spotifyURI.parse(url);
let tracks: SpotifyApi.TrackObjectSimplified[] = [];
@@ -258,7 +260,7 @@ export default class {
let nSongsNotFound = 0;
// Get rid of null values
- songs = songs.reduce((accum: QueuedSongWithoutChannel[], song) => {
+ songs = songs.reduce((accum: SongMetadata[], song) => {
if (song) {
accum.push(song);
} else {
@@ -268,10 +270,10 @@ export default class {
return accum;
}, []);
- return [songs as QueuedSongWithoutChannel[], nSongsNotFound, originalNSongs];
+ return [songs as SongMetadata[], nSongsNotFound, originalNSongs];
}
- private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<QueuedSongWithoutChannel> {
+ private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<SongMetadata> {
return this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
}
}
diff --git a/src/services/natural-language-commands.ts b/src/services/natural-language-commands.ts
index 1401eac..4ce8ea3 100644
--- a/src/services/natural-language-commands.ts
+++ b/src/services/natural-language-commands.ts
@@ -32,6 +32,8 @@ export default class {
playlist: null,
isLive: false,
addedInChannelId: msg.channel.id,
+ thumbnailUrl: null,
+ requestedBy: msg.author.id,
}, 8, 10),
]);
@@ -49,6 +51,8 @@ export default class {
playlist: null,
isLive: false,
addedInChannelId: msg.channel.id,
+ thumbnailUrl: null,
+ requestedBy: msg.author.id,
}, 358, 5.5),
]);
@@ -66,6 +70,8 @@ export default class {
playlist: null,
isLive: false,
addedInChannelId: msg.channel.id,
+ thumbnailUrl: null,
+ requestedBy: msg.author.id,
}, 50, 13),
]);
diff --git a/src/services/player.ts b/src/services/player.ts
index cee59bc..fc4b989 100644
--- a/src/services/player.ts
+++ b/src/services/player.ts
@@ -22,6 +22,8 @@ export interface QueuedSong {
playlist: QueuedPlaylist | null;
isLive: boolean;
addedInChannelId: Snowflake;
+ thumbnailUrl: string | null;
+ requestedBy: string;
}
export enum STATUS {