diff --git a/.gitignore b/.gitignore index b42aeedce19278e7b17c864442f89e7aa844c497..f34077a8d0f05b2f13620e134b06fe2488882833 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 e0630dca66cd5558d0b78e03b11b8adb254946ae..1b5ce8185683e45b554abd860d66c87166c6ae14 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 8e5a161ab2292ee7e7ca7bf078081bf3704cf0e4..247b3b52b685081cff876d9d45678452e4f7d17b 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 3b95af2fb5cf9244301e1adc14ca6e1ec4883438..9306a6c43be8a7bcb0552d6d8ee6e6d0d16f7910 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 d1430aca77176cde3ce6fdd05e0ba8d287fe5e71..24cd87cd7df3e9ee58325bf602df0a74a2fe9f44 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 28dd4889dc9451c6aa043d9445fc5fa3d6aa464c..16950eba8dcb8a0a988274f397ddad56ae242319 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 07555ccd4ceea9af0bc1fdc68bd8f65bd9b8bcde..cdd0376ffb2c1cbd2b7270a303278e6aae5c0d1d 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