Implemented spotify plugin on server

This commit is contained in:
RemixDev 2021-05-29 12:06:26 +02:00
parent fee34f2b2a
commit 731295a317
25 changed files with 353 additions and 28 deletions

19
server/dist/main.js vendored
View File

@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.restoreQueueFromDisk = exports.clearCompletedDownloads = exports.cancelAllDownloads = exports.cancelDownload = exports.startQueue = exports.addToQueue = exports.currentJob = exports.queue = exports.queueOrder = exports.saveSettings = exports.listener = exports.getArlFromAccessToken = exports.getAccessToken = exports.sessionDZ = exports.settings = exports.configFolder = exports.defaultSettings = void 0; exports.restoreQueueFromDisk = exports.clearCompletedDownloads = exports.cancelAllDownloads = exports.cancelDownload = exports.startQueue = exports.addToQueue = exports.currentJob = exports.queue = exports.queueOrder = exports.saveSettings = exports.getSettings = exports.listener = exports.plugins = exports.getArlFromAccessToken = exports.getAccessToken = exports.sessionDZ = exports.settings = exports.configFolder = exports.defaultSettings = void 0;
const fs_1 = __importDefault(require("fs")); const fs_1 = __importDefault(require("fs"));
const path_1 = require("path"); const path_1 = require("path");
const uuid_1 = require("uuid"); const uuid_1 = require("uuid");
@ -29,7 +29,10 @@ exports.settings = deemix_1.default.settings.load(exports.configFolder);
exports.sessionDZ = {}; exports.sessionDZ = {};
exports.getAccessToken = deemix_1.default.utils.deezer.getAccessToken; exports.getAccessToken = deemix_1.default.utils.deezer.getAccessToken;
exports.getArlFromAccessToken = deemix_1.default.utils.deezer.getArlFromAccessToken; exports.getArlFromAccessToken = deemix_1.default.utils.deezer.getArlFromAccessToken;
const deemixPlugins = {}; exports.plugins = {
spotify: new deemix_1.default.plugins.spotify()
};
exports.plugins.spotify.setup();
exports.listener = { exports.listener = {
send(key, data) { send(key, data) {
console.log(key, data); console.log(key, data);
@ -40,9 +43,14 @@ exports.listener = {
}); });
} }
}; };
function saveSettings(newSettings) { function getSettings() {
return { settings: exports.settings, defaultSettings: exports.defaultSettings, spotifySettings: exports.plugins.spotify.getCredentials() };
}
exports.getSettings = getSettings;
function saveSettings(newSettings, newSpotifySettings) {
deemix_1.default.settings.save(newSettings, exports.configFolder); deemix_1.default.settings.save(newSettings, exports.configFolder);
exports.settings = newSettings; exports.settings = newSettings;
exports.plugins.spotify.setCredentials(newSpotifySettings);
} }
exports.saveSettings = saveSettings; exports.saveSettings = saveSettings;
exports.queueOrder = []; exports.queueOrder = [];
@ -62,7 +70,7 @@ function addToQueue(dz, url, bitrate) {
for (let i = 0; i < url.length; i++) { for (let i = 0; i < url.length; i++) {
link = url[i]; link = url[i];
console.log(`Adding ${link} to queue`); console.log(`Adding ${link} to queue`);
let downloadObj = yield deemix_1.default.generateDownloadObject(dz, link, bitrate, deemixPlugins, exports.listener); let downloadObj = yield deemix_1.default.generateDownloadObject(dz, link, bitrate, exports.plugins, exports.listener);
if (Array.isArray(downloadObj)) { if (Array.isArray(downloadObj)) {
downloadObjs.concat(downloadObj); downloadObjs.concat(downloadObj);
} }
@ -122,7 +130,8 @@ function startQueue(dz) {
break; break;
case 'Convertable': case 'Convertable':
downloadObject = new Convertable(currentItem); downloadObject = new Convertable(currentItem);
// Convert object here downloadObject = yield exports.plugins[downloadObject.plugin].convert(dz, downloadObject, exports.settings, exports.listener);
fs_1.default.writeFileSync(exports.configFolder + `queue${path_1.sep}${downloadObject.uuid}.json`, JSON.stringify(Object.assign(Object.assign({}, downloadObject.toDict()), { status: 'inQueue' })));
break; break;
} }
exports.currentJob = new Downloader(dz, downloadObject, exports.settings, exports.listener); exports.currentJob = new Downloader(dz, downloadObject, exports.settings, exports.listener);

View File

@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/getSettings'; const path = '/getSettings';
const handler = (_, res) => { const handler = (_, res) => {
res.send({ settings: main_1.settings, defaultSettings: main_1.defaultSettings }); res.send(main_1.getSettings());
}; };
const apiHandler = { path, handler }; const apiHandler = { path, handler };
exports.default = apiHandler; exports.default = apiHandler;

View File

@ -26,6 +26,48 @@ const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
res.send(artistAPI); res.send(artistAPI);
break; break;
} }
case 'spotifyplaylist':
case 'spotify_playlist': {
if (!main_1.plugins.spotify.enabled) {
res.send({
collaborative: false,
description: "",
external_urls: { spotify: null },
followers: { total: 0, href: null },
id: null,
images: [],
name: "Something went wrong",
owner: {
display_name: "Error",
id: null
},
public: true,
tracks: [],
type: 'playlist',
uri: null
});
break;
}
let sp = main_1.plugins.spotify.sp;
let playlist = yield sp.getPlaylist(list_id);
playlist = playlist.body;
let tracklist = playlist.tracks.items;
while (playlist.tracks.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next);
let offset = regExec[1];
let limit = regExec[2];
let playlistTracks = yield sp.getPlaylistTracks(list_id, { offset, limit });
playlist.tracks = playlistTracks.body;
tracklist = tracklist.concat(playlist.tracks.items);
}
tracklist.forEach((item, i) => {
tracklist[i] = item.track;
tracklist[i].selected = false;
});
playlist.tracks = tracklist;
res.send(playlist);
break;
}
default: { default: {
const releaseAPI = yield dz.api[`get_${list_type}`](list_id); const releaseAPI = yield dz.api[`get_${list_type}`](list_id);
let releaseTracksAPI = yield dz.api[`get_${list_type}_tracks`](list_id); let releaseTracksAPI = yield dz.api[`get_${list_type}_tracks`](list_id);

View File

@ -1 +1,40 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main");
const path = '/getUserSpotifyPlaylists';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
let data;
if (main_1.plugins.spotify.enabled) {
let sp = main_1.plugins.spotify.sp;
const username = req.query.spotifyUser;
data = [];
let playlists = yield sp.getUserPlaylists(username);
let playlistList = playlists.body.items;
while (playlists.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next);
let offset = regExec[1];
let limit = regExec[2];
let newPlaylists = yield sp.getUserPlaylists(username, { offset, limit });
playlists = newPlaylists.body;
playlistList = playlistList.concat(playlists.items);
}
playlistList.forEach((playlist) => {
data.push(main_1.plugins.spotify._convertPlaylistStructure(playlist));
});
}
else {
data = { error: 'spotifyNotEnabled' };
}
res.send(data);
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -15,6 +15,7 @@ const getUserTracks_1 = __importDefault(require("./getUserTracks"));
const getUserAlbums_1 = __importDefault(require("./getUserAlbums")); const getUserAlbums_1 = __importDefault(require("./getUserAlbums"));
const getUserArtists_1 = __importDefault(require("./getUserArtists")); const getUserArtists_1 = __importDefault(require("./getUserArtists"));
const getUserPlaylists_1 = __importDefault(require("./getUserPlaylists")); const getUserPlaylists_1 = __importDefault(require("./getUserPlaylists"));
const getUserSpotifyPlaylists_1 = __importDefault(require("./getUserSpotifyPlaylists"));
const getUserFavorites_1 = __importDefault(require("./getUserFavorites")); const getUserFavorites_1 = __importDefault(require("./getUserFavorites"));
const getQueue_1 = __importDefault(require("./getQueue")); const getQueue_1 = __importDefault(require("./getQueue"));
exports.default = [ exports.default = [
@ -30,6 +31,7 @@ exports.default = [
getUserAlbums_1.default, getUserAlbums_1.default,
getUserArtists_1.default, getUserArtists_1.default,
getUserPlaylists_1.default, getUserPlaylists_1.default,
getUserSpotifyPlaylists_1.default,
getUserFavorites_1.default, getUserFavorites_1.default,
getQueue_1.default getQueue_1.default
]; ];

View File

@ -1 +1,19 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main");
const path = '/cancelAllDownloads';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
main_1.cancelAllDownloads();
res.send({ result: true });
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -6,4 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
const login_arl_1 = __importDefault(require("./login-arl")); const login_arl_1 = __importDefault(require("./login-arl"));
const addToQueue_1 = __importDefault(require("./addToQueue")); const addToQueue_1 = __importDefault(require("./addToQueue"));
const loginWithCredentials_1 = __importDefault(require("./loginWithCredentials")); const loginWithCredentials_1 = __importDefault(require("./loginWithCredentials"));
exports.default = [login_arl_1.default, addToQueue_1.default, loginWithCredentials_1.default]; const cancelAllDownloads_1 = __importDefault(require("./cancelAllDownloads"));
const removeFinishedDownloads_1 = __importDefault(require("./removeFinishedDownloads"));
const removeFromQueue_1 = __importDefault(require("./removeFromQueue"));
const logout_1 = __importDefault(require("./logout"));
const saveSettings_1 = __importDefault(require("./saveSettings"));
exports.default = [
login_arl_1.default,
addToQueue_1.default,
loginWithCredentials_1.default,
cancelAllDownloads_1.default,
removeFinishedDownloads_1.default,
removeFromQueue_1.default,
logout_1.default,
saveSettings_1.default
];

View File

@ -19,7 +19,7 @@ const LoginStatus = {
ALREADY_LOGGED: 2, ALREADY_LOGGED: 2,
FORCED_SUCCESS: 3 FORCED_SUCCESS: 3
}; };
const path = '/login-arl/'; const path = '/login-arl';
const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
if (!main_1.sessionDZ[req.session.id]) if (!main_1.sessionDZ[req.session.id])
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer(); main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();

View File

@ -12,15 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main"); const main_1 = require("../../../main");
const path = '/loginWithCredentials'; const path = '/loginWithCredentials';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () { const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { username, password } = req.body; const { email, password } = req.body;
let accessToken = req.body.accessToken; let accessToken = req.body.accessToken;
if (!accessToken) { if (!accessToken) {
const accessToken = yield main_1.getAccessToken(username, password); accessToken = yield main_1.getAccessToken(email, password);
console.log({ accessToken });
} }
let arl; let arl;
if (accessToken) if (accessToken)
arl = main_1.getArlFromAccessToken(accessToken); arl = yield main_1.getArlFromAccessToken(accessToken);
console.log({ accessToken, arl });
res.send({ accessToken, arl }); res.send({ accessToken, arl });
}); });
const apiHandler = { path, handler }; const apiHandler = { path, handler };

