From c3a35390734956d1ec06579090e2721f8c7517a8 Mon Sep 17 00:00:00 2001 From: "cool.gitter.choco" Date: Sat, 25 Jan 2025 18:20:01 -0600 Subject: [PATCH] Created utils for playlist, album and track download --- .gitignore | 4 ++- routes/utils/album.py | 60 ++++++++++++++++++++++++++++++++++++++++ routes/utils/playlist.py | 60 ++++++++++++++++++++++++++++++++++++++++ routes/utils/track.py | 59 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 routes/utils/album.py create mode 100644 routes/utils/playlist.py create mode 100644 routes/utils/track.py diff --git a/.gitignore b/.gitignore index 922c41b..17c19b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /credentials.json /test.py /venv -/downloads/ \ No newline at end of file +/downloads/ +/creds/ +Test.py diff --git a/routes/utils/album.py b/routes/utils/album.py new file mode 100644 index 0000000..b98154f --- /dev/null +++ b/routes/utils/album.py @@ -0,0 +1,60 @@ +import os +import json +import traceback +from deezspot.spotloader import SpoLogin +from deezspot.deezloader import DeeLogin + +def download_album(service, url, account): + try: + if service == 'spotify': + # Construct Spotify credentials path + creds_dir = os.path.join('./creds/spotify', account) + credentials_path = os.path.abspath(os.path.join(creds_dir, 'credentials.json')) + + # Initialize Spotify client + spo = SpoLogin(credentials_path=credentials_path) + + # Download Spotify album + spo.download_album( + link_album=url, + output_dir="./downloads/albums", + quality_download="NORMAL", + recursive_quality=True, + recursive_download=False, + not_interface=False, + method_save=1, + make_zip=True + ) + + elif service == 'deezer': + # Construct Deezer credentials path + creds_dir = os.path.join('./creds/deezer', account) + creds_path = os.path.abspath(os.path.join(creds_dir, 'credentials.json')) + + # Load Deezer credentials + with open(creds_path, 'r') as f: + creds = json.load(f) + + # Initialize Deezer client + dl = DeeLogin( + arl=creds.get('arl', ''), + email=creds.get('email', ''), + password=creds.get('password', '') + ) + + # Download Deezer album + dl.download_albumdee( + link_album=url, + output_dir="./downloads/albums", + quality_download="FLAC", + recursive_quality=True, + recursive_download=False, + method_save=1 + ) + + else: + raise ValueError(f"Unsupported service: {service}") + + except Exception as e: + traceback.print_exc() + raise \ No newline at end of file diff --git a/routes/utils/playlist.py b/routes/utils/playlist.py new file mode 100644 index 0000000..3d05504 --- /dev/null +++ b/routes/utils/playlist.py @@ -0,0 +1,60 @@ +import os +import json +import traceback +from deezspot.spotloader import SpoLogin +from deezspot.deezloader import DeeLogin + +def download_playlist(service, url, account): + try: + if service == 'spotify': + # Construct Spotify credentials path + creds_dir = os.path.join('./creds/spotify', account) + credentials_path = os.path.abspath(os.path.join(creds_dir, 'credentials.json')) + + # Initialize Spotify client + spo = SpoLogin(credentials_path=credentials_path) + + # Download Spotify playlist + spo.download_playlist( + link_playlist=url, + output_dir="./downloads/playlists", + quality_download="NORMAL", + recursive_quality=True, + recursive_download=False, + not_interface=False, + method_save=1, + make_zip=True + ) + + elif service == 'deezer': + # Construct Deezer credentials path + creds_dir = os.path.join('./creds/deezer', account) + creds_path = os.path.abspath(os.path.join(creds_dir, 'credentials.json')) + + # Load Deezer credentials + with open(creds_path, 'r') as f: + creds = json.load(f) + + # Initialize Deezer client + dl = DeeLogin( + arl=creds.get('arl', ''), + email=creds.get('email', ''), + password=creds.get('password', '') + ) + + # Download Deezer playlist + dl.download_playlistdee( + link_playlist=url, + output_dir="./downloads/playlists", + quality_download="FLAC", + recursive_quality=False, + recursive_download=False, + method_save=1 + ) + + else: + raise ValueError(f"Unsupported service: {service}") + + except Exception as e: + traceback.print_exc() + raise \ No newline at end of file diff --git a/routes/utils/track.py b/routes/utils/track.py new file mode 100644 index 0000000..8b62eb7 --- /dev/null +++ b/routes/utils/track.py @@ -0,0 +1,59 @@ +import os +import json +import traceback +from deezspot.spotloader import SpoLogin +from deezspot.deezloader import DeeLogin + +def download_track(service, url, account): + try: + if service == 'spotify': + # Construct Spotify credentials path + creds_dir = os.path.join('./creds/spotify', account) + credentials_path = os.path.abspath(os.path.join(creds_dir, 'credentials.json')) + + # Initialize Spotify client + spo = SpoLogin(credentials_path=credentials_path) + + # Download Spotify track + spo.download_track( + link_track=url, + output_dir="./downloads/tracks", + quality_download="NORMAL", + recursive_quality=False, + recursive_download=False, + not_interface=False, + method_save=1 + ) + + elif service == 'deezer': + # Construct Deezer credentials path + creds_dir = os.path.join('./creds/deezer', account) + creds_path = os.path.abspath(os.path.join(creds_dir, 'credentials.json')) + + # Load Deezer credentials + with open(creds_path, 'r') as f: + creds = json.load(f) + + # Initialize Deezer client + dl = DeeLogin( + arl=creds.get('arl', ''), + email=creds.get('email', ''), + password=creds.get('password', '') + ) + + # Download Deezer track + dl.download_trackdee( + link_track=url, + output_dir="./downloads/tracks", + quality_download="FLAC", + recursive_quality=False, + recursive_download=False, + method_save=1 + ) + + else: + raise ValueError(f"Unsupported service: {service}") + + except Exception as e: + traceback.print_exc() + raise \ No newline at end of file