Skip to content

Commit 011b946

Browse files
authored
Add option to install Widevine from ChromeOS image specified by URL or local. (#499)
1 parent b14d984 commit 011b946

File tree

7 files changed

+109
-20
lines changed

7 files changed

+109
-20
lines changed

.github/workflows/addon-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
python-version: 3.8
2121
- name: Install dependencies
2222
run: |
23+
sudo apt-get update
2324
sudo apt-get install libxml2-utils xmlstarlet
2425
python -m pip install --upgrade pip packaging
2526
pip install kodi-addon-checker

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
uses: actions/checkout@v2
1313
- name: Build zip files
1414
run: |
15+
sudo apt-get update
1516
sudo apt-get install libxml2-utils
1617
make multizip release=1
1718
- name: Get Krypton filename

lib/inputstreamhelper/__init__.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import os
77

88
from . import config
9-
from .kodiutils import (addon_version, delete, exists, get_proxies, get_setting, get_setting_bool, get_setting_float, get_setting_int, jsonrpc,
9+
from .kodiutils import (addon_version, browsesingle, delete, exists, get_proxies, get_setting, get_setting_bool, get_setting_float, get_setting_int, jsonrpc,
1010
kodi_to_ascii, kodi_version, listdir, localize, log, notification, ok_dialog, progress_dialog, select_dialog,
1111
set_setting, set_setting_bool, textviewer, translate_path, yesno_dialog)
1212
from .utils import arch, http_download, parse_version, remove_tree, store, system_os, temp_path, unzip
13-
from .widevine.arm import install_widevine_arm
13+
from .widevine.arm import dl_extract_widevine, extract_widevine, install_widevine_arm
1414
from .widevine.widevine import (backup_path, has_widevinecdm, ia_cdm_path, install_cdm_from_backup, latest_available_widevine_from_repo,
1515
latest_widevine_version, load_widevine_config, missing_widevine_libs, widevine_config_path, widevine_eula, widevinecdm_path)
1616
from .unicodes import compat_path
@@ -229,6 +229,33 @@ def install_widevine(self):
229229
ok_dialog(localize(30004), localize(30005)) # An error occurred
230230
return False
231231

232+
@cleanup_decorator
233+
def install_widevine_from(self):
234+
"""Install Widevine from a given URL or file."""
235+
if yesno_dialog(None, localize(30066)): # download resource with widevine from url? no means specify local
236+
result = dl_extract_widevine(get_setting("image_url"), backup_path())
237+
if not result:
238+
return result
239+
240+
if self.install_and_finish(*result):
241+
return True
242+
243+
else:
244+
image_path = browsesingle(1, localize(30067), "files")
245+
if not image_path:
246+
return False
247+
248+
image_version = os.path.basename(image_path).split("_")[1]
249+
progress = extract_widevine(backup_path(), image_path, image_version)
250+
if not progress:
251+
return False
252+
253+
if self.install_and_finish(progress, image_version):
254+
return True
255+
256+
return False
257+
258+
232259
@staticmethod
233260
def remove_widevine():
234261
"""Removes Widevine CDM"""

lib/inputstreamhelper/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def run(params):
2323
check_inputstream(params[2], drm=params[3])
2424
elif params[1] == 'info':
2525
info_dialog()
26+
elif params[1] == 'widevine_install_from':
27+
widevine_install_from()
2628
else:
2729
log(4, "Invalid API call method '{method}'", method=params[1])
2830

@@ -42,6 +44,11 @@ def widevine_install():
4244
Helper('mpd', drm='widevine').install_widevine()
4345

4446

47+
def widevine_install_from():
48+
"""The API interface to install Widevine CDM from a given resource (URL or local ChromeOS image)."""
49+
Helper('mpd', drm='widevine').install_widevine_from()
50+
51+
4552
def widevine_remove():
4653
"""The API interface to remove Widevine CDM"""
4754
Helper('mpd', drm='widevine').remove_widevine()

lib/inputstreamhelper/widevine/arm.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,58 @@ def install_widevine_arm(backup_path):
9292

9393
log(2, 'Downloading ChromeOS image for Widevine: {hwid} ({version})'.format(**arm_device))
9494
url = arm_device['url']
95+
96+
extracted = dl_extract_widevine(url, backup_path, arm_device)
97+
if extracted:
98+
recovery_file = os.path.join(backup_path, arm_device['version'], os.path.basename(config.CHROMEOS_RECOVERY_URL))
99+
with open_file(recovery_file, 'w') as reco_file: # pylint: disable=unspecified-encoding
100+
reco_file.write(json.dumps(devices, indent=4))
101+
102+
return extracted
103+
104+
return False
105+
106+
107+
def dl_extract_widevine(url, backup_path, arm_device=None):
108+
"""Download the ChromeOS image and extract Widevine from it"""
109+
if arm_device:
95110
downloaded = http_download(url, message=localize(30022), checksum=arm_device['sha1'], hash_alg='sha1',
96111
dl_size=int(arm_device['zipfilesize'])) # Downloading the recovery image
97-
if downloaded:
98-
progress = progress_dialog()
99-
progress.create(heading=localize(30043), message=localize(30044)) # Extracting Widevine CDM
112+
image_version = arm_device['version']
113+
else:
114+
downloaded = http_download(url, message=localize(30022))
115+
image_version = os.path.basename(url).split('_')[1]
100116

101-
extracted = ChromeOSImage(store('download_path')).extract_file(
102-
filename=config.WIDEVINE_CDM_FILENAME[system_os()],
103-
extract_path=os.path.join(backup_path, arm_device['version']),
104-
progress=progress)
117+
if downloaded:
118+
image_path = store('download_path')
105119

106-
if not extracted:
107-
log(4, 'Extracting widevine from the zip failed!')
108-
progress.close()
109-
return False
120+
progress = extract_widevine(backup_path, image_path, image_version)
121+
if not progress:
122+
return False
110123

111-
recovery_file = os.path.join(backup_path, arm_device['version'], os.path.basename(config.CHROMEOS_RECOVERY_URL))
112-
config_file = os.path.join(backup_path, arm_device['version'], 'config.json')
113-
with open_file(recovery_file, 'w') as reco_file: # pylint: disable=unspecified-encoding
114-
reco_file.write(json.dumps(devices, indent=4))
124+
if arm_device:
125+
config_file = os.path.join(backup_path, image_version, 'config.json')
115126
with open_file(config_file, 'w') as conf_file:
116127
conf_file.write(json.dumps(arm_device))
117128

118-
return (progress, arm_device['version'])
129+
return (progress, image_version)
119130

120131
return False
132+
133+
134+
def extract_widevine(backup_path, image_path, image_version):
135+
"""Extract Widevine from the given ChromeOS image"""
136+
progress = progress_dialog()
137+
progress.create(heading=localize(30043), message=localize(30044)) # Extracting Widevine CDM
138+
139+
extracted = ChromeOSImage(image_path).extract_file(
140+
filename=config.WIDEVINE_CDM_FILENAME[system_os()],
141+
extract_path=os.path.join(backup_path, image_version),
142+
progress=progress)
143+
144+
if not extracted:
145+
log(4, 'Extracting widevine from the zip failed!')
146+
progress.close()
147+
return False
148+
149+
return progress

resources/language/resource.language.en_gb/strings.po

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ msgctxt "#30065"
257257
msgid "Shall we try again?"
258258
msgstr ""
259259

260+
msgctxt "#30066"
261+
msgid "Should the resource containing the Widevine library be downloaded from the URL specified in settings?\nNo means specifying the resource locally."
262+
msgstr ""
263+
264+
msgctxt "#30067"
265+
msgid "Specify the resource Widevine should be extracted from."
266+
msgstr ""
267+
260268

261269
### INFORMATION DIALOG
262270
msgctxt "#30800"
@@ -336,3 +344,15 @@ msgstr ""
336344
msgctxt "#30915"
337345
msgid "Restore Widevine CDM library..."
338346
msgstr ""
347+
348+
msgctxt "#30950"
349+
msgid "Debug"
350+
msgstr ""
351+
352+
msgctxt "#30953"
353+
msgid "Install Widevine from:"
354+
msgstr ""
355+
356+
msgctxt "#30955"
357+
msgid "Install Widevine CDM library from specific source..."
358+
msgstr ""

resources/settings.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
<setting id="version" default="" visible="false"/>
88
<setting label="30901" help="30902" type="action" action="RunScript(script.module.inputstreamhelper, info)"/>
99
<setting type="sep"/>
10-
<setting label="30903" help="30904" type="bool" id="disabled" default="false"/>
11-
<setting label="30904" type="text" enable="false"/> <!-- disabled_warning -->
1210
<setting label="30905" help="30906" type="slider" id="update_frequency" default="31" range="1,3,90" option="int" enable="eq(-2,false)" visible="![System.Platform.Android | String.StartsWith(System.BuildVersion, 17)]"/>
1311
<setting label="30907" help="30908" type="folder" id="temp_path" source="" option="writeable" default="special://masterprofile/addon_data/script.module.inputstreamhelper" visible="![System.Platform.Android | String.StartsWith(System.BuildVersion, 17)]"/>
1412
<setting label="30913" help="30914" type="slider" id="backups" default="4" range="0,1,20" option="int" visible="![System.Platform.Android | String.StartsWith(System.BuildVersion, 17)]"/>
@@ -17,4 +15,10 @@
1715
<setting label="30911" help="30912" type="action" action="RunScript(script.module.inputstreamhelper, widevine_remove)" enable="String.StartsWith(System.BuildVersion,18) + System.HasAddon(inputstream.adaptive) | System.AddonIsEnabled(inputstream.adaptive)" visible="![System.Platform.Android | String.StartsWith(System.BuildVersion, 17)]"/>
1816
<setting label="30915" help="30916" type="action" action="RunScript(script.module.inputstreamhelper, rollback)" enable="String.StartsWith(System.BuildVersion,18) + System.HasAddon(inputstream.adaptive) | System.AddonIsEnabled(inputstream.adaptive)" visible="![System.Platform.Android | String.StartsWith(System.BuildVersion, 17)]"/>
1917
</category>
18+
<category label="30950">
19+
<setting label="30903" help="30904" type="bool" id="disabled" default="false"/>
20+
<setting label="30904" type="text" enable="false"/> <!-- disabled_warning -->
21+
<setting label="30953" help="30954" type="text" id="image_url" option="urlencoded" default="https://dl.google.com/dl/edgedl/chromeos/recovery/chromeos_14092.77.0_veyron-fievel_recovery_stable-channel_fievel-mp.bin.zip"/>
22+
<setting label="30955" help="30956" type="action" action="RunScript(script.module.inputstreamhelper, widevine_install_from)" enable="String.StartsWith(System.BuildVersion,18) + System.HasAddon(inputstream.adaptive) | System.AddonIsEnabled(inputstream.adaptive)" visible="![System.Platform.Android | String.StartsWith(System.BuildVersion, 17)]"/>
23+
</category>
2024
</settings>

0 commit comments

Comments
 (0)