thedesk/app/node_modules/itunes-nowplaying-mac/dist/index.js
2018-05-20 15:17:10 +09:00

71 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const child_process = require("child_process");
const path = require("path");
async function getRawData() {
const raw_res = await new Promise((resolve, reject) => {
var stdout = "";
var stderr = "";
var process = child_process.spawn("osascript", [path.join(__dirname, "itunes.js")]);
process.stdout.on("data", (data) => {
if (data instanceof Buffer) {
data = data.toString("utf-8");
}
stdout += data;
});
process.stderr.on("data", (data) => {
if (data instanceof Buffer) {
data = data.toString("utf-8");
}
stderr += data;
});
process.on("close", (code) => {
if (code != 0) {
reject(stderr);
}
else {
resolve(stdout);
}
});
});
const res = JSON.parse(raw_res);
return res;
}
exports.getRawData = getRawData;
async function getData() {
const res = await getRawData();
if (res == null) {
return null;
}
return {
name: res.name,
duration: res.duration,
artist: res.artist,
composer: res.composer,
album: {
name: res.album,
artist: res.albumArtist,
loved: res.albumLoved,
disliked: res.albumDisliked,
},
genre: res.genre,
track: {
length: res.trackCount,
number: res.trackNumber,
},
disc: {
length: res.discCount,
number: res.discNumber,
},
sampleRate: res.sampleRate,
comment: res.comment,
loved: res.loved,
disliked: res.disliked,
state: res.state,
};
}
Object.defineProperty(getData, "default", { value: getData });
module.exports = getData;
module.exports.getRawData = getRawData;
exports.default = getData;