From 5e4453a4310c89c19275d8677e3c4ad11c36de2b Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Thu, 14 Apr 2022 22:13:36 +0200 Subject: [PATCH] #2 - added settings option to specify a path for the login .cache file --- .gitignore | 5 ++++- SpotifyAutoPlaylistCreator.py | 11 ++++++++--- SpotifyBackup.py | 12 +++++++++--- config/settings-creator-example.json | 3 ++- config/settings-example.json | 3 ++- pyproject.toml | 2 +- version.json | 6 +++--- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index b42aeed..f34077a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ exports/ config/settings.json config/settings-import.json -config/settings-creator.json \ No newline at end of file +config/settings-creator.json + +.cache +.cache_creator diff --git a/SpotifyAutoPlaylistCreator.py b/SpotifyAutoPlaylistCreator.py index e0630dc..1b5ce81 100644 --- a/SpotifyAutoPlaylistCreator.py +++ b/SpotifyAutoPlaylistCreator.py @@ -3,6 +3,7 @@ from typing import Dict, List import spotipy from TheCodeLabs_BaseUtils.DefaultLogger import DefaultLogger +from spotipy import CacheFileHandler from spotipy.oauth2 import SpotifyOAuth LOG_FORMAT = '[%(levelname)-7s] - %(asctime)s - %(message)s' @@ -16,7 +17,8 @@ class SpotifyAutoPlaylistCreator: destinationPlaylistInfo: Dict[str, str], numberOfTracks: int, redirectUrl: str, - openBrowser: bool): + openBrowser: bool, + cacheFilePath: str): self._clientID = clientID self._clientSecret = clientSecret self._playlistInfo = playlistInfo @@ -24,6 +26,7 @@ class SpotifyAutoPlaylistCreator: self._numberOfTracks = numberOfTracks self._redirectUrl = redirectUrl self._openBrowser = openBrowser + self._cacheFilePath = cacheFilePath self._spotify = self.login() @@ -32,7 +35,8 @@ class SpotifyAutoPlaylistCreator: client_secret=self._clientSecret, redirect_uri=self._redirectUrl, scope='playlist-modify-private,playlist-modify-public', - open_browser=self._openBrowser) + open_browser=self._openBrowser, + cache_handler=CacheFileHandler(cache_path=self._cacheFilePath)) return spotipy.Spotify(client_credentials_manager=client_credentials_manager) def run(self): @@ -111,7 +115,8 @@ if __name__ == '__main__': SETTINGS['destinationPlaylist'], SETTINGS['numberOfTracks'], SETTINGS['redirectUrl'], - SETTINGS['openBrowser']) + SETTINGS['openBrowser'], + SETTINGS['cacheFilePath']) spotifyBackup.run() diff --git a/SpotifyBackup.py b/SpotifyBackup.py index 8e5a161..247b3b5 100644 --- a/SpotifyBackup.py +++ b/SpotifyBackup.py @@ -4,6 +4,7 @@ from typing import Dict, List import spotipy from TheCodeLabs_BaseUtils.DefaultLogger import DefaultLogger +from spotipy import CacheFileHandler from spotipy.oauth2 import SpotifyClientCredentials from BackupHandler import BackupHandler @@ -13,14 +14,18 @@ LOGGER = DefaultLogger().create_logger_if_not_exists('SpotifyBackup', logFormat= class SpotifyBackup(BackupHandler): - def __init__(self, clientID: str, clientSecret: str, exportFolder: str, playlists: List[Dict[str, str]]): + def __init__(self, clientID: str, clientSecret: str, exportFolder: str, + playlists: List[Dict[str, str]], cacheFilePath: str): self._clientSecret = clientSecret + self._cacheFilePath = cacheFilePath super().__init__(exportFolder, clientID) self._playlists = playlists def login(self) -> spotipy.Spotify: client_credentials_manager = SpotifyClientCredentials(client_id=self._clientID, - client_secret=self._clientSecret) + client_secret=self._clientSecret, + cache_handler=CacheFileHandler( + cache_path=self._cacheFilePath)) return spotipy.Spotify(client_credentials_manager=client_credentials_manager) def backup(self): @@ -82,7 +87,8 @@ if __name__ == '__main__': spotifyBackup = SpotifyBackup(SETTINGS['spotifyAPI']['clientID'], SETTINGS['spotifyAPI']['clientSecret'], SETTINGS['exportFolder'], - SETTINGS['playlists']) + SETTINGS['playlists'], + SETTINGS['cacheFilePath']) spotifyBackup.clean_old_exports(SETTINGS['daysToKeep']) spotifyBackup.backup() diff --git a/config/settings-creator-example.json b/config/settings-creator-example.json index 3b95af2..9306a6c 100644 --- a/config/settings-creator-example.json +++ b/config/settings-creator-example.json @@ -16,5 +16,6 @@ }, "numberOfTracks": 10, "redirectUrl": "http://localhost:8080", - "openBrowser": false + "openBrowser": false, + "cacheFilePath": ".cache" } \ No newline at end of file diff --git a/config/settings-example.json b/config/settings-example.json index d1430ac..24cd87c 100644 --- a/config/settings-example.json +++ b/config/settings-example.json @@ -10,5 +10,6 @@ "user": "", "id": "" } - ] + ], + "cacheFilePath": ".cache" } \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 28dd488..16950eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "SpotifyBackup" -version = "1.7.0" +version = "1.8.1" description = "Simple script for backing up public playlists from Spotify." authors = ["deadlocker8"] diff --git a/version.json b/version.json index 07555cc..cdd0376 100644 --- a/version.json +++ b/version.json @@ -1,7 +1,7 @@ { "version": { - "name": "v1.8.0", - "code": 10, - "date": "26.03.22" + "name": "v1.8.1", + "code": 11, + "date": "14.04.22" } } \ No newline at end of file -- GitLab