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.
This commit is contained in:
+34
-25
@@ -16,48 +16,57 @@ FORMAT_TEMPLATE_EXPLICIT: str = " (Explicit)"
|
|||||||
|
|
||||||
|
|
||||||
class QualityVideo(StrEnum):
|
class QualityVideo(StrEnum):
|
||||||
P360: str = "360"
|
P360 = "360"
|
||||||
P480: str = "480"
|
P480 = "480"
|
||||||
P720: str = "720"
|
P720 = "720"
|
||||||
P1080: str = "1080"
|
P1080 = "1080"
|
||||||
|
|
||||||
|
|
||||||
class MediaType(StrEnum):
|
class MediaType(StrEnum):
|
||||||
TRACK: str = "track"
|
TRACK = "track"
|
||||||
VIDEO: str = "video"
|
VIDEO = "video"
|
||||||
PLAYLIST: str = "playlist"
|
PLAYLIST = "playlist"
|
||||||
ALBUM: str = "album"
|
ALBUM = "album"
|
||||||
MIX: str = "mix"
|
MIX = "mix"
|
||||||
ARTIST: str = "artist"
|
ARTIST = "artist"
|
||||||
|
|
||||||
|
|
||||||
class CoverDimensions(StrEnum):
|
class CoverDimensions(StrEnum):
|
||||||
Px80: str = "80"
|
Px80 = "80"
|
||||||
Px160: str = "160"
|
Px160 = "160"
|
||||||
Px320: str = "320"
|
Px320 = "320"
|
||||||
Px640: str = "640"
|
Px640 = "640"
|
||||||
Px1280: str = "1280"
|
Px1280 = "1280"
|
||||||
PxORIGIN: str = "origin"
|
PxORIGIN = "origin"
|
||||||
|
|
||||||
|
|
||||||
class TidalLists(StrEnum):
|
class TidalLists(StrEnum):
|
||||||
Playlists: str = "Playlists"
|
Playlists = "Playlists"
|
||||||
Favorites: str = "Favorites"
|
Favorites = "Favorites"
|
||||||
Mixes: str = "Mixes"
|
Mixes = "Mixes"
|
||||||
|
|
||||||
|
|
||||||
class QueueDownloadStatus(StrEnum):
|
class QueueDownloadStatus(StrEnum):
|
||||||
Waiting: str = "⏳️"
|
Waiting = "⏳️"
|
||||||
Downloading: str = "▶️"
|
Downloading = "▶️"
|
||||||
Finished: str = "✅"
|
Finished = "✅"
|
||||||
Failed: str = "❌"
|
Failed = "❌"
|
||||||
Skipped: str = "↪️"
|
Skipped = "↪️"
|
||||||
|
|
||||||
|
|
||||||
FAVORITES: {} = {
|
FAVORITES: dict[str, dict[str, str]] = {
|
||||||
"fav_videos": {"name": "Videos", "function_name": "videos"},
|
"fav_videos": {"name": "Videos", "function_name": "videos"},
|
||||||
"fav_tracks": {"name": "Tracks", "function_name": "tracks"},
|
"fav_tracks": {"name": "Tracks", "function_name": "tracks"},
|
||||||
"fav_mixes": {"name": "Mixes & Radio", "function_name": "mixes"},
|
"fav_mixes": {"name": "Mixes & Radio", "function_name": "mixes"},
|
||||||
"fav_artists": {"name": "Artists", "function_name": "artists"},
|
"fav_artists": {"name": "Artists", "function_name": "artists"},
|
||||||
"fav_albums": {"name": "Albums", "function_name": "albums"},
|
"fav_albums": {"name": "Albums", "function_name": "albums"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AudioExtensionsValid(StrEnum):
|
||||||
|
FLAC = ".flac"
|
||||||
|
M4A = ".m4a"
|
||||||
|
MP4 = ".mp4"
|
||||||
|
MP3 = ".mp3"
|
||||||
|
OGG = ".ogg"
|
||||||
|
ALAC = ".alac"
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ from tidal_dl_ng.constants import (
|
|||||||
PLAYLIST_EXTENSION,
|
PLAYLIST_EXTENSION,
|
||||||
PLAYLIST_PREFIX,
|
PLAYLIST_PREFIX,
|
||||||
REQUESTS_TIMEOUT_SEC,
|
REQUESTS_TIMEOUT_SEC,
|
||||||
|
AudioExtensionsValid,
|
||||||
CoverDimensions,
|
CoverDimensions,
|
||||||
MediaType,
|
MediaType,
|
||||||
QualityVideo,
|
QualityVideo,
|
||||||
@@ -1496,7 +1497,7 @@ class Download:
|
|||||||
# Get all tracks in the directory
|
# Get all tracks in the directory
|
||||||
path_tracks: list[pathlib.Path] = []
|
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}"))
|
path_tracks = path_tracks + list(dir_scoped.glob(f"*{extension_audio!s}"))
|
||||||
|
|
||||||
# Sort alphabetically, e.g. if items are prefixed with numbers
|
# Sort alphabetically, e.g. if items are prefixed with numbers
|
||||||
|
|||||||
Reference in New Issue
Block a user