👷 Cleanup of . value usage for Enum access.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from enum import StrEnum
|
from enum import IntEnum, StrEnum
|
||||||
|
|
||||||
CTX_TIDAL: str = "tidal"
|
CTX_TIDAL: str = "tidal"
|
||||||
REQUESTS_TIMEOUT_SEC: int = 45
|
REQUESTS_TIMEOUT_SEC: int = 45
|
||||||
@@ -7,7 +7,7 @@ UNIQUIFY_THRESHOLD: int = 99
|
|||||||
FILENAME_SANITIZE_PLACEHOLDER: str = "_"
|
FILENAME_SANITIZE_PLACEHOLDER: str = "_"
|
||||||
|
|
||||||
|
|
||||||
class QualityVideo(StrEnum):
|
class QualityVideo(IntEnum):
|
||||||
P360: int = 360
|
P360: int = 360
|
||||||
P480: int = 480
|
P480: int = 480
|
||||||
P720: int = 720
|
P720: int = 720
|
||||||
@@ -23,7 +23,7 @@ class MediaType(StrEnum):
|
|||||||
|
|
||||||
|
|
||||||
class SkipExisting(StrEnum):
|
class SkipExisting(StrEnum):
|
||||||
Disabled: bool = False
|
Disabled: str = "False"
|
||||||
Filename: str = "exact"
|
Filename: str = "exact"
|
||||||
ExtensionIgnore: str = "extension_ignore"
|
ExtensionIgnore: str = "extension_ignore"
|
||||||
Append: str = "append"
|
Append: str = "append"
|
||||||
@@ -35,7 +35,7 @@ class StreamManifestMimeType(StrEnum):
|
|||||||
VIDEO: str = "video/mp2t"
|
VIDEO: str = "video/mp2t"
|
||||||
|
|
||||||
|
|
||||||
class CoverDimensions(StrEnum):
|
class CoverDimensions(IntEnum):
|
||||||
Px80: int = 80
|
Px80: int = 80
|
||||||
Px160: int = 160
|
Px160: int = 160
|
||||||
Px320: int = 320
|
Px320: int = 320
|
||||||
|
|||||||
+17
-17
@@ -59,7 +59,7 @@ class RequestsClient:
|
|||||||
class Download:
|
class Download:
|
||||||
settings: Settings
|
settings: Settings
|
||||||
session: Session
|
session: Session
|
||||||
skip_existing: SkipExisting = False
|
skip_existing: SkipExisting = SkipExisting.Disabled
|
||||||
fn_logger: Callable
|
fn_logger: Callable
|
||||||
progress_gui: ProgressBars
|
progress_gui: ProgressBars
|
||||||
progress: Progress
|
progress: Progress
|
||||||
@@ -210,7 +210,7 @@ class Download:
|
|||||||
mime_type: str = stream.manifest_mime_type
|
mime_type: str = stream.manifest_mime_type
|
||||||
else:
|
else:
|
||||||
manifest: str = media.get_url()
|
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)
|
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)
|
path_file = path_file_sanitize(path_file + stream_manifest.file_extension, adapt=True, uniquify=uniquify)
|
||||||
|
|
||||||
# Compute if and how downloads need to be skipped.
|
# 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
|
extension_ignore: bool = self.skip_existing == SkipExisting.ExtensionIgnore
|
||||||
file_exists: bool = check_file_exists(path_file, extension_ignore=extension_ignore)
|
file_exists: bool = check_file_exists(path_file, extension_ignore=extension_ignore)
|
||||||
else:
|
else:
|
||||||
@@ -327,7 +327,7 @@ class Download:
|
|||||||
totaltrack=track.album.num_tracks if track.album and track.album.num_tracks else 1,
|
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,
|
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,
|
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()
|
m.save()
|
||||||
@@ -408,28 +408,28 @@ class Download:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_file_extension(self, stream_url: str, stream_codec: str) -> str:
|
def get_file_extension(self, stream_url: str, stream_codec: str) -> str:
|
||||||
if AudioExtensions.FLAC.value in stream_url:
|
if AudioExtensions.FLAC in stream_url:
|
||||||
result: str = AudioExtensions.FLAC.value
|
result: str = AudioExtensions.FLAC
|
||||||
elif AudioExtensions.MP4.value in stream_url:
|
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:
|
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:
|
else:
|
||||||
result: str = AudioExtensions.MP4.value
|
result: str = AudioExtensions.MP4
|
||||||
elif VideoExtensions.TS.value in stream_url:
|
elif VideoExtensions.TS in stream_url:
|
||||||
result: str = VideoExtensions.TS.value
|
result: str = VideoExtensions.TS
|
||||||
else:
|
else:
|
||||||
result: str = AudioExtensions.MP4.value
|
result: str = AudioExtensions.MP4
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _video_convert(self, path_file: str) -> str:
|
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()
|
result, _ = ffmpeg.input(path_file).output(path_file_out, map=0, c="copy").run()
|
||||||
|
|
||||||
return path_file_out
|
return path_file_out
|
||||||
|
|
||||||
def stream_manifest_parse(self, manifest: str, mime_type: str) -> StreamManifest:
|
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.
|
# Stream Manifest is base64 encoded.
|
||||||
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
|
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
|
||||||
mpd = MPEGDASHParser.parse(manifest_parsed)
|
mpd = MPEGDASHParser.parse(manifest_parsed)
|
||||||
@@ -451,7 +451,7 @@ class Download:
|
|||||||
for index in range(segments_count):
|
for index in range(segments_count):
|
||||||
stream_urls.append(segment_template.media.replace("$Number$", str(index)))
|
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.
|
# Stream Manifest is base64 encoded.
|
||||||
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
|
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
|
||||||
# JSON string to object.
|
# JSON string to object.
|
||||||
@@ -464,11 +464,11 @@ class Download:
|
|||||||
encryption_key: str | None = (
|
encryption_key: str | None = (
|
||||||
stream_manifest["encryptionKey"] if self.is_encrypted(encryption_type) else 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
|
# Parse M3U8 video playlist
|
||||||
m3u8_variant: m3u8.M3U8 = m3u8.load(manifest)
|
m3u8_variant: m3u8.M3U8 = m3u8.load(manifest)
|
||||||
# Find the desired video resolution or the next best one.
|
# 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.
|
# Populate urls.
|
||||||
stream_urls: list[str] = m3u8_playlist.files
|
stream_urls: list[str] = m3u8_playlist.files
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -242,13 +242,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def on_populate_tree_lists(self, user_lists: [Playlist | UserPlaylist | Mix]):
|
def on_populate_tree_lists(self, user_lists: [Playlist | UserPlaylist | Mix]):
|
||||||
twi_playlists: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
|
twi_playlists: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
|
||||||
TidalLists.Playlists.value, QtCore.Qt.MatchExactly, 0
|
TidalLists.Playlists, QtCore.Qt.MatchExactly, 0
|
||||||
)[0]
|
)[0]
|
||||||
twi_mixes: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
|
twi_mixes: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
|
||||||
TidalLists.Favorites.value, QtCore.Qt.MatchExactly, 0
|
TidalLists.Favorites, QtCore.Qt.MatchExactly, 0
|
||||||
)[0]
|
)[0]
|
||||||
twi_favorites: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
|
twi_favorites: QtWidgets.QTreeWidgetItem = self.tr_lists_user.findItems(
|
||||||
TidalLists.Mixes.value, QtCore.Qt.MatchExactly, 0
|
TidalLists.Mixes, QtCore.Qt.MatchExactly, 0
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
# Remove all children if present
|
# Remove all children if present
|
||||||
@@ -543,7 +543,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
name=name,
|
name=name,
|
||||||
quality="<quality>",
|
quality="<quality>",
|
||||||
type_media=type(media).__name__,
|
type_media=type(media).__name__,
|
||||||
status=QueueDownloadStatus.Waiting.value,
|
status=QueueDownloadStatus.Waiting,
|
||||||
obj=media,
|
obj=media,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -618,14 +618,14 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
self.pb_list.setFormat(f"%p% {value}")
|
self.pb_list.setFormat(f"%p% {value}")
|
||||||
|
|
||||||
def on_quality_set_audio(self, index):
|
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()
|
self.settings.save()
|
||||||
|
|
||||||
if self.tidal:
|
if self.tidal:
|
||||||
self.tidal.settings_apply()
|
self.tidal.settings_apply()
|
||||||
|
|
||||||
def on_quality_set_video(self, index):
|
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()
|
self.settings.save()
|
||||||
|
|
||||||
if self.tidal:
|
if self.tidal:
|
||||||
@@ -697,11 +697,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def on_queue_download_clear_all(self):
|
def on_queue_download_clear_all(self):
|
||||||
self.on_clear_queue_download(
|
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):
|
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):
|
def on_clear_queue_download(self, regex: str):
|
||||||
items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.findItems(
|
items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.findItems(
|
||||||
@@ -720,7 +720,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
for item in items:
|
for item in items:
|
||||||
status: str = item.text(0)
|
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))
|
self.tr_queue_download.takeTopLevelItem(self.tr_queue_download.indexOfTopLevelItem(item))
|
||||||
else:
|
else:
|
||||||
logger_gui.info("Cannot remove a currently downloading item from queue.")
|
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:
|
def watcher_queue_download(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.findItems(
|
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:
|
if len(items) > 0:
|
||||||
@@ -770,13 +770,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
def on_queue_download_item_downloading(self, item: QtWidgets.QTreeWidgetItem) -> None:
|
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:
|
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:
|
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:
|
def queue_download_item_status(self, item: QtWidgets.QTreeWidgetItem, status: str) -> None:
|
||||||
item.setText(0, status)
|
item.setText(0, status)
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ def check_file_exists(path_file: str, extension_ignore: bool = False) -> bool:
|
|||||||
path_files: [str] = []
|
path_files: [str] = []
|
||||||
|
|
||||||
for extension in AudioExtensions:
|
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:
|
else:
|
||||||
path_files: [str] = [path_file]
|
path_files: [str] = [path_file]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user