From 46594aa21b7fab9e404c953175463728525f7722 Mon Sep 17 00:00:00 2001 From: replydev Date: Wed, 20 May 2020 16:36:01 +0200 Subject: [PATCH 1/2] Bot mode --- deemix/__main__.py | 7 +++++-- deemix/app/settings.py | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/deemix/__main__.py b/deemix/__main__.py index 3eff695..4fd7874 100644 --- a/deemix/__main__.py +++ b/deemix/__main__.py @@ -8,9 +8,10 @@ from os.path import isfile @click.command() @click.option('-b', '--bitrate', default=None, help='Overwrites the default bitrate selected') +@click.option('-bot', '--botmode', is_flag=True, help='Enables bot mode') @click.argument('url', nargs=-1, required=True) -def download(bitrate, url): - settings = initSettings() +def download(bitrate, botmode, url): + settings = initSettings(botmode) app.login() if isfile(url[0]): filename = url[0] @@ -19,6 +20,8 @@ def download(bitrate, url): for u in url: app.downloadLink(u, settings, bitrate) click.echo("All done!") + if botmode: + click.echo(settings['downloadLocation']) #folder name output if __name__ == '__main__': diff --git a/deemix/app/settings.py b/deemix/app/settings.py index 226132d..8e937e0 100644 --- a/deemix/app/settings.py +++ b/deemix/app/settings.py @@ -2,6 +2,8 @@ import json import os.path as path from os import makedirs +import random +import string import deemix.utils.localpaths as localpaths @@ -9,7 +11,7 @@ settings = {} defaultSettings = {} -def initSettings(): +def initSettings(bot_mode = False): global settings global defaultSettings currentFolder = path.abspath(path.dirname(__file__)) @@ -17,15 +19,20 @@ def initSettings(): makedirs(configFolder, exist_ok=True) with open(path.join(currentFolder, 'default.json'), 'r') as d: defaultSettings = json.load(d) - defaultSettings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music') + defaultSettings['downloadLocation'] = "" if not path.isfile(path.join(configFolder, 'config.json')): with open(path.join(configFolder, 'config.json'), 'w') as f: json.dump(defaultSettings, f, indent=2) with open(path.join(configFolder, 'config.json'), 'r') as configFile: settings = json.load(configFile) settingsCheck() - if settings['downloadLocation'] == "": - settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music') + + if bot_mode: + print("Im using bot mode") + settings['downloadLocation'] = randomString(12) + elif settings['downloadLocation'] == "": + print("I'm using normal mode") + settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music') saveSettings(settings) makedirs(settings['downloadLocation'], exist_ok=True) return settings @@ -63,3 +70,8 @@ def settingsCheck(): changes += 1 if changes > 0: saveSettings(settings) + + +def randomString(stringLength=8): + letters = string.ascii_lowercase + return ''.join(random.choice(letters) for i in range(stringLength)) From b82e4045d13420951ce908b0f048abfe41e9de7a Mon Sep 17 00:00:00 2001 From: replydev Date: Wed, 20 May 2020 16:38:11 +0200 Subject: [PATCH 2/2] Set default download location --- deemix/app/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deemix/app/settings.py b/deemix/app/settings.py index 8e937e0..a25dc79 100644 --- a/deemix/app/settings.py +++ b/deemix/app/settings.py @@ -19,7 +19,7 @@ def initSettings(bot_mode = False): makedirs(configFolder, exist_ok=True) with open(path.join(currentFolder, 'default.json'), 'r') as d: defaultSettings = json.load(d) - defaultSettings['downloadLocation'] = "" + defaultSettings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music') if not path.isfile(path.join(configFolder, 'config.json')): with open(path.join(configFolder, 'config.json'), 'w') as f: json.dump(defaultSettings, f, indent=2)