Browse code

Add implementation

Robert Cranston authored on 26/03/2022 11:46:59
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,39 @@
1
+#!/usr/bin/env python3
2
+
3
+
4
+import os
5
+import sys
6
+import configparser
7
+import urllib.request
8
+import json
9
+
10
+
11
+FIREFOX_PATH  = os.path.expanduser('~/.mozilla/firefox')
12
+PROFILES_PATH = os.path.join(FIREFOX_PATH, 'profiles.ini')
13
+API_BASE_URL  = 'https://services.addons.mozilla.org/api/v4/addons/addon'
14
+
15
+
16
+extension = sys.argv[1]
17
+
18
+
19
+profiles = configparser.ConfigParser()
20
+profiles.optionxform = str
21
+profiles.read(PROFILES_PATH)
22
+for section in profiles.sections():
23
+    if section.startswith('Profile'):
24
+        profile = dict(profiles.items(section))
25
+        if int(profile['Default']):
26
+            profile_path = profile['Path']
27
+            if int(profile.get('IsRelative', '0')):
28
+                profile_path = os.path.join(FIREFOX_PATH, profile_path)
29
+
30
+
31
+with urllib.request.urlopen(f'{API_BASE_URL}/{extension}') as response:
32
+    info = json.loads(response.read())
33
+guid = info['guid']
34
+url = info['current_version']['files'][0]['url']
35
+path = os.path.join(profile_path, 'extensions', f'{guid}.xpi')
36
+os.makedirs(os.path.dirname(path), exist_ok=True)
37
+if not os.path.exists(path):
38
+    urllib.request.urlretrieve(url, path)
39
+    print(extension)