This commit is contained in:
replydev 2020-05-20 16:36:01 +02:00
parent 8c2f2ee6af
commit 46594aa21b
2 changed files with 21 additions and 6 deletions

View File

@ -8,9 +8,10 @@ from os.path import isfile
@click.command() @click.command()
@click.option('-b', '--bitrate', default=None, help='Overwrites the default bitrate selected') @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) @click.argument('url', nargs=-1, required=True)
def download(bitrate, url): def download(bitrate, botmode, url):
settings = initSettings() settings = initSettings(botmode)
app.login() app.login()
if isfile(url[0]): if isfile(url[0]):
filename = url[0] filename = url[0]
@ -19,6 +20,8 @@ def download(bitrate, url):
for u in url: for u in url:
app.downloadLink(u, settings, bitrate) app.downloadLink(u, settings, bitrate)
click.echo("All done!") click.echo("All done!")
if botmode:
click.echo(settings['downloadLocation']) #folder name output
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -2,6 +2,8 @@
import json import json
import os.path as path import os.path as path
from os import makedirs from os import makedirs
import random
import string
import deemix.utils.localpaths as localpaths import deemix.utils.localpaths as localpaths
@ -9,7 +11,7 @@ settings = {}
defaultSettings = {} defaultSettings = {}
def initSettings(): def initSettings(bot_mode = False):
global settings global settings
global defaultSettings global defaultSettings
currentFolder = path.abspath(path.dirname(__file__)) currentFolder = path.abspath(path.dirname(__file__))
@ -17,15 +19,20 @@ def initSettings():
makedirs(configFolder, exist_ok=True) makedirs(configFolder, exist_ok=True)
with open(path.join(currentFolder, 'default.json'), 'r') as d: with open(path.join(currentFolder, 'default.json'), 'r') as d:
defaultSettings = json.load(d) defaultSettings = json.load(d)
defaultSettings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music') defaultSettings['downloadLocation'] = ""
if not path.isfile(path.join(configFolder, 'config.json')): if not path.isfile(path.join(configFolder, 'config.json')):
with open(path.join(configFolder, 'config.json'), 'w') as f: with open(path.join(configFolder, 'config.json'), 'w') as f:
json.dump(defaultSettings, f, indent=2) json.dump(defaultSettings, f, indent=2)
with open(path.join(configFolder, 'config.json'), 'r') as configFile: with open(path.join(configFolder, 'config.json'), 'r') as configFile:
settings = json.load(configFile) settings = json.load(configFile)
settingsCheck() 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) saveSettings(settings)
makedirs(settings['downloadLocation'], exist_ok=True) makedirs(settings['downloadLocation'], exist_ok=True)
return settings return settings
@ -63,3 +70,8 @@ def settingsCheck():
changes += 1 changes += 1
if changes > 0: if changes > 0:
saveSettings(settings) saveSettings(settings)
def randomString(stringLength=8):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))