View File

@ -1 +1,21 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-expect-error
const deezer_js_1 = require("deezer-js");
const main_1 = require("../../../main");
const path = '/logout';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
main_1.sessionDZ[req.session.id] = new deezer_js_1.Deezer();
res.send({ logged_out: true });
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -1 +1,19 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main");
const path = '/removeFinishedDownloads';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
main_1.clearCompletedDownloads();
res.send({ result: true });
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -1 +1,25 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main");
const path = '/removeFromQueue';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { uuid } = req.query;
if (uuid) {
main_1.cancelDownload(uuid);
res.send({ result: true });
}
else {
res.send({ result: false });
}
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -0,0 +1,21 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const main_1 = require("../../../main");
const path = '/saveSettings';
const handler = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { settings, spotifySettings } = req.query;
main_1.saveSettings(settings, spotifySettings);
main_1.listener.send('updateSettings', { settings, spotifySettings });
res.send({ result: true });
});
const apiHandler = { path, handler };
exports.default = apiHandler;

View File

@ -5,7 +5,7 @@ const main_1 = require("../../main");
const eventName = 'saveSettings'; const eventName = 'saveSettings';
const cb = (data, _, __) => { const cb = (data, _, __) => {
const { settings, spotifySettings } = data; const { settings, spotifySettings } = data;
main_1.saveSettings(settings); main_1.saveSettings(settings, spotifySettings);
errors_1.consoleInfo('Settings saved'); errors_1.consoleInfo('Settings saved');
main_1.listener.send('updateSettings', { settings, spotifySettings }); main_1.listener.send('updateSettings', { settings, spotifySettings });
}; };

