-
Notifications
You must be signed in to change notification settings - Fork 3
/
media_info.js
57 lines (46 loc) · 1.61 KB
/
media_info.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
const Me = imports.misc.extensionUtils.getCurrentExtension();
const DBusIface = Me.imports.dbus;
var MediaInfo = class Media_Info {
constructor(busName, owner, callback) {
this.owner = owner;
new DBusIface.Properties(busName,
(proxy) => {
this._prop = proxy;
this._ready();
});
new DBusIface.MediaServer2Player(busName,
(proxy) => {
this._mediaServerPlayer = proxy;
this._server_ready();
});
this._callback = callback;
}
_ready() {
this._propChangedId = this._prop.connectSignal('PropertiesChanged',
(proxy, sender, [iface, props]) => {
if (!props.Metadata)
return;
this.parse_data(props.Metadata.deep_unpack());
});
}
_server_ready(){
this.parse_data(this._mediaServerPlayer.Metadata);
}
parse_data(metadata) {
if (!metadata || Object.keys(metadata).length < 2) {
metadata = {};
}
const title = metadata["xesam:title"] ? metadata["xesam:title"].unpack() : "";
let artist = metadata["xesam:artist"] ? metadata["xesam:artist"].deep_unpack().toString() : "";
artist = metadata["rhythmbox:streamTitle"] ? metadata["rhythmbox:streamTitle"].unpack() : artist;
if (title.trim().length == 0){
this._callback(null, null);
return;
}
this._callback(title, artist);
}
disconnect() {
this._prop.disconnectSignal(this._propChangedId);
this._callback(null, null);
}
}