Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.log
package-lock.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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"
Expand All @@ -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"
Expand 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 = [];
Expand Down
6 changes: 5 additions & 1 deletion lib/airplay.js
Original file line number Diff line number Diff line change
@@ -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++) {
Expand Down
29 changes: 28 additions & 1 deletion lib/art.applescript
Original file line number Diff line number Diff line change
@@ -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 tryend write_to_filetell 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 tryend tell
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down