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 | var exec = require('child_process').exec;
|
36 |
|
37 | var applescript = require("applescript");
|
38 |
|
39 | exports.setup = function(cb) {
|
40 | var child = exec("osascript -e 'help'", function(error, stdout, stderr) {
|
41 | if(error)
|
42 | cb(null);
|
43 | else
|
44 | cb("quicktime", "QuickTime", "Video Player");
|
45 | });
|
46 | };
|
47 |
|
48 | exports.execute = function(req, res) {
|
49 | console.log("Executing quicktime command: " + req.params[0]);
|
50 |
|
51 | var script_string = "";
|
52 |
|
53 | if(req.params[0] == "play") {
|
54 | var script_string = 'tell application "QuickTime Player" to play document frontmost\n';
|
55 | } else if(req.params[0] == "pause") {
|
56 | var script_string = 'tell application "QuickTime Player" to pause document frontmost\n';
|
57 | } else if(req.params[0] == "seek") {
|
58 | if(req.param("action") == "fwd")
|
59 | var script_string = 'tell application "QuickTime Player" to step forward document frontmost\n';
|
60 | else if(req.param("action") == "bwd")
|
61 | var script_string = 'tell application "QuickTime Player" to step backward document frontmost\n';
|
62 | } else if(req.params[0] == "fullscreen") {
|
63 | var script_string = 'tell application "QuickTime Player"\n';
|
64 |
|
65 | script_string += 'if presenting of document frontmost is true\n';
|
66 |
|
67 | script_string += 'set present of document frontmost to false\nelse\n';
|
68 |
|
69 | script_string += 'set present of document frontmost to true\nend if\nend tell\n';
|
70 | } else if(req.params[0] == "mute") {
|
71 | var script_string = 'tell application "QuickTime Player" to set muted of document frontmost to ' +
|
72 | req.param("state") + '\n';
|
73 | } else if(req.params[0] == "volume") {
|
74 | var script_string = 'tell application "QuickTime Player" to set audio volume of document frontmost to ' +
|
75 | (req.param("value") / 100) + "\n";
|
76 | }
|
77 |
|
78 | script_string += 'tell application "QuickTime Player" to get ' +
|
79 | '{playing, name, presenting, audio volume, muted} of document frontmost';
|
80 |
|
81 | applescript.execString(script_string, function(error, result) {
|
82 | if(error) {
|
83 | res.send({"state": "stopped", "fullscreen": false, "volume": 0, "mute": true});
|
84 | } else {
|
85 | var state = "paused";
|
86 |
|
87 | if(result[0] == "true")
|
88 | state = "playing";
|
89 |
|
90 | res.send({"state": state, "title": result[1], "fullscreen": (result[2] == "true"),
|
91 | "volume": Math.round(result[3] * 100), "mute": (result[4] == "true")});
|
92 | }
|
93 | });
|
94 | };
|
95 |
|