From 6daf0f1a1c961242bae1cc75c4f440fd36f113a7 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Wed, 8 Apr 2020 00:19:27 +0200 Subject: [PATCH] Started working on the UI --- deemix/__main__.py | 2 +- deemix/app/cli.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ deemix/app/main.py | 21 ++++++++++++++--- deemix/utils/misc.py | 8 +++++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 deemix/app/cli.py diff --git a/deemix/__main__.py b/deemix/__main__.py index cd8d011..3ca28d8 100644 --- a/deemix/__main__.py +++ b/deemix/__main__.py @@ -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() diff --git a/deemix/app/cli.py b/deemix/app/cli.py new file mode 100644 index 0000000..167f33a --- /dev/null +++ b/deemix/app/cli.py @@ -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)) diff --git a/deemix/app/main.py b/deemix/app/main.py index 78d22e9..6ce66c6 100644 --- a/deemix/app/main.py +++ b/deemix/app/main.py @@ -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) diff --git a/deemix/utils/misc.py b/deemix/utils/misc.py index 31f241f..31213f1 100644 --- a/deemix/utils/misc.py +++ b/deemix/utils/misc.py @@ -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