maddox / itunes-api

🎵 A simple server providing a RESTful service for controlling iTunes
MIT License
200 stars 45 forks source link

Add macOS Catalina compatibility #45

Open DrMachin opened 4 years ago

DrMachin commented 4 years ago

This will add compatibility for macOS Catalina and Apple Music while still keeping iTunes compatibly.

The only breaking change is to the now playing artwork as I could not come up with a clean way of keeping it compatible with iTunes.

maddox commented 4 years ago

What exactly is the broken change with the artwork?

DrMachin commented 4 years ago

I changed tell application "iTunes" to tell application "Music" which will make it work with Apple Music but not iTunes. I couldn't find a good way to check or failover to the correct application.

maddox commented 4 years ago

Ahhh I see. Could you check the version of macOS before the command, and do either or?

DrMachin commented 4 years ago

I've tried a few things. Checking os version, app/file exists, and wrapping the whole thing in a try block and running the on error. keep running into Expected end of line but found identifier.

Basically since the iTunes (or Music) library doesn't exist anymore it fails when it sees it.

The closest I got was doing this:

tell me
    try
        get application id "com.apple.Music"
        set pathToPlayer to "Music.app"
    on error
        get application id "com.apple.iTunes"
        set pathToPlayer to "iTunes.app"
    end try
    using terms from application "Music"
        tell application pathToPlayer
            try
                set aTrack to the current track
                set aArtwork to data of artwork 1 of aTrack
                my write_to_file(aArtwork, "/tmp/currently-playing.jpg", false)
            on error
                log "error getting info"
            end try
        end tell
    end using terms from
end tell

But since I need to wrap it in using terms from application to make it work, I'm back to square one.