fix: better converter
This commit is contained in:
2 files changed
+27
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
class Track {
|
||||
constructor(tid, { url, info: [{ id, title, duration }] }) {
|
||||
this.url = url
|
||||
constructor(tid, [{ id, title, duration }]) {
|
||||
this.url = `https://www.youtube.com/watch?v=${id}`
|
||||
this.tid = tid
|
||||
this.ytid = id
|
||||
this.title = title
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import spotifyToYt from 'spotify-to-yt'
|
||||
import { YouTube } from 'youtube-sr'
|
||||
import {
|
||||
createWriteStream,
|
||||
existsSync,
|
||||
@@ -11,12 +12,36 @@ import ytdl from 'ytdl-core'
|
||||
import { logAction, logError } from './log.js'
|
||||
|
||||
import Track from '../classes/Track.js'
|
||||
import { getTrack } from './calls.js'
|
||||
|
||||
const cache = './cache'
|
||||
|
||||
function convert(tids) {
|
||||
logAction(`Running converter`, tids.length)
|
||||
|
||||
return Promise.all(
|
||||
tids.map(async (tid) => {
|
||||
let { title, artists } = await getTrack(tid)
|
||||
|
||||
return await YouTube.search(
|
||||
`${title} ${artists.join(' ')} official audio`,
|
||||
{ limit: 10, type: 'video' }
|
||||
).then((videos) => {
|
||||
if (videos.length < 1) {
|
||||
logError('No videos found, retrying', tid)
|
||||
return YouTube.search(`${title} ${artists.join(' ')}`, {
|
||||
limit: 10,
|
||||
type: 'video',
|
||||
}).then((videos) => {
|
||||
if (videos.length < 1) {
|
||||
logError(`Conversion failed twice, I give up`, tid)
|
||||
} else return videos
|
||||
})
|
||||
} else return videos
|
||||
})
|
||||
})
|
||||
).then((ytd) => tids.map((tid, i) => new Track(tid, ytd[i])))
|
||||
|
||||
return Promise.all(
|
||||
tids.map((tid) =>
|
||||
spotifyToYt.trackGet(`spotify:track:${tid}`).catch((err) => {
|
||||
|
||||
Reference in new issue
Block a user