summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-04-20 16:02:29 +0200
committerRobert Honz <exislow+github@gmail.com>2024-04-20 16:02:29 +0200
commit68ad21276bcf6300827aceed7017ff70230fe320 (patch)
tree2bed13ad2586bbe8369679cfdee7dc62d979be37
parent3455e6f08a4a60218892c418c77c329697146660 (diff)
downloadtidal-dl-ng-68ad21276bcf6300827aceed7017ff70230fe320.tar.gz
👷 Migrated media constants to `tidalpi`.
-rw-r--r--tidal_dl_ng/constants.py16
-rw-r--r--tidal_dl_ng/download.py29
-rw-r--r--tidal_dl_ng/helper/path.py3
3 files changed, 9 insertions, 39 deletions
diff --git a/tidal_dl_ng/constants.py b/tidal_dl_ng/constants.py
index ba99ec6..2c58e36 100644
--- a/tidal_dl_ng/constants.py
+++ b/tidal_dl_ng/constants.py
@@ -29,12 +29,6 @@ class SkipExisting(StrEnum):
Append: str = "append"
-class StreamManifestMimeType(StrEnum):
- MPD: str = "application/dash+xml"
- BTS: str = "application/vnd.tidal.bts"
- VIDEO: str = "video/mp2t"
-
-
class CoverDimensions(IntEnum):
Px80: int = 80
Px160: int = 160
@@ -49,16 +43,6 @@ class TidalLists(StrEnum):
Mixes: str = "Mixes"
-class AudioExtensions(StrEnum):
- FLAC: str = ".flac"
- M4A: str = ".m4a"
- MP4: str = ".mp4"
-
-
-class VideoExtensions(StrEnum):
- TS: str = ".ts"
-
-
class QueueDownloadStatus(StrEnum):
Waiting: str = "⏳️"
Downloading: str = "▶️"
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py
index 219e342..c8c59c2 100644
--- a/tidal_dl_ng/download.py
+++ b/tidal_dl_ng/download.py
@@ -15,17 +15,10 @@ from mpegdash.parser import MPEGDASHParser
from requests.exceptions import HTTPError
from rich.progress import Progress, TaskID
from tidalapi import Album, Mix, Playlist, Session, Track, UserPlaylist, Video
+from tidalapi.media import AudioExtensions, ManifestMimeType, VideoExtensions
from tidal_dl_ng.config import Settings
-from tidal_dl_ng.constants import (
- EXTENSION_LYRICS,
- REQUESTS_TIMEOUT_SEC,
- AudioExtensions,
- MediaType,
- SkipExisting,
- StreamManifestMimeType,
- VideoExtensions,
-)
+from tidal_dl_ng.constants import EXTENSION_LYRICS, REQUESTS_TIMEOUT_SEC, MediaType, SkipExisting
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
from tidal_dl_ng.helper.exceptions import MediaMissing, UnknownManifestFormat
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize
@@ -203,16 +196,8 @@ class Download:
return False, ""
- # Populate StreamManifest for further download.
- if isinstance(media, Track):
- stream = media.get_stream()
- manifest: str = stream.manifest
- mime_type: str = stream.manifest_mime_type
- else:
- manifest: str = media.get_url()
- mime_type: str = StreamManifestMimeType.VIDEO
-
- stream_manifest = self.stream_manifest_parse(manifest, mime_type)
+ # Populate StreamManifest for further download action.
+ stream_manifest = media.get_stream().get_stream_manifest()
# Create file name and path
file_name_relative = format_path_media(file_template, media)
@@ -429,7 +414,7 @@ class Download:
return path_file_out
def stream_manifest_parse(self, manifest: str, mime_type: str) -> StreamManifest:
- if mime_type == StreamManifestMimeType.MPD:
+ if mime_type == ManifestMimeType.MPD:
# Stream Manifest is base64 encoded.
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
mpd = MPEGDASHParser.parse(manifest_parsed)
@@ -451,7 +436,7 @@ class Download:
for index in range(segments_count):
stream_urls.append(segment_template.media.replace("$Number$", str(index)))
- elif mime_type == StreamManifestMimeType.BTS:
+ elif mime_type == ManifestMimeType.BTS:
# Stream Manifest is base64 encoded.
manifest_parsed: str = base64.b64decode(manifest).decode("utf-8")
# JSON string to object.
@@ -464,7 +449,7 @@ class Download:
encryption_key: str | None = (
stream_manifest["encryptionKey"] if self.is_encrypted(encryption_type) else None
)
- elif mime_type == StreamManifestMimeType.VIDEO:
+ elif mime_type == ManifestMimeType.VIDEO:
# Parse M3U8 video playlist
m3u8_variant: m3u8.M3U8 = m3u8.load(manifest)
# Find the desired video resolution or the next best one.
diff --git a/tidal_dl_ng/helper/path.py b/tidal_dl_ng/helper/path.py
index 1b9fe96..e857801 100644
--- a/tidal_dl_ng/helper/path.py
+++ b/tidal_dl_ng/helper/path.py
@@ -7,9 +7,10 @@ from pathlib import Path, PosixPath
from pathvalidate import sanitize_filename, sanitize_filepath
from pathvalidate.error import ValidationError
from tidalapi import Album, Mix, Playlist, Track, UserPlaylist, Video
+from tidalapi.media import AudioExtensions
from tidal_dl_ng import __name_display__
-from tidal_dl_ng.constants import FILENAME_SANITIZE_PLACEHOLDER, UNIQUIFY_THRESHOLD, AudioExtensions, MediaType
+from tidal_dl_ng.constants import FILENAME_SANITIZE_PLACEHOLDER, UNIQUIFY_THRESHOLD, MediaType
from tidal_dl_ng.helper.tidal import name_builder_album_artist, name_builder_artist, name_builder_title