From 50b4785b59001637d59f1562f722ff49d5ae9789 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Mon, 31 May 2021 23:25:53 +0200 Subject: [PATCH] Implemented execute command after download --- deemix/downloader.js | 7 ++++++- deemix/utils/index.js | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/deemix/downloader.js b/deemix/downloader.js index 2da5576..a747087 100644 --- a/deemix/downloader.js +++ b/deemix/downloader.js @@ -2,7 +2,7 @@ const { Track } = require('./types/Track.js') const { StaticPicture } = require('./types/Picture.js') const { streamTrack, generateStreamURL, DownloadCanceled } = require('./decryption.js') const { tagID3, tagID3v1, tagFLAC } = require('./tagger.js') -const { USER_AGENT_HEADER, pipeline } = require('./utils/index.js') +const { USER_AGENT_HEADER, pipeline, shellEscape } = require('./utils/index.js') const { DEFAULTS, OverwriteOption } = require('./settings.js') const { generatePath, generateAlbumName, generateArtistName, generateDownloadObjectName } = require('./utils/pathtemplates.js') const { TrackFormats } = require('deezer-js') @@ -10,6 +10,7 @@ const got = require('got') const fs = require('fs') const { tmpdir } = require('os') const { queue, each, eachOf } = require('async') +const { exec } = require("child_process") const extensions = { [TrackFormats.FLAC]: '.flac', @@ -520,6 +521,8 @@ class Downloader { } // Execute command after download + if (this.settings.executeCommand !== "") + exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.extrasPath)).replaceAll("%filename%", shellEscape(track.filename))) } async afterDownloadCollection(tracks){ @@ -575,6 +578,8 @@ class Downloader { } // Execute command after download + if (this.settings.executeCommand !== "") + exec(this.settings.executeCommand.replaceAll("%folder%", shellEscape(this.extrasPath)).replaceAll("%filename%", '')) } } diff --git a/deemix/utils/index.js b/deemix/utils/index.js index 643d919..af65d86 100644 --- a/deemix/utils/index.js +++ b/deemix/utils/index.js @@ -71,6 +71,12 @@ function uniqueArray(arr){ return arr } +function shellEscape(s){ + if (typeof s !== 'string') return '' + if (!(/[^\w@%+=:,./-]/g.test(s))) return s + return "'" + s.replaceAll("'", "'\"'\"'") + "'" +} + function removeDuplicateArtists(artist, artists){ artists = uniqueArray(artists) Object.keys(artist).forEach((role) => { @@ -88,5 +94,6 @@ module.exports = { removeDuplicateArtists, pipeline, canWrite, - changeCase + changeCase, + shellEscape }