diff --git a/.gitignore b/.gitignore index eb03e3e..740a0a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules *.log +package-lock.json diff --git a/README.md b/README.md index 9457934..652c0a9 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ you can integrate its control into any of your own software. This is especially convenient for integrating into any sort of Home Automation you might have. -Last confirmed working version of iTunes: `12.2.1`. +Last confirmed working version of Apple Music: `1.0.6.10`. ## Features diff --git a/app.js b/app.js index e7b49a4..258a57d 100755 --- a/app.js +++ b/app.js @@ -18,7 +18,11 @@ var logFormat = "'[:date[iso]] - :remote-addr - :method :url :status :response-t app.use(morgan(logFormat)) function getCurrentState(){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } playerState = itunes.playerState(); currentState = {}; @@ -63,7 +67,11 @@ function sendResponse(error, res){ } function playPlaylist(nameOrId){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } if ((nameOrId - 0) == nameOrId && ('' + nameOrId).trim().length > 0) { id = parseInt(nameOrId); @@ -76,7 +84,11 @@ function playPlaylist(nameOrId){ } function setVolume(level){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } if (level) { itunes.soundVolume = parseInt(level); @@ -87,7 +99,11 @@ function setVolume(level){ } function setMuted(muted){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } if (muted) { itunes.mute = muted; @@ -98,7 +114,11 @@ function setMuted(muted){ } function setShuffle(mode){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } if (!mode) { mode = "songs" @@ -115,7 +135,11 @@ function setShuffle(mode){ } function setRepeat(mode){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } if (!mode) { mode = "all" @@ -131,7 +155,11 @@ function setRepeat(mode){ } function getPlaylistsFromItunes(){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } playlists = itunes.playlists(); playlistNames = []; diff --git a/lib/airplay.js b/lib/airplay.js index 3c16c54..500faf4 100644 --- a/lib/airplay.js +++ b/lib/airplay.js @@ -1,7 +1,11 @@ module.exports = { listAirPlayDevices: function (callback){ - itunes = Application('iTunes'); + try { + itunes = Application('Music'); + } catch (error) { + itunes = Application('iTunes'); + } airPlayDevices = itunes.airplayDevices(); airPlayResults = []; for (i = 0; i < airPlayDevices.length; i++) { diff --git a/lib/art.applescript b/lib/art.applescript index 0f23e17..08c6a04 100644 --- a/lib/art.applescript +++ b/lib/art.applescript @@ -1 +1,28 @@ -on write_to_file(this_data, target_file, append_data) try set the target_file to the target_file as string log target_file set the open_target_file to open for access target_file with write permission log "trying" if append_data is false then set eof of the open_target_file to 0 write this_data to the open_target_file starting at eof close access the open_target_file return true on error log "failed" try close access file target_file end try return false end try end write_to_file tell application "iTunes" 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 \ No newline at end of file +on write_to_file(this_data, target_file, append_data) + try + set the target_file to the target_file as string + log target_file + set the open_target_file to open for access target_file with write permission + log "trying" + if append_data is false then set eof of the open_target_file to 0 + write this_data to the open_target_file starting at eof + close access the open_target_file + return true + on error + log "failed" + try + close access file target_file + end try + return false + end try +end write_to_file + +tell application "Music" + 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 diff --git a/package.json b/package.json index 3b6edb2..6412f4a 100755 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "express": "^4.12.4", "morgan": "^1.6.1", "body-parser": "^1.12.4", - "local-itunes": "^0.3.0", + "local-itunes": "^0.4.0", "osa": "2.2.0", "osascript": "1.2.0", "parameterize": "^0.0.7"