├── .yarnrc ├── server ├── src │ ├── websocket │ │ ├── modules │ │ │ ├── logout.ts │ │ │ ├── analyzeLink.ts │ │ │ ├── changeAccount.ts │ │ │ ├── queueRestored.ts │ │ │ ├── index.ts │ │ │ ├── cancelAllDownloads.ts │ │ │ ├── removeFromQueue.ts │ │ │ ├── removeFinishedDownloads.ts │ │ │ └── saveSettings.ts │ │ └── index.ts │ ├── helpers │ │ ├── primitive-checks.ts │ │ ├── paths.ts │ │ ├── port.ts │ │ ├── errors.ts │ │ └── server-callbacks.ts │ ├── routes │ │ ├── api │ │ │ ├── delete │ │ │ │ └── index.ts │ │ │ ├── patch │ │ │ │ └── index.ts │ │ │ ├── get │ │ │ │ ├── getSettings.ts │ │ │ │ ├── spotifyStatus.ts │ │ │ │ ├── getQueue.ts │ │ │ │ ├── checkForUpdates.ts │ │ │ │ ├── getHome.ts │ │ │ │ ├── getUserAlbums.ts │ │ │ │ ├── getUserArtists.ts │ │ │ │ ├── getUserTracks.ts │ │ │ │ ├── getUserPlaylists.ts │ │ │ │ ├── getCharts.ts │ │ │ │ ├── getUserFavorites.ts │ │ │ │ ├── analyzeLink.spec.ts │ │ │ │ ├── getUserSpotifyPlaylists.ts │ │ │ │ ├── index.ts │ │ │ │ ├── getChartTracks.ts │ │ │ │ ├── search.ts │ │ │ │ ├── analyzeLink.ts │ │ │ │ ├── albumSearch.spec.ts │ │ │ │ ├── albumSearch.ts │ │ │ │ ├── newReleases.ts │ │ │ │ ├── mainSearch.ts │ │ │ │ └── getTracklist.ts │ │ │ ├── post │ │ │ │ ├── cancelAllDownloads.ts │ │ │ │ ├── removeFinishedDownloads.ts │ │ │ │ ├── logout.ts │ │ │ │ ├── removeFromQueue.ts │ │ │ │ ├── changeAccount.spec.ts │ │ │ │ ├── index.ts │ │ │ │ ├── saveSettings.ts │ │ │ │ ├── loginEmail.ts │ │ │ │ ├── changeAccount.ts │ │ │ │ ├── addToQueue.ts │ │ │ │ ├── loginArl.spec.ts │ │ │ │ └── loginArl.ts │ │ │ └── register.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── middlewares.ts │ ├── app.ts │ ├── types.ts │ └── main.ts ├── .eslintignore ├── .prettierrc.yml ├── jest.config.js ├── .eslintrc.yml ├── tests │ ├── utils.ts │ └── cookie-parser.spec.ts ├── webpack.config.js ├── .gitignore ├── package.json ├── tsconfig.json └── dist │ └── app.js.LICENSE.txt ├── .gitmodules ├── scripts ├── reset-version.js ├── set-version.js └── gen-version.js ├── preload.js ├── .gitignore ├── README.md ├── package.json ├── index.js ├── .gitattributes └── LICENSE.txt /.yarnrc: -------------------------------------------------------------------------------- 1 | save-prefix: "" 2 | -------------------------------------------------------------------------------- /server/src/websocket/modules/logout.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /server/.eslintignore: -------------------------------------------------------------------------------- 1 | bin/www 2 | dist/ 3 | -------------------------------------------------------------------------------- /server/src/websocket/modules/analyzeLink.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /server/src/websocket/modules/changeAccount.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /server/src/websocket/modules/queueRestored.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "webui"] 2 | path = webui 3 | url = ../deemix-webui 4 | -------------------------------------------------------------------------------- /server/src/helpers/primitive-checks.ts: -------------------------------------------------------------------------------- 1 | export const isObjectEmpy = (obj: any) => Object.keys(obj).length === 0 2 | -------------------------------------------------------------------------------- /server/src/routes/api/delete/index.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | 3 | export default [] as ApiHandler[] 4 | -------------------------------------------------------------------------------- /server/src/routes/api/patch/index.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | 3 | export default [] as ApiHandler[] 4 | -------------------------------------------------------------------------------- /server/.prettierrc.yml: -------------------------------------------------------------------------------- 1 | tabWidth: 2 2 | printWidth: 120 3 | useTabs: true 4 | semi: false 5 | singleQuote: true 6 | bracketSpacing: true 7 | arrowParens: avoid 8 | trailingComma: none 9 | -------------------------------------------------------------------------------- /server/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | clearMocks: true, 3 | roots: ['/src', '/tests'], 4 | testEnvironment: 'node', 5 | preset: 'ts-jest', 6 | setupFiles: ['dotenv/config'] 7 | } 8 | -------------------------------------------------------------------------------- /server/src/helpers/paths.ts: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | 3 | export const ROOT_DIR = path.resolve(path.join(__dirname, '..', '..')) 4 | export const WEBUI_DIR = path.join(ROOT_DIR, 'webui', 'public') 5 | export const GUI_PACKAGE = path.join(ROOT_DIR, 'package.json') 6 | -------------------------------------------------------------------------------- /scripts/reset-version.js: -------------------------------------------------------------------------------- 1 | const { execSync } = require('child_process') 2 | const fs = require('fs') 3 | 4 | let package = JSON.parse(fs.readFileSync('package.json')) 5 | package.version = "0.0.0" 6 | fs.writeFileSync('package.json', JSON.stringify(package, null, 2)+"\n") 7 | -------------------------------------------------------------------------------- /scripts/set-version.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const generateVersion = require('./gen-version.js') 3 | 4 | let package = JSON.parse(fs.readFileSync('package.json')) 5 | package.version = generateVersion() 6 | fs.writeFileSync('package.json', JSON.stringify(package, null, 2)+"\n") 7 | -------------------------------------------------------------------------------- /server/src/websocket/modules/index.ts: -------------------------------------------------------------------------------- 1 | import saveSettings from './saveSettings' 2 | import removeFinishedDownloads from './removeFinishedDownloads' 3 | import removeFromQueue from './removeFromQueue' 4 | import cancelAllDownloads from './cancelAllDownloads' 5 | 6 | export default [saveSettings, removeFinishedDownloads, removeFromQueue, cancelAllDownloads] 7 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getSettings.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { getSettings } from '../../../main' 3 | 4 | const path: ApiHandler['path'] = '/getSettings' 5 | 6 | const handler: ApiHandler['handler'] = (_, res) => { 7 | res.send(getSettings()) 8 | } 9 | 10 | const apiHandler: ApiHandler = { path, handler } 11 | 12 | export default apiHandler 13 | -------------------------------------------------------------------------------- /server/.eslintrc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: 3 | - "@nuxtjs" 4 | - plugin:prettier/recommended 5 | plugins: 6 | - "@typescript-eslint" 7 | parserOptions: 8 | parser: "@typescript-eslint/parser" 9 | rules: 10 | "@typescript-eslint/no-unused-vars": 11 | - error 12 | - args: all 13 | argsIgnorePattern: ^_ 14 | no-unused-vars: off 15 | no-console: off 16 | camelcase: off 17 | -------------------------------------------------------------------------------- /server/src/routes/api/post/cancelAllDownloads.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { cancelAllDownloads } from '../../../main' 3 | 4 | const path = '/cancelAllDownloads' 5 | 6 | const handler: ApiHandler['handler'] = (_, res) => { 7 | cancelAllDownloads() 8 | res.send({ result: true }) 9 | } 10 | 11 | const apiHandler = { path, handler } 12 | 13 | export default apiHandler 14 | -------------------------------------------------------------------------------- /server/src/routes/api/get/spotifyStatus.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { plugins } from '../../../main' 3 | 4 | const path: ApiHandler['path'] = '/spotifyStatus' 5 | 6 | const handler: ApiHandler['handler'] = (_, res) => { 7 | res.send({ spotifyEnabled: plugins.spotify.enabled }) 8 | } 9 | 10 | const apiHandler: ApiHandler = { path, handler } 11 | 12 | export default apiHandler 13 | -------------------------------------------------------------------------------- /server/src/websocket/modules/cancelAllDownloads.ts: -------------------------------------------------------------------------------- 1 | import { Server as WsServer } from 'ws' 2 | import { consoleInfo } from '../../helpers/errors' 3 | import { cancelAllDownloads } from '../../main' 4 | 5 | const eventName = 'cancelAllDownloads' 6 | 7 | const cb = (_: any, __: any, ___: WsServer) => { 8 | cancelAllDownloads() 9 | consoleInfo(`Queue cleared`) 10 | } 11 | 12 | export default { eventName, cb } 13 | -------------------------------------------------------------------------------- /server/src/websocket/modules/removeFromQueue.ts: -------------------------------------------------------------------------------- 1 | import { Server as WsServer } from 'ws' 2 | import { consoleInfo } from '../../helpers/errors' 3 | import { cancelDownload } from '../../main' 4 | 5 | const eventName = 'removeFromQueue' 6 | 7 | const cb = (data: any, __: any, ___: WsServer) => { 8 | cancelDownload(data) 9 | consoleInfo(`Cancelled ${data}`) 10 | } 11 | 12 | export default { eventName, cb } 13 | -------------------------------------------------------------------------------- /server/src/routes/api/post/removeFinishedDownloads.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { clearCompletedDownloads } from '../../../main' 3 | 4 | const path = '/removeFinishedDownloads' 5 | 6 | const handler: ApiHandler['handler'] = (_, res) => { 7 | clearCompletedDownloads() 8 | res.send({ result: true }) 9 | } 10 | 11 | const apiHandler = { path, handler } 12 | 13 | export default apiHandler 14 | -------------------------------------------------------------------------------- /server/tests/utils.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express' 2 | import request from 'supertest' 3 | import { app } from '../src/app' 4 | 5 | export const sendGet = (app: Application) => (uri: string) => request(app).get(uri).send() 6 | export const sendPost = (app: Application) => (uri: string) => request(app).post(uri).send() 7 | 8 | export const appSendGet = sendGet(app) 9 | export const appSendPost = sendPost(app) 10 | -------------------------------------------------------------------------------- /server/src/websocket/modules/removeFinishedDownloads.ts: -------------------------------------------------------------------------------- 1 | import { Server as WsServer } from 'ws' 2 | import { consoleInfo } from '../../helpers/errors' 3 | import { clearCompletedDownloads } from '../../main' 4 | 5 | const eventName = 'removeFinishedDownloads' 6 | 7 | const cb = (_: any, __: any, ___: WsServer) => { 8 | clearCompletedDownloads() 9 | consoleInfo('Completed downloads cleared') 10 | } 11 | 12 | export default { eventName, cb } 13 | -------------------------------------------------------------------------------- /server/src/helpers/port.ts: -------------------------------------------------------------------------------- 1 | import { Port } from '../types' 2 | 3 | /** 4 | * Normalize a port into a number, string, or false. 5 | * 6 | * @since 0.0.0 7 | */ 8 | export function normalizePort(portString: string): Port { 9 | const port = parseInt(portString, 10) 10 | 11 | if (isNaN(port)) { 12 | // named pipe 13 | return portString 14 | } 15 | 16 | if (port >= 0) { 17 | // port number 18 | return port 19 | } 20 | 21 | return false 22 | } 23 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getQueue.ts: -------------------------------------------------------------------------------- 1 | // import { Deezer } from 'deezer-js' 2 | import { ApiHandler } from '../../../types' 3 | import { getQueue } from '../../../main' 4 | 5 | const path: ApiHandler['path'] = '/getQueue' 6 | 7 | // let homeCache: any 8 | 9 | const handler: ApiHandler['handler'] = (_, res) => { 10 | const result: any = getQueue() 11 | res.send(result) 12 | } 13 | 14 | const apiHandler: ApiHandler = { path, handler } 15 | 16 | export default apiHandler 17 | -------------------------------------------------------------------------------- /server/src/routes/api/post/logout.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/logout' 7 | 8 | const handler: ApiHandler['handler'] = (req, res) => { 9 | sessionDZ[req.session.id] = new Deezer() 10 | res.send({ logged_out: true }) 11 | } 12 | 13 | const apiHandler: ApiHandler = { path, handler } 14 | 15 | export default apiHandler 16 | -------------------------------------------------------------------------------- /server/src/routes/api/post/removeFromQueue.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { cancelDownload } from '../../../main' 3 | 4 | const path = '/removeFromQueue' 5 | 6 | const handler: ApiHandler['handler'] = (req, res) => { 7 | const { uuid } = req.query 8 | if (uuid) { 9 | cancelDownload(uuid) 10 | res.send({ result: true }) 11 | } else { 12 | res.send({ result: false }) 13 | } 14 | } 15 | 16 | const apiHandler = { path, handler } 17 | 18 | export default apiHandler 19 | -------------------------------------------------------------------------------- /server/src/routes/api/get/checkForUpdates.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { getLatestVersion, isUpdateAvailable } from '../../../main' 3 | 4 | const path: ApiHandler['path'] = '/checkForUpdates' 5 | 6 | const handler: ApiHandler['handler'] = async (_, res) => { 7 | const latestCommit = await getLatestVersion() 8 | res.send({ 9 | latestCommit, 10 | updateAvailable: isUpdateAvailable() 11 | }) 12 | } 13 | 14 | const apiHandler: ApiHandler = { path, handler } 15 | 16 | export default apiHandler 17 | -------------------------------------------------------------------------------- /server/src/routes/api/post/changeAccount.spec.ts: -------------------------------------------------------------------------------- 1 | import { appSendGet } from '../../../../tests/utils' 2 | 3 | describe('analyzeLink requests', () => { 4 | it('should respond 200 to calls with supported child number', async () => { 5 | const res = await appSendGet('/api/changeAccount/?child=1') 6 | 7 | expect(res.status).toBe(200) 8 | }) 9 | 10 | it('should respond 400 to calls with not supported child number', async () => { 11 | const res = await appSendGet('/api/changeAccount/') 12 | 13 | expect(res.status).toBe(400) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /scripts/gen-version.js: -------------------------------------------------------------------------------- 1 | const { execSync } = require('child_process') 2 | function generateVersion(){ 3 | const now = new Date(); 4 | const year = now.getFullYear(); 5 | const month = now.getMonth()+1; 6 | const day = now.getDate(); 7 | 8 | const commitsNumber = String(execSync('git rev-list --count HEAD')).trim() 9 | const commitHash = String(execSync('git rev-parse --short=10 HEAD')).trim() 10 | 11 | return `${year}.${month}.${day}-r${commitsNumber}.${commitHash}` 12 | } 13 | 14 | console.log(generateVersion()) 15 | 16 | module.exports = generateVersion 17 | -------------------------------------------------------------------------------- /server/src/routes/api/post/index.ts: -------------------------------------------------------------------------------- 1 | import changeAccount from './changeAccount' 2 | import loginArl from './loginArl' 3 | import addToQueue from './addToQueue' 4 | import loginEmail from './loginEmail' 5 | import cancelAllDownloads from './cancelAllDownloads' 6 | import removeFinishedDownloads from './removeFinishedDownloads' 7 | import removeFromQueue from './removeFromQueue' 8 | import logout from './logout' 9 | import saveSettings from './saveSettings' 10 | 11 | export default [ 12 | changeAccount, 13 | loginArl, 14 | addToQueue, 15 | loginEmail, 16 | cancelAllDownloads, 17 | removeFinishedDownloads, 18 | removeFromQueue, 19 | logout, 20 | saveSettings 21 | ] 22 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getHome.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getHome' 7 | 8 | let homeCache: any 9 | 10 | const handler: ApiHandler['handler'] = async (req, res) => { 11 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 12 | const dz = sessionDZ[req.session.id] 13 | 14 | if (!homeCache) { 15 | homeCache = await dz.api.get_chart(0, { limit: 30 }) 16 | } 17 | res.send(homeCache) 18 | } 19 | 20 | const apiHandler: ApiHandler = { path, handler } 21 | 22 | export default apiHandler 23 | -------------------------------------------------------------------------------- /server/src/routes/api/post/saveSettings.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler, Settings, SpotifySettings } from '../../../types' 2 | import { saveSettings, listener } from '../../../main' 3 | 4 | const path = '/saveSettings' 5 | 6 | export interface SaveSettingsData { 7 | settings: Settings 8 | spotifySettings: SpotifySettings 9 | } 10 | 11 | const handler: ApiHandler['handler'] = (req, res) => { 12 | const { settings, spotifySettings }: SaveSettingsData = req.query 13 | saveSettings(settings, spotifySettings) 14 | listener.send('updateSettings', { settings, spotifySettings }) 15 | res.send({ result: true }) 16 | } 17 | 18 | const apiHandler = { path, handler } 19 | 20 | export default apiHandler 21 | -------------------------------------------------------------------------------- /server/src/routes/api/post/loginEmail.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { getAccessToken, getArlFromAccessToken } from '../../../main' 3 | 4 | const path = '/loginEmail' 5 | 6 | const handler: ApiHandler['handler'] = async (req, res) => { 7 | const { email, password } = req.body 8 | let accessToken = req.body.accessToken 9 | 10 | if (!accessToken) { 11 | accessToken = await getAccessToken(email, password) 12 | if (accessToken === 'undefined') accessToken = undefined 13 | } 14 | let arl 15 | if (accessToken) arl = await getArlFromAccessToken(accessToken) 16 | 17 | res.send({ accessToken, arl }) 18 | } 19 | 20 | const apiHandler = { path, handler } 21 | 22 | export default apiHandler 23 | -------------------------------------------------------------------------------- /server/src/websocket/modules/saveSettings.ts: -------------------------------------------------------------------------------- 1 | import { Server as WsServer } from 'ws' 2 | import { consoleInfo } from '../../helpers/errors' 3 | import { saveSettings, listener } from '../../main' 4 | import { Settings, SpotifySettings } from '../../types' 5 | 6 | const eventName = 'saveSettings' 7 | 8 | export interface SaveSettingsData { 9 | settings: Settings 10 | spotifySettings: SpotifySettings 11 | } 12 | 13 | const cb = (data: SaveSettingsData, _: any, __: WsServer) => { 14 | const { settings, spotifySettings } = data 15 | saveSettings(settings, spotifySettings) 16 | consoleInfo('Settings saved') 17 | listener.send('updateSettings', { settings, spotifySettings }) 18 | } 19 | 20 | export default { eventName, cb } 21 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getUserAlbums.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getUserAlbums' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | let data 12 | 13 | if (dz.logged_in) { 14 | const userID = dz.current_user.id 15 | data = await dz.gw.get_user_albums(userID, { limit: -1 }) 16 | } else { 17 | data = { error: 'notLoggedIn' } 18 | } 19 | res.send(data) 20 | } 21 | 22 | const apiHandler: ApiHandler = { path, handler } 23 | 24 | export default apiHandler 25 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getUserArtists.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getUserArtists' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | let data 12 | 13 | if (dz.logged_in) { 14 | const userID = dz.current_user.id 15 | data = await dz.gw.get_user_artists(userID, { limit: -1 }) 16 | } else { 17 | data = { error: 'notLoggedIn' } 18 | } 19 | res.send(data) 20 | } 21 | 22 | const apiHandler: ApiHandler = { path, handler } 23 | 24 | export default apiHandler 25 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getUserTracks.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getUserTracks' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | let data 12 | 13 | if (dz.logged_in) { 14 | const userID = dz.current_user.id 15 | data = await dz.gw.get_user_tracks(userID, { limit: -1 }) 16 | } else { 17 | data = { error: 'notLoggedIn' } 18 | } 19 | res.send(data) 20 | } 21 | 22 | const apiHandler: ApiHandler = { path, handler } 23 | 24 | export default apiHandler 25 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getUserPlaylists.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getUserPlaylists' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | let data 12 | 13 | if (dz.logged_in) { 14 | const userID = dz.current_user.id 15 | data = await dz.gw.get_user_playlists(userID, { limit: -1 }) 16 | } else { 17 | data = { error: 'notLoggedIn' } 18 | } 19 | res.send(data) 20 | } 21 | 22 | const apiHandler: ApiHandler = { path, handler } 23 | 24 | export default apiHandler 25 | -------------------------------------------------------------------------------- /server/tests/cookie-parser.spec.ts: -------------------------------------------------------------------------------- 1 | // Taken from https://github.com/visionmedia/supertest 2 | 3 | import request from 'supertest' 4 | import express from 'express' 5 | import cookieParser from 'cookie-parser' 6 | 7 | describe('cookie parser', () => { 8 | const app = express() 9 | app.use(cookieParser()) 10 | 11 | app.get('/', (_, res) => { 12 | res.cookie('cookie', 'hey') 13 | res.send() 14 | }) 15 | 16 | app.get('/return', (req, res) => { 17 | if (req.cookies.cookie) res.send(req.cookies.cookie) 18 | else res.send(':(') 19 | }) 20 | 21 | const agent = request.agent(app) 22 | 23 | it('should save cookies', done => { 24 | agent.get('/').expect('set-cookie', 'cookie=hey; Path=/', done) 25 | }) 26 | 27 | it('should send cookies', done => { 28 | agent.get('/return').expect('hey', done) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /server/src/websocket/index.ts: -------------------------------------------------------------------------------- 1 | import { Server as WsServer } from 'ws' 2 | 3 | import { consoleError, consoleInfo } from '../helpers/errors' 4 | import wsModules from './modules' 5 | 6 | // ? Is this needed? 7 | // ? https://github.com/websockets/ws#how-to-detect-and-close-broken-connections 8 | 9 | export const registerWebsocket = (wss: WsServer) => { 10 | wss.on('connection', ws => { 11 | ws.on('message', message => { 12 | const data = JSON.parse(message.toString()) 13 | 14 | wsModules.forEach(module => { 15 | if (data.key === module.eventName) { 16 | module.cb(data.data, ws, wss) 17 | } 18 | }) 19 | }) 20 | }) 21 | 22 | wss.on('error', () => { 23 | consoleError('An error occurred to the WebSocket server.') 24 | }) 25 | 26 | wss.on('close', () => { 27 | consoleInfo('Connection to the WebSocket server closed.') 28 | }) 29 | } 30 | -------------------------------------------------------------------------------- /preload.js: -------------------------------------------------------------------------------- 1 | const { 2 | contextBridge, 3 | ipcRenderer 4 | } = require("electron"); 5 | 6 | // Expose protected methods that allow the renderer process to use 7 | // the ipcRenderer without exposing the entire object 8 | contextBridge.exposeInMainWorld( 9 | "api", { 10 | send: (channel, data) => { 11 | // whitelist channels 12 | let validChannels = ["openDownloadsFolder", "applogin", "selectDownloadFolder"]; 13 | if (validChannels.includes(channel)) { 14 | ipcRenderer.send(channel, data); 15 | } 16 | }, 17 | receive: (channel, func) => { 18 | let validChannels = ["downloadFolderSelected", "applogin_arl"]; 19 | if (validChannels.includes(channel)) { 20 | // Deliberately strip event as it includes `sender` 21 | ipcRenderer.on(channel, (event, ...args) => func(...args)); 22 | } 23 | } 24 | } 25 | ); 26 | -------------------------------------------------------------------------------- /server/src/routes/api/post/changeAccount.ts: -------------------------------------------------------------------------------- 1 | import { RequestHandler } from 'express' 2 | // @ts-expect-error 3 | import { Deezer } from 'deezer-js' 4 | 5 | import { ApiHandler } from '../../../types' 6 | import { sessionDZ } from '../../../main' 7 | 8 | const path: ApiHandler['path'] = '/changeAccount' 9 | 10 | interface ChangeAccountQuery { 11 | child: number 12 | } 13 | 14 | const handler: RequestHandler<{}, {}, {}, ChangeAccountQuery> = (req, res) => { 15 | if (!req.query || !req.query.child) { 16 | return res.status(400).send({ errorMessage: 'No child specified', errorCode: 'CA01' }) 17 | } 18 | 19 | const { child: accountNum } = req.query 20 | 21 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 22 | const dz = sessionDZ[req.session.id] 23 | 24 | const accountData = dz.change_account(accountNum) 25 | 26 | return res.status(200).send(accountData) 27 | } 28 | 29 | const apiHandler: ApiHandler = { path, handler } 30 | 31 | export default apiHandler 32 | -------------------------------------------------------------------------------- /server/src/middlewares.ts: -------------------------------------------------------------------------------- 1 | import type { Application } from 'express' 2 | import express from 'express' 3 | import logger from 'morgan' 4 | import cookieParser from 'cookie-parser' 5 | import session from 'express-session' 6 | 7 | import { WEBUI_DIR } from './helpers/paths' 8 | 9 | const MemoryStore = require('memorystore')(session) 10 | 11 | declare module 'express-session' { 12 | export interface SessionData { 13 | dz: any 14 | } 15 | } 16 | 17 | export function registerMiddlewares(app: Application) { 18 | app.use(express.json()) 19 | app.use(express.urlencoded({ extended: false })) 20 | app.use(cookieParser()) 21 | app.use( 22 | session({ 23 | store: new MemoryStore({ 24 | checkPeriod: 86400000 // prune expired entries every 24h 25 | }), 26 | secret: 'U2hoLCBpdHMgYSBzZWNyZXQh', 27 | resave: true, 28 | saveUninitialized: true 29 | }) 30 | ) 31 | app.use(express.static(WEBUI_DIR)) 32 | 33 | if (process.env.NODE_ENV === 'development') { 34 | app.use(logger('dev')) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getCharts.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getCharts' 7 | 8 | let chartsCache: any 9 | 10 | const handler: ApiHandler['handler'] = async (req, res) => { 11 | if (!chartsCache) { 12 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 13 | const dz = sessionDZ[req.session.id] 14 | 15 | const chartsData = await dz.api.get_countries_charts() 16 | const countries: any[] = [] 17 | chartsData.forEach((country: any) => { 18 | countries.push({ 19 | title: country.title.replace('Top ', ''), 20 | id: country.id, 21 | picture_small: country.picture_small, 22 | picture_medium: country.picture_medium, 23 | picture_big: country.picture_big 24 | }) 25 | }) 26 | chartsCache = { data: countries } 27 | } 28 | res.send(chartsCache) 29 | } 30 | 31 | const apiHandler: ApiHandler = { path, handler } 32 | 33 | export default apiHandler 34 | -------------------------------------------------------------------------------- /server/src/routes/index.spec.ts: -------------------------------------------------------------------------------- 1 | import request from 'supertest' 2 | import { app } from '../app' 3 | 4 | describe('root path requests', () => { 5 | it('responds 200 to the GET method', async () => { 6 | const result = await request(app).get('/').send() 7 | 8 | expect(result.status).toBe(200) 9 | }) 10 | 11 | it('responds 404 to the POST method', async () => { 12 | const result = await request(app).post('/').send() 13 | 14 | expect(result.status).toBe(404) 15 | }) 16 | 17 | it('responds 404 to the PATCH method', async () => { 18 | const result = await request(app).patch('/').send() 19 | 20 | expect(result.status).toBe(404) 21 | }) 22 | 23 | it('responds 404 to the DELETE method', async () => { 24 | const result = await request(app).delete('/').send() 25 | 26 | expect(result.status).toBe(404) 27 | }) 28 | 29 | it('redirects to root when a non existing server route is requested', async () => { 30 | const result = await request(app).get('/settings').send() 31 | 32 | expect(result.header.location).toBe('/') 33 | expect(result.status).toBe(302) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getUserFavorites.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getUserFavorites' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | 12 | let result: any = {} 13 | 14 | if (dz.logged_in) { 15 | const userID = dz.current_user.id 16 | 17 | result.playlists = await dz.gw.get_user_playlists(userID, { limit: -1 }) 18 | result.albums = await dz.gw.get_user_albums(userID, { limit: -1 }) 19 | result.artists = await dz.gw.get_user_artists(userID, { limit: -1 }) 20 | result.tracks = await dz.gw.get_user_tracks(userID, { limit: -1 }) 21 | result.lovedTracks = `https://deezer.com/playlist/${dz.current_user.loved_tracks}` 22 | } else { 23 | result = { error: 'notLoggedIn' } 24 | } 25 | res.send(result) 26 | } 27 | 28 | const apiHandler: ApiHandler = { path, handler } 29 | 30 | export default apiHandler 31 | -------------------------------------------------------------------------------- /server/src/routes/api/register.ts: -------------------------------------------------------------------------------- 1 | import type { Application } from 'express' 2 | import type { ApiHandler } from '../../types' 3 | import getEndpoints from './get' 4 | import deleteEndpoints from './delete' 5 | import postEndpoints from './post' 6 | import patchEndpoints from './patch' 7 | 8 | const prependApiPath = (path: string) => `/api${path}` 9 | 10 | interface Method { 11 | method: string 12 | endpoints: ApiHandler[] 13 | } 14 | 15 | const methods: Method[] = [ 16 | { 17 | method: 'get', 18 | endpoints: getEndpoints 19 | }, 20 | { 21 | method: 'delete', 22 | endpoints: deleteEndpoints 23 | }, 24 | { 25 | method: 'post', 26 | endpoints: postEndpoints 27 | }, 28 | { 29 | method: 'patch', 30 | endpoints: patchEndpoints 31 | } 32 | ] 33 | 34 | export function registerApis(app: Application) { 35 | methods.forEach(({ method, endpoints }) => { 36 | endpoints.forEach(endpoint => { 37 | // @ts-expect-error 38 | app[method](prependApiPath(endpoint.path), endpoint.handler) 39 | }) 40 | }) 41 | 42 | // Fallback, for SPA mode 43 | app.get('*', (_, res) => { 44 | res.redirect('/') 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /server/src/helpers/errors.ts: -------------------------------------------------------------------------------- 1 | import { concat } from 'ramda' 2 | 3 | const prependDeemix = concat('[deemix-server]: ') 4 | 5 | export const consoleInfo = (infoText: string) => console.info(prependDeemix(infoText)) 6 | export const consoleError = (errorText: string) => console.error(prependDeemix(errorText)) 7 | 8 | export class BadRequestError extends Error { 9 | constructor() { 10 | super() 11 | this.message = 'Bad request!' 12 | } 13 | } 14 | 15 | export const isBadRequestError = (error: any) => error instanceof BadRequestError 16 | 17 | export class QueueError extends Error { 18 | constructor(message: string) { 19 | super(message) 20 | this.name = 'QueueError' 21 | } 22 | } 23 | 24 | export class AlreadyInQueue extends QueueError { 25 | item: any 26 | silent: boolean 27 | constructor(dwObj: any, silent: boolean) { 28 | super(`${dwObj.artist} - ${dwObj.title} is already in queue.`) 29 | this.name = 'AlreadyInQueue' 30 | this.item = dwObj 31 | this.silent = silent 32 | } 33 | } 34 | 35 | export class NotLoggedIn extends QueueError { 36 | constructor() { 37 | super(`You must be logged in to start a download.`) 38 | this.name = 'NotLoggedIn' 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const webpack = require('webpack') 3 | const NodemonPlugin = require('nodemon-webpack-plugin') 4 | 5 | module.exports = env => { 6 | const isProduction = !!env.production 7 | const config = { 8 | mode: isProduction ? 'production' : 'development', 9 | entry: './src/app.ts', 10 | devtool: isProduction ? false : 'eval', 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.tsx?$/, 15 | use: 'ts-loader', 16 | exclude: /node_modules/ 17 | } 18 | ] 19 | }, 20 | resolve: { 21 | extensions: ['.tsx', '.ts', '.js'] 22 | }, 23 | output: { 24 | path: path.resolve(__dirname, 'dist'), 25 | filename: 'app.js', 26 | sourceMapFilename: '[file].map', 27 | library: { 28 | name: 'DeemixServer', 29 | type: 'umd' 30 | } 31 | }, 32 | target: 'node', 33 | plugins: [ 34 | new NodemonPlugin(), 35 | new webpack.DefinePlugin({ 'global.GENTLY': false }), 36 | new webpack.ContextReplacementPlugin(/[/\\](express|keyv)[/\\]/, data => { 37 | delete data.dependencies[0].critical 38 | return data 39 | }), 40 | new webpack.ContextReplacementPlugin(/yargs/) 41 | ] 42 | } 43 | 44 | return config 45 | } 46 | -------------------------------------------------------------------------------- /server/src/routes/api/get/analyzeLink.spec.ts: -------------------------------------------------------------------------------- 1 | import { appSendGet } from '../../../../tests/utils' 2 | 3 | describe('analyzeLink requests', () => { 4 | it('should respond 200 to calls with supported term', async () => { 5 | const res = await appSendGet('/api/analyzeLink/?term=https://www.deezer.com/en/album/100896762') 6 | 7 | expect(res.status).toBe(200) 8 | }) 9 | 10 | it('should respond with an error to calls with not supported term', async () => { 11 | const res = await appSendGet('/api/analyzeLink/?term=https://www.deezer.com/en/artist/15166511') 12 | 13 | expect(res.status).toBe(400) 14 | expect(res.body.errorMessage).toBe('Not supported') 15 | }) 16 | 17 | it('should respond album analyzed data', async () => { 18 | const res = await appSendGet('/api/analyzeLink/?term=https://www.deezer.com/en/album/100896762') 19 | 20 | expect(res.body.type).toBe('album') 21 | expect(res.body.artist.name).toBe('Lil Nas X') 22 | }) 23 | 24 | it('should respond track analyzed data', async () => { 25 | const res = await appSendGet('/api/analyzeLink/?term=https://www.deezer.com/en/track/1283264142') 26 | 27 | expect(res.body.type).toBe('track') 28 | expect(res.body.artist.name).toBe('Lil Nas X') 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getUserSpotifyPlaylists.ts: -------------------------------------------------------------------------------- 1 | import { ApiHandler } from '../../../types' 2 | import { plugins } from '../../../main' 3 | 4 | const path: ApiHandler['path'] = '/getUserSpotifyPlaylists' 5 | 6 | const handler: ApiHandler['handler'] = async (req, res) => { 7 | let data 8 | 9 | if (plugins.spotify.enabled) { 10 | const sp = plugins.spotify.sp 11 | const username = req.query.spotifyUser 12 | data = [] 13 | let playlists = await sp.getUserPlaylists(username) 14 | playlists = playlists.body 15 | let playlistList = playlists.items 16 | while (playlists.next) { 17 | const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlists.next) 18 | const offset = regExec![1] 19 | const limit = regExec![2] 20 | const newPlaylists = await sp.getUserPlaylists(username, { offset, limit }) 21 | playlists = newPlaylists.body 22 | playlistList = playlistList.concat(playlists.items) 23 | } 24 | playlistList.forEach((playlist: any) => { 25 | data.push(plugins.spotify._convertPlaylistStructure(playlist)) 26 | }) 27 | } else { 28 | data = { error: 'spotifyNotEnabled' } 29 | } 30 | res.send(data) 31 | } 32 | 33 | const apiHandler: ApiHandler = { path, handler } 34 | 35 | export default apiHandler 36 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # IDE 64 | .vscode 65 | .idea 66 | -------------------------------------------------------------------------------- /server/src/routes/api/post/addToQueue.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ, addToQueue, getSettings, listener } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/addToQueue' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | 12 | const url = req.body.url.split(/[\s;]+/) 13 | let bitrate = req.body.bitrate 14 | if (bitrate === 'null' || bitrate === null) bitrate = getSettings().settings.maxBitrate 15 | let obj: any 16 | 17 | try { 18 | obj = await addToQueue(dz, url, bitrate) 19 | } catch (e) { 20 | switch (e.name) { 21 | case 'NotLoggedIn': 22 | res.send({ result: false, errid: e.name, data: { url, bitrate } }) 23 | listener.send('loginNeededToDownload') 24 | break 25 | default: 26 | console.error(e) 27 | res.send({ result: false, errid: e.name, data: { url, bitrate } }) 28 | break 29 | } 30 | return 31 | } 32 | 33 | res.send({ result: true, data: { url, bitrate, obj } }) 34 | } 35 | 36 | const apiHandler: ApiHandler = { path, handler } 37 | 38 | export default apiHandler 39 | -------------------------------------------------------------------------------- /server/src/routes/index.ts: -------------------------------------------------------------------------------- 1 | import express from 'express' 2 | // @ts-expect-error 3 | import { Deezer } from 'deezer-js' 4 | import { consoleInfo } from '../helpers/errors' 5 | import { sessionDZ, getQueue, deemixVersion, currentVersion, isDeezerAvailable, plugins, getSettings } from '../main' 6 | 7 | const router = express.Router() 8 | let update: any = null 9 | 10 | router.get('/connect', async (req, res) => { 11 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 12 | const dz = sessionDZ[req.session.id] 13 | 14 | if (!update) { 15 | consoleInfo(`Currently running deemix-gui version ${currentVersion}`) 16 | consoleInfo(`deemix-lib version ${deemixVersion}`) 17 | update = { 18 | currentCommit: currentVersion, 19 | deemixVersion 20 | } 21 | } 22 | 23 | const result: any = { 24 | update, 25 | autologin: !dz.logged_in, 26 | currentUser: dz.current_user, 27 | deezerAvailable: await isDeezerAvailable(), 28 | spotifyEnabled: plugins.spotify.enabled, 29 | settingsData: getSettings() 30 | } 31 | 32 | if (result.settingsData.settings.autoCheckForUpdates) result.checkForUpdates = true 33 | 34 | const queue = getQueue() 35 | 36 | if (Object.keys(queue.queue).length > 0) { 37 | result.queue = queue 38 | } 39 | 40 | res.send(result) 41 | }) 42 | 43 | export default router 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # IDE 64 | .vscode 65 | .idea 66 | 67 | # development 68 | *.map 69 | dev.sh 70 | 71 | # distribution 72 | dist/* 73 | server-dist/* 74 | -------------------------------------------------------------------------------- /server/src/routes/api/get/index.ts: -------------------------------------------------------------------------------- 1 | import analyzeLink from './analyzeLink' 2 | import getHome from './getHome' 3 | import getCharts from './getCharts' 4 | import mainSearch from './mainSearch' 5 | import search from './search' 6 | import newReleases from './newReleases' 7 | import getTracklist from './getTracklist' 8 | import { apiHandler as albumSearch } from './albumSearch' 9 | import getChartTracks from './getChartTracks' 10 | import getSettings from './getSettings' 11 | import getUserTracks from './getUserTracks' 12 | import getUserAlbums from './getUserAlbums' 13 | import getUserArtists from './getUserArtists' 14 | import getUserPlaylists from './getUserPlaylists' 15 | import getUserSpotifyPlaylists from './getUserSpotifyPlaylists' 16 | import getUserFavorites from './getUserFavorites' 17 | import getQueue from './getQueue' 18 | import spotifyStatus from './spotifyStatus' 19 | import checkForUpdates from './checkForUpdates' 20 | 21 | export default [ 22 | albumSearch, 23 | analyzeLink, 24 | getHome, 25 | getCharts, 26 | getChartTracks, 27 | mainSearch, 28 | search, 29 | newReleases, 30 | getTracklist, 31 | getSettings, 32 | getUserTracks, 33 | getUserAlbums, 34 | getUserArtists, 35 | getUserPlaylists, 36 | getUserSpotifyPlaylists, 37 | getUserFavorites, 38 | getQueue, 39 | spotifyStatus, 40 | checkForUpdates 41 | ] 42 | -------------------------------------------------------------------------------- /server/src/helpers/server-callbacks.ts: -------------------------------------------------------------------------------- 1 | import http from 'http' 2 | import type { Debugger } from 'debug' 3 | import { consoleInfo } from './errors' 4 | 5 | /** 6 | * Event listener for HTTP server "error" event. 7 | * 8 | * @since 0.0.0 9 | */ 10 | export function getErrorCb(port: number | string | boolean) { 11 | return (error: any) => { 12 | if (error.syscall !== 'listen') { 13 | throw error 14 | } 15 | 16 | const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port 17 | 18 | // handle specific listen errors with friendly messages 19 | switch (error.code) { 20 | case 'EACCES': { 21 | console.error(bind + ' requires elevated privileges') 22 | process.exit(1) 23 | } 24 | case 'EADDRINUSE': { 25 | console.error(bind + ' is already in use') 26 | process.exit(1) 27 | } 28 | default: 29 | throw error 30 | } 31 | } 32 | } 33 | 34 | /** 35 | * Event listener for HTTP server "listening" event. 36 | * 37 | * @since 0.0.0 38 | */ 39 | export function getListeningCb(server: http.Server, debug: Debugger) { 40 | return () => { 41 | const addr = server.address() 42 | 43 | if (addr) { 44 | const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port 45 | 46 | debug(`Listening on ${bind}`) 47 | consoleInfo(`Listening on ${bind}`) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getChartTracks.ts: -------------------------------------------------------------------------------- 1 | import { RequestHandler } from 'express' 2 | // @ts-expect-error 3 | import { Deezer } from 'deezer-js' 4 | import { ApiHandler } from '../../../types' 5 | import { sessionDZ } from '../../../main' 6 | 7 | import { isObjectEmpy } from '../../../helpers/primitive-checks' 8 | import { BadRequestError, isBadRequestError, consoleError } from '../../../helpers/errors' 9 | 10 | export interface RawChartTracksQuery { 11 | id: string 12 | index?: number 13 | limit?: number 14 | } 15 | 16 | const path: ApiHandler['path'] = '/getChartTracks' 17 | 18 | const handler: RequestHandler<{}, {}, {}, RawChartTracksQuery> = async (req, res, next) => { 19 | try { 20 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 21 | const dz = sessionDZ[req.session.id] 22 | 23 | if (isObjectEmpy(req.query) || !req.query.id) { 24 | throw new BadRequestError() 25 | } 26 | 27 | const playlistId = req.query.id 28 | const index = req.query.index 29 | const limit = req.query.limit 30 | 31 | const response = await dz.api.get_playlist_tracks(playlistId, { index, limit }) 32 | return res.status(200).send(response) 33 | } catch (error) { 34 | if (isBadRequestError(error)) { 35 | consoleError(error.message) 36 | res.status(400).send() 37 | return next() 38 | } 39 | } 40 | } 41 | 42 | const apiHandler: ApiHandler = { path, handler } 43 | 44 | export default apiHandler 45 | -------------------------------------------------------------------------------- /server/src/routes/api/get/search.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/search' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | 12 | const term = String(req.query.term) 13 | const type = String(req.query.type) 14 | const start = parseInt(String(req.query.start)) 15 | const nb = parseInt(String(req.query.nb)) 16 | 17 | let data 18 | 19 | switch (type) { 20 | case 'track': 21 | data = await dz.api.search_track(term, { limit: nb, index: start }) 22 | break 23 | case 'album': 24 | data = await dz.api.search_album(term, { limit: nb, index: start }) 25 | break 26 | case 'artist': 27 | data = await dz.api.search_artist(term, { limit: nb, index: start }) 28 | break 29 | case 'playlist': 30 | data = await dz.api.search_playlist(term, { limit: nb, index: start }) 31 | break 32 | case 'radio': 33 | data = await dz.api.search_radio(term, { limit: nb, index: start }) 34 | break 35 | case 'user': 36 | data = await dz.api.search_user(term, { limit: nb, index: start }) 37 | break 38 | default: 39 | data = await dz.api.search(term, { limit: nb, index: start }) 40 | break 41 | } 42 | 43 | data.type = type 44 | res.send(data) 45 | } 46 | 47 | const apiHandler: ApiHandler = { path, handler } 48 | 49 | export default apiHandler 50 | -------------------------------------------------------------------------------- /server/src/routes/api/post/loginArl.spec.ts: -------------------------------------------------------------------------------- 1 | import { appSendPost } from '../../../../tests/utils' 2 | 3 | describe('loginArl requests', () => { 4 | it('should respond 200 to calls with arl', async () => { 5 | const responseStatusCollector: number[] = [] 6 | const batchCalls = ['/api/loginArl/?arl=abcdef1234'] 7 | 8 | for (const uri of batchCalls) { 9 | responseStatusCollector.push((await appSendPost(uri)).status) 10 | } 11 | 12 | expect(responseStatusCollector).toMatchObject(new Array(batchCalls.length).fill(200)) 13 | expect(responseStatusCollector).toMatchObject(new Array(responseStatusCollector.length).fill(200)) 14 | }) 15 | 16 | it('should respond 400 to calls without arl', async () => { 17 | const responseStatusCollector: number[] = [] 18 | const batchCalls = ['/api/loginArl/', '/api/loginArl/?dummy=test', '/api/loginArl/?email=aaa@aa.com'] 19 | 20 | for (const uri of batchCalls) { 21 | responseStatusCollector.push((await appSendPost(uri)).status) 22 | } 23 | 24 | expect(responseStatusCollector).toMatchObject(new Array(responseStatusCollector.length).fill(400)) 25 | }) 26 | 27 | it('should login using ARL', async () => { 28 | const response = await appSendPost(`/api/loginArl/?arl=${process.env.DEEZER_ARL}`) 29 | 30 | expect(response.status).toBe(200) 31 | expect(response.body.status).toBe(true) 32 | }) 33 | 34 | it('should not login using wrong ARL', async () => { 35 | const response = await appSendPost(`/api/loginArl/?arl=abcdef1234`) 36 | 37 | expect(response.status).toBe(200) 38 | expect(response.body.status).toBe(false) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /server/src/routes/api/get/analyzeLink.ts: -------------------------------------------------------------------------------- 1 | import type { RequestHandler } from 'express' 2 | // @ts-expect-error 3 | import deemix from 'deemix' 4 | // @ts-expect-error 5 | import { Deezer } from 'deezer-js' 6 | 7 | import type { ApiHandler, GetTrackResponse, GetAlbumResponse } from '../../../types' 8 | import { sessionDZ } from '../../../main' 9 | 10 | export interface AnalyzeQuery { 11 | term?: string 12 | } 13 | 14 | type ResBody = GetAlbumResponse | GetTrackResponse 15 | 16 | const path: ApiHandler['path'] = '/analyzeLink' 17 | 18 | const handler: RequestHandler = async (req, res) => { 19 | try { 20 | if (!req.query || !req.query.term) { 21 | return res.status(400).send({ errorMessage: 'No term specified', errorCode: 'AL01' }) 22 | } 23 | 24 | const { term: linkToAnalyze } = req.query 25 | const [, linkType, linkId] = await deemix.parseLink(linkToAnalyze) 26 | const isTrackOrAlbum = ['track', 'album'].includes(linkType) 27 | 28 | if (isTrackOrAlbum) { 29 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 30 | const dz = sessionDZ[req.session.id] 31 | const apiMethod = linkType === 'track' ? 'get_track' : 'get_album' 32 | const resBody: ResBody = await dz.api[apiMethod](linkId) 33 | 34 | return res.status(200).send(resBody) 35 | } 36 | 37 | return res.status(400).send({ errorMessage: 'Not supported', errorCode: 'AL02' }) 38 | } catch (error) { 39 | return res 40 | .status(500) 41 | .send({ errorMessage: 'The server had a problem. Please try again', errorObject: error, errorCode: 'AL03' }) 42 | } 43 | } 44 | 45 | const apiHandler: ApiHandler = { path, handler } 46 | 47 | export default apiHandler 48 | -------------------------------------------------------------------------------- /server/src/routes/api/get/albumSearch.spec.ts: -------------------------------------------------------------------------------- 1 | import { appSendGet } from '../../../../tests/utils' 2 | 3 | describe('albumSearch requests', () => { 4 | it('should respond 200 to calls with term', async () => { 5 | const responseStatusCollector: number[] = [] 6 | const batchCalls = [ 7 | '/api/album-search/?term=eminem', 8 | '/api/album-search/?term=eminem?start=10', 9 | '/api/album-search/?term=eminem?ack=aa', 10 | '/api/album-search/?term=eminem?ack=aa?start=10', 11 | '/api/album-search/?term=eminem?ack=aa?start=10?nb=34' 12 | ] 13 | 14 | for (const uri of batchCalls) { 15 | responseStatusCollector.push((await appSendGet(uri)).status) 16 | } 17 | 18 | expect(responseStatusCollector).toMatchObject(new Array(batchCalls.length).fill(200)) 19 | expect(responseStatusCollector).toMatchObject(new Array(responseStatusCollector.length).fill(200)) 20 | }) 21 | 22 | it('should respond 400 to calls without term', async () => { 23 | const responseStatusCollector: number[] = [] 24 | const batchCalls = [ 25 | '/api/album-search/', 26 | '/api/album-search/?start=10', 27 | '/api/album-search/?ack=aa', 28 | '/api/album-search/?ack=aa?start=10', 29 | '/api/album-search/?ack=aa?start=10?nb=34' 30 | ] 31 | 32 | for (const uri of batchCalls) { 33 | responseStatusCollector.push((await appSendGet(uri)).status) 34 | } 35 | 36 | expect(responseStatusCollector).toMatchObject(new Array(responseStatusCollector.length).fill(400)) 37 | }) 38 | 39 | it('should respond the desired search result', async () => { 40 | const res = (await appSendGet('/api/album-search/?term=eminem')).body 41 | 42 | expect(res.data.data.length).not.toBe(0) 43 | }) 44 | 45 | // TODO Understand whic should be the correct response 46 | it.skip('should respond the desired search result with a start parameter', async () => { 47 | const res = (await appSendGet('/api/album-search/?term=eminem?start=10')).body 48 | 49 | expect(res.data.data.length).not.toBe(0) 50 | }) 51 | }) 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deemix-gui 2 | An electron app that wraps deemix-webui and lets you use the deemix-js library 3 | 4 | ## Downloads 5 | Downloads are available [here](https://www.reddit.com/r/deemix/comments/hmrhhs/download_links/) 6 | 7 | ## Running from source 8 | You need to use nodejs 16.x, using `yarn` is recommended. 9 | 10 | If you're using git to get this repo you should use `git submodule update --init --recursive` as well. If you're just downloading the archive.zip, make sure you download and extract deemix-webui into the webui folder. 11 | 12 | Install the dependencies using `yarn install` or just `yarn`. 13 | Then you should be able to run the app with `yarn start`. 14 | 15 | You can change the default port by setting the environment variable `PORT` to any other number before starting the app. 16 | 17 | ## Building the app 18 | To build the app you need to have git installed and the repo cloned with `git`. 19 | Make sure you've installed the dependencies for all packages (the root folder, `server` and `webui`). 20 | You can install them with `yarn install-all`. 21 | Then from the root folder run `yarn dist` to make a distributable package for your current OS or `yarn dist-server` 22 | to make an executable for only the server. 23 | 24 | ## Feature requests 25 | Before asking for a feature make sure it isn't an already open issue on the repo 26 | 27 | # License 28 | This program is free software: you can redistribute it and/or modify 29 | it under the terms of the GNU General Public License as published by 30 | the Free Software Foundation, either version 3 of the License, or 31 | (at your option) any later version. 32 | 33 | This program is distributed in the hope that it will be useful, 34 | but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | GNU General Public License for more details. 37 | 38 | You should have received a copy of the GNU General Public License 39 | along with this program. If not, see . 40 | -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@deemix-gui/deemix-server", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "webpack --watch", 7 | "start-build": "node dist/app.js", 8 | "lint": "eslint \"./{src, tests}/**\" --fix", 9 | "lint-build": "eslint \"./src/**\" --fix", 10 | "prebuild": "yarn lint-build", 11 | "build": "webpack --env production", 12 | "test": "jest", 13 | "test-watch": "jest --watch" 14 | }, 15 | "bin": "./dist/app.js", 16 | "pkg": { 17 | "scripts": "./dist/**/*.js", 18 | "assets": [ 19 | "../webui/public/**/*", 20 | "../package.json" 21 | ], 22 | "targets": [ 23 | "node16-linux-x64", 24 | "node16-win-x64", 25 | "node16-macos-x64" 26 | ] 27 | }, 28 | "dependencies": { 29 | "bufferutil": "4.0.3", 30 | "cookie-parser": "1.4.5", 31 | "debug": "2.6.9", 32 | "deemix": "^3.6.0", 33 | "deezer-js": "^1.3.0", 34 | "dotenv": "8.2.0", 35 | "express": "4.17.1", 36 | "express-session": "^1.17.1", 37 | "memorystore": "1.6.6", 38 | "morgan": "1.10.0", 39 | "ramda": "0.27.1", 40 | "utf-8-validate": "5.0.5", 41 | "uuid": "8.3.2", 42 | "ws": "7.4.5", 43 | "yargs": "17.0.1" 44 | }, 45 | "devDependencies": { 46 | "@nuxtjs/eslint-config": "6.0.0", 47 | "@types/cookie-parser": "1.4.2", 48 | "@types/debug": "4.1.5", 49 | "@types/express": "4.17.11", 50 | "@types/express-session": "^1.17.3", 51 | "@types/jest": "26.0.22", 52 | "@types/morgan": "1.9.2", 53 | "@types/node": "14.14.37", 54 | "@types/ramda": "0.27.40", 55 | "@types/supertest": "2.0.11", 56 | "@types/uuid": "8.3.0", 57 | "@types/ws": "7.4.1", 58 | "@types/yargs": "17.0.0", 59 | "@typescript-eslint/eslint-plugin": "4.21.0", 60 | "@typescript-eslint/parser": "4.21.0", 61 | "eslint": "7.23.0", 62 | "eslint-config-prettier": "8.1.0", 63 | "eslint-plugin-prettier": "3.3.1", 64 | "jest": "26.6.3", 65 | "nodemon": "2.0.7", 66 | "nodemon-webpack-plugin": "4.5.2", 67 | "prettier": "2.2.1", 68 | "supertest": "6.1.3", 69 | "ts-jest": "26.5.4", 70 | "ts-loader": "9.2.3", 71 | "ts-node": "9.1.1", 72 | "ts-node-dev": "1.1.6", 73 | "typescript": "4.2.4", 74 | "webpack": "5.41.1", 75 | "webpack-cli": "4.7.2" 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /server/src/app.ts: -------------------------------------------------------------------------------- 1 | import http from 'http' 2 | import express, { Application } from 'express' 3 | import { Server as WsServer } from 'ws' 4 | import yargs from 'yargs' 5 | import initDebug from 'debug' 6 | import { hideBin } from 'yargs/helpers' 7 | 8 | import { registerMiddlewares } from './middlewares' 9 | 10 | import indexRouter from './routes' 11 | 12 | import { normalizePort } from './helpers/port' 13 | import { getErrorCb, getListeningCb } from './helpers/server-callbacks' 14 | import { registerApis } from './routes/api/register' 15 | import { registerWebsocket } from './websocket' 16 | import type { Arguments } from './types' 17 | import { consoleInfo } from './helpers/errors' 18 | 19 | export { getSettings } from './main' 20 | 21 | // TODO: Remove type assertion while keeping correct types 22 | const argv = yargs(hideBin(process.argv)).options({ 23 | port: { type: 'string', default: '6595' }, 24 | host: { type: 'string', default: '127.0.0.1' } 25 | }).argv as Arguments 26 | 27 | const DEEMIX_SERVER_PORT = normalizePort(process.env.DEEMIX_SERVER_PORT ?? argv.port) 28 | const DEEMIX_HOST = process.env.DEEMIX_HOST ?? argv.host 29 | 30 | const debug = initDebug('deemix-gui:server') 31 | export const wss = new WsServer({ noServer: true }) 32 | const app: Application = express() 33 | const server = http.createServer(app) 34 | 35 | /* === Middlewares === */ 36 | registerMiddlewares(app) 37 | 38 | /* === Routes === */ 39 | app.use('/', indexRouter) 40 | 41 | /* === APIs === */ 42 | registerApis(app) 43 | 44 | /* === Config === */ 45 | app.set('port', DEEMIX_SERVER_PORT) 46 | 47 | /* === Server port === */ 48 | if (process.env.NODE_ENV !== 'test') { 49 | server.listen({ port: DEEMIX_SERVER_PORT, host: DEEMIX_HOST }) 50 | } 51 | 52 | registerWebsocket(wss) 53 | 54 | /* === Server callbacks === */ 55 | app.on('mount', a => { 56 | console.log(a) 57 | }) 58 | server.on('connect', () => { 59 | consoleInfo('Server connected') 60 | }) 61 | server.on('upgrade', (request, socket, head) => { 62 | wss.handleUpgrade(request, socket, head, socket => { 63 | wss.emit('connection', socket, request) 64 | }) 65 | }) 66 | server.on('error', getErrorCb(DEEMIX_SERVER_PORT)) 67 | server.on('listening', getListeningCb(server, debug)) 68 | -------------------------------------------------------------------------------- /server/src/routes/api/post/loginArl.ts: -------------------------------------------------------------------------------- 1 | import { RequestHandler } from 'express' 2 | // @ts-expect-error 3 | import { Deezer } from 'deezer-js' 4 | import { sessionDZ, startQueue, isDeezerAvailable } from '../../../main' 5 | import { ApiHandler } from '../../../types' 6 | 7 | export interface RawLoginArlBody { 8 | arl: string 9 | child?: number 10 | } 11 | 12 | const LoginStatus = { 13 | NOT_AVAILABLE: -1, 14 | FAILED: 0, 15 | SUCCESS: 1, 16 | ALREADY_LOGGED: 2, 17 | FORCED_SUCCESS: 3 18 | } 19 | 20 | const path: ApiHandler['path'] = '/loginArl' 21 | 22 | const handler: RequestHandler<{}, {}, RawLoginArlBody, {}> = async (req, res, _) => { 23 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 24 | const dz = sessionDZ[req.session.id] 25 | 26 | if (!req.body) { 27 | return res.status(400).send() 28 | } 29 | 30 | if (!req.body.arl) { 31 | return res.status(400).send() 32 | } 33 | 34 | const loginParams: (string | number)[] = [req.body.arl] 35 | 36 | // TODO Handle the child === 0 case, don't want to rely on the login_via_arl default param (it may change in the 37 | // future) 38 | if (req.body.child) { 39 | loginParams.push(req.body.child) 40 | } 41 | 42 | let response 43 | 44 | if (process.env.NODE_ENV !== 'test') { 45 | if (!dz.logged_in) { 46 | try { 47 | response = await dz.login_via_arl(...loginParams) 48 | } catch (e) { 49 | console.trace(e) 50 | response = false 51 | } 52 | response = response ? 1 : 0 53 | } else { 54 | response = LoginStatus.ALREADY_LOGGED 55 | } 56 | } else { 57 | const testDz = new Deezer() 58 | response = await testDz.login_via_arl(...loginParams) 59 | } 60 | if (response === LoginStatus.FAILED) sessionDZ[req.session.id] = new Deezer() 61 | if (!(await isDeezerAvailable())) response = LoginStatus.NOT_AVAILABLE 62 | const returnValue = { 63 | status: response, 64 | arl: req.body.arl, 65 | user: dz.current_user, 66 | childs: dz.childs, 67 | currentChild: dz.selected_account 68 | } 69 | 70 | if (response !== LoginStatus.NOT_AVAILABLE && response !== LoginStatus.FAILED) startQueue(dz) 71 | return res.status(200).send(returnValue) 72 | } 73 | 74 | const apiHandler = { path, handler } 75 | 76 | export default apiHandler 77 | -------------------------------------------------------------------------------- /server/src/routes/api/get/albumSearch.ts: -------------------------------------------------------------------------------- 1 | import type { RequestHandler } from 'express' 2 | // @ts-expect-error 3 | import { Deezer } from 'deezer-js' 4 | 5 | import type { ApiHandler } from '../../../types' 6 | import { sessionDZ } from '../../../main' 7 | 8 | export interface RawAlbumQuery { 9 | term: string 10 | start?: string 11 | nb?: string 12 | } 13 | 14 | export interface AlbumSearchParams extends Omit { 15 | start: number 16 | nb: number 17 | } 18 | 19 | export interface AlbumResponse { 20 | data: any[] 21 | total: number 22 | } 23 | 24 | const path: ApiHandler['path'] = '/album-search/' 25 | 26 | const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = async (req, res) => { 27 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 28 | const dz = sessionDZ[req.session.id] 29 | 30 | if (!req.query) { 31 | return res.status(400).send() 32 | } 33 | 34 | const { term, start, nb } = parseQuery(req.query) 35 | 36 | if (!term || term.trim() === '') { 37 | return res.status(400).send() 38 | } 39 | 40 | const results = await dz.gw.search_music(term, 'ALBUM', { index: start, limit: nb }) 41 | 42 | const albums = await Promise.all(results.data.map((c: any) => getAlbumDetails(dz, c.ALB_ID))) 43 | 44 | const output: AlbumResponse = { 45 | data: albums, 46 | total: albums.length 47 | } 48 | 49 | return res.send(output) 50 | } 51 | 52 | const apiHandler = { path, handler } 53 | 54 | function parseQuery(query: RawAlbumQuery): AlbumSearchParams { 55 | let startingPoint = 0 56 | 57 | if (typeof query.start !== 'undefined') { 58 | startingPoint = parseInt(query.start) 59 | } 60 | 61 | let newNb = 30 62 | 63 | if (typeof query.nb !== 'undefined') { 64 | newNb = parseInt(query.nb) 65 | } 66 | 67 | return { 68 | term: query.term, 69 | start: startingPoint, 70 | nb: newNb 71 | } 72 | } 73 | 74 | async function getAlbumDetails(dz: any, albumId: string): Promise { 75 | const result = await dz.gw.get_album_page(albumId) 76 | const output = result.DATA 77 | 78 | let duration = 0 79 | result.SONGS.data.forEach((s: any) => { 80 | if ('DURATION' in s) { 81 | duration += parseInt(s.DURATION) 82 | } 83 | }) 84 | 85 | output.DURATION = duration 86 | output.NUMBER_TRACK = result.SONGS.total 87 | output.LINK = `https://deezer.com/album/${output.ALB_ID}` 88 | 89 | return output 90 | } 91 | 92 | export { apiHandler, getAlbumDetails } 93 | -------------------------------------------------------------------------------- /server/src/routes/api/get/newReleases.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | import { getAlbumDetails } from './albumSearch' 6 | 7 | const path: ApiHandler['path'] = '/newReleases' 8 | 9 | const handler: ApiHandler['handler'] = async (req, res) => { 10 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 11 | const dz = sessionDZ[req.session.id] 12 | 13 | const results = await dz.gw.get_page('channels/explore') 14 | 15 | const music_section = results.sections.find((e: any) => 16 | e.section_id.includes('module_id=83718b7b-5503-4062-b8b9-3530e2e2cefa') 17 | ) 18 | 19 | const channels = music_section.items.map((e: any) => e.target) 20 | 21 | const newReleasesByChannel = await Promise.all(channels.map((c: string) => channelNewReleases(dz, c))) 22 | 23 | const seen = new Set() 24 | const distinct: any[] = [] 25 | 26 | newReleasesByChannel.forEach(l => { 27 | l.forEach(r => { 28 | if (!seen.has(r.ALB_ID)) { 29 | seen.add(r.ALB_ID) 30 | distinct.push(r) 31 | } 32 | }) 33 | }) 34 | 35 | distinct.sort((a, b) => 36 | a.DIGITAL_RELEASE_DATE < b.DIGITAL_RELEASE_DATE ? 1 : b.DIGITAL_RELEASE_DATE < a.DIGITAL_RELEASE_DATE ? -1 : 0 37 | ) 38 | 39 | const now = Date.now() 40 | const delta = 8 * 24 * 60 * 60 * 1000 41 | 42 | const recent = distinct.filter((x: any) => now - Date.parse(x.DIGITAL_RELEASE_DATE) < delta) 43 | 44 | const albums = await Promise.all(recent.map((c: any) => getAlbumDetails(dz, c.ALB_ID))) 45 | 46 | const output = { 47 | data: albums, 48 | total: albums.length 49 | } 50 | 51 | return res.send(output) 52 | } 53 | 54 | const apiHandler: ApiHandler = { path, handler } 55 | 56 | export default apiHandler 57 | 58 | async function channelNewReleases(dz: any, channelName: string): Promise { 59 | const channelData = await dz.gw.get_page(channelName) 60 | const re = /^New.*releases$/ 61 | 62 | const newReleases = channelData.sections.find((e: any) => re.test(e.title)) 63 | 64 | if (!newReleases) { 65 | return [] 66 | } else if ('target' in newReleases) { 67 | const showAll = await dz.gw.get_page(newReleases.target) 68 | return showAll.sections[0].items.map((e: any) => e.data) 69 | } else if ('items' in newReleases) { 70 | return newReleases.items.map((e: any) => e.data) 71 | } else { 72 | return [] 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /server/src/routes/api/get/mainSearch.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/mainSearch' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | 12 | const term = String(req.query.term) 13 | const results = await dz.gw.search(term) 14 | const order: string[] = [] 15 | results.ORDER.forEach((element: string) => { 16 | if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].includes(element)) order.push(element) 17 | }) 18 | if (results.TOP_RESULT && results.TOP_RESULT.length) { 19 | const originalTopResult = results.TOP_RESULT[0] 20 | const topResult: any = { 21 | type: originalTopResult.__TYPE__ 22 | } 23 | switch (topResult.type) { 24 | case 'artist': 25 | topResult.id = originalTopResult.ART_ID 26 | topResult.picture = `https://e-cdns-images.dzcdn.net/images/artist/${originalTopResult.ART_PICTURE}` 27 | topResult.title = originalTopResult.ART_NAME 28 | topResult.nb_fan = originalTopResult.NB_FAN 29 | break 30 | case 'album': 31 | topResult.id = originalTopResult.ALB_ID 32 | topResult.picture = `https://e-cdns-images.dzcdn.net/images/cover/${originalTopResult.ALB_PICTURE}` 33 | topResult.title = originalTopResult.ALB_TITLE 34 | topResult.artist = originalTopResult.ART_NAME 35 | topResult.nb_song = originalTopResult.NUMBER_TRACK 36 | break 37 | case 'playlist': 38 | topResult.id = originalTopResult.PLAYLIST_ID 39 | topResult.picture = `https://e-cdns-images.dzcdn.net/images/${originalTopResult.PICTURE_TYPE}/${originalTopResult.PLAYLIST_PICTURE}` 40 | topResult.title = originalTopResult.TITLE 41 | topResult.artist = originalTopResult.PARENT_USERNAME 42 | topResult.nb_song = originalTopResult.NB_SONG 43 | break 44 | default: 45 | topResult.id = '0' 46 | topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover' 47 | break 48 | } 49 | topResult.picture += '/156x156-000000-80-0-0.jpg' 50 | topResult.link = `https://deezer.com/${topResult.type}/${topResult.id}` 51 | results.TOP_RESULT = [topResult] 52 | } 53 | results.ORDER = order 54 | res.send(results) 55 | } 56 | 57 | const apiHandler: ApiHandler = { path, handler } 58 | 59 | export default apiHandler 60 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deemix-gui", 3 | "version": "0.0.0", 4 | "main": "index.js", 5 | "repository": "https://gitlab.com/RemixDev/deemix-gui.git", 6 | "author": "RemixDev ", 7 | "license": "GPL-3.0-only", 8 | "scripts": { 9 | "install-all": "yarn install && yarn --cwd server install && yarn --cwd webui install", 10 | "dev": "yarn --cwd webui dev", 11 | "start": "electron . --dev", 12 | "predist": "yarn build-server && yarn build-webui", 13 | "dist": "yarn set-version && electron-builder && yarn reset-version", 14 | "dist:dir": "yarn set-version && yarn predist && electron-builder --dir && yarn reset-version", 15 | "dist-server": "yarn set-version && yarn predist && ./node_modules/.bin/pkg --out-dir dist ./server/package.json && yarn reset-version", 16 | "start-server": "yarn --cwd server start", 17 | "start-server-build": "yarn --cwd server start-build", 18 | "build-server": "yarn --cwd server build", 19 | "build-webui": "yarn --cwd webui build", 20 | "set-version": "node scripts/set-version.js", 21 | "reset-version": "node scripts/reset-version.js" 22 | }, 23 | "devDependencies": { 24 | "electron": "^12.0.9", 25 | "electron-builder": "22.11.4", 26 | "pkg": "5.3.0" 27 | }, 28 | "dependencies": { 29 | "electron-context-menu": "^3.1.0", 30 | "electron-window-state-manager": "^0.3.2", 31 | "yargs": "17.0.1" 32 | }, 33 | "build": { 34 | "appId": "app.deemix.gui", 35 | "productName": "deemix-gui", 36 | "files": [ 37 | "index.js", 38 | "preload.js", 39 | "server/dist/**/*", 40 | "webui/public/**/*", 41 | "build/**/*", 42 | "package.json" 43 | ], 44 | "mac": { 45 | "target": "dmg", 46 | "artifactName": "deemix-gui.${ext}", 47 | "category": "public.app-category.music" 48 | }, 49 | "win": { 50 | "target": [ 51 | { 52 | "target": "nsis", 53 | "arch": "x64" 54 | }, 55 | { 56 | "target": "portable", 57 | "arch": "x64" 58 | } 59 | ] 60 | }, 61 | "linux": { 62 | "target": [ 63 | "appimage", 64 | "deb" 65 | ], 66 | "artifactName": "deemix-gui.${ext}", 67 | "category": "AudioVideo,Audio", 68 | "icon": "build/icon.icns" 69 | }, 70 | "nsis": { 71 | "artifactName": "${productName}_setup.${ext}", 72 | "oneClick": false, 73 | "license": "LICENSE.txt", 74 | "allowToChangeInstallationDirectory": true, 75 | "uninstallDisplayName": "${productName}", 76 | "deleteAppDataOnUninstall": true 77 | }, 78 | "portable": { 79 | "artifactName": "${productName}.${ext}", 80 | "requestExecutionLevel": "user" 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /server/src/routes/api/get/getTracklist.ts: -------------------------------------------------------------------------------- 1 | // @ts-expect-error 2 | import { Deezer } from 'deezer-js' 3 | import { ApiHandler } from '../../../types' 4 | import { sessionDZ, plugins } from '../../../main' 5 | 6 | const path: ApiHandler['path'] = '/getTracklist' 7 | 8 | const handler: ApiHandler['handler'] = async (req, res) => { 9 | if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() 10 | const dz = sessionDZ[req.session.id] 11 | 12 | const list_id = String(req.query.id) 13 | const list_type = String(req.query.type) 14 | switch (list_type) { 15 | case 'artist': { 16 | const artistAPI = await dz.api.get_artist(list_id) 17 | artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, { limit: 100 }) 18 | res.send(artistAPI) 19 | break 20 | } 21 | case 'spotifyplaylist': 22 | case 'spotify_playlist': { 23 | if (!plugins.spotify.enabled) { 24 | res.send({ 25 | collaborative: false, 26 | description: '', 27 | external_urls: { spotify: null }, 28 | followers: { total: 0, href: null }, 29 | id: null, 30 | images: [], 31 | name: 'Something went wrong', 32 | owner: { 33 | display_name: 'Error', 34 | id: null 35 | }, 36 | public: true, 37 | tracks: [], 38 | type: 'playlist', 39 | uri: null 40 | }) 41 | break 42 | } 43 | const sp = plugins.spotify.sp 44 | let playlist = await sp.getPlaylist(list_id) 45 | playlist = playlist.body 46 | let tracklist = playlist.tracks.items 47 | while (playlist.tracks.next) { 48 | const regExec = /offset=(\d+)&limit=(\d+)/g.exec(playlist.tracks.next) 49 | const offset = regExec![1] 50 | const limit = regExec![2] 51 | const playlistTracks = await sp.getPlaylistTracks(list_id, { offset, limit }) 52 | playlist.tracks = playlistTracks.body 53 | tracklist = tracklist.concat(playlist.tracks.items) 54 | } 55 | tracklist.forEach((item: any, i: number) => { 56 | tracklist[i] = item.track 57 | tracklist[i].selected = false 58 | }) 59 | playlist.tracks = tracklist 60 | res.send(playlist) 61 | break 62 | } 63 | default: { 64 | const releaseAPI = await dz.api[`get_${list_type}`](list_id) 65 | let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id) 66 | releaseTracksAPI = releaseTracksAPI.data 67 | 68 | const tracks: any[] = [] 69 | const showdiscs = 70 | list_type === 'album' && 71 | releaseTracksAPI.length && 72 | releaseTracksAPI[releaseTracksAPI.length - 1].disk_number !== 1 73 | let current_disk = 0 74 | 75 | releaseTracksAPI.forEach((track: any) => { 76 | if (showdiscs && parseInt(track.disk_number) !== current_disk) { 77 | current_disk = parseInt(track.disk_number) 78 | tracks.push({ type: 'disc_separator', number: current_disk }) 79 | } 80 | track.selected = false 81 | tracks.push(track) 82 | }) 83 | releaseAPI.tracks = tracks 84 | res.send(releaseAPI) 85 | break 86 | } 87 | } 88 | } 89 | 90 | const apiHandler: ApiHandler = { path, handler } 91 | 92 | export default apiHandler 93 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { app, BrowserWindow, ipcMain, shell, dialog, Menu, MenuItem } = require('electron') 2 | const contextMenu = require('electron-context-menu') 3 | const WindowStateManager = require('electron-window-state-manager') 4 | const path = require('path') 5 | const os = require('os') 6 | const yargs = require('yargs/yargs') 7 | const { hideBin } = require('yargs/helpers') 8 | const argv = yargs(hideBin(process.argv)).options({ 9 | port: { type: 'string', default: '6595' }, 10 | host: { type: 'string', default: '127.0.0.1' }, 11 | dev: { type: 'boolean', default: false} 12 | }).argv 13 | const server = require('./server/dist/app.js') 14 | 15 | const PORT = process.env.DEEMIX_SERVER_PORT || argv.port 16 | 17 | process.env.DEEMIX_SERVER_PORT = PORT 18 | process.env.DEEMIX_HOST = argv.host 19 | 20 | let win 21 | const windowState = new WindowStateManager('mainWindow', { 22 | defaultWidth: 800, 23 | defaultHeight: 600 24 | }) 25 | 26 | function createWindow () { 27 | win = new BrowserWindow({ 28 | width: windowState.width, 29 | height: windowState.height, 30 | x: windowState.x, 31 | y: windowState.y, 32 | useContentSize: true, 33 | autoHideMenuBar: true, 34 | icon: path.join(__dirname, os.platform() === 'win32' ? 'build/icon.ico' : 'build/64x64.png'), 35 | webPreferences: { 36 | preload: path.join(__dirname, 'preload.js') 37 | } 38 | }) 39 | 40 | win.setMenu(null) 41 | 42 | if (argv.dev){ 43 | const menu = new Menu() 44 | menu.append(new MenuItem({ 45 | label: 'DevTools', 46 | submenu: [ 47 | { role: 'reload', accelerator: 'f5', click: () => { win.reload() } }, 48 | { role: 'devtools', accelerator: 'f12', click: () => { win.webContents.toggleDevTools() } } 49 | ] 50 | })) 51 | Menu.setApplicationMenu(menu) 52 | } 53 | 54 | // Open links in external browser 55 | win.webContents.on('new-window', function(e, url) { 56 | e.preventDefault() 57 | shell.openExternal(url) 58 | }) 59 | 60 | win.loadURL(`http://${argv.host}:${PORT}`) 61 | 62 | if (windowState.maximized) { 63 | win.maximize(); 64 | } 65 | 66 | win.on('close', (event)=>{ 67 | windowState.saveState(win); 68 | }) 69 | } 70 | 71 | app.whenReady().then(() => { 72 | createWindow() 73 | contextMenu({ 74 | showLookUpSelection: false, 75 | showSearchWithGoogle: false, 76 | showInspectElement: false 77 | }) 78 | 79 | // Only one istance per time 80 | app.on('activate', () => { 81 | if (BrowserWindow.getAllWindows().length === 0) { 82 | createWindow() 83 | } 84 | }) 85 | }) 86 | 87 | app.on('window-all-closed', () => { 88 | if (process.platform !== 'darwin') { 89 | app.quit() 90 | } 91 | }) 92 | 93 | ipcMain.on('openDownloadsFolder', (event)=>{ 94 | const { downloadLocation } = server.getSettings().settings 95 | shell.openPath(downloadLocation) 96 | }) 97 | 98 | ipcMain.on('selectDownloadFolder', async (event, downloadLocation)=>{ 99 | let path = await dialog.showOpenDialog(win, { 100 | defaultPath: downloadLocation, 101 | properties: ["openDirectory", "createDirectory"] 102 | }) 103 | if (path.filePaths[0]) win.webContents.send("downloadFolderSelected", path.filePaths[0]) 104 | }) 105 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ## Source: https://github.com/ptkdev-boilerplate/node-cli-boilerplate/blob/main/.gitattributes 2 | 3 | ## AUTO-DETECT 4 | * text=auto 5 | 6 | ## SOURCE CODE 7 | *.bat text eol=crlf 8 | *.css text eol=lf 9 | *.html text diff=html eol=lf 10 | *.ini text eol=crlf 11 | *.js text eol=lf 12 | *.json text eol=lf 13 | *.php text diff=php eol=lf 14 | *.py text diff=python eol=lf 15 | *.rb text diff=ruby 16 | *.sass text eol=lf 17 | *.scss text eol=lf 18 | *.sh text eol=lf 19 | *.sql text eol=lf 20 | *.ts text eol=lf 21 | *.vue text eol=lf 22 | *.svelte text eol=lf 23 | *.xml text eol=lf 24 | *.xhtml text diff=html eol=lf 25 | 26 | ## DOCKER 27 | *.dockerignore text eol=lf 28 | Dockerfile text eol=lf 29 | 30 | ## DOCUMENTATION 31 | *.md text eol=lf 32 | *.txt text eol=lf 33 | AUTHORS text eol=lf 34 | CHANGELOG text eol=lf 35 | CHANGES text eol=lf 36 | CONTRIBUTING text eol=lf 37 | COPYING text eol=lf 38 | INSTALL text eol=lf 39 | license text eol=lf 40 | LICENSE text eol=lf 41 | NEWS text eol=lf 42 | README text eol=lf 43 | TODO text eol=lf 44 | 45 | ## TEMPLATES 46 | *.dot text eol=lf 47 | *.tpl text eol=lf 48 | *.twig text eol=lf 49 | 50 | ## LINTERS 51 | .csslintrc text eol=lf 52 | .eslintrc text eol=lf 53 | .htmlhintrc text eol=lf 54 | .jscsrc text eol=lf 55 | .jshintrc text eol=lf 56 | .jshintignore text eol=lf 57 | .stylelintrc text eol=lf 58 | .npmignore text eol=lf 59 | 60 | ## CONFIGS 61 | *.bowerrc text eol=lf 62 | *.cnf text eol=lf 63 | *.conf text eol=lf 64 | *.config text eol=lf 65 | .babelrc text eol=lf 66 | .browserslistrc text eol=lf 67 | .editorconfig text eol=lf 68 | .env text eol=lf 69 | .gitattributes text eol=lf 70 | .gitconfig text eol=lf 71 | .htaccess text eol=lf 72 | *.lock text eol=lf 73 | *.npmignore text eol=lf 74 | *.yaml text eol=lf 75 | *.yml text eol=lf 76 | browserslist text eol=lf 77 | Makefile text eol=lf 78 | makefile text eol=lf 79 | 80 | ## GRAPHICS 81 | *.ai binary 82 | *.bmp binary 83 | *.eps binary 84 | *.gif binary 85 | *.ico binary 86 | *.jng binary 87 | *.jp2 binary 88 | *.jpg binary 89 | *.jpeg binary 90 | *.jpx binary 91 | *.jxr binary 92 | *.pdf binary 93 | *.png binary 94 | *.psb binary 95 | *.psd binary 96 | *.svg text 97 | *.svgz binary 98 | *.tif binary 99 | *.tiff binary 100 | *.wbmp binary 101 | *.webp binary 102 | 103 | ## AUDIO 104 | *.kar binary 105 | *.m4a binary 106 | *.mid binary 107 | *.midi binary 108 | *.mp3 binary 109 | *.ogg binary 110 | *.ra binary 111 | 112 | ## VIDEO 113 | *.3gpp binary 114 | *.3gp binary 115 | *.as binary 116 | *.asf binary 117 | *.asx binary 118 | *.fla binary 119 | *.flv binary 120 | *.m4v binary 121 | *.mng binary 122 | *.mov binary 123 | *.mp4 binary 124 | *.mpeg binary 125 | *.mpg binary 126 | *.ogv binary 127 | *.swc binary 128 | *.swf binary 129 | *.webm binary 130 | 131 | ## ARCHIVES 132 | *.7z binary 133 | *.gz binary 134 | *.jar binary 135 | *.rar binary 136 | *.tar binary 137 | *.zip binary 138 | 139 | ## FONTS 140 | *.ttf binary 141 | *.eot binary 142 | *.otf binary 143 | *.woff binary 144 | *.woff2 binary 145 | 146 | ## EXECUTABLES 147 | *.exe binary 148 | *.pyc binary 149 | -------------------------------------------------------------------------------- /server/src/types.ts: -------------------------------------------------------------------------------- 1 | import { RequestHandler } from 'express' 2 | 3 | /* === Utilities === */ 4 | // https://github.com/Microsoft/TypeScript/issues/25760#issuecomment-614417742 5 | export type Optional = Omit & Partial 6 | 7 | export type Port = number | string | boolean 8 | 9 | export interface ApiHandler { 10 | path: string 11 | handler: RequestHandler 12 | } 13 | 14 | export interface Tags { 15 | title: boolean 16 | artist: boolean 17 | album: boolean 18 | cover: boolean 19 | trackNumber: boolean 20 | trackTotal: boolean 21 | discNumber: boolean 22 | discTotal: boolean 23 | albumArtist: boolean 24 | genre: boolean 25 | year: boolean 26 | date: boolean 27 | explicit: boolean 28 | isrc: boolean 29 | length: boolean 30 | barcode: boolean 31 | bpm: boolean 32 | replayGain: boolean 33 | label: boolean 34 | lyrics: boolean 35 | syncedLyrics: boolean 36 | copyright: boolean 37 | composer: boolean 38 | involvedPeople: boolean 39 | source: boolean 40 | savePlaylistAsCompilation: boolean 41 | useNullSeparator: boolean 42 | saveID3v1: boolean 43 | multiArtistSeparator: string 44 | singleAlbumArtist: boolean 45 | coverDescriptionUTF8: boolean 46 | } 47 | 48 | export interface Settings { 49 | downloadLocation: string 50 | tracknameTemplate: string 51 | albumTracknameTemplate: string 52 | playlistTracknameTemplate: string 53 | createPlaylistFolder: boolean 54 | playlistNameTemplate: string 55 | createArtistFolder: boolean 56 | artistNameTemplate: string 57 | createAlbumFolder: boolean 58 | albumNameTemplate: string 59 | createCDFolder: boolean 60 | createStructurePlaylist: boolean 61 | createSingleFolder: boolean 62 | padTracks: boolean 63 | paddingSize: string 64 | illegalCharacterReplacer: string 65 | queueConcurrency: number 66 | maxBitrate: string 67 | fallbackBitrate: boolean 68 | fallbackSearch: boolean 69 | logErrors: boolean 70 | logSearched: boolean 71 | saveDownloadQueue: boolean 72 | overwriteFile: string 73 | createM3U8File: boolean 74 | playlistFilenameTemplate: string 75 | syncedLyrics: boolean 76 | embeddedArtworkSize: number 77 | embeddedArtworkPNG: boolean 78 | localArtworkSize: number 79 | localArtworkFormat: string 80 | saveArtwork: boolean 81 | coverImageTemplate: string 82 | saveArtworkArtist: boolean 83 | artistImageTemplate: string 84 | jpegImageQuality: number 85 | dateFormat: string 86 | albumVariousArtists: boolean 87 | removeAlbumVersion: boolean 88 | removeDuplicateArtists: boolean 89 | tagsLanguage: string 90 | featuredToTitle: string 91 | titleCasing: string 92 | artistCasing: string 93 | executeCommand: string 94 | tags: Tags 95 | } 96 | 97 | // TODO 98 | export interface SpotifySettings {} 99 | 100 | interface BaseDeezerObject { 101 | id: number 102 | type: string 103 | } 104 | 105 | interface NamedDeezerObject extends BaseDeezerObject { 106 | name: string 107 | } 108 | 109 | interface PicturedDeezerObject extends BaseDeezerObject { 110 | picture: string 111 | picture_small: string 112 | picture_medium: string 113 | picture_big: string 114 | picture_xl: string 115 | } 116 | 117 | interface CoveredDeezerObject extends BaseDeezerObject { 118 | cover: string 119 | cover_small: string 120 | cover_medium: string 121 | cover_big: string 122 | cover_xl: string 123 | } 124 | 125 | interface DeezerWrapper { 126 | data: Type[] 127 | } 128 | 129 | export interface DeezerContributor extends NamedDeezerObject, PicturedDeezerObject { 130 | link: string 131 | share: string 132 | radio: boolean 133 | tracklist: string 134 | role: string 135 | } 136 | 137 | export interface DeezerTrackArtist extends NamedDeezerObject, PicturedDeezerObject { 138 | link: string 139 | share: string 140 | radio: boolean 141 | tracklist: string 142 | } 143 | 144 | export interface DeezerAlbumArtist extends NamedDeezerObject, PicturedDeezerObject { 145 | tracklist: string 146 | } 147 | 148 | export interface DeezerAlbum extends BaseDeezerObject, CoveredDeezerObject { 149 | title: string 150 | link: string 151 | md5_image: string 152 | release_date: string 153 | tracklist: string 154 | } 155 | 156 | export interface DeezerGenre extends NamedDeezerObject { 157 | picture: string 158 | } 159 | 160 | type DeezerGenres = DeezerWrapper 161 | 162 | export interface GetAlbumTrackArtist extends NamedDeezerObject { 163 | tracklist: string 164 | } 165 | 166 | export interface DeezerTrack extends BaseDeezerObject { 167 | readable: boolean 168 | title: string 169 | title_short: string 170 | title_version: string 171 | link: string 172 | duration: number 173 | rank: number 174 | explicit_lyrics: boolean 175 | explicit_content_lyrics: number 176 | explicit_content_cover: number 177 | preview: string 178 | md5_image: string 179 | artist: GetAlbumTrackArtist 180 | } 181 | 182 | type DeezerTracks = DeezerWrapper 183 | 184 | export interface GetTrackResponse extends BaseDeezerObject { 185 | readable: boolean 186 | title: string 187 | title_short: string 188 | title_version: string 189 | isrc: string 190 | link: string 191 | share: string 192 | duration: number 193 | track_position: number 194 | disk_number: number 195 | rank: number 196 | release_date: string 197 | explicit_lyrics: boolean 198 | explicit_content_lyrics: number 199 | explicit_content_cover: number 200 | preview: string 201 | bpm: number 202 | gain: number 203 | available_countries: string[] 204 | contributors: DeezerContributor[] 205 | md5_image: string 206 | artist: DeezerTrackArtist 207 | album: DeezerAlbum 208 | } 209 | 210 | export interface GetAlbumResponse extends BaseDeezerObject, CoveredDeezerObject { 211 | title: string 212 | upc: string 213 | link: string 214 | share: string 215 | md5_image: string 216 | genre_id: number 217 | genres: DeezerGenres 218 | label: string 219 | nb_tracks: number 220 | duration: number 221 | fans: number 222 | rating: number 223 | release_date: string 224 | record_type: string 225 | available: boolean 226 | tracklist: string 227 | explicit_lyrics: boolean 228 | explicit_content_lyrics: number 229 | explicit_content_cover: number 230 | contributors: DeezerContributor[] 231 | artist: DeezerAlbumArtist 232 | tracks: DeezerTracks 233 | } 234 | 235 | export interface Arguments { 236 | port: string 237 | host: string 238 | 239 | [x: string]: unknown 240 | $0: string 241 | } 242 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Basic Options */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 8 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 9 | // "lib": [], /* Specify library files to be included in the compilation. */ 10 | // "allowJs": true, /* Allow javascript files to be compiled. */ 11 | // "checkJs": true, /* Report errors in .js files. */ 12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ 13 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 14 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 15 | "sourceMap": true, /* Generates corresponding '.map' file. */ 16 | // "outFile": "./", /* Concatenate and emit output to single file. */ 17 | "outDir": "./dist", /* Redirect output structure to the directory. */ 18 | "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 19 | // "composite": true, /* Enable project compilation */ 20 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 21 | // "removeComments": true, /* Do not emit comments to output. */ 22 | // "noEmit": true, /* Do not emit outputs. */ 23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 26 | 27 | /* Strict Type-Checking Options */ 28 | "strict": true, /* Enable all strict type-checking options. */ 29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 30 | // "strictNullChecks": true, /* Enable strict null checks. */ 31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 36 | 37 | /* Additional Checks */ 38 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 42 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 43 | // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ 44 | 45 | /* Module Resolution Options */ 46 | "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 47 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 48 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 49 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 50 | // "typeRoots": [], /* List of folders to include type definitions from. */ 51 | // "types": [], /* Type declaration files to be included in compilation. */ 52 | "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 53 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 54 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 55 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 56 | 57 | /* Source Map Options */ 58 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 59 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 60 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 61 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 62 | 63 | /* Experimental Options */ 64 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 65 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 66 | 67 | /* Advanced Options */ 68 | "skipLibCheck": true, /* Skip type checking of declaration files. */ 69 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 70 | }, 71 | "exclude": [ 72 | "node_modules", 73 | "**/*.spec.ts", 74 | "tests/**" 75 | ] 76 | } 77 | -------------------------------------------------------------------------------- /server/dist/app.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * Connect - session - Cookie 3 | * Copyright(c) 2010 Sencha Inc. 4 | * Copyright(c) 2011 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /*! 9 | * Connect - session - Session 10 | * Copyright(c) 2010 Sencha Inc. 11 | * Copyright(c) 2011 TJ Holowaychuk 12 | * MIT Licensed 13 | */ 14 | 15 | /*! 16 | * Connect - session - Store 17 | * Copyright(c) 2010 Sencha Inc. 18 | * Copyright(c) 2011 TJ Holowaychuk 19 | * MIT Licensed 20 | */ 21 | 22 | /*! 23 | * Copyright (c) 2015, Salesforce.com, Inc. 24 | * All rights reserved. 25 | * 26 | * Redistribution and use in source and binary forms, with or without 27 | * modification, are permitted provided that the following conditions are met: 28 | * 29 | * 1. Redistributions of source code must retain the above copyright notice, 30 | * this list of conditions and the following disclaimer. 31 | * 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, 33 | * this list of conditions and the following disclaimer in the documentation 34 | * and/or other materials provided with the distribution. 35 | * 36 | * 3. Neither the name of Salesforce.com nor the names of its contributors may 37 | * be used to endorse or promote products derived from this software without 38 | * specific prior written permission. 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 41 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 44 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 46 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 47 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 48 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 50 | * POSSIBILITY OF SUCH DAMAGE. 51 | */ 52 | 53 | /*! 54 | * Copyright (c) 2018, Salesforce.com, Inc. 55 | * All rights reserved. 56 | * 57 | * Redistribution and use in source and binary forms, with or without 58 | * modification, are permitted provided that the following conditions are met: 59 | * 60 | * 1. Redistributions of source code must retain the above copyright notice, 61 | * this list of conditions and the following disclaimer. 62 | * 63 | * 2. Redistributions in binary form must reproduce the above copyright notice, 64 | * this list of conditions and the following disclaimer in the documentation 65 | * and/or other materials provided with the distribution. 66 | * 67 | * 3. Neither the name of Salesforce.com nor the names of its contributors may 68 | * be used to endorse or promote products derived from this software without 69 | * specific prior written permission. 70 | * 71 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 72 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 73 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 74 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 75 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 76 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 77 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 78 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 79 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 80 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 81 | * POSSIBILITY OF SUCH DAMAGE. 82 | */ 83 | 84 | /*! 85 | * Prototype. 86 | */ 87 | 88 | /*! 89 | * accepts 90 | * Copyright(c) 2014 Jonathan Ong 91 | * Copyright(c) 2015 Douglas Christopher Wilson 92 | * MIT Licensed 93 | */ 94 | 95 | /*! 96 | * basic-auth 97 | * Copyright(c) 2013 TJ Holowaychuk 98 | * Copyright(c) 2014 Jonathan Ong 99 | * Copyright(c) 2015-2016 Douglas Christopher Wilson 100 | * MIT Licensed 101 | */ 102 | 103 | /*! 104 | * body-parser 105 | * Copyright(c) 2014 Jonathan Ong 106 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 107 | * MIT Licensed 108 | */ 109 | 110 | /*! 111 | * body-parser 112 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 113 | * MIT Licensed 114 | */ 115 | 116 | /*! 117 | * bytes 118 | * Copyright(c) 2012-2014 TJ Holowaychuk 119 | * Copyright(c) 2015 Jed Watson 120 | * MIT Licensed 121 | */ 122 | 123 | /*! 124 | * content-disposition 125 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 126 | * MIT Licensed 127 | */ 128 | 129 | /*! 130 | * content-type 131 | * Copyright(c) 2015 Douglas Christopher Wilson 132 | * MIT Licensed 133 | */ 134 | 135 | /*! 136 | * cookie 137 | * Copyright(c) 2012-2014 Roman Shtylman 138 | * Copyright(c) 2015 Douglas Christopher Wilson 139 | * MIT Licensed 140 | */ 141 | 142 | /*! 143 | * cookie-parser 144 | * Copyright(c) 2014 TJ Holowaychuk 145 | * Copyright(c) 2015 Douglas Christopher Wilson 146 | * MIT Licensed 147 | */ 148 | 149 | /*! 150 | * depd 151 | * Copyright(c) 2014 Douglas Christopher Wilson 152 | * MIT Licensed 153 | */ 154 | 155 | /*! 156 | * depd 157 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 158 | * MIT Licensed 159 | */ 160 | 161 | /*! 162 | * depd 163 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 164 | * MIT Licensed 165 | */ 166 | 167 | /*! 168 | * depd 169 | * Copyright(c) 2014-2018 Douglas Christopher Wilson 170 | * MIT Licensed 171 | */ 172 | 173 | /*! 174 | * depd 175 | * Copyright(c) 2015 Douglas Christopher Wilson 176 | * MIT Licensed 177 | */ 178 | 179 | /*! 180 | * destroy 181 | * Copyright(c) 2014 Jonathan Ong 182 | * MIT Licensed 183 | */ 184 | 185 | /*! 186 | * ee-first 187 | * Copyright(c) 2014 Jonathan Ong 188 | * MIT Licensed 189 | */ 190 | 191 | /*! 192 | * encodeurl 193 | * Copyright(c) 2016 Douglas Christopher Wilson 194 | * MIT Licensed 195 | */ 196 | 197 | /*! 198 | * escape-html 199 | * Copyright(c) 2012-2013 TJ Holowaychuk 200 | * Copyright(c) 2015 Andreas Lubbe 201 | * Copyright(c) 2015 Tiancheng "Timothy" Gu 202 | * MIT Licensed 203 | */ 204 | 205 | /*! 206 | * etag 207 | * Copyright(c) 2014-2016 Douglas Christopher Wilson 208 | * MIT Licensed 209 | */ 210 | 211 | /*! 212 | * express 213 | * Copyright(c) 2009-2013 TJ Holowaychuk 214 | * Copyright(c) 2013 Roman Shtylman 215 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 216 | * MIT Licensed 217 | */ 218 | 219 | /*! 220 | * express 221 | * Copyright(c) 2009-2013 TJ Holowaychuk 222 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 223 | * MIT Licensed 224 | */ 225 | 226 | /*! 227 | * express-session 228 | * Copyright(c) 2010 Sencha Inc. 229 | * Copyright(c) 2011 TJ Holowaychuk 230 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 231 | * MIT Licensed 232 | */ 233 | 234 | /*! 235 | * express-session 236 | * Copyright(c) 2010 Sencha Inc. 237 | * Copyright(c) 2011 TJ Holowaychuk 238 | * Copyright(c) 2015 Douglas Christopher Wilson 239 | * MIT Licensed 240 | */ 241 | 242 | /*! 243 | * finalhandler 244 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 245 | * MIT Licensed 246 | */ 247 | 248 | /*! 249 | * forwarded 250 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 251 | * MIT Licensed 252 | */ 253 | 254 | /*! 255 | * fresh 256 | * Copyright(c) 2012 TJ Holowaychuk 257 | * Copyright(c) 2016-2017 Douglas Christopher Wilson 258 | * MIT Licensed 259 | */ 260 | 261 | /*! 262 | * http-errors 263 | * Copyright(c) 2014 Jonathan Ong 264 | * Copyright(c) 2016 Douglas Christopher Wilson 265 | * MIT Licensed 266 | */ 267 | 268 | /*! 269 | * media-typer 270 | * Copyright(c) 2014 Douglas Christopher Wilson 271 | * MIT Licensed 272 | */ 273 | 274 | /*! 275 | * memorystore 276 | * Copyright(c) 2020 Rocco Musolino <@roccomuso> 277 | * MIT Licensed 278 | */ 279 | 280 | /*! 281 | * merge-descriptors 282 | * Copyright(c) 2014 Jonathan Ong 283 | * Copyright(c) 2015 Douglas Christopher Wilson 284 | * MIT Licensed 285 | */ 286 | 287 | /*! 288 | * methods 289 | * Copyright(c) 2013-2014 TJ Holowaychuk 290 | * Copyright(c) 2015-2016 Douglas Christopher Wilson 291 | * MIT Licensed 292 | */ 293 | 294 | /*! 295 | * mime-db 296 | * Copyright(c) 2014 Jonathan Ong 297 | * MIT Licensed 298 | */ 299 | 300 | /*! 301 | * mime-types 302 | * Copyright(c) 2014 Jonathan Ong 303 | * Copyright(c) 2015 Douglas Christopher Wilson 304 | * MIT Licensed 305 | */ 306 | 307 | /*! 308 | * morgan 309 | * Copyright(c) 2010 Sencha Inc. 310 | * Copyright(c) 2011 TJ Holowaychuk 311 | * Copyright(c) 2014 Jonathan Ong 312 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 313 | * MIT Licensed 314 | */ 315 | 316 | /*! 317 | * negotiator 318 | * Copyright(c) 2012 Federico Romero 319 | * Copyright(c) 2012-2014 Isaac Z. Schlueter 320 | * Copyright(c) 2015 Douglas Christopher Wilson 321 | * MIT Licensed 322 | */ 323 | 324 | /*! 325 | * on-finished 326 | * Copyright(c) 2013 Jonathan Ong 327 | * Copyright(c) 2014 Douglas Christopher Wilson 328 | * MIT Licensed 329 | */ 330 | 331 | /*! 332 | * on-headers 333 | * Copyright(c) 2014 Douglas Christopher Wilson 334 | * MIT Licensed 335 | */ 336 | 337 | /*! 338 | * parseurl 339 | * Copyright(c) 2014 Jonathan Ong 340 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 341 | * MIT Licensed 342 | */ 343 | 344 | /*! 345 | * proxy-addr 346 | * Copyright(c) 2014-2016 Douglas Christopher Wilson 347 | * MIT Licensed 348 | */ 349 | 350 | /*! 351 | * random-bytes 352 | * Copyright(c) 2016 Douglas Christopher Wilson 353 | * MIT Licensed 354 | */ 355 | 356 | /*! 357 | * range-parser 358 | * Copyright(c) 2012-2014 TJ Holowaychuk 359 | * Copyright(c) 2015-2016 Douglas Christopher Wilson 360 | * MIT Licensed 361 | */ 362 | 363 | /*! 364 | * raw-body 365 | * Copyright(c) 2013-2014 Jonathan Ong 366 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 367 | * MIT Licensed 368 | */ 369 | 370 | /*! 371 | * send 372 | * Copyright(c) 2012 TJ Holowaychuk 373 | * Copyright(c) 2014-2016 Douglas Christopher Wilson 374 | * MIT Licensed 375 | */ 376 | 377 | /*! 378 | * serve-static 379 | * Copyright(c) 2010 Sencha Inc. 380 | * Copyright(c) 2011 TJ Holowaychuk 381 | * Copyright(c) 2014-2016 Douglas Christopher Wilson 382 | * MIT Licensed 383 | */ 384 | 385 | /*! 386 | * statuses 387 | * Copyright(c) 2014 Jonathan Ong 388 | * Copyright(c) 2016 Douglas Christopher Wilson 389 | * MIT Licensed 390 | */ 391 | 392 | /*! 393 | * toidentifier 394 | * Copyright(c) 2016 Douglas Christopher Wilson 395 | * MIT Licensed 396 | */ 397 | 398 | /*! 399 | * type-is 400 | * Copyright(c) 2014 Jonathan Ong 401 | * Copyright(c) 2014-2015 Douglas Christopher Wilson 402 | * MIT Licensed 403 | */ 404 | 405 | /*! 406 | * uid-safe 407 | * Copyright(c) 2014 Jonathan Ong 408 | * Copyright(c) 2015-2017 Douglas Christopher Wilson 409 | * MIT Licensed 410 | */ 411 | 412 | /*! 413 | * unpipe 414 | * Copyright(c) 2015 Douglas Christopher Wilson 415 | * MIT Licensed 416 | */ 417 | 418 | /*! 419 | * vary 420 | * Copyright(c) 2014-2017 Douglas Christopher Wilson 421 | * MIT Licensed 422 | */ 423 | 424 | /*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ 425 | 426 | /*! safe-buffer. MIT License. Feross Aboukhadijeh */ 427 | -------------------------------------------------------------------------------- /server/src/main.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import { sep } from 'path' 3 | import { v4 as uuidv4 } from 'uuid' 4 | // @ts-expect-error 5 | import deemix from 'deemix' 6 | import WebSocket from 'ws' 7 | import got from 'got' 8 | import { wss } from './app' 9 | import { Settings } from './types' 10 | import { NotLoggedIn } from './helpers/errors' 11 | 12 | import { GUI_PACKAGE } from './helpers/paths' 13 | 14 | const Downloader = deemix.downloader.Downloader 15 | const { Single, Collection, Convertable } = deemix.types.downloadObjects 16 | export const defaultSettings: Settings = deemix.settings.DEFAULTS 17 | export const configFolder: string = deemix.utils.localpaths.getConfigFolder() 18 | export const sessionDZ: any = {} 19 | let settings: any = deemix.settings.load(configFolder) 20 | 21 | export const getAccessToken = deemix.utils.deezer.getAccessToken 22 | export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken 23 | 24 | export const deemixVersion = require('../node_modules/deemix/package.json').version 25 | const currentVersionTemp = JSON.parse(String(fs.readFileSync(GUI_PACKAGE))).version 26 | export const currentVersion = currentVersionTemp === '0.0.0' ? 'continuous' : currentVersionTemp 27 | let deezerAvailable: boolean | null = null 28 | let latestVersion: string | null = null 29 | 30 | export async function isDeezerAvailable(): Promise { 31 | if (deezerAvailable === null) { 32 | let response 33 | try { 34 | response = await got.get('https://www.deezer.com/', { 35 | headers: { Cookie: 'dz_lang=en; Domain=deezer.com; Path=/; Secure; hostOnly=false;' }, 36 | https: { 37 | rejectUnauthorized: false 38 | }, 39 | retry: 5 40 | }) 41 | } catch (e) { 42 | console.trace(e) 43 | deezerAvailable = false 44 | return deezerAvailable 45 | } 46 | const title = (response.body.match(/]*>([^<]+)<\/title>/)![1] || '').trim() 47 | deezerAvailable = title !== 'Deezer will soon be available in your country.' 48 | } 49 | return deezerAvailable 50 | } 51 | 52 | export async function getLatestVersion(force = false): Promise { 53 | if ((latestVersion === null || force) && !settings.disableUpdateCheck) { 54 | let response 55 | try { 56 | response = await got.get('https://deemix.app/gui/latest', { 57 | https: { 58 | rejectUnauthorized: false 59 | } 60 | }) 61 | } catch (e) { 62 | console.trace(e) 63 | latestVersion = 'NotFound' 64 | return latestVersion 65 | } 66 | latestVersion = response.body.trim() 67 | } 68 | return latestVersion 69 | } 70 | 71 | function parseVersion(version: string | null): any { 72 | if (version === null || version === 'continuous' || version === 'NotFound') return null 73 | try { 74 | const matchResult = version.match(/(\d+)\.(\d+)\.(\d+)-r(\d)+\.(.+)/) || [] 75 | return { 76 | year: parseInt(matchResult[1]), 77 | month: parseInt(matchResult[2]), 78 | day: parseInt(matchResult[3]), 79 | revision: parseInt(matchResult[4]), 80 | commit: matchResult[5] || '' 81 | } 82 | } catch (e) { 83 | console.trace(e) 84 | return null 85 | } 86 | } 87 | 88 | export function isUpdateAvailable(): boolean { 89 | const currentVersionObj: any = parseVersion(currentVersion) 90 | const latestVersionObj: any = parseVersion(latestVersion) 91 | if (currentVersionObj === null || latestVersionObj === null) return false 92 | if (latestVersionObj.year > currentVersionObj.year) return true 93 | if (latestVersionObj.month > currentVersionObj.month) return true 94 | if (latestVersionObj.day > currentVersionObj.day) return true 95 | if (latestVersionObj.revision > currentVersionObj.revision) return true 96 | if (latestVersionObj.commit !== currentVersionObj.commit) return true 97 | return false 98 | } 99 | 100 | export const plugins: any = { 101 | // eslint-disable-next-line new-cap 102 | spotify: new deemix.plugins.spotify() 103 | } 104 | plugins.spotify.setup() 105 | 106 | export const listener = { 107 | send(key: string, data?: any) { 108 | const logLine = deemix.utils.formatListener(key, data) 109 | if (logLine) console.log(logLine) 110 | if (['downloadInfo', 'downloadWarn'].includes(key)) return 111 | wss.clients.forEach(client => { 112 | if (client.readyState === WebSocket.OPEN) { 113 | client.send(JSON.stringify({ key, data })) 114 | } 115 | }) 116 | } 117 | } 118 | 119 | export function getSettings(): any { 120 | return { settings, defaultSettings, spotifySettings: plugins.spotify.getSettings() } 121 | } 122 | 123 | export function saveSettings(newSettings: any, newSpotifySettings: any) { 124 | newSettings.executeCommand = settings.executeCommand 125 | deemix.settings.save(newSettings, configFolder) 126 | settings = newSettings 127 | plugins.spotify.saveSettings(newSpotifySettings) 128 | } 129 | 130 | let queueOrder: string[] = [] 131 | const queue: any = {} 132 | let currentJob: any = null 133 | 134 | restoreQueueFromDisk() 135 | 136 | export function getQueue() { 137 | const result: any = { 138 | queue, 139 | queueOrder 140 | } 141 | if (currentJob && currentJob !== true) { 142 | result.current = currentJob.downloadObject.getSlimmedDict() 143 | } 144 | return result 145 | } 146 | 147 | export async function addToQueue(dz: any, url: string[], bitrate: number) { 148 | if (!dz.logged_in) throw new NotLoggedIn() 149 | 150 | let downloadObjs: any[] = [] 151 | const downloadErrors: any[] = [] 152 | let link: string = '' 153 | const requestUUID = uuidv4() 154 | 155 | if (url.length > 1) { 156 | listener.send('startGeneratingItems', { uuid: requestUUID, total: url.length }) 157 | } 158 | 159 | for (let i = 0; i < url.length; i++) { 160 | link = url[i] 161 | console.log(`Adding ${link} to queue`) 162 | let downloadObj 163 | try { 164 | downloadObj = await deemix.generateDownloadObject(dz, link, bitrate, plugins, listener) 165 | } catch (e) { 166 | downloadErrors.push(e) 167 | } 168 | if (Array.isArray(downloadObj)) { 169 | downloadObjs = downloadObjs.concat(downloadObj) 170 | } else if (downloadObj) downloadObjs.push(downloadObj) 171 | } 172 | 173 | if (downloadErrors.length) { 174 | downloadErrors.forEach((e: any) => { 175 | if (!e.errid) console.trace(e) 176 | listener.send('queueError', { link: e.link, error: e.message, errid: e.errid }) 177 | }) 178 | } 179 | 180 | if (url.length > 1) { 181 | listener.send('finishGeneratingItems', { uuid: requestUUID, total: downloadObjs.length }) 182 | } 183 | 184 | const slimmedObjects: any[] = [] 185 | 186 | downloadObjs.forEach((downloadObj: any, pos: number) => { 187 | // Check if element is already in queue 188 | if (Object.keys(queue).includes(downloadObj.uuid)) { 189 | listener.send('alreadyInQueue', downloadObj.getEssentialDict()) 190 | delete downloadObjs[pos] 191 | return 192 | } 193 | 194 | // Save queue status when adding something to the queue 195 | if (!fs.existsSync(configFolder + 'queue')) fs.mkdirSync(configFolder + 'queue') 196 | 197 | queueOrder.push(downloadObj.uuid) 198 | fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder)) 199 | queue[downloadObj.uuid] = downloadObj.getEssentialDict() 200 | queue[downloadObj.uuid].status = 'inQueue' 201 | 202 | const savedObject = downloadObj.toDict() 203 | savedObject.status = 'inQueue' 204 | fs.writeFileSync(configFolder + `queue${sep}${downloadObj.uuid}.json`, JSON.stringify(savedObject)) 205 | 206 | slimmedObjects.push(downloadObj.getSlimmedDict()) 207 | }) 208 | const isSingleObject = downloadObjs.length === 1 209 | if (isSingleObject) listener.send('addedToQueue', downloadObjs[0].getSlimmedDict()) 210 | else listener.send('addedToQueue', slimmedObjects) 211 | 212 | startQueue(dz) 213 | return slimmedObjects 214 | } 215 | 216 | export async function startQueue(dz: any): Promise { 217 | do { 218 | if (currentJob !== null || queueOrder.length === 0) { 219 | // Should not start another download 220 | return null 221 | } 222 | currentJob = true // lock currentJob 223 | 224 | let currentUUID: string 225 | do { 226 | currentUUID = queueOrder.shift() || '' 227 | } while (queue[currentUUID] === undefined && queueOrder.length) 228 | queue[currentUUID].status = 'downloading' 229 | const currentItem: any = JSON.parse(fs.readFileSync(configFolder + `queue${sep}${currentUUID}.json`).toString()) 230 | let downloadObject: any 231 | switch (currentItem.__type__) { 232 | case 'Single': 233 | downloadObject = new Single(currentItem) 234 | break 235 | case 'Collection': 236 | downloadObject = new Collection(currentItem) 237 | break 238 | case 'Convertable': 239 | downloadObject = new Convertable(currentItem) 240 | downloadObject = await plugins[downloadObject.plugin].convert(dz, downloadObject, settings, listener) 241 | fs.writeFileSync( 242 | configFolder + `queue${sep}${downloadObject.uuid}.json`, 243 | JSON.stringify({ ...downloadObject.toDict(), status: 'inQueue' }) 244 | ) 245 | break 246 | } 247 | currentJob = new Downloader(dz, downloadObject, settings, listener) 248 | listener.send('startDownload', currentUUID) 249 | await currentJob.start() 250 | 251 | if (!downloadObject.isCanceled) { 252 | // Set status 253 | if (downloadObject.failed === downloadObject.size && downloadObject.size !== 0) { 254 | queue[currentUUID].status = 'failed' 255 | } else if (downloadObject.failed > 0) { 256 | queue[currentUUID].status = 'withErrors' 257 | } else { 258 | queue[currentUUID].status = 'completed' 259 | } 260 | 261 | const savedObject = downloadObject.getSlimmedDict() 262 | savedObject.status = queue[currentUUID].status 263 | 264 | // Save queue status 265 | queue[currentUUID] = savedObject 266 | fs.writeFileSync(configFolder + `queue${sep}${currentUUID}.json`, JSON.stringify(savedObject)) 267 | } 268 | console.log(queueOrder) 269 | fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder)) 270 | 271 | currentJob = null 272 | } while (queueOrder.length) 273 | } 274 | 275 | export function cancelDownload(uuid: string) { 276 | if (Object.keys(queue).includes(uuid)) { 277 | switch (queue[uuid].status) { 278 | case 'downloading': 279 | currentJob.downloadObject.isCanceled = true 280 | listener.send('cancellingCurrentItem', uuid) 281 | break 282 | case 'inQueue': 283 | queueOrder.splice(queueOrder.indexOf(uuid), 1) 284 | fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder)) 285 | // break 286 | // eslint-disable-next-line no-fallthrough 287 | default: 288 | // This gets called even in the 'inQueue' case. Is this the expected behaviour? If no, de-comment the break 289 | listener.send('removedFromQueue', uuid) 290 | break 291 | } 292 | fs.unlinkSync(configFolder + `queue${sep}${uuid}.json`) 293 | delete queue[uuid] 294 | } 295 | } 296 | 297 | export function cancelAllDownloads() { 298 | queueOrder = [] 299 | let currentItem: string | null = null 300 | Object.values(queue).forEach((downloadObject: any) => { 301 | if (downloadObject.status === 'downloading') { 302 | currentJob.downloadObject.isCanceled = true 303 | listener.send('cancellingCurrentItem', downloadObject.uuid) 304 | currentItem = downloadObject.uuid 305 | } 306 | fs.unlinkSync(configFolder + `queue${sep}${downloadObject.uuid}.json`) 307 | delete queue[downloadObject.uuid] 308 | }) 309 | fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder)) 310 | listener.send('removedAllDownloads', currentItem) 311 | } 312 | 313 | export function clearCompletedDownloads() { 314 | Object.values(queue).forEach((downloadObject: any) => { 315 | if (downloadObject.status === 'completed') { 316 | fs.unlinkSync(configFolder + `queue${sep}${downloadObject.uuid}.json`) 317 | delete queue[downloadObject.uuid] 318 | } 319 | }) 320 | listener.send('removedFinishedDownloads') 321 | } 322 | 323 | export function restoreQueueFromDisk() { 324 | if (!fs.existsSync(configFolder + 'queue')) fs.mkdirSync(configFolder + 'queue') 325 | const allItems: string[] = fs.readdirSync(configFolder + 'queue') 326 | allItems.forEach((filename: string) => { 327 | if (filename === 'order.json') { 328 | try { 329 | queueOrder = JSON.parse(fs.readFileSync(configFolder + `queue${sep}order.json`).toString()) 330 | } catch { 331 | queueOrder = [] 332 | fs.writeFileSync(configFolder + `queue${sep}order.json`, JSON.stringify(queueOrder)) 333 | } 334 | } else { 335 | let currentItem: any 336 | try { 337 | currentItem = JSON.parse(fs.readFileSync(configFolder + `queue${sep}${filename}`).toString()) 338 | } catch { 339 | fs.unlinkSync(configFolder + `queue${sep}${filename}`) 340 | return 341 | } 342 | if (currentItem.status === 'inQueue') { 343 | let downloadObject: any 344 | switch (currentItem.__type__) { 345 | case 'Single': 346 | downloadObject = new Single(currentItem) 347 | break 348 | case 'Collection': 349 | downloadObject = new Collection(currentItem) 350 | break 351 | case 'Convertable': 352 | downloadObject = new Convertable(currentItem) 353 | break 354 | } 355 | queue[downloadObject.uuid] = downloadObject.getEssentialDict() 356 | queue[downloadObject.uuid].status = 'inQueue' 357 | } else { 358 | queue[currentItem.uuid] = currentItem 359 | } 360 | } 361 | }) 362 | } 363 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | --------------------------------------------------------------------------------