diff options
| author | Robert Honz <exislow+github@gmail.com> | 2025-08-13 08:17:11 +0200 |
|---|---|---|
| committer | Robert Honz <exislow+github@gmail.com> | 2025-08-13 08:17:11 +0200 |
| commit | 8dd75897e3c138826893cb99822dbeebc8efc54c (patch) | |
| tree | d72769d332592460899441abd32c8644894d657c /tidal_dl_ng | |
| parent | 0d8bc88f96e4e60b258f3b88b19f9114c2ef99c6 (diff) | |
| download | tidal-dl-ng-8dd75897e3c138826893cb99822dbeebc8efc54c.tar.gz | |
refactor(constants): streamline enums and enhance type annotations
This commit refactors the codebase to improve readability and maintainability by updating enums and type annotations:
- ✨ **Replaced `StrEnum` attributes**: Removed explicit type declarations for enum values to simplify the code.
- 🛠️ **Introduced `AudioExtensionsValid` enum**: Added a new enum for valid audio file extensions.
- 🔄 **Enhanced type annotations**: Updated `FAVORITES` dictionary to include specific type hints for clarity.
- 🧹 **Updated references**: Replaced outdated `AudioExtensions` usage with the new `AudioExtensionsValid`.
These changes improve code clarity, enforce stricter typing, and enhance extensibility.
Diffstat (limited to 'tidal_dl_ng')
| -rw-r--r-- | tidal_dl_ng/constants.py | 59 | ||||
| -rw-r--r-- | tidal_dl_ng/download.py | 3 |
2 files changed, 36 insertions, 26 deletions
diff --git a/tidal_dl_ng/constants.py b/tidal_dl_ng/constants.py index 300a403..2e75153 100644 --- a/tidal_dl_ng/constants.py +++ b/tidal_dl_ng/constants.py @@ -16,48 +16,57 @@ FORMAT_TEMPLATE_EXPLICIT: str = " (Explicit)" class QualityVideo(StrEnum): - P360: str = "360" - P480: str = "480" - P720: str = "720" - P1080: str = "1080" + P360 = "360" + P480 = "480" + P720 = "720" + P1080 = "1080" class MediaType(StrEnum): - TRACK: str = "track" - VIDEO: str = "video" - PLAYLIST: str = "playlist" - ALBUM: str = "album" - MIX: str = "mix" - ARTIST: str = "artist" + TRACK = "track" + VIDEO = "video" + PLAYLIST = "playlist" + ALBUM = "album" + MIX = "mix" + ARTIST = "artist" class CoverDimensions(StrEnum): - Px80: str = "80" - Px160: str = "160" - Px320: str = "320" - Px640: str = "640" - Px1280: str = "1280" - PxORIGIN: str = "origin" + Px80 = "80" + Px160 = "160" + Px320 = "320" + Px640 = "640" + Px1280 = "1280" + PxORIGIN = "origin" class TidalLists(StrEnum): - Playlists: str = "Playlists" - Favorites: str = "Favorites" - Mixes: str = "Mixes" + Playlists = "Playlists" + Favorites = "Favorites" + Mixes = "Mixes" class QueueDownloadStatus(StrEnum): - Waiting: str = "⏳️" - Downloading: str = "▶️" - Finished: str = "✅" - Failed: str = "❌" - Skipped: str = "↪️" + Waiting = "⏳️" + Downloading = "▶️" + Finished = "✅" + Failed = "❌" + Skipped = "↪️" -FAVORITES: {} = { +FAVORITES: dict[str, dict[str, str]] = { "fav_videos": {"name": "Videos", "function_name": "videos"}, "fav_tracks": {"name": "Tracks", "function_name": "tracks"}, "fav_mixes": {"name": "Mixes & Radio", "function_name": "mixes"}, "fav_artists": {"name": "Artists", "function_name": "artists"}, "fav_albums": {"name": "Albums", "function_name": "albums"}, } + + +class AudioExtensionsValid(StrEnum): + FLAC = ".flac" + M4A = ".m4a" + MP4 = ".mp4" + MP3 = ".mp3" + OGG = ".ogg" + ALAC = ".alac" diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py index cf95df8..56c3099 100644 --- a/tidal_dl_ng/download.py +++ b/tidal_dl_ng/download.py @@ -38,6 +38,7 @@ from tidal_dl_ng.constants import ( PLAYLIST_EXTENSION, PLAYLIST_PREFIX, REQUESTS_TIMEOUT_SEC, + AudioExtensionsValid, CoverDimensions, MediaType, QualityVideo, @@ -1496,7 +1497,7 @@ class Download: # Get all tracks in the directory path_tracks: list[pathlib.Path] = [] - for extension_audio in AudioExtensions: + for extension_audio in AudioExtensionsValid: path_tracks = path_tracks + list(dir_scoped.glob(f"*{extension_audio!s}")) # Sort alphabetically, e.g. if items are prefixed with numbers |
