Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: maddox/itunes-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: DrMachin/itunes-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Jul 28, 2020

  1. Add macOS Catalina compatibility

    Daniel Machin committed Jul 28, 2020
    Copy the full SHA
    48a263e View commit details
  2. Fix artwork applescript

    Daniel Machin committed Jul 28, 2020
    Copy the full SHA
    12613ae View commit details
  3. Clean line endings

    Daniel Machin committed Jul 28, 2020
    Copy the full SHA
    a6e7705 View commit details
Showing with 71 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 README.md
  3. +35 −7 app.js
  4. +5 −1 lib/airplay.js
  5. +28 −1 lib/art.applescript
  6. +1 −1 package.json
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
@@ -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
42 changes: 35 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -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 = [];
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++) {
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
@@ -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"