mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-11 20:31:35 +02:00
parent
da72cd708b
commit
59cbc8b474
12 changed files with 317 additions and 190 deletions
|
@ -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}"`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
]);
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ export interface QueuedSong {
|
|||
playlist: QueuedPlaylist | null;
|
||||
isLive: boolean;
|
||||
addedInChannelId: Snowflake;
|
||||
thumbnailUrl: string | null;
|
||||
requestedBy: string;
|
||||
}
|
||||
|
||||
export enum STATUS {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue