mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Don't silently fail
This commit is contained in:
parent
dcdec2d49e
commit
65dd43ac68
|
@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Changed
|
||||||
|
- Track lookups no longer fail silently (error is returned and logged)
|
||||||
|
|
||||||
## [0.3.1] - 2022-01-06
|
## [0.3.1] - 2022-01-06
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -43,58 +43,50 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
async youtubeVideoSearch(query: string): Promise<QueuedSongWithoutChannel | null> {
|
async youtubeVideoSearch(query: string): Promise<QueuedSongWithoutChannel | null> {
|
||||||
try {
|
const {items} = await this.ytsrQueue.add(async () => this.cache.wrap(
|
||||||
const {items} = await this.ytsrQueue.add(async () => this.cache.wrap(
|
ytsr,
|
||||||
ytsr,
|
query,
|
||||||
query,
|
{
|
||||||
{
|
limit: 10,
|
||||||
limit: 10,
|
},
|
||||||
},
|
{
|
||||||
{
|
expiresIn: ONE_HOUR_IN_SECONDS,
|
||||||
expiresIn: ONE_HOUR_IN_SECONDS,
|
},
|
||||||
},
|
));
|
||||||
));
|
|
||||||
|
|
||||||
let firstVideo: Video | undefined;
|
let firstVideo: Video | undefined;
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (item.type === 'video') {
|
if (item.type === 'video') {
|
||||||
firstVideo = item;
|
firstVideo = item;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!firstVideo) {
|
|
||||||
throw new Error('No video found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await this.youtubeVideo(firstVideo.id);
|
|
||||||
} catch (_: unknown) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!firstVideo) {
|
||||||
|
throw new Error('No video found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.youtubeVideo(firstVideo.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async youtubeVideo(url: string): Promise<QueuedSongWithoutChannel | null> {
|
async youtubeVideo(url: string): Promise<QueuedSongWithoutChannel | null> {
|
||||||
try {
|
const videoDetails = await this.cache.wrap(
|
||||||
const videoDetails = await this.cache.wrap(
|
this.youtube.videos.get,
|
||||||
this.youtube.videos.get,
|
cleanUrl(url),
|
||||||
cleanUrl(url),
|
{
|
||||||
{
|
expiresIn: ONE_HOUR_IN_SECONDS,
|
||||||
expiresIn: ONE_HOUR_IN_SECONDS,
|
},
|
||||||
},
|
);
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: videoDetails.snippet.title,
|
title: videoDetails.snippet.title,
|
||||||
artist: videoDetails.snippet.channelTitle,
|
artist: videoDetails.snippet.channelTitle,
|
||||||
length: toSeconds(parse(videoDetails.contentDetails.duration)),
|
length: toSeconds(parse(videoDetails.contentDetails.duration)),
|
||||||
url: videoDetails.id,
|
url: videoDetails.id,
|
||||||
playlist: null,
|
playlist: null,
|
||||||
isLive: videoDetails.snippet.liveBroadcastContent === 'live',
|
isLive: videoDetails.snippet.liveBroadcastContent === 'live',
|
||||||
};
|
};
|
||||||
} catch (_: unknown) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async youtubePlaylist(listId: string): Promise<QueuedSongWithoutChannel[]> {
|
async youtubePlaylist(listId: string): Promise<QueuedSongWithoutChannel[]> {
|
||||||
|
@ -280,10 +272,6 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<QueuedSongWithoutChannel | null> {
|
private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<QueuedSongWithoutChannel | null> {
|
||||||
try {
|
return this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
|
||||||
return await this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
|
|
||||||
} catch (_: unknown) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue