fix: queue too large

This commit is contained in:
Mateusz Pstrucha committed 2021-10-28 08:39:21 +02:00
1 parent 8d57412eff
commit 77f3df982c
3 files changed
+21 -12

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
import dotenv from 'dotenv'
const config = dotenv.config()
export default config
+5 -5
View File
@@ -1,4 +1,4 @@
import dotenv from 'dotenv'
import env from './env.js'
import chalk from 'chalk'
import { player, queueCommand } from './modules/playback.js'
@@ -7,8 +7,6 @@ import { now, durations, seconds } from './modules/timings.js'
import Track from './Track.js'
dotenv.config()
const defaultVolume = parseInt(process.env.VOLUME_DEFAULT ?? 100),
offset = Number(process.env.OFFSET ?? 0),
verbose = Number(process.env.VERBOSE ?? 0)
@@ -32,7 +30,9 @@ function pad(n) {
}
console.info(
`Volume: ${chalk.yellow(defaultVolume)}, Verbose: ${chalk.yellow(verbose)}`
`Volume: ${chalk.yellow(defaultVolume)}, Verbose: ${chalk.yellow(
verbose
)}, Limit: ${chalk.yellow(process.env.LIMIT)}`
)
console.info(`Fetching playlist (${chalk.yellow(process.env.DOMAIN)})`)
@@ -97,7 +97,7 @@ getTop()
)}]`
)
if (sched < 0) return
if (sched < -10) return
setTimeout(() => {
console.info(
+11 -7
View File
@@ -1,13 +1,11 @@
import chalk from 'chalk'
import dotenv from 'dotenv'
import got from 'got'
import spotifyToYt from 'spotify-to-yt'
dotenv.config()
const { DOMAIN, SECRET } = process.env,
headers = { authorization: 'Bearer ' + SECRET },
verbose = Number(process.env.VERBOSE)
verbose = Number(process.env.VERBOSE),
limit = Number(process.env.LIMIT ?? 40)
function updateStatus(tid, progress, duration, paused) {
return new Promise((resolve, reject) => {
@@ -53,11 +51,17 @@ function getTop() {
})
.json()
.then((top) => {
console.info(`Resolving ${chalk.cyan(top.length)} tracks`)
console.info(
`Resolving ${chalk.cyan(
top.length > limit ? limit + '/' + top.length : top.length
)} tracks`
)
Promise.all(
top.map((tid) => spotifyToYt.trackGet(`spotify:track:${tid}`))
top
.slice(0, limit)
.map((tid) => spotifyToYt.trackGet(`spotify:track:${tid}`))
).then((yts) => {
top.map((tid, i) => {
top.slice(0, limit).map((tid, i) => {
yts[i].tid = tid
})
resolve(yts)