Skip to content

Commit

Permalink
Added readme, fixed status not accurate, tried to fix artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeApp2014 committed Oct 21, 2020
1 parent 4d7aa26 commit cbe3621
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# iTunes MPRIS service
A service intended to integrate iTunes into D-Bus session
## Support
Supports setting metadata, pause, resume, next, previous
## Configuration
To use this you should
* Set `wineprefix` in index.js to location of your iTunes prefix
* In the prefix, install `wsh57` (`WINEPREFIX=/path/ winetricks wsh57`)
* Run using node
(A more streamlined procedure involving a systemd unit is under development)
13 changes: 11 additions & 2 deletions com-scripts/mainLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ITEvent_OnPlayerPlayEvent (newTrack) {
}
//Write current image
var a = Math.random() * 10;
newTrack.artwork.item(1).saveArtworkToFile(path + "\\artwork" + a);
if (newTrack.artwork.count > 0) newTrack.artwork.item(1).saveArtworkToFile(path + "\\artwork" + a);
var updatePacket = {
newStatus: itunesApp.playerState,
name: newTrack.name,
Expand All @@ -49,7 +49,16 @@ function ITEvent_OnAboutToPromptUserToQuitEvent(){
}

var ITEvent_OnPlayerPlayingTrackChangedEvent = ITEvent_OnPlayerPlayEvent;
var ITEvent_OnPlayerStopEvent = ITEvent_OnPlayerPlayEvent;

function ITEvent_OnPlayerStopEvent(newTrack) {
WScript.StdOut.WriteBlankLines(1);
if (newTrack.artist)
var updatePacket = {
newStatus: "Stopped"
}
if (newTrack.artist) updatePacket.newStatus = "Paused"
WScript.StdOut.Write(JSON.stringify(updatePacket));
}

WScript.ConnectObject(itunesApp, "ITEvent_");

Expand Down
31 changes: 20 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@ child.stdout.on('data', function(data) {
if (data.replace(/[\x00-\x1F\x7F]*/g, "").replace(/\[(\?25\S|K)/g, "") == "") return;
let result = data.replace(/[\x00-\x1F\x7F]*/g, "").replace(/\[(\?25\S|K)/g, "");
// console.log(require("util").inspect(result), result.length, result[0], result[result.length], result[result.length-1]);
let obj = JSON.parse(result);
player.metadata = {
"mpris:trackid": player.objectPath('track/' + Math.floor(Math.random() * 100)),
"mpris.length": obj.duration * 1000 * 1000,
"mpris:artUrl": "file://" + __dirname + "/com-scripts/artwork" + obj.artKey,
"xesam:title": obj.name,
"xesam:album": obj.album,
"xesam:artist": [ obj.artist ]
let obj;
try {
obj = JSON.parse(result);
} catch {
console.log(result);
}
if (obj.name){
player.metadata = {
"mpris:trackid": player.objectPath('track/' + Math.floor(Math.random() * 100)),
"mpris.length": obj.duration * 1000 * 1000,
"mpris:artUrl": "file://" + __dirname + "/com-scripts/artwork" + obj.artKey,
"xesam:title": obj.name,
"xesam:album": obj.album,
"xesam:artist": [ obj.artist ]
}
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
} else {
player.playbackStatus = obj.newStatus
}
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
});

child.on('close', function(code) {
Expand All @@ -51,7 +60,7 @@ function pause() {
let a = cp.execSync('script --return -qc "bash -c \'WINEPREFIX=' + wineprefix +' wine wscript ./com-scripts/togglePlayPause.js\' 2> /dev/null " /dev/null').toString();
switch (a) {
case "0":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PAUSED;
player.playbackStatus = "Paused";
break;
case "1":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
Expand All @@ -66,7 +75,7 @@ player.on("next", () => {
let a = cp.execSync('script --return -qc "bash -c \'WINEPREFIX=' + wineprefix +' wine wscript ./com-scripts/next.js\' 2> /dev/null " /dev/null').toString();
switch (a) {
case "0":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PAUSED;
player.playbackStatus = "Stopped";
break;
case "1":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
Expand Down

0 comments on commit cbe3621

Please sign in to comment.