👷 Migrated media constants to tidalpi.

This commit is contained in:
Robert Honz
2024-04-20 16:02:29 +02:00
parent 3455e6f08a
commit 68ad21276b
3 changed files with 9 additions and 39 deletions
-16
View File
@@ -29,12 +29,6 @@ class SkipExisting(StrEnum):
Append: str = "append" Append: str = "append"
class StreamManifestMimeType(StrEnum):
MPD: str = "application/dash+xml"
BTS: str = "application/vnd.tidal.bts"
VIDEO: str = "video/mp2t"
class CoverDimensions(IntEnum): class CoverDimensions(IntEnum):
Px80: int = 80 Px80: int = 80
Px160: int = 160 Px160: int = 160
@@ -49,16 +43,6 @@ class TidalLists(StrEnum):
Mixes: str = "Mixes" Mixes: str = "Mixes"
class AudioExtensions(StrEnum):
FLAC: str = ".flac"
M4A: str = ".m4a"
MP4: str = ".mp4"
class VideoExtensions(StrEnum):
TS: str = ".ts"
class QueueDownloadStatus(StrEnum): class QueueDownloadStatus(StrEnum):
Waiting: str = "⏳️" Waiting: str = "⏳️"
Downloading: str = "▶️" Downloading: str = "▶️"
+7 -22
View File
@@ -15,17 +15,10 @@ from mpegdash.parser import MPEGDASHParser
from requests.exceptions import HTTPError from requests.exceptions import HTTPError
from rich.progress import Progress, TaskID from rich.progress import Progress, TaskID
from tidalapi import Album, Mix, Playlist, Session, Track, UserPlaylist, Video 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.config import Settings
from tidal_dl_ng.constants import ( from tidal_dl_ng.constants import EXTENSION_LYRICS, REQUESTS_TIMEOUT_SEC, MediaType, SkipExisting
EXTENSION_LYRICS,
REQUESTS_TIMEOUT_SEC,
AudioExtensions,
MediaType,
SkipExisting,
StreamManifestMimeType,
VideoExtensions,
)
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token 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.exceptions import MediaMissing, UnknownManifestFormat
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize
@@ -203,16 +196,8 @@ class Download:
return False, "" return False, ""
# Populate StreamManifest for further download. # Populate StreamManifest for further download action.
if isinstance(media, Track): stream_manifest = media.get_stream().get_stream_manifest()
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)
# Create file name and path # Create file name and path
file_name_relative = format_path_media(file_template, media) file_name_relative = format_path_media(file_template, media)
@@ -429,7 +414,7 @@ class Download:
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: if mime_type == ManifestMimeType.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 +436,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: elif mime_type == ManifestMimeType.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,7 +449,7 @@ 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: elif mime_type == ManifestMimeType.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.
+2 -1
View File
@@ -7,9 +7,10 @@ from pathlib import Path, PosixPath
from pathvalidate import sanitize_filename, sanitize_filepath from pathvalidate import sanitize_filename, sanitize_filepath
from pathvalidate.error import ValidationError from pathvalidate.error import ValidationError
from tidalapi import Album, Mix, Playlist, Track, UserPlaylist, Video 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 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 from tidal_dl_ng.helper.tidal import name_builder_album_artist, name_builder_artist, name_builder_title