Playback error fix, downloading on windows crash fix, logging POC
This commit is contained in:
@ -156,6 +156,27 @@ class Downloads {
|
||||
fs.promises.mkdir(Settings.getTempDownloads(), {recursive: true});
|
||||
}
|
||||
}
|
||||
|
||||
//Remove download
|
||||
async delete(index) {
|
||||
//Clear all
|
||||
if (index == -1) {
|
||||
this.downloads = [];
|
||||
await new Promise((res, rej) => {
|
||||
this.db.remove({state: 0}, {}, (e) => {});
|
||||
res();
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
//Remove single
|
||||
if (index >= this.downloads.length) return;
|
||||
await new Promise((res, rej) => {
|
||||
this.db.remove({_id: this.downloads[index].id}, {}, (e) => {});
|
||||
res();
|
||||
});
|
||||
this.downloads.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
class Download {
|
||||
@ -263,9 +284,11 @@ class Download {
|
||||
} catch (e) {};
|
||||
|
||||
//Decrypt
|
||||
decryptor.decryptFile(decryptor.getKey(this.track.id), tmp, this.path);
|
||||
decryptor.decryptFile(decryptor.getKey(this.track.id), tmp, `${tmp}.DEC`);
|
||||
fs.promises.copyFile(`${tmp}.DEC`, this.path);
|
||||
//Delete encrypted
|
||||
await fs.promises.unlink(tmp);
|
||||
await fs.promises.unlink(`${tmp}.DEC`);
|
||||
|
||||
//Tags
|
||||
await this.tagAudio(this.path, this.track);
|
||||
|
@ -274,7 +274,7 @@ app.get('/stream/:info', (req, res) => {
|
||||
let dStart = start - (start % 2048);
|
||||
|
||||
//Make request to Deezer CDN
|
||||
https.get(url, {headers: {'Range': `bytes=${dStart}-${end}`}}, (r) => {
|
||||
let _request = https.get(url, {headers: {'Range': `bytes=${dStart}-${end}`}}, (r) => {
|
||||
//Error from Deezer
|
||||
//TODO: Quality fallback
|
||||
if (r.statusCode < 200 || r.statusCode > 300) {
|
||||
@ -311,6 +311,13 @@ app.get('/stream/:info', (req, res) => {
|
||||
//Pipe: Deezer -> Decryptor -> Response
|
||||
decryptor.pipe(res);
|
||||
r.pipe(decryptor);
|
||||
|
||||
});
|
||||
//Internet/Request error
|
||||
_request.on('error', (e) => {
|
||||
//console.log('Streaming error: ' + e);
|
||||
//HTML audio will restart automatically
|
||||
res.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
@ -400,6 +407,27 @@ app.get('/downloads', async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
//Delete singel download
|
||||
app.delete('/downloads/:index', async (req, res) => {
|
||||
let index = parseInt(req.params.index, 10);
|
||||
await downloads.delete(index);
|
||||
res.status(200).end();
|
||||
});
|
||||
|
||||
//Log listen to deezer
|
||||
app.put('/log/:id', async (req, res) => {
|
||||
await deezer.callApi('log.listen', {
|
||||
params: {
|
||||
timestamp: Math.floor(new Date() / 1000),
|
||||
ts_listen: Math.floor(new Date() / 1000),
|
||||
type: 1,
|
||||
stat: {seek: 0, pause: 0, sync: 0},
|
||||
media: {id: req.params.id.toString(), type: 'song', format: 'MP3_128'}
|
||||
}
|
||||
});
|
||||
res.status(200).end();
|
||||
});
|
||||
|
||||
//Redirect to index on unknown path
|
||||
app.all('*', (req, res) => {
|
||||
res.redirect('/');
|
||||
|
@ -22,6 +22,8 @@ class Settings {
|
||||
this.createAlbumFolder = true;
|
||||
this.createArtistFolder = true;
|
||||
this.downloadFilename = '%0trackNumber%. %artists% - %title%';
|
||||
|
||||
this.logListen = false;
|
||||
}
|
||||
|
||||
//Based on electorn app.getPath
|
||||
|
Reference in New Issue
Block a user