aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2022-01-06 16:25:59 -0600
committerMax Isom <[email protected]>2022-01-06 16:27:38 -0600
commit65dd43ac6807d43f1af19975d4f0404a487cb71f (patch)
tree4e51d20ed9da5981a5f90cd5502498447947ec73 /src/services
parentdcdec2d49e2f457244b4fd15866f55f96d44492b (diff)
downloadmuse-65dd43ac6807d43f1af19975d4f0404a487cb71f.tar.xz
muse-65dd43ac6807d43f1af19975d4f0404a487cb71f.zip
Don't silently fail
Diffstat (limited to 'src/services')
-rw-r--r--src/services/get-songs.ts84
1 files changed, 36 insertions, 48 deletions
diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts
index ebf779a..55fb260 100644
--- a/src/services/get-songs.ts
+++ b/src/services/get-songs.ts
@@ -43,58 +43,50 @@ export default class {
}
async youtubeVideoSearch(query: string): Promise<QueuedSongWithoutChannel | null> {
- try {
- const {items} = await this.ytsrQueue.add(async () => this.cache.wrap(
- ytsr,
- query,
- {
- limit: 10,
- },
- {
- expiresIn: ONE_HOUR_IN_SECONDS,
- },
- ));
-
- let firstVideo: Video | undefined;
+ const {items} = await this.ytsrQueue.add(async () => this.cache.wrap(
+ ytsr,
+ query,
+ {
+ limit: 10,
+ },
+ {
+ expiresIn: ONE_HOUR_IN_SECONDS,
+ },
+ ));
- for (const item of items) {
- if (item.type === 'video') {
- firstVideo = item;
- break;
- }
- }
+ let firstVideo: Video | undefined;
- if (!firstVideo) {
- throw new Error('No video found.');
+ for (const item of items) {
+ if (item.type === 'video') {
+ firstVideo = item;
+ break;
}
+ }
- 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> {
- try {
- const videoDetails = await this.cache.wrap(
- this.youtube.videos.get,
- cleanUrl(url),
- {
- expiresIn: ONE_HOUR_IN_SECONDS,
- },
- );
+ const videoDetails = await this.cache.wrap(
+ this.youtube.videos.get,
+ cleanUrl(url),
+ {
+ expiresIn: ONE_HOUR_IN_SECONDS,
+ },
+ );
- return {
- title: videoDetails.snippet.title,
- artist: videoDetails.snippet.channelTitle,
- length: toSeconds(parse(videoDetails.contentDetails.duration)),
- url: videoDetails.id,
- playlist: null,
- isLive: videoDetails.snippet.liveBroadcastContent === 'live',
- };
- } catch (_: unknown) {
- return null;
- }
+ return {
+ title: videoDetails.snippet.title,
+ artist: videoDetails.snippet.channelTitle,
+ length: toSeconds(parse(videoDetails.contentDetails.duration)),
+ url: videoDetails.id,
+ playlist: null,
+ isLive: videoDetails.snippet.liveBroadcastContent === 'live',
+ };
}
async youtubePlaylist(listId: string): Promise<QueuedSongWithoutChannel[]> {
@@ -280,10 +272,6 @@ export default class {
}
private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<QueuedSongWithoutChannel | null> {
- try {
- return await this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
- } catch (_: unknown) {
- return null;
- }
+ return this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
}
}