Added can't stream error before adding to queue
This commit is contained in:
parent
59d8222177
commit
12d6cafdd0
@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import deemix from 'deemix'
|
||||
import got from 'got'
|
||||
import { Settings, Listener } from './types'
|
||||
import { NotLoggedIn } from './helpers/errors'
|
||||
import { NotLoggedIn, CantStream } from './helpers/errors'
|
||||
|
||||
import { GUI_PACKAGE } from './helpers/paths'
|
||||
import { logger } from './helpers/logger'
|
||||
@ -160,6 +160,11 @@ export class DeemixApp {
|
||||
|
||||
async addToQueue(dz: any, url: string[], bitrate: number) {
|
||||
if (!dz.logged_in) throw new NotLoggedIn()
|
||||
if (
|
||||
!this.settings.feelingLucky &&
|
||||
((!dz.current_user.can_stream_lossless && bitrate === 9) || (!dz.current_user.can_stream_hq && bitrate === 3))
|
||||
)
|
||||
throw new CantStream(bitrate)
|
||||
|
||||
let downloadObjs: any[] = []
|
||||
const downloadErrors: any[] = []
|
||||
|
@ -1,3 +1,16 @@
|
||||
const { TrackFormats } = require('deezer-js')
|
||||
|
||||
const bitrateLabels = {
|
||||
[TrackFormats.MP4_RA3]: '360 HQ',
|
||||
[TrackFormats.MP4_RA2]: '360 MQ',
|
||||
[TrackFormats.MP4_RA1]: '360 LQ',
|
||||
[TrackFormats.FLAC]: 'FLAC',
|
||||
[TrackFormats.MP3_320]: '320kbps',
|
||||
[TrackFormats.MP3_128]: '128kbps',
|
||||
[TrackFormats.DEFAULT]: '128kbps',
|
||||
[TrackFormats.LOCAL]: 'MP3'
|
||||
}
|
||||
|
||||
export class BadRequestError extends Error {
|
||||
constructor() {
|
||||
super()
|
||||
@ -31,3 +44,12 @@ export class NotLoggedIn extends QueueError {
|
||||
this.name = 'NotLoggedIn'
|
||||
}
|
||||
}
|
||||
|
||||
export class CantStream extends QueueError {
|
||||
bitrate: number
|
||||
constructor(bitrate: number) {
|
||||
super(`Your account can't stream at ${bitrateLabels[bitrate]}.`)
|
||||
this.name = 'CantStream'
|
||||
this.bitrate = bitrate
|
||||
}
|
||||
}
|
||||
|
@ -14,19 +14,22 @@ const handler: ApiHandler['handler'] = async (req, res) => {
|
||||
const url = req.body.url.split(/[\s;]+/)
|
||||
let bitrate = req.body.bitrate
|
||||
if (bitrate === 'null' || bitrate === null) bitrate = deemix.getSettings().settings.maxBitrate
|
||||
bitrate = Number(bitrate)
|
||||
let obj: any
|
||||
|
||||
try {
|
||||
obj = await deemix.addToQueue(dz, url, bitrate)
|
||||
} catch (e) {
|
||||
res.send({ result: false, errid: e.name, data: { url, bitrate } })
|
||||
switch (e.name) {
|
||||
case 'NotLoggedIn':
|
||||
res.send({ result: false, errid: e.name, data: { url, bitrate } })
|
||||
deemix.listener.send('loginNeededToDownload')
|
||||
deemix.listener.send('queueError' + e.name)
|
||||
break
|
||||
case 'CantStream':
|
||||
deemix.listener.send('queueError' + e.name, e.bitrate)
|
||||
break
|
||||
default:
|
||||
logger.error(e)
|
||||
res.send({ result: false, errid: e.name, data: { url, bitrate } })
|
||||
break
|
||||
}
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user