From a5ee9aa57d106316861631cf9b1fecf7c4c25d86 Mon Sep 17 00:00:00 2001 From: N0chteil <53608074+N0chteil@users.noreply.github.com> Date: Sat, 29 May 2021 22:47:17 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=8F=AD=20Special?= =?UTF-8?q?=20character=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- package.json | 2 +- wscript/iTunesFetcher.js | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a3f05a5..95c4ec2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ var iTunesEmitter = iTunes.emitter; switch(currentTrack.playerState){ case "playing": { - var exampleMsg = "iTunes is currently playing " + currentTrack.name + " by " + currentTrack.artist + ' from the album "' + currentTrack.album + '". This song is ' + currentTrack.duration + 's long and will finish in ' + currentTrack.remainingTime+'s'; + var exampleMsg = "iTunes is currently playing " + decodeURIComponent(currentTrack.name) + " by " + decodeURIComponent(currentTrack.artist) + ' from the album "' + decodeURIComponent(currentTrack.album) + '". This song is ' + currentTrack.duration + 's long and will finish in ' + currentTrack.remainingTime+'s'; var exampleMsg2 = "You have " + iTunes.getPlaylistCount('/Users/steve/Music/iTunes/iTunes Library.xml') + " playlists in your library and " + iTunes.getTrackCount('/Users/steve/Music/iTunes/iTunes Library.xml') + " tracks!"; console.log(exampleMsg); console.log(exampleMsg2); @@ -38,16 +38,16 @@ switch(currentTrack.playerState){ iTunesEmitter.on('playing', function(type, currentTrack){ // If it is a paused track that restarts playing if(type === "player_state_change") { - console.log(currentTrack.name + " has been resumed! "); + console.log(decodeURIComponent(currentTrack.name) + " has been resumed! "); // Or if it is a new track }else if(type === 'new_track'){ - console.log(currentTrack.name+" is now playing!") + console.log(decodeURIComponent(currentTrack.name)+" is now playing!") } }); // Do something when iTunes is paused iTunesEmitter.on('paused', function(type, currentTrack){ - console.log(currentTrack.name+" is now paused!"); + console.log(decodeURIComponent(currentTrack.name)+" is now paused!"); }); // Do something when iTunes is stopped iTunesEmitter.on('stopped', function(){ diff --git a/package.json b/package.json index 56a1ee1..12b07e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "itunes-bridge", - "version": "0.6.6", + "version": "0.6.7", "description": "A macOS and Windows NodeJS package to control and get informations from iTunes and macOS Music app through AppleScript", "main": "itunes-bridge.js", "repository": { diff --git a/wscript/iTunesFetcher.js b/wscript/iTunesFetcher.js index 9ea6100..03d0780 100644 --- a/wscript/iTunesFetcher.js +++ b/wscript/iTunesFetcher.js @@ -30,16 +30,16 @@ function getCurrentTrack(){ } } json = { - "name": currentTrack.name, - "artist": currentTrack.artist, - "album": currentTrack.album, + "name": encodeURIComponent(currentTrack.name), + "artist": encodeURIComponent(currentTrack.artist), + "album": encodeURIComponent(currentTrack.album), "mediaKind": currentTrack.kind, "duration": currentTrack.duration, "elapsedTime": iTunesApp.PlayerPosition, "remainingTime": remainingTime, - "genre": currentTrack.genre, + "genre": encodeURIComponent(currentTrack.genre), "releaseYear": currentTrack.year, - "id": currentTrack.name, // I haven't found a way to get the current track ID with iTunes COM :/ + "id": encodeURIComponent(currentTrack.name), // I haven't found a way to get the current track ID with iTunes COM :/ "playerState": playerState }; } catch (e) { From 1aeb11d1e4a070046ecb407e0f9c98afcd23259b Mon Sep 17 00:00:00 2001 From: Steve Labus Date: Mon, 31 May 2021 13:56:55 +0200 Subject: [PATCH 2/2] Decode URI when result is obtained from shell --- README.md | 8 ++++---- itunes-bridge.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95c4ec2..a3f05a5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ var iTunesEmitter = iTunes.emitter; switch(currentTrack.playerState){ case "playing": { - var exampleMsg = "iTunes is currently playing " + decodeURIComponent(currentTrack.name) + " by " + decodeURIComponent(currentTrack.artist) + ' from the album "' + decodeURIComponent(currentTrack.album) + '". This song is ' + currentTrack.duration + 's long and will finish in ' + currentTrack.remainingTime+'s'; + var exampleMsg = "iTunes is currently playing " + currentTrack.name + " by " + currentTrack.artist + ' from the album "' + currentTrack.album + '". This song is ' + currentTrack.duration + 's long and will finish in ' + currentTrack.remainingTime+'s'; var exampleMsg2 = "You have " + iTunes.getPlaylistCount('/Users/steve/Music/iTunes/iTunes Library.xml') + " playlists in your library and " + iTunes.getTrackCount('/Users/steve/Music/iTunes/iTunes Library.xml') + " tracks!"; console.log(exampleMsg); console.log(exampleMsg2); @@ -38,16 +38,16 @@ switch(currentTrack.playerState){ iTunesEmitter.on('playing', function(type, currentTrack){ // If it is a paused track that restarts playing if(type === "player_state_change") { - console.log(decodeURIComponent(currentTrack.name) + " has been resumed! "); + console.log(currentTrack.name + " has been resumed! "); // Or if it is a new track }else if(type === 'new_track'){ - console.log(decodeURIComponent(currentTrack.name)+" is now playing!") + console.log(currentTrack.name+" is now playing!") } }); // Do something when iTunes is paused iTunesEmitter.on('paused', function(type, currentTrack){ - console.log(decodeURIComponent(currentTrack.name)+" is now paused!"); + console.log(currentTrack.name+" is now paused!"); }); // Do something when iTunes is stopped iTunesEmitter.on('stopped', function(){ diff --git a/itunes-bridge.js b/itunes-bridge.js index 65e47ec..47033a1 100644 --- a/itunes-bridge.js +++ b/itunes-bridge.js @@ -307,7 +307,7 @@ function runScript(req, type, args, isJson) { switch(type){ case "fetch": { if(isJson) { - return JSON.parse(execSync('cscript //Nologo ' + iTunesFetcherScpt + ' ' + req, { encoding: 'utf8'})); + return JSON.parse(decodeURIComponent(execSync('cscript //Nologo ' + iTunesFetcherScpt + ' ' + req, { encoding: 'utf8'}))); }else{ return execSync('cscript //Nologo ' + iTunesFetcherScpt+' ' + req, { encoding: 'utf8'}); }