-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (84 loc) · 3.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const MprisPlayer = require("mpris-service");
const wineprefix = "~/ituneswine/"
const player = MprisPlayer({
name: "itunes",
identity: "Apple iTunes (wine)",
supportedInterfaces: ["player"],
supportedUriSchemes: ["file"],
supportedMimeTypes: ["audio/mpeg", "audio/mp4a-latm", "audio/aiff"]
});
var cp = require('child_process');
let scriptOutput = "";
let child = cp.exec('script --return -qc "bash -c \'WINEPREFIX=' + wineprefix +' wine wscript ./com-scripts/mainLoop.js\' 2> /dev/null " /dev/null');
child.stdout.setEncoding('utf8');
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;
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
}
});
child.on('close', function(code) {
console.log("Main loop exited, exiting script");
process.exit();
});
player.getPosition = function() {
// return the position of your player
return 0;
}
var events = ['raise', 'quit', 'stop', 'seek', 'position', 'open', 'volume', 'loopStatus', 'shuffle'];
events.forEach(function (eventName) {
player.on(eventName, function () {
console.log('Event:', eventName, arguments);
});
});
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 = "Paused";
break;
case "1":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
}
}
player.on("playpause", pause);
player.on("pause", pause);
player.on("play", pause);
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 = "Stopped";
break;
case "1":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
}
})
player.on("previous", () => {
let a = cp.execSync('script --return -qc "bash -c \'WINEPREFIX=' + wineprefix +' wine wscript ./com-scripts/previous.js\' 2> /dev/null " /dev/null').toString();
switch (a) {
case "0":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PAUSED;
break;
case "1":
player.playbackStatus = MprisPlayer.PLAYBACK_STATUS_PLAYING;
}
})