deemix-py/deemix/app/cli.py

51 lines
1.7 KiB
Python
Raw Normal View History

2020-04-07 22:19:27 +00:00
#!/usr/bin/env python3
import os.path as path
2020-08-15 21:03:05 +00:00
import string
import random
2020-06-13 07:58:45 +00:00
from os import mkdir
2020-08-15 21:03:05 +00:00
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):
2020-08-15 21:03:05 +00:00
super().__init__(configFolder)
if path:
self.set.settings['downloadLocation'] = str(path)
print("Using folder: "+self.set.settings['downloadLocation'])
2020-08-15 21:03:05 +00:00
if local:
self.set.settings['downloadLocation'] = randomString(12)
2020-08-29 14:09:35 +00:00
print("Using a local download folder: "+self.set.settings['downloadLocation'])
2020-08-15 21:03:05 +00:00
def downloadLink(self, url, bitrate=None):
for link in url:
if ';' in link:
for l in link.split(";"):
self.qm.addToQueue(self.dz, self.sp, l, self.set.settings, bitrate)
else:
self.qm.addToQueue(self.dz, self.sp, link, self.set.settings, bitrate)
def requestValidArl(self):
while True:
arl = input("Paste here your arl:")
if self.dz.login_via_arl(arl):
break
return arl
def login(self):
configFolder = self.set.configFolder
if not path.isdir(configFolder):
mkdir(configFolder)
if path.isfile(path.join(configFolder, '.arl')):
with open(path.join(configFolder, '.arl'), 'r') as f:
arl = f.readline().rstrip("\n")
if not self.dz.login_via_arl(arl):
arl = self.requestValidArl()
else:
2020-08-15 21:03:05 +00:00
arl = self.requestValidArl()
with open(path.join(configFolder, '.arl'), 'w') as f:
f.write(arl)