Summary
Status updates don't always have all media fields popuplated. The current MediaStatus.update() method only updates media_data-related fields with non-empty values but never clears them. This results in stale title/artist/album being reported, for example, when switching from "real" YouTube Music songs (media.metadata populated) to YouTube videos that can also be accessed through YouTube Music (media.metadata unpoulated).
Reproduction steps
- From phone or desktop, start playing YouTube music on a Chromecast on a "proper", label-provided YouTube Music song, e.g. https://music.youtube.com/watch?v=QAvV1iKljmI
- Register a
MediaStatusListener to the Chromecast.
- Observe that MediaStatus contains the correct title (
"Tuoppein'nostelulaulu" for the given example)
- Switch the song to a song that's a regular YouTube video uploaded by a random channel, e.g. https://music.youtube.com/watch?v=IrSRcotvzhk.
Expected behavior
The MediaStatusListener from step 2 eventually receives an update that either has the correct title for the song chosen in step 4 ("BONK! - Für immer") or an empty title.
Actual behavior
All following updates still contain the title of the song chosen in step 1 ("Tuoppein'nostelulaulu") even though another song is playing.
Suggested Change
If a status update is received that sets media.metadata, all metadata-related fields in the MediaStatus object should be cleared if not set in the latest update, instead of reusing their old values.
Possible caveats
The suggested change fixes the staleness in my scenario, but I have no idea whether the carrying over of old values was a deliberate decision to fix issues with other scenarios. Wanted to discuss the issue first before sending a PR.
Example status updates
Output of pprint.pprint(data) at the top of MediaStatus.update().
For proper YTM song
{'status': [{'currentTime': 0.857,
'customData': {'playerState': 1},
'media': {'contentId': 'QAvV1iKljmI',
'contentType': 'x-youtube/video',
'customData': {'currentIndex': 0,
'listId': 'RQ7rX-LBVjUAyfQO5oKou_yN6ZT9I'},
'duration': 395,
'metadata': {'albumName': 'Betrayal, Justice, Revenge',
'artist': 'Kivimetsän Druidi',
'images': [{'height': 544,
'url': 'https://lh3.googleusercontent.com/01qD63QrFeoSqw7UhW97SMhcqQrFy1k8haonCt2LKwY56TVv7IdKE8BLHbClH_dB7BQR9U6gs7KQwGE=w544-h544-l90-rj',
'width': 544},
{'height': 302,
'url': 'https://lh3.googleusercontent.com/01qD63QrFeoSqw7UhW97SMhcqQrFy1k8haonCt2LKwY56TVv7IdKE8BLHbClH_dB7BQR9U6gs7KQwGE=w302-h302-l90-rj',
'width': 302},
{'height': 180,
'url': 'https://lh3.googleusercontent.com/01qD63QrFeoSqw7UhW97SMhcqQrFy1k8haonCt2LKwY56TVv7IdKE8BLHbClH_dB7BQR9U6gs7KQwGE=w180-h180-l90-rj',
'width': 180},
{'height': 120,
'url': 'https://lh3.googleusercontent.com/01qD63QrFeoSqw7UhW97SMhcqQrFy1k8haonCt2LKwY56TVv7IdKE8BLHbClH_dB7BQR9U6gs7KQwGE=w120-h120-l90-rj',
'width': 120},
{'height': 60,
'url': 'https://lh3.googleusercontent.com/01qD63QrFeoSqw7UhW97SMhcqQrFy1k8haonCt2LKwY56TVv7IdKE8BLHbClH_dB7BQR9U6gs7KQwGE=w60-h60-l90-rj',
'width': 60}],
'metadataType': 3,
'title': "Tuoppein'nostelulaulu"},
'streamType': 'BUFFERED'},
'mediaSessionId': 1794657190,
'playbackRate': 1,
'playerState': 'PLAYING',
'supportedMediaCommands': 311363,
'volume': {'level': 1, 'muted': False}}],
'type': 'MEDIA_STATUS'}
For YouTube video
{'status': [{'currentTime': 1.029,
'customData': {'playerState': 1},
'media': {'contentId': 'IrSRcotvzhk',
'contentType': 'x-youtube/video',
'customData': {'currentIndex': 0,
'listId': 'RQ7rX-LBVjUAyfQO5oKou_yN6ZT9I'},
'duration': 175,
'streamType': 'BUFFERED'},
'mediaSessionId': 1794657190,
'playbackRate': 1,
'playerState': 'PLAYING',
'supportedMediaCommands': 311363,
'volume': {'level': 1, 'muted': False}}],
'type': 'MEDIA_STATUS'}
Summary
Status updates don't always have all
mediafields popuplated. The currentMediaStatus.update()method only updatesmedia_data-related fields with non-empty values but never clears them. This results in stale title/artist/album being reported, for example, when switching from "real" YouTube Music songs (media.metadatapopulated) to YouTube videos that can also be accessed through YouTube Music (media.metadataunpoulated).Reproduction steps
MediaStatusListenerto the Chromecast."Tuoppein'nostelulaulu"for the given example)Expected behavior
The
MediaStatusListenerfrom step 2 eventually receives an update that either has the correct title for the song chosen in step 4 ("BONK! - Für immer") or an empty title.Actual behavior
All following updates still contain the title of the song chosen in step 1 ("Tuoppein'nostelulaulu") even though another song is playing.
Suggested Change
If a status update is received that sets
media.metadata, all metadata-related fields in theMediaStatusobject should be cleared if not set in the latest update, instead of reusing their old values.Possible caveats
The suggested change fixes the staleness in my scenario, but I have no idea whether the carrying over of old values was a deliberate decision to fix issues with other scenarios. Wanted to discuss the issue first before sending a PR.
Example status updates
Output of
pprint.pprint(data)at the top ofMediaStatus.update().For proper YTM song
For YouTube video