diff options
| author | Winman486 <harpsystems@gmail.com> | 2025-10-21 15:23:18 -0500 |
|---|---|---|
| committer | Winman486 <harpsystems@gmail.com> | 2025-10-21 15:23:18 -0500 |
| commit | e9070eef66622ac80c9e7a68b00aa268e669e8fa (patch) | |
| tree | 8366d7f88b411fc583ef06427a10584c1ef93af6 /tidal_dl_ng/config.py | |
| parent | 6c1704e3c466e043acf6afcb7929b27d131df92f (diff) | |
| download | tidal-dl-ng-e9070eef66622ac80c9e7a68b00aa268e669e8fa.tar.gz | |
refactor: Make rate limiting configurable and move session validation to Tidal class
- Add api_rate_limit_batch_size and api_rate_limit_delay_sec to Settings (cfg.py)
- Move validate_session() and is_authentication_error() to Tidal class (config.py)
- Update _load_albums_with_rate_limiting() to use config values instead of hardcoded 20/3
- Update _handle_album_load_error() to use Tidal.is_authentication_error()
- Remove _validate_session() from gui.py (now uses Tidal.validate_session())
- Addresses maintainer feedback: configurable tweaking variables and proper separation of concerns
Diffstat (limited to 'tidal_dl_ng/config.py')
| -rw-r--r-- | tidal_dl_ng/config.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tidal_dl_ng/config.py b/tidal_dl_ng/config.py index 72b9f93..f390e4c 100644 --- a/tidal_dl_ng/config.py +++ b/tidal_dl_ng/config.py @@ -190,6 +190,26 @@ class Tidal(BaseConfig, metaclass=SingletonMeta): return True + def validate_session(self) -> bool: + """Validate that the TIDAL session is still authenticated. + + Returns: + bool: True if session is valid, False otherwise. + """ + return self.session.check_login() + + def is_authentication_error(self, error: Exception) -> bool: + """Check if an error is related to authentication/OAuth issues. + + Args: + error (Exception): The exception to check. + + Returns: + bool: True if the error is authentication-related, False otherwise. + """ + error_msg = str(error) + return "401" in error_msg or "OAuth" in error_msg or "token" in error_msg.lower() + class HandlingApp(metaclass=SingletonMeta): event_abort: Event = Event() |
