From e0fcdaedbb260921748aa6149a0976f4dca86ce6 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 3 Sep 2020 16:13:57 +0200 Subject: [PATCH] removed --local and added --portable --- deemix/__main__.py | 21 ++++++++++++++------- deemix/app/cli.py | 16 ++++------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/deemix/__main__.py b/deemix/__main__.py index 7e2fdfb..a32f8fc 100644 --- a/deemix/__main__.py +++ b/deemix/__main__.py @@ -2,25 +2,32 @@ import click from deemix.app.cli import cli -from os.path import isfile +import os.path @click.command() +@click.option('--portable', is_flag=True, help='Creates the config folder in the same directory where the script is launched') @click.option('-b', '--bitrate', default=None, help='Overwrites the default bitrate selected') -@click.option('-l', '--local', is_flag=True, help='Downloads in a local folder insted of using the default') @click.option('-p', '--path', type=str, help='Downloads in the given folder') @click.argument('url', nargs=-1, required=True) -def download(bitrate, local, url, path): - app = cli(local, path) +def download(url, bitrate, portable, path): + localpath = os.path.realpath('.') + + configFolder = None + if portable: + configFolder = os.path.join(localpath, 'config') + if path is not None: + if path == '': path = '.' + path = os.path.realpath(path) + + app = cli(path, configFolder) app.login() url = list(url) - if isfile(url[0]): + if os.path.isfile(url[0]): filename = url[0] with open(filename) as f: url = f.readlines() app.downloadLink(url, bitrate) click.echo("All done!") - if local: - click.echo(app.set.settings['downloadLocation']) #folder name output if __name__ == '__main__': download() diff --git a/deemix/app/cli.py b/deemix/app/cli.py index 4a4144e..2b4106f 100644 --- a/deemix/app/cli.py +++ b/deemix/app/cli.py @@ -1,24 +1,16 @@ #!/usr/bin/env python3 import os.path as path -import string -import random -from os import mkdir +from os import makedirs from deemix.app import deemix -def randomString(stringLength=8): - letters = string.ascii_lowercase - return ''.join(random.choice(letters) for i in range(stringLength)) - class cli(deemix): - def __init__(self, local, path, configFolder=None): + def __init__(self, path, configFolder=None): super().__init__(configFolder) if path: self.set.settings['downloadLocation'] = str(path) + makedirs(path, exist_ok=True) print("Using folder: "+self.set.settings['downloadLocation']) - if local: - self.set.settings['downloadLocation'] = randomString(12) - print("Using a local download folder: "+self.set.settings['downloadLocation']) def downloadLink(self, url, bitrate=None): for link in url: @@ -38,7 +30,7 @@ class cli(deemix): def login(self): configFolder = self.set.configFolder if not path.isdir(configFolder): - mkdir(configFolder) + makedirs(configFolder, exist_ok=True) if path.isfile(path.join(configFolder, '.arl')): with open(path.join(configFolder, '.arl'), 'r') as f: arl = f.readline().rstrip("\n")