Started working on the UI

This commit is contained in:
RemixDev 2020-04-08 00:19:27 +02:00
parent e0cc901a9d
commit 6daf0f1a1c
4 changed files with 83 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import click
import deemix.app.main as app
import deemix.app.cli as app
from deemix.app.settings import initSettings
@click.command()

56
deemix/app/cli.py Normal file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python3
from deemix.api.deezer import Deezer
import deemix.utils.localpaths as localpaths
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
from deemix.app.downloader import download_track, download_album, download_playlist, download_artist, download_spotifytrack, download_spotifyalbum
from os import system as execute
import os.path as path
from os import mkdir
dz = Deezer()
def requestValidArl():
while True:
arl = input("Paste here your arl:")
if dz.login_via_arl(arl):
break
return arl
def login():
configFolder = localpaths.getConfigFolder()
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.read()
if not dz.login_via_arl(arl):
arl = requestValidArl()
else:
arl = requestValidArl()
with open(path.join(configFolder, '.arl'), 'w') as f:
f.write(arl)
def downloadLink(url, settings, bitrate=None):
forcedBitrate = getBitrateInt(bitrate)
type = getTypeFromLink(url)
id = getIDFromLink(url, type)
folder = settings['downloadLocation']
if type == None or id == None:
print("URL not recognized")
if type == "track":
folder = download_track(dz, id, settings, forcedBitrate)
elif type == "album":
folder = download_album(dz, id, settings, forcedBitrate)
elif type == "playlist":
folder = download_playlist(dz, id, settings, forcedBitrate)
elif type == "artist":
download_artist(dz, id, settings, forcedBitrate)
elif type == "spotifytrack":
folder = download_spotifytrack(dz, id, settings, forcedBitrate)
elif type == "spotifyalbum":
folder = download_spotifyalbum(dz, id, settings, forcedBitrate)
else:
print("URL not supported yet")
return None
if settings['executeCommand'] != "":
execute(settings['executeCommand'].replace("%folder%", folder))

View File

@ -1,13 +1,14 @@
#!/usr/bin/env python3
from deemix.api.deezer import Deezer
import deemix.utils.localpaths as localpaths
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt
from deemix.utils.misc import getIDFromLink, getTypeFromLink, getBitrateInt, isValidLink
from deemix.app.downloader import download_track, download_album, download_playlist, download_artist, download_spotifytrack, download_spotifyalbum
from deemix.app.settings import initSettings
from os import system as execute
import os.path as path
from os import mkdir, rmdir
dz = Deezer()
settings = {}
def requestValidArl():
while True:
@ -30,8 +31,22 @@ def login():
with open(path.join(configFolder, '.arl'), 'w') as f:
f.write(arl)
def initialize():
global settings
settings = initSettings()
login()
return True
def downloadLink(url, settings, bitrate=None):
def search(term):
if isValidLink(term):
downloadLink(term)
return {"message": "Downloaded!"}
result = dz.search(term, "track")
print(result)
return result
def downloadLink(url, bitrate=None):
global settings
forcedBitrate = getBitrateInt(bitrate)
type = getTypeFromLink(url)
id = getIDFromLink(url, type)

View File

@ -84,3 +84,11 @@ def getTypeFromLink(link):
elif '/artist' in link:
type = 'artist'
return type
def isValidLink(text):
if text.lower().startswith("http"):
if "deezer.com" in text.lower() or "open.spotify.com" in text.lower():
return True
elif text.lower().startswith("spotify:"):
return True
return False