tehkillerbee/mopidy-tidal

API call to get track playback quality

Opened this issue · 15 comments

I am looking for a way to get from mopidy-tidal (maybe an API call?) the quality of the playing track (i.e.: HI_RES_LOSSLESS, LOSSLESS, etc), for my extension.
Is it feasible, or should I parse the log?

You cannot get this info through mopidy-tidal, but you can get it indirectly through the tidalapi:
session.track(track_id).media_metadata_tags

The list of media_metadata_tags will contain the available quality for your track. If the quality requested by your mopidy-tidal configuration is not available, a comparable quality will be used. So if HIRES_LOSSLESS was requested but only LOSSLESS was available, LOSSLESS will be used for playback.

If the Stream object is accessed instead, more details are available wrt. the audio resolution, codec, quality etc. of the available audio stream for the selected track:

stream = session.track(track_id).get_stream()
...
quality = stream.audio_quality # LOW, HIGH, LOSSLESS, HI_RES, HI_RES_LOSSLESS
bit_depth = stream.bit_depth # bit_depth: int = 16
sample_rate = stream.sample_rate #      sample_rate: int = 44100

Ideally, this functionality should be added to mopidy itself, as discussed here:
mopidy/mopidy#2085

Thank you very much for your info's! I agree, it should be added to mopidy.

One question (waiting for the functionality in mopidy): if I run a separate python script to access tidalapi, it will ask again for login authentication... is it correct? How can I use the same auth I have with mopidy-tidal?

@fmarzocca Not sure what you are trying to do. Does your extension rely on mopidy-tidal? if so, it must use the session/authentication provided by this extension. But you would of course need to modify mopidy-tidal to access the tidalapi backend directly and get eg. the track playback quality directly, as it is currently not exposed directly by mopidy.

If you use tidalapi "standalone", you just have to create a new session - or reuse the session json generated by mopidy-tidal. It can also be loaded by tidalapi. A good starting point is one of the examples here: https://github.com/tamland/python-tidal/tree/master/examples

or reuse the session json generated by mopidy-tidal.

Yes, this is the way I am going to take.
Thank you!

@tehkillerbee, I made a standalone script which is now able to extract quality and codec from playing track uri, (I am accessing the stream from tidalapi).
I have just a question to make it more generalized: as I have to set the audio quality in the tidalapi session, how can I read the content of the related config line of mopidy-tidal?

how can I read the content of the related config line of mopidy-tidal

If I find the way for this, I can embed the mod in my extension, making it available to all of those who are using mopidy-tidal.

Screenshot 2024-03-21 alle 11 18 47

how can I read the content of the related config line of mopidy-tidal

The config params are defined here:

def get_config_schema(self):

The config params are accessed here.

self._tidal_config = config[Extension.ext_name]

So what you are proposing is essentially an extension to mopidy-tidal? You can also consider if it makes sense to merge it in.

So what you are proposing is essentially an extension to mopidy-tidal?

Not really. My extension enables user to interact with mopidy through MQTT. I'd like it to report Track Quality/Codec too, if the user has mopidy-tidal installed. This while waiting for mopidy/mopidy#2085.
I already made the mod for my own purposes, and I will stay with it if no chances to go ahead.

I see.

After thinking more about this and seeing your example, I realized that it would probably be a good idea if we have a quality string in addition to the more technical quality settings (audio resolution etc.). While mostly relevant for streaming services services such as tidal, it would allow the backend to communicate a human readable quality string further to the frontend (eg "HI_RES_LOSSLESS").

Otherwise, you would still need to hook directly into mopidy-tidal track metadata to get the tidal quality - even after #2085 is merged.

Yes, getting the tidal quality from mopidy-tidal is still an issue for me.

@tehkillerbee
Johannes, in my script that grab quality/code I had to hardcode my setting:

session.audio_quality = Quality.hi_res

then I access the stream to get the playing quality:
quality = stream.audio_quality

Can you give me an hint about how to get the quality setting form mopidy-tidal settings, so that I don't hardcode it in my script?

@tehkillerbee
i was thinking that it would be very useful if mopidy-tidal could export a function like this one, so as to make it available externally:

def getTrackQuality(track_id):
    trk_details = {}
    stream = session.track(track_id).get_stream()
    manifest = stream.get_stream_manifest()
    trk_details['quality'] = stream.audio_quality
    trk_details['codec'] = manifest.get_codecs()
    trk_details["depth"] = stream.bit_depth
    trk_deatils["rate"] = stream.sample_rate
    return (json.dumps(trk_details))

Can you give me an hint about how to get the quality setting form mopidy-tidal settings, so that I don't hardcode it in my script?

The extension config is read here and each field can be read here

i was thinking that it would be very useful if mopidy-tidal could export a function like this one, so as to make it available externally.

I think I understand the point of this addition but I am not sure this is the right way to do it, as they would result in extra calls to the API for information that we already have.. Perhaps we should consider extending the TidalPlaybackProvider here so it populates the variables when playback begins (instead of just printing them to the log) and then add a function similar to your suggestion that allows returning the quality parameters for the playing track.

Perhaps we should consider extending the TidalPlaybackProvider here so

of course I posted those lines in my message just to give you an idea, but I agree that the right place is in TidalPlaybackProvider.