1.1.6 UI fixes, electron public api call
This commit is contained in:
@ -144,7 +144,42 @@ class DeezerAPI {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Wrapper because electron is piece of shit
|
||||
async callPublicApi(path, params) {
|
||||
if (this.electron) return await this._callPublicApiElectron(path, params);
|
||||
return await this._callPublicApiAxios(path, params);
|
||||
}
|
||||
|
||||
async _callPublicApiElectron(path, params) {
|
||||
const net = require('electron').net;
|
||||
let data = await new Promise((resolve, reject) => {
|
||||
//Create request
|
||||
let req = net.request({
|
||||
method: 'GET',
|
||||
url: `https://api.deezer.com/${encodeURIComponent(path)}/${encodeURIComponent(params)}`
|
||||
});
|
||||
|
||||
req.on('response', (res) => {
|
||||
let data = Buffer.alloc(0);
|
||||
//Response data
|
||||
res.on('data', (buffer) => {
|
||||
data = Buffer.concat([data, buffer]);
|
||||
});
|
||||
res.on('end', () => {
|
||||
resolve(data);
|
||||
})
|
||||
});
|
||||
req.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
req.end();
|
||||
});
|
||||
|
||||
data = JSON.parse(data.toString('utf-8'));
|
||||
return data;
|
||||
}
|
||||
|
||||
async _callPublicApiAxios(path, params) {
|
||||
let res = await axios({
|
||||
url: `https://api.deezer.com/${encodeURIComponent(path)}/${encodeURIComponent(params)}`,
|
||||
responseType: 'json',
|
||||
@ -212,7 +247,7 @@ class DeezerAPI {
|
||||
return this.fallback(newTrack.streamUrl);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn('TrackID Fallback failed: ' + e);
|
||||
logger.warn('TrackID Fallback failed: ' + e + ' Original ID: ' + qualityInfo.trackId);
|
||||
}
|
||||
//ISRC Fallback
|
||||
try {
|
||||
@ -222,7 +257,7 @@ class DeezerAPI {
|
||||
let newTrack = new Track(newTrackData.results.DATA);
|
||||
return this.fallback(newTrack.streamUrl);
|
||||
} catch (e) {
|
||||
logger.warn('ISRC Fallback failed: ' + e);
|
||||
logger.warn('ISRC Fallback failed: ' + e + ' Original ID: ' + qualityInfo.trackId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ const sanitize = require('sanitize-filename');
|
||||
const ID3Writer = require('browser-id3-writer');
|
||||
const Metaflac = require('metaflac-js2');
|
||||
const { Track, Lyrics } = require('./definitions');
|
||||
const { throwDeprecation } = require('process');
|
||||
|
||||
let deezer;
|
||||
|
||||
@ -220,15 +221,23 @@ class DownloadThread {
|
||||
this.qualityInfo = await deezer.fallback(this.download.track.streamUrl, this.download.quality);
|
||||
if (!this.qualityInfo) {
|
||||
this.download.state = -1;
|
||||
this._cb();
|
||||
return;
|
||||
}
|
||||
|
||||
//Get track info
|
||||
if (!this.isUserUploaded) {
|
||||
this.rawTrack = await deezer.callApi('deezer.pageTrack', {'sng_id': this.download.track.id});
|
||||
this.track = new Track(this.rawTrack.results.DATA);
|
||||
this.publicTrack = await deezer.callPublicApi('track', this.track.id);
|
||||
this.publicAlbum = await deezer.callPublicApi('album', this.track.album.id);
|
||||
try {
|
||||
this.rawTrack = await deezer.callApi('deezer.pageTrack', {'sng_id': this.qualityInfo.trackId});
|
||||
this.track = new Track(this.rawTrack.results.DATA);
|
||||
this.publicTrack = await deezer.callPublicApi('track', this.track.id);
|
||||
this.publicAlbum = await deezer.callPublicApi('album', this.track.album.id);
|
||||
} catch (e) {
|
||||
logger.error(`Error fetching metadata for ID: ${this.qualityInfo.trackId}, Error: ${e}`);
|
||||
this.download.state = -1;
|
||||
this._cb();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Check if exists
|
||||
|
@ -38,6 +38,8 @@ class Settings {
|
||||
this.crossfadeDuration = 3000;
|
||||
this.lightTheme = false;
|
||||
this.playlistFolder = false;
|
||||
|
||||
this.forceWhiteTrayIcon = false;
|
||||
}
|
||||
|
||||
//Based on electorn app.getPath
|
||||
|
Reference in New Issue
Block a user