This commit is contained in:
exttex
2021-01-21 19:19:14 +01:00
parent 5c40db1242
commit 87eb351e80
29 changed files with 2060 additions and 890 deletions

View File

@ -66,7 +66,7 @@ class DeezerAPI {
//Invalid CSRF
if (data.data.error && data.data.error.VALID_TOKEN_REQUIRED) {
await this.callApi('deezer.getUserData');
await this.authorize();
return await this.callApi(method, args, gatewayInput);
}
@ -127,7 +127,7 @@ class DeezerAPI {
//Invalid CSRF
if (data.error && data.error.VALID_TOKEN_REQUIRED) {
await this.callApi('deezer.getUserData');
await this.authorize();
return await this.callApi(method, args, gatewayInput);
}

View File

@ -122,14 +122,13 @@ class DeezerImage {
this.hash = hash;
this.type = type;
//Create full and thumb, to standardize size and because functions aren't preserved
this.full = this.url(1400);
this.thumb = this.url(256);
this.full = DeezerImage.url(this.hash, this.type, 1400);
this.thumb = DeezerImage.url(this.hash, this.type, 256);
}
url(size = 256) {
if (!this.hash)
return `https://e-cdns-images.dzcdn.net/images/${this.type}/${size}x${size}-000000-80-0-0.jpg`;
return `https://e-cdns-images.dzcdn.net/images/${this.type}/${this.hash}/${size}x${size}-000000-80-0-0.jpg`;
static url(hash, type, size = 256) {
if (!hash)
return `https://e-cdns-images.dzcdn.net/images/${type}/${size}x${size}-000000-80-0-0.jpg`;
return `https://e-cdns-images.dzcdn.net/images/${type}/${hash}/${size}x${size}-000000-80-0-0.jpg`;
}
}

View File

@ -9,7 +9,7 @@ const decryptor = require('nodeezcryptor');
const sanitize = require('sanitize-filename');
const ID3Writer = require('browser-id3-writer');
const Metaflac = require('metaflac-js2');
const { Track, Lyrics } = require('./definitions');
const { Track, Lyrics, DeezerImage } = require('./definitions');
const { throwDeprecation } = require('process');
let deezer;
@ -206,6 +206,7 @@ class DownloadThread {
this.settings = settings;
this.stopped = true;
this.isUserUploaded = download.track.id.toString().startsWith('-');
this.coverPath = null;
}
//Callback wrapper
@ -328,9 +329,11 @@ class DownloadThread {
await fs.promises.unlink(`${tmp}.DEC`);
await fs.promises.unlink(tmp);
let cover = null;
if (!this.isUserUploaded) {
//Tag
await this.tagTrack(outPath);
//Tag, returns cover to prevent double downlaoding
cover = await this.tagTrack(outPath);
//Lyrics
if (this.settings.downloadLyrics) {
@ -346,6 +349,25 @@ class DownloadThread {
}
}
}
//Cover
if (this.coverPath) {
if (!fs.existsSync(this.coverPath)) {
//Create empty file to "lock"
fs.closeSync(fs.openSync(this.coverPath, 'w'));
if (!cover) {
try {
cover = await this.downloadCover(DeezerImage.url(this.track.albumArt.hash, 'cover', this.settings.coverResolution));
} catch (e) {}
}
if (!cover) {
logger.warn("Error downloading album art!");
} else {
await fs.promises.writeFile(this.coverPath, cover);
}
}
}
this.download.state = 3;
@ -355,7 +377,7 @@ class DownloadThread {
async tagTrack(path) {
let cover;
try {
cover = await this.downloadCover(this.track.albumArt.full);
cover = await this.downloadCover(this.track.albumArt.hash, 'cover', this.settings.coverResolution);
} catch (e) {}
//Genre tag
@ -392,7 +414,8 @@ class DownloadThread {
//Write
await fs.promises.writeFile(path, Buffer.from(writer.arrayBuffer));
return;
return cover;
}
//Tag FLAC
@ -496,7 +519,12 @@ class DownloadThread {
}
//Generate folders
if (this.settings.createArtistFolder) folder = path.join(folder, sanitize(this.track.artists[0].name));
if (this.settings.createAlbumFolder) folder = path.join(folder, sanitize(this.track.album.title));
if (this.settings.createAlbumFolder) {
folder = path.join(folder, sanitize(this.track.album.title));
if (this.settings.downloadCover) {
this.coverPath = path.join(folder, "cover.jpg");
}
}
//Extension
if (quality.toString() == '9') {

View File

@ -204,6 +204,15 @@ app.get('/profile', async (req, res) => {
res.send(profile);
});
//Get shuffled library
app.get('/shuffle', async (req, res) => {
let data = await deezer.callApi('tracklist.getShuffledCollection', {
nb: 50,
start: 0
});
res.send(data.results.data.map((t) => new Track(t)));
});
//Get list of `type` from library
app.get('/library/:type', async (req, res) => {
let type = req.params.type;

View File

@ -23,6 +23,8 @@ class Settings {
this.createArtistFolder = true;
this.downloadFilename = '%0trackNumber%. %artists% - %title%';
this.downloadDialog = true;
this.downloadCover = true;
this.coverResolution = 1400;
this.logListen = false;
this.lastFM = null;