minor: move some functions
This commit is contained in:
3 files changed
+36
-24
No files matched your search
+18
-9
@@ -6,38 +6,47 @@ import { logAction, logValue } from './log.js'
|
||||
|
||||
const headers = { authorization: 'Bearer ' + secret }
|
||||
|
||||
function updateStatus(tid, progress, duration, paused) {
|
||||
function updateStatus(track, progress = null, duration = null, paused) {
|
||||
return new Promise((resolve, reject) => {
|
||||
verbose > 1 && console.info(`PUT status`, tid, progress, duration, paused)
|
||||
console.log({
|
||||
tid: track?.tid ?? null,
|
||||
progress,
|
||||
duration,
|
||||
paused: paused ?? track ? false : true,
|
||||
})
|
||||
got
|
||||
.put(`https://${DOMAIN}/api/player/set/status`, {
|
||||
.put(`https://${domain}/api/player/set/status`, {
|
||||
headers,
|
||||
json: {
|
||||
tid,
|
||||
tid: track?.tid ?? null,
|
||||
progress,
|
||||
duration,
|
||||
paused,
|
||||
paused: paused ?? track ? false : true,
|
||||
},
|
||||
})
|
||||
.json()
|
||||
.then((ok) => resolve(ok))
|
||||
.catch((err) => reject(err))
|
||||
|
||||
verbose > 1 &&
|
||||
console.info(`PUT status`, track?.tid, progress, duration, paused)
|
||||
})
|
||||
}
|
||||
|
||||
function updateNext(tid) {
|
||||
function updateNext(track) {
|
||||
return new Promise((resolve, reject) => {
|
||||
verbose > 1 && console.info(`PUT next`, tid)
|
||||
got
|
||||
.put(`https://${DOMAIN}/api/player/set/next`, {
|
||||
.put(`https://${domain}/api/player/set/next`, {
|
||||
headers,
|
||||
json: {
|
||||
tid,
|
||||
tid: track ? track.tid : null,
|
||||
},
|
||||
})
|
||||
.json()
|
||||
.then((ok) => resolve(ok))
|
||||
.catch((err) => reject(err))
|
||||
|
||||
verbose > 1 && console.info(`PUT next`, track?.tid)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+17
-1
@@ -1,6 +1,7 @@
|
||||
import { verbose } from '../../env.js'
|
||||
import { defaultVolume, verbose } from '../../env.js'
|
||||
|
||||
import { spawn } from 'child_process'
|
||||
import { updateStatus } from './calls.js'
|
||||
|
||||
class PlaybackError extends Error {
|
||||
constructor(message = '', ...args) {
|
||||
@@ -65,6 +66,21 @@ function queueCommand(comm, data) {
|
||||
} else sendCommand(comm, data)
|
||||
}
|
||||
|
||||
function stream(track) {
|
||||
queueCommand('change', [track.url])
|
||||
player.play()
|
||||
queueCommand('volume', [defaultVolume])
|
||||
}
|
||||
|
||||
function local(track) {
|
||||
queueCommand('local', [`./cache/${track.tid}.mp4`])
|
||||
player.play()
|
||||
queueCommand('volume', [defaultVolume])
|
||||
updateStatus(track, 0, track.duration)
|
||||
}
|
||||
|
||||
export { stream, local }
|
||||
|
||||
const player = {
|
||||
play: () => queueCommand('play'),
|
||||
pause: () => queueCommand('pause'),
|
||||
|
||||
+1
-14
@@ -4,21 +4,8 @@ import playback, { player, queueCommand } from './modules/playback.js'
|
||||
import { getTop, updateNext, updateStatus } from './modules/calls.js'
|
||||
import { convert } from './modules/youtube.js'
|
||||
import { parse, cache, scheduler } from './modules/parse.js'
|
||||
|
||||
import { logAction, logSchedule, logTrack, logValue } from './modules/log.js'
|
||||
|
||||
function stream(track) {
|
||||
queueCommand('change', [track.url])
|
||||
player.play()
|
||||
queueCommand('volume', [defaultVolume])
|
||||
}
|
||||
|
||||
function local(track) {
|
||||
queueCommand('local', [`./cache/${track.tid}.mp4`])
|
||||
player.play()
|
||||
queueCommand('volume', [defaultVolume])
|
||||
updateStatus(track.tid, 0, track.duration, false)
|
||||
}
|
||||
import { local } from './modules/playback.js'
|
||||
|
||||
export default async function standalone() {
|
||||
logValue('Volume', defaultVolume)
|
||||
|
||||
Reference in new issue
Block a user