View File

@ -15,7 +15,7 @@
"dependencies": { "dependencies": {
"cookie-parser": "1.4.5", "cookie-parser": "1.4.5",
"debug": "2.6.9", "debug": "2.6.9",
"deemix": "0.0.9", "deemix": "0.0.10",
"deezer-js": "0.0.10", "deezer-js": "0.0.10",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"express": "4.17.1", "express": "4.17.1",

View File

@ -18,7 +18,10 @@ export const sessionDZ: any = {}
export const getAccessToken = deemix.utils.deezer.getAccessToken export const getAccessToken = deemix.utils.deezer.getAccessToken
export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken
const deemixPlugins = {} export const plugins: any = {
spotify: new deemix.plugins.spotify()
}
plugins.spotify.setup()
export const listener = { export const listener = {
send(key: string, data?: any) { send(key: string, data?: any) {
@ -31,9 +34,14 @@ export const listener = {
} }
} }
export function saveSettings(newSettings: any) { export function getSettings(): any {
return {settings, defaultSettings, spotifySettings: plugins.spotify.getCredentials()}
}
export function saveSettings(newSettings: any, newSpotifySettings: any) {
deemix.settings.save(newSettings, configFolder) deemix.settings.save(newSettings, configFolder)
settings = newSettings settings = newSettings
plugins.spotify.setCredentials(newSpotifySettings)
} }
export let queueOrder: string[] = [] export let queueOrder: string[] = []
@ -56,7 +64,7 @@ export async function addToQueue(dz: any, url: string[], bitrate: number) {
for (let i = 0; i < url.length; i++){ for (let i = 0; i < url.length; i++){
link = url[i] link = url[i]
console.log(`Adding ${link} to queue`) console.log(`Adding ${link} to queue`)
let downloadObj = await deemix.generateDownloadObject(dz, link, bitrate, deemixPlugins, listener) let downloadObj = await deemix.generateDownloadObject(dz, link, bitrate, plugins, listener)
if (Array.isArray(downloadObj)){ if (Array.isArray(downloadObj)){
downloadObjs.concat(downloadObj) downloadObjs.concat(downloadObj)
} else { } else {
@ -119,7 +127,8 @@ export async function startQueue(dz: any): Promise<any> {
break break
case 'Convertable': case 'Convertable':
downloadObject = new Convertable(currentItem) downloadObject = new Convertable(currentItem)
// Convert object here downloadObject = await plugins[downloadObject.plugin].convert(dz, downloadObject, settings, listener)
fs.writeFileSync(configFolder + `queue${sep}${downloadObject.uuid}.json`, JSON.stringify({...downloadObject.toDict(), status: 'inQueue'}))
break break
} }
currentJob = new Downloader(dz, downloadObject, settings, listener) currentJob = new Downloader(dz, downloadObject, settings, listener)

View File

@ -1,10 +1,10 @@
import { ApiHandler } from '../../../types' import { ApiHandler } from '../../../types'
import { settings, defaultSettings } from '../../../main' import { getSettings } from '../../../main'
const path: ApiHandler['path'] = '/getSettings' const path: ApiHandler['path'] = '/getSettings'
const handler: ApiHandler['handler'] = (_, res) => { const handler: ApiHandler['handler'] = (_, res) => {
res.send({ settings, defaultSettings }) res.send(getSettings())
} }
const apiHandler: ApiHandler = { path, handler } const apiHandler: ApiHandler = { path, handler }

View File

@ -1,7 +1,7 @@
// @ts-expect-error // @ts-expect-error
import { Deezer } from 'deezer-js' import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types' import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main' import { sessionDZ, plugins } from '../../../main'
const path: ApiHandler['path'] = '/getTracklist' const path: ApiHandler['path'] = '/getTracklist'
@ -18,6 +18,48 @@ const handler: ApiHandler['handler'] = async (req, res) => {
res.send(artistAPI) res.send(artistAPI)
break break
} }
case 'spotifyplaylist':
case 'spotify_playlist': {
if (!plugins.spotify.enabled){
res.send({
collaborative: false,
description: "",
external_urls: {spotify: null},
followers: {total: 0, href: null},
id: null,
images: [],
name: "Something went wrong",
owner: {
display_name: "Error",
id: null
},
public: true,
tracks : [],
type: 'playlist',
uri: null
})
break
}
let sp = plugins.spotify.sp
let playlist = await sp.getPlaylist(list_id)
playlist = playlist.body
let tracklist = playlist.tracks.items
while (playlist.tracks.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next)
let offset = regExec![1]
let limit = regExec![2]
let playlistTracks = await sp.getPlaylistTracks(list_id, { offset, limit })
playlist.tracks = playlistTracks.body
tracklist = tracklist.concat(playlist.tracks.items)
}
tracklist.forEach((item:any, i:number) => {
tracklist[i] = item.track
tracklist[i].selected = false
});
playlist.tracks = tracklist
res.send(playlist)
break
}
default: { default: {
const releaseAPI = await dz.api[`get_${list_type}`](list_id) const releaseAPI = await dz.api[`get_${list_type}`](list_id)
let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id) let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id)

View File

@ -0,0 +1,34 @@
import { ApiHandler } from '../../../types'
import { plugins } from '../../../main'
const path: ApiHandler['path'] = '/getUserSpotifyPlaylists'
const handler: ApiHandler['handler'] = async (req, res) => {
let data
if (plugins.spotify.enabled){
let sp = plugins.spotify.sp
const username = req.query.spotifyUser
data = []
let playlists = await sp.getUserPlaylists(username)
let playlistList = playlists.body.items
while (playlists.next) {
let regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next)
let offset = regExec![1]
let limit = regExec![2]
let newPlaylists = await sp.getUserPlaylists(username, { offset, limit })
playlists = newPlaylists.body
playlistList = playlistList.concat(playlists.items)
}
playlistList.forEach((playlist: any) => {
data.push(plugins.spotify._convertPlaylistStructure(playlist))
})
} else {
data = { error: 'spotifyNotEnabled'}
}
res.send(data)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@ -10,6 +10,7 @@ import getUserTracks from './getUserTracks'
import getUserAlbums from './getUserAlbums' import getUserAlbums from './getUserAlbums'
import getUserArtists from './getUserArtists' import getUserArtists from './getUserArtists'
import getUserPlaylists from './getUserPlaylists' import getUserPlaylists from './getUserPlaylists'
import getUserSpotifyPlaylists from './getUserSpotifyPlaylists'
import getUserFavorites from './getUserFavorites' import getUserFavorites from './getUserFavorites'
import getQueue from './getQueue' import getQueue from './getQueue'
@ -26,6 +27,7 @@ export default [
getUserAlbums, getUserAlbums,
getUserArtists, getUserArtists,
getUserPlaylists, getUserPlaylists,
getUserSpotifyPlaylists,
getUserFavorites, getUserFavorites,
getQueue getQueue
] ]

View File

@ -5,6 +5,7 @@ import cancelAllDownloads from './cancelAllDownloads'
import removeFinishedDownloads from './removeFinishedDownloads' import removeFinishedDownloads from './removeFinishedDownloads'
import removeFromQueue from './removeFromQueue' import removeFromQueue from './removeFromQueue'
import logout from './logout' import logout from './logout'
import saveSettings from './saveSettings'
export default [ export default [
loginArl, loginArl,
@ -13,5 +14,6 @@ export default [
cancelAllDownloads, cancelAllDownloads,
removeFinishedDownloads, removeFinishedDownloads,
removeFromQueue, removeFromQueue,
logout logout,
saveSettings
] ]

View File

@ -0,0 +1,21 @@
import { ApiHandler } from '../../../types'
import { saveSettings, listener } from '../../../main'
import { Settings, SpotifySettings } from '../../../types'
const path = '/saveSettings'
export interface SaveSettingsData {
settings: Settings
spotifySettings: SpotifySettings
}
const handler: ApiHandler['handler'] = async (req, res) => {
const { settings, spotifySettings }: SaveSettingsData = req.query
saveSettings(settings, spotifySettings)
listener.send('updateSettings', { settings, spotifySettings })
res.send({ result: true })
}
const apiHandler = { path, handler }
export default apiHandler

View File

@ -12,7 +12,7 @@ export interface SaveSettingsData {
const cb = (data: SaveSettingsData, _: any, __: WsServer) => { const cb = (data: SaveSettingsData, _: any, __: WsServer) => {
const { settings, spotifySettings } = data const { settings, spotifySettings } = data
saveSettings(settings) saveSettings(settings, spotifySettings)
consoleInfo('Settings saved') consoleInfo('Settings saved')
listener.send('updateSettings', { settings, spotifySettings }) listener.send('updateSettings', { settings, spotifySettings })
} }

View File

@ -1883,10 +1883,10 @@ decompress-response@^6.0.0:
dependencies: dependencies:
mimic-response "^3.1.0" mimic-response "^3.1.0"
deemix@0.0.7: deemix@0.0.10:
version "0.0.7" version "0.0.10"
resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.0.7.tgz#64ac4caa435d8dd373469c219e2557350afd4a03" resolved "https://registry.yarnpkg.com/deemix/-/deemix-0.0.10.tgz#630244c7b454b684337a807437b14a20a605e0ff"
integrity sha512-iCi4MCnMoh2PSGvUteS8XISx62i/Y4qoE2plEm083z3tGEqU9VhEW6clUnHwpAyfCeCamRdbAzMUq9V4RxaVoA== integrity sha512-dNGoJY3h8naxhtTNLH7d93wCTnk7yln6oMeseTcUOiizJvT0CfX8g2xN1BAnozlk0wzs948b6VOeCPbeOAhglA==
dependencies: dependencies:
async "^3.2.0" async "^3.2.0"
browser-id3-writer "^4.4.0" browser-id3-writer "^4.4.0"
@ -1894,6 +1894,7 @@ deemix@0.0.7:
deezer-js "^0.0.8" deezer-js "^0.0.8"
got "^11.8.2" got "^11.8.2"
metaflac-js2 "^1.0.7" metaflac-js2 "^1.0.7"
spotify-web-api-node "^5.0.2"
deep-extend@^0.6.0: deep-extend@^0.6.0:
version "0.6.0" version "0.6.0"
@ -5576,6 +5577,13 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies: dependencies:
extend-shallow "^3.0.0" extend-shallow "^3.0.0"
spotify-web-api-node@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/spotify-web-api-node/-/spotify-web-api-node-5.0.2.tgz#683669b3ccc046a5a357300f151df93a2b3539fe"
integrity sha512-r82dRWU9PMimHvHEzL0DwEJrzFk+SMCVfq249SLt3I7EFez7R+jeoKQd+M1//QcnjqlXPs2am4DFsGk8/GCsrA==
dependencies:
superagent "^6.1.0"
sprintf-js@~1.0.2: sprintf-js@~1.0.2:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"

2
webui

@ -1 +1 @@
Subproject commit 8479bf328cd399ed751ada61a2f5a2a9526f3930 Subproject commit bd22aef8cc1c00d8446f5d3a518e5552acba133d