deemix-py/deemix/app/cli.py

43 lines
1.5 KiB
Python
Raw Normal View History

from pathlib import Path
2020-09-03 14:13:57 +00:00
from os import makedirs
2020-08-15 21:03:05 +00:00
from deemix.app import deemix
from deemix.utils import checkFolder
2020-08-15 21:03:05 +00:00
class cli(deemix):
def __init__(self, downloadpath, configFolder=None):
2020-08-15 21:03:05 +00:00
super().__init__(configFolder)
if downloadpath:
if checkFolder(downloadpath):
self.set.settings['downloadLocation'] = str(downloadpath)
print("Using 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(";"):
2020-09-13 17:26:53 +00:00
self.qm.addToQueue(self.dz, l, self.set.settings, bitrate)
2020-08-15 21:03:05 +00:00
else:
2020-09-13 17:26:53 +00:00
self.qm.addToQueue(self.dz, link, self.set.settings, bitrate)
2020-08-15 21:03:05 +00:00
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 = Path(self.set.configFolder)
if not configFolder.is_dir():
2020-09-03 14:13:57 +00:00
makedirs(configFolder, exist_ok=True)
if (configFolder / '.arl').is_file():
with open(configFolder / '.arl', 'r') as f:
2020-08-15 21:03:05 +00:00
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(configFolder / '.arl', 'w') as f:
2020-08-15 21:03:05 +00:00
f.write(arl)