removed --local and added --portable

This commit is contained in:
RemixDev 2020-09-03 16:13:57 +02:00
parent 01dc66dadd
commit e0fcdaedbb
2 changed files with 18 additions and 19 deletions

View File

@ -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()

View File

@ -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")