Skip to content

Commit

Permalink
Playback: Use streams instead of direct URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
tehkillerbee committed Feb 7, 2024
1 parent 3d53764 commit 711e311
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions mopidy_tidal/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from mopidy import backend
from tidalapi import Quality
from tidalapi.media import ManifestMimeType
from pathlib import Path

from . import Extension, context
Expand All @@ -35,15 +36,24 @@ def translate_uri(self, uri):
"No HI_RES available for this track; Using playback quality: %s",
"LOSSLESS",
)
if session.is_pkce:
manifest = session.track(track_id).get_stream().get_stream_manifest()

stream = session.track(track_id).get_stream()
manifest = stream.get_stream_manifest()
logger.info("MimeType:{}".format(stream.manifest_mime_type))
logger.info(
"Starting playback of track:{}, (quality:{}, codec:{}, {}bit/{}Hz)".format(track_id,
stream.audio_quality,
manifest.get_codecs(),
stream.bit_depth,
stream.sample_rate))
if stream.manifest_mime_type == ManifestMimeType.MPD.value:
hls = manifest.get_hls()
hls_path = Path(Extension.get_cache_dir(context.get_config()), "hls.m3u8")
with open(hls_path, "w") as my_file:
my_file.write(hls)
logger.info("Starting playback of {}, (codec:{}, sampling rate:{} Hz)".format(hls_path, manifest.get_codecs(), manifest.get_sampling_rate()))
return "file://{}".format(hls_path)
else:
newurl = session.track(track_id).get_url()
logger.info("transformed into %s", newurl)
return newurl
if hls:
hls_path = Path(Extension.get_cache_dir(context.get_config()), "hls.m3u8")
with open(hls_path, "w") as my_file:
my_file.write(hls)
return "file://{}".format(hls_path)
else:
raise AttributeError("No HLS stream available")
elif stream.manifest_mime_type == ManifestMimeType.BTS.value:
return manifest.get_urls()

0 comments on commit 711e311

Please sign in to comment.