diff options
| author | Max Isom <[email protected]> | 2020-10-24 13:11:29 -0400 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2020-10-24 13:11:29 -0400 |
| commit | e103282cd7c283ba1c7fe9c92b2bd8feaed5b120 (patch) | |
| tree | f4df4866f062c86981df5c9ca8b3c56f30a4ef92 | |
| parent | 7a2cdc20de5c3fc25afe69f73d647ad063d74d6b (diff) | |
| download | muse-e103282cd7c283ba1c7fe9c92b2bd8feaed5b120.tar.xz muse-e103282cd7c283ba1c7fe9c92b2bd8feaed5b120.zip | |
Fix auto translate search function
| -rw-r--r-- | src/services/get-songs.ts | 19 | ||||
| -rw-r--r-- | src/services/player.ts | 2 |
2 files changed, 6 insertions, 15 deletions
diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index 48a1dc7..8041d0b 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -4,13 +4,11 @@ import {toSeconds, parse} from 'iso8601-duration'; import got from 'got'; import spotifyURI from 'spotify-uri'; import Spotify from 'spotify-web-api-node'; -import ytsr from 'ytsr'; import YouTube from 'youtube.ts'; import pLimit from 'p-limit'; import uniqueRandomArray from 'unique-random-array'; import {QueuedSong, QueuedPlaylist} from '../services/player'; import {TYPES} from '../types'; -import {parseTime} from '../utils/time'; @injectable() export default class { @@ -183,23 +181,16 @@ export default class { return [songs as QueuedSong[], nSongsNotFound, originalNSongs]; } - private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, playlist: QueuedPlaylist | null): Promise<QueuedSong | null> { + private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<QueuedSong | null> { try { - const {items} = await ytsr(`"${track.name}" "${track.artists[0].name}" offical`, {limit: 5}); - const video = items.find(item => item.type === 'video'); + const {items} = await this.youtube.videos.search({q: `"${track.name}" "${track.artists[0].name}"`, maxResults: 10}); + const videoResult = items[0]; // Items.find(item => item.type === 'video'); - if (!video || video.type !== 'video') { + if (!videoResult) { throw new Error('No video found for query.'); } - return { - title: video.title, - artist: track.artists[0].name, - length: video.duration ? parseTime(video.duration) : 0, - url: video.link, - playlist, - isLive: video.live - }; + return await this.youtubeVideo(videoResult.id.videoId); } catch (_: unknown) { return null; } diff --git a/src/services/player.ts b/src/services/player.ts index 76ff73f..d149826 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -83,7 +83,7 @@ export default class { } const stream = await this.getStream(currentSong.url, {seek: positionSeconds}); - this.dispatcher = this.voiceConnection.play(stream, {type: 'webm/opus'}); + this.dispatcher = this.voiceConnection.play(stream, {type: 'webm/opus', bitrate: 'auto'}); this.attachListeners(); this.startTrackingPosition(positionSeconds); |
