summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-04-02 16:26:57 +0200
committerRobert Honz <exislow+github@gmail.com>2024-04-02 16:26:57 +0200
commitfe5d9880cb96f9f3cde2a483c54b0f90a1da322a (patch)
treeab45ee418f30ae8f140a6357792c61f3dbf8b0c6
parent007900eafeea8215c041e9d47d9bd9af4cf5812b (diff)
downloadtidal-dl-ng-fe5d9880cb96f9f3cde2a483c54b0f90a1da322a.tar.gz
👷 Cleanup of `. value` usage for Enum access.
-rw-r--r--tidal_dl_ng/constants.py8
-rw-r--r--tidal_dl_ng/download.py34
-rw-r--r--tidal_dl_ng/gui.py26
-rw-r--r--tidal_dl_ng/helper/path.py2
4 files changed, 35 insertions, 35 deletions
diff --git a/tidal_dl_ng/constants.py b/tidal_dl_ng/constants.py
index cd1caa7..91cb0f3 100644
--- a/tidal_dl_ng/constants.py
+++ b/tidal_dl_ng/constants.py
@@ -1,4 +1,4 @@
-from enum import StrEnum
+from enum import IntEnum, StrEnum
CTX_TIDAL: str = "tidal"
REQUESTS_TIMEOUT_SEC: int = 45
@@ -7,7 +7,7 @@ UNIQUIFY_THRESHOLD: int = 99
FILENAME_SANITIZE_PLACEHOLDER: str = "_"
-class QualityVideo(StrEnum):
+class QualityVideo(IntEnum):
P360: int = 360
P480: int = 480
P720: int = 720
@@ -23,7 +23,7 @@ class MediaType(StrEnum):
class SkipExisting(StrEnum):
- Disabled: bool = False
+ Disabled: str = "False"
Filename: str = "exact"
ExtensionIgnore: str = "extension_ignore"
Append: str = "append"
@@ -35,7 +35,7 @@ class StreamManifestMimeType(StrEnum):
VIDEO: str = "video/mp2t"
-class CoverDimensions(StrEnum):
+class CoverDimensions(IntEnum):
Px80: int = 80
Px160: int = 160
Px320: int = 320
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py
index 3b9a3f4..4ad3af2 100644
--- a/tidal_dl_ng/download.py
+++ b/tidal_dl_ng/download.py
@@ -59,7 +59,7 @@ class RequestsClient:
class Download:
settings: Settings
session: Session
- skip_existing: SkipExisting = False
+ skip_existing: SkipExisting = SkipExisting.Disabled
fn_logger: Callable
progress_gui: ProgressBars
progress: Progress
@@ -210,7 +210,7 @@ class Download:
mime_type: str = stream.manifest_mime_type
else:
manifest: str = media.get_url()
- mime_type: str = StreamManifestMimeType.VIDEO.value
+ mime_type: str = StreamManifestMimeType.VIDEO
stream_manifest = self.stream_manifest_parse(manifest, mime_type)
@@ -225,7 +225,7 @@ class Download:
path_file = path_file_sanitize(path_file + stream_manifest.file_extension, adapt=True, uniquify=uniquify)
# Compute if and how downloads need to be skipped.
- if self.skip_existing.value in (SkipExisting.ExtensionIgnore.value, SkipExisting.Filename.value):
+ if self.skip_existing in (SkipExisting.ExtensionIgnore, SkipExisting.Filename):
extension_ignore: bool = self.skip_existing == SkipExisting.ExtensionIgnore
file_exists: bool = check_file_exists(path_file, extension_ignore=extension_ignore)
else:
@@ -327,7 +327,7 @@ class Download:
totaltrack=track.album.num_tracks if track.album and track.album.num_tracks else 1,
totaldisc=track.album.num_volumes if track.album and track.album.num_volumes else 1,
discnumber=track.volume_num if track.volume_num else 1,
- url_cover=track.album.image(self.settings.data.metadata_cover_dimension.value),
+ url_cover=track.album.image(self.settings.data.metadata_cover_dimension),
)
m.save()
@@ -408,28 +408,28 @@ class Download:
return result
def get_file_extension(self, stream_url: str, stream_codec: str) -> str:
- if AudioExtensions.FLAC.value in stream_url:
- result: str = AudioExtensions.FLAC.value
- elif AudioExtensions.MP4.value in stream_url:
+ if AudioExtensions.FLAC in stream_url:
+ result: str = AudioExtensions.FLAC
+ elif AudioExtensions.MP4 in stream_url:
if "ac4" in stream_codec or "mha1" in stream_codec or "flac" in stream_codec or "mp4a" in stream_codec:
- result: str = AudioExtensions.M4A.value
+ result: str = AudioExtensions.M4A
else:
- result: str = AudioExtensions.MP4.value
- elif VideoExtensions.TS.value in stream_url:
- result: str = VideoExtensions.TS.value
+ result: str = AudioExtensions.MP4
+ elif VideoExtensions.TS in stream_url:
+ result: str = VideoExtensions.TS
else:
- result: str = AudioExtensions.MP4.value
+ result: str = AudioExtensions.MP4
return result
def _video_convert(self, path_file: str) -> str:
- path_file_out = os.path.splitext(path_file)[0] + AudioExtensions.MP4.value
+ path_file_out = os.path.splitext(path_file)[0] + AudioExtensions.MP4
result, _ = ffmpeg.input(path_file).output(path_file_out, map=0, c="copy").run()
return path_file_out
def stream_manifest_parse(self, manifest: str, mime_type: str) -> StreamManifest:
- if mime_type == StreamManifestMimeType.MPD.value:
+ if mime_type == StreamManifestMimeType.MPD:
# Stream Manifest is base64 encoded.
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
mpd = MPEGDASHParser.parse(manifest_parsed)
@@ -451,7 +451,7 @@ class Download:
for index in range(segments_count):
stream_urls.append(segment_template.media.replace("$Number$", str(index)))
- elif mime_type == StreamManifestMimeType.BTS.value:
+ elif mime_type == StreamManifestMimeType.BTS:
# Stream Manifest is base64 encoded.
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
# JSON string to object.
@@ -464,11 +464,11 @@ class Download:
encryption_key: str | None = (
stream_manifest["encryptionKey"] if self.is_encrypted(encryption_type) else None
)
- elif mime_type == StreamManifestMimeType.VIDEO.value:
+ elif mime_type == StreamManifestMimeType.VIDEO:
# Parse M3U8 video playlist
m3u8_variant: m3u8.M3U8 = m3u8.load(manifest)
# Find the desired video resolution or the next best one.
- m3u8_playlist, codecs = self._extract_video_stream(m3u8_variant, self.settings.data.quality_video.value)
+ m3u8_playlist, codecs = self._extract_video_stream(m3u8_variant, self.settings.data.quality_video)
# Populate urls.
stream_urls: list[str] = m3u8_playlist.files
diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py
index d78f6d9..4f550cf 100644
--- a/tidal_dl_ng/gui.py
+++ b/tidal_dl_ng/gui.py
@@ -242,13 +242,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def on_populate_tree_lists(self, user_lists: [Playlist | UserPlaylist | Mix]):
twi_playlists: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
- TidalLists.Playlists.value, QtCore.Qt.MatchExactly, 0
+ TidalLists.Playlists, QtCore.Qt.MatchExactly, 0
)[0]
twi_mixes: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
- TidalLists.Favorites.value, QtCore.Qt.MatchExactly, 0
+ TidalLists.Favorites, QtCore.Qt.MatchExactly, 0
)[0]
twi_favorites: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
- TidalLists.Mixes.value, QtCore.Qt.MatchExactly, 0
+ TidalLists.Mixes, QtCore.Qt.MatchExactly, 0
)[0]
# Remove all children if present
@@ -543,7 +543,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
name=name,
quality="<quality>",
type_media=type(media).__name__,
- status=QueueDownloadStatus.Waiting.value,
+ status=QueueDownloadStatus.Waiting,
obj=media,
)
else:
@@ -618,14 +618,14 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.pb_list.setFormat(f"%p% {value}")
def on_quality_set_audio(self, index):
- self.settings.data.quality_audio = Quality(self.cb_quality_audio.itemData(index).value)
+ self.settings.data.quality_audio = Quality(self.cb_quality_audio.itemData(index))
self.settings.save()
if self.tidal:
self.tidal.settings_apply()
def on_quality_set_video(self, index):
- self.settings.data.quality_video = QualityVideo(self.cb_quality_video.itemData(index).value)
+ self.settings.data.quality_video = QualityVideo(self.cb_quality_video.itemData(index))
self.settings.save()
if self.tidal:
@@ -697,11 +697,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def on_queue_download_clear_all(self):
self.on_clear_queue_download(
- f"({QueueDownloadStatus.Waiting.value}|{QueueDownloadStatus.Finished.value}|{QueueDownloadStatus.Failed.value})"
+ f"({QueueDownloadStatus.Waiting}|{QueueDownloadStatus.Finished}|{QueueDownloadStatus.Failed})"
)
def on_queue_download_clear_finished(self):
- self.on_clear_queue_download(f"[{QueueDownloadStatus.Finished.value}]")
+ self.on_clear_queue_download(f"[{QueueDownloadStatus.Finished}]")
def on_clear_queue_download(self, regex: str):
items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.findItems(
@@ -720,7 +720,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
for item in items:
status: str = item.text(0)
- if status != QueueDownloadStatus.Downloading.value:
+ if status != QueueDownloadStatus.Downloading:
self.tr_queue_download.takeTopLevelItem(self.tr_queue_download.indexOfTopLevelItem(item))
else:
logger_gui.info("Cannot remove a currently downloading item from queue.")
@@ -753,7 +753,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def watcher_queue_download(self) -> None:
while True:
items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.findItems(
- QueueDownloadStatus.Waiting.value, QtCore.Qt.MatchFlag.MatchExactly, column=0
+ QueueDownloadStatus.Waiting, QtCore.Qt.MatchFlag.MatchExactly, column=0
)
if len(items) > 0:
@@ -770,13 +770,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
time.sleep(2)
def on_queue_download_item_downloading(self, item: QtWidgets.QTreeWidgetItem) -> None:
- self.queue_download_item_status(item, QueueDownloadStatus.Downloading.value)
+ self.queue_download_item_status(item, QueueDownloadStatus.Downloading)
def on_queue_download_item_finished(self, item: QtWidgets.QTreeWidgetItem) -> None:
- self.queue_download_item_status(item, QueueDownloadStatus.Finished.value)
+ self.queue_download_item_status(item, QueueDownloadStatus.Finished)
def on_queue_download_item_failed(self, item: QtWidgets.QTreeWidgetItem) -> None:
- self.queue_download_item_status(item, QueueDownloadStatus.Failed.value)
+ self.queue_download_item_status(item, QueueDownloadStatus.Failed)
def queue_download_item_status(self, item: QtWidgets.QTreeWidgetItem, status: str) -> None:
item.setText(0, status)
diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py
index 53d3290..df56654 100644
--- a/tidal_dl_ng/helper/path.py
+++ b/tidal_dl_ng/helper/path.py
@@ -236,7 +236,7 @@ def check_file_exists(path_file: str, extension_ignore: bool = False) -> bool:
path_files: [str] = []
for extension in AudioExtensions:
- path_files.append(str(path_parent.joinpath(path_file_stem + extension.value)))
+ path_files.append(str(path_parent.joinpath(path_file_stem + extension)))
else:
path_files: [str] = [path_file]