kirtan-shah / nowplaying-cli

macOS command-line utility for retrieving currently playing media
GNU General Public License v3.0
148 stars 9 forks source link

Get bundle identifier of the app playing the media? #7

Closed twio142 closed 1 year ago

twio142 commented 1 year ago

Is this possible?

P.S. Thank you so much for developing this tool! I've been looking for something like this for a long time.

nyxaria commented 12 months ago

Would it be possible to get the name of the app playing the media currently? Can you please help me?

nyxaria commented 12 months ago

I tried decoding the string directly inside nowplaying.mm but it prints out (null) for some reason -- can you please take a look?

...
else if([key isEqualToString:@"kMRMediaRemoteNowPlayingInfoArtworkData"] || [key isEqualToString:@"kMRMediaRemoteNowPlayingInfoClientPropertiesData"]) {
                NSData *data = (NSData *) rawValue;
                NSString *decodeString = [data base64EncodedStringWithOptions:0];

                NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:decodeString options:0];
                NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];

                printf("%s\n", [decodeString UTF8String]);
                printf("%s\n", [decodedString UTF8String]);
            }
...

output:

CJ4REhFjb20uYnJhdmUuQnJvd3NlciD1AzoNQnJhdmUgQnJvd3Nlcg==
(null)

With an online decoder I seem to be able to decode it to give me:

com.brave.Browser :
Brave Browser

However when using terminal I get the following:

$ base64 -d <<< $(./nowplaying-cli get clientPropertiesData)
Brave Browser%   
twio142 commented 12 months ago

@nyxaria I don't think you can do the base64 decoding from within the code because the string contains some strange characters. I'd just pipe the result to base64 -d in the terminal.

nyxaria commented 12 months ago

I appreciate it!

nyxaria commented 12 months ago

I tried using python and it managed to decode it properly - as you said there are weird characters but at least now I can do partial matches


In [3]: s = "CJ4REhFjb20uYnJhdmUuQnJvd3NlciD1AzoNQnJhdmUgQnJvd3Nlcg=="

In [4]: base64.b64decode(s)
Out[4]: b'\x08\x9e\x11\x12\x11com.brave.Browser \xf5\x03:\rBrave Browser'