forked from beingmohit/browser-playerctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
executable file
·68 lines (52 loc) · 2.04 KB
/
install.py
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
#!/usr/bin/env python3
import json
import os
import sys
XDG_CONFIG_HOME = os.environ.get("XDG_CONFIG_HOME",
default=os.path.expanduser("~/.config"))
BROWSERS = [
os.path.join(XDG_CONFIG_HOME, "chromium"),
os.path.join(XDG_CONFIG_HOME, "google-chrome"),
]
def die(msg):
print(msg, file=sys.stderr)
sys.exit(1)
def main(args):
if len(args) < 1:
args.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'mpris2'))
ext_id = "ojjjidifjmbbckdjfiagdfdepbcmnicg"
prog_path = args[0]
# Chrome's extension IDs are in hexadecimal but using a-p, referred
# internally as "mpdecimal". https://stackoverflow.com/a/2050916
if not all(97 <= ord(c) <= 112 for c in ext_id):
die("Not valid extension ID")
# Check that python-gobject is available. This is done because it's hard
# to see if chrome-mpris2 fails with an import error; you'd need to check
# the X log. Of course it's possible that any dependencies met during
# installation are unavailable later but what can you do.
try:
from gi.repository import GLib, Gio
except ImportError:
die("Required dependency python-gobject not found")
# Before that, Gio couldn't publish DBus objects (introspection bug)
if (GLib.MAJOR_VERSION, GLib.MINOR_VERSION) < (2, 46):
die("Your GLib version is too old")
manifest = {
"name": "org.mpris.browser_host",
"description": "A DBus service",
"path": prog_path,
"type": "stdio",
"allowed_origins": [
"chrome-extension://" + ext_id + "/",
]
}
for browser in BROWSERS:
if not os.path.exists(browser):
continue
message_hosts = os.path.join(browser, "NativeMessagingHosts")
manifest_path = os.path.join(message_hosts, "org.mpris.browser_host.json")
os.makedirs(message_hosts, exist_ok=True)
with open(manifest_path, "w") as f:
json.dump(manifest, f)
if __name__ == "__main__":
main(sys.argv[1:])