Pass through more simple media item info to MacOS

This commit is contained in:
Danielle McLean 2023-12-06 12:02:13 +11:00
parent eb7509a4e0
commit 28da4da69f
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
2 changed files with 22 additions and 0 deletions

View file

@ -6,8 +6,12 @@ from Foundation import CGSize, NSMutableDictionary
from MediaPlayer import ( from MediaPlayer import (
MPMediaItemArtwork, MPMediaItemArtwork,
MPMediaItemPropertyAlbumTitle, MPMediaItemPropertyAlbumTitle,
MPMediaItemPropertyAlbumTrackNumber,
MPMediaItemPropertyArtist, MPMediaItemPropertyArtist,
MPMediaItemPropertyArtwork, MPMediaItemPropertyArtwork,
MPMediaItemPropertyComposer,
MPMediaItemPropertyDiscNumber,
MPMediaItemPropertyGenre,
MPMediaItemPropertyPlaybackDuration, MPMediaItemPropertyPlaybackDuration,
MPMediaItemPropertyTitle, MPMediaItemPropertyTitle,
MPMusicPlaybackState, MPMusicPlaybackState,
@ -18,7 +22,11 @@ from MediaPlayer import (
MPNowPlayingInfoMediaTypeAudio, MPNowPlayingInfoMediaTypeAudio,
MPNowPlayingInfoMediaTypeNone, MPNowPlayingInfoMediaTypeNone,
MPNowPlayingInfoPropertyElapsedPlaybackTime, MPNowPlayingInfoPropertyElapsedPlaybackTime,
MPNowPlayingInfoPropertyExternalContentIdentifier,
MPNowPlayingInfoPropertyMediaType, MPNowPlayingInfoPropertyMediaType,
MPNowPlayingInfoPropertyPlaybackQueueCount,
MPNowPlayingInfoPropertyPlaybackQueueIndex,
MPNowPlayingInfoPropertyPlaybackRate,
MPRemoteCommandCenter, MPRemoteCommandCenter,
MPRemoteCommandEvent, MPRemoteCommandEvent,
MPRemoteCommandHandlerStatus, MPRemoteCommandHandlerStatus,
@ -70,12 +78,24 @@ def song_to_media_item(song: Song) -> NSMutableDictionary:
nowplaying_info = nothing_to_media_item() nowplaying_info = nothing_to_media_item()
nowplaying_info[MPNowPlayingInfoPropertyMediaType] = MPNowPlayingInfoMediaTypeAudio nowplaying_info[MPNowPlayingInfoPropertyMediaType] = MPNowPlayingInfoMediaTypeAudio
nowplaying_info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = song.elapsed nowplaying_info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = song.elapsed
nowplaying_info[MPNowPlayingInfoPropertyExternalContentIdentifier] = song.file
nowplaying_info[MPNowPlayingInfoPropertyPlaybackQueueCount] = song.queue_length
nowplaying_info[MPNowPlayingInfoPropertyPlaybackQueueIndex] = song.queue_index
nowplaying_info[MPMediaItemPropertyTitle] = song.title nowplaying_info[MPMediaItemPropertyTitle] = song.title
nowplaying_info[MPMediaItemPropertyArtist] = song.artist nowplaying_info[MPMediaItemPropertyArtist] = song.artist
nowplaying_info[MPMediaItemPropertyAlbumTitle] = song.album nowplaying_info[MPMediaItemPropertyAlbumTitle] = song.album
nowplaying_info[MPMediaItemPropertyAlbumTrackNumber] = song.track
nowplaying_info[MPMediaItemPropertyDiscNumber] = song.disc
nowplaying_info[MPMediaItemPropertyGenre] = song.genre
nowplaying_info[MPMediaItemPropertyComposer] = song.composer
nowplaying_info[MPMediaItemPropertyPlaybackDuration] = song.duration nowplaying_info[MPMediaItemPropertyPlaybackDuration] = song.duration
# MPD can't play back music at different rates, so we just want to set it
# to 1.0 if the song is playing. (Leave it at 0.0 if the song is paused.)
if song.state == PlaybackState.play:
nowplaying_info[MPNowPlayingInfoPropertyPlaybackRate] = 1.0
if song.art: if song.art:
nowplaying_info[MPMediaItemPropertyArtwork] = ns_image_to_media_item_artwork( nowplaying_info[MPMediaItemPropertyArtwork] = ns_image_to_media_item_artwork(
data_to_ns_image(song.art) data_to_ns_image(song.art)
@ -88,6 +108,7 @@ def nothing_to_media_item() -> NSMutableDictionary:
nowplaying_info[MPNowPlayingInfoPropertyMediaType] = MPNowPlayingInfoMediaTypeNone nowplaying_info[MPNowPlayingInfoPropertyMediaType] = MPNowPlayingInfoMediaTypeNone
nowplaying_info[MPMediaItemPropertyArtwork] = MPD_LOGO nowplaying_info[MPMediaItemPropertyArtwork] = MPD_LOGO
nowplaying_info[MPMediaItemPropertyTitle] = "MPD (stopped)" nowplaying_info[MPMediaItemPropertyTitle] = "MPD (stopped)"
nowplaying_info[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
return nowplaying_info return nowplaying_info

View file

@ -24,6 +24,7 @@ MPNowPlayingInfoPropertyMediaType: Final = "MPNowPlayingInfoPropertyMediaType"
MPNowPlayingInfoMediaTypeAudio: Final = 1 MPNowPlayingInfoMediaTypeAudio: Final = 1
MPNowPlayingInfoMediaTypeNone: Final = 0 MPNowPlayingInfoMediaTypeNone: Final = 0
MPNowPlayingInfoPropertyPlaybackRate: Final = "MPNowPlayingInfoPropertyPlaybackRate"
MPNowPlayingInfoPropertyPlaybackQueueCount: Final = ( MPNowPlayingInfoPropertyPlaybackQueueCount: Final = (
"MPNowPlayingInfoPropertyPlaybackQueueCount" "MPNowPlayingInfoPropertyPlaybackQueueCount"
) )