[Playback Controller] Reformat metadata handler

Metadata notifier should have been reformatted to use the properties as
dotted members, and also check for empty strings.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-19 01:43:08 -07:00
parent 7fcfdb373b
commit 8306bd31f4
1 changed files with 14 additions and 14 deletions

View File

@ -793,36 +793,36 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
if(entry) {
if([entry title])
[songInfo setObject:[entry title] forKey:MPMediaItemPropertyTitle];
if([entry artist])
[songInfo setObject:[entry artist] forKey:MPMediaItemPropertyArtist];
if([entry album])
[songInfo setObject:[entry album] forKey:MPMediaItemPropertyAlbumTitle];
if([entry albumArt]) {
if(entry.title && [entry.title length])
[songInfo setObject:entry.title forKey:MPMediaItemPropertyTitle];
if(entry.artist && [entry.artist length])
[songInfo setObject:entry.artist forKey:MPMediaItemPropertyArtist];
if(entry.album && [entry.album length])
[songInfo setObject:entry.album forKey:MPMediaItemPropertyAlbumTitle];
if(entry.albumArt) {
// can't do && with @available
if(@available(macOS 10.13.2, *)) {
CGSize artworkSize = CGSizeMake(500, 500);
MPMediaItemArtwork *mpArtwork = [[MPMediaItemArtwork alloc] initWithBoundsSize:artworkSize
requestHandler:^NSImage *_Nonnull(CGSize size) {
return [entry albumArt];
return entry.albumArt;
}];
[songInfo setObject:mpArtwork forKey:MPMediaItemPropertyArtwork];
}
}
// I don't know what NPIC does with these since they aren't exposed in UI, but if we have them, use it.
// There's a bunch of other metadata, but PlaylistEntry can't represent a lot of it.
if([entry genre])
[songInfo setObject:[entry genre] forKey:MPMediaItemPropertyGenre];
if([entry year]) {
if(entry.genre && [entry.genre length])
[songInfo setObject:entry.genre forKey:MPMediaItemPropertyGenre];
if(entry.year) {
// If PlaylistEntry can represent a full date like some tag formats can do, change it
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *releaseYear = [calendar dateWithEra:1 year:entry.year month:0 day:0 hour:0 minute:0 second:0 nanosecond:0];
[songInfo setObject:releaseYear forKey:MPMediaItemPropertyReleaseDate];
}
[songInfo setObject:@([entry currentPosition]) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[songInfo setObject:[entry length] forKey:MPMediaItemPropertyPlaybackDuration];
[songInfo setObject:@([entry index]) forKey:MPMediaItemPropertyPersistentID];
[songInfo setObject:@(entry.currentPosition) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[songInfo setObject:entry.length forKey:MPMediaItemPropertyPlaybackDuration];
[songInfo setObject:@(entry.index) forKey:MPMediaItemPropertyPersistentID];
}
switch(playbackStatus) {