Skip to content

Commit 2a58096

Browse files
Add Widevine support for ARM64 Mac (#429)
Co-authored-by: horstle <37619239+horstle@users.noreply.github.com>
1 parent 13a1e82 commit 2a58096

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

lib/inputstreamhelper/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
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, userspace64
1313
from .widevine.arm import dl_extract_widevine, extract_widevine, install_widevine_arm
14-
from .widevine.widevine import (backup_path, has_widevinecdm, ia_cdm_path, install_cdm_from_backup, latest_available_widevine_from_repo,
14+
from .widevine.widevine import (backup_path, cdm_from_repo, 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
1717

@@ -142,7 +142,7 @@ def _supports_widevine(self):
142142
ok_dialog(localize(30004), localize(30007, arch=arch())) # Widevine not available on this architecture
143143
return False
144144

145-
if arch() == 'arm64' and system_os() != 'Android' and userspace64():
145+
if arch() == 'arm64' and system_os() not in ['Android', 'Darwin'] and userspace64():
146146
is_version = parse_version(addon_version(self.inputstream_addon))
147147
try:
148148
compat_version = parse_version(config.MINIMUM_INPUTSTREAM_VERSION_ARM64[self.inputstream_addon])
@@ -173,8 +173,8 @@ def _supports_widevine(self):
173173
return True
174174

175175
@staticmethod
176-
def _install_widevine_x86(bpath):
177-
"""Install Widevine CDM on x86 based architectures."""
176+
def _install_widevine_from_repo(bpath):
177+
"""Install Widevine CDM from Google's library CDM repository"""
178178
cdm = latest_available_widevine_from_repo()
179179
cdm_version = cdm.get('version')
180180

@@ -219,8 +219,8 @@ def install_widevine(self):
219219
if not widevine_eula():
220220
return False
221221

222-
if 'x86' in arch():
223-
result = self._install_widevine_x86(backup_path())
222+
if cdm_from_repo():
223+
result = self._install_widevine_from_repo(backup_path())
224224
else:
225225
result = install_widevine_arm(backup_path())
226226
if not result:
@@ -307,7 +307,7 @@ def _update_widevine(self):
307307
if not wv_config:
308308
log(3, 'Widevine config missing. Could not determine current version, forcing update.')
309309
current_version = '0'
310-
elif 'x86' in arch():
310+
elif cdm_from_repo():
311311
component = 'Widevine CDM'
312312
current_version = wv_config['version']
313313
latest_version = latest_available_widevine_from_repo().get('version')
@@ -343,9 +343,9 @@ def _check_widevine(self):
343343
ok_dialog(localize(30001), localize(30031)) # An update of Widevine is required
344344
return self.install_widevine()
345345

346-
if 'x86' in arch(): # check that widevine arch matches system arch
346+
if cdm_from_repo(): # check that widevine arch matches system arch
347347
wv_config = load_widevine_config()
348-
if config.WIDEVINE_ARCH_MAP_X86[arch()] != wv_config['arch']:
348+
if config.WIDEVINE_ARCH_MAP_REPO[arch()] != wv_config['arch']:
349349
log(4, 'Widevine/system arch mismatch. Reinstall is required.')
350350
ok_dialog(localize(30001), localize(30031)) # An update of Widevine is required
351351
return self.install_widevine()
@@ -454,7 +454,7 @@ def info_dialog(self):
454454
else:
455455
wv_updated = 'Never'
456456
text += localize(30821, version=self._get_lib_version(widevinecdm_path()), date=wv_updated) + '\n'
457-
if arch() in ('arm', 'arm64'): # Chrome OS version
457+
if arch() == 'arm' or arch() == 'arm64' and system_os() != 'Darwin': # Chrome OS version
458458
wv_cfg = load_widevine_config()
459459
if wv_cfg:
460460
text += localize(30822, name=wv_cfg['hwidmatch'].split()[0].lstrip('^'), version=wv_cfg['version']) + '\n'
@@ -485,7 +485,7 @@ def rollback_libwv(self):
485485
installed_version = load_widevine_config()['version']
486486
del versions[versions.index(installed_version)]
487487

488-
if 'x86' in arch():
488+
if cdm_from_repo():
489489
show_versions = versions
490490
else:
491491
show_versions = []

lib/inputstreamhelper/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
'arm64'
4343
]
4444

45-
WIDEVINE_ARCH_MAP_X86 = {
45+
WIDEVINE_ARCH_MAP_REPO = {
4646
'x86_64': 'x64',
47-
'x86': 'ia32'
47+
'x86': 'ia32',
48+
'arm64': 'arm64'
4849
}
4950

5051
WIDEVINE_OS_MAP = {

lib/inputstreamhelper/widevine/widevine.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def install_cdm_from_backup(version):
2828

2929
def widevine_eula():
3030
"""Displays the Widevine EULA and prompts user to accept it."""
31-
if 'x86' in arch():
31+
if cdm_from_repo():
3232
cdm_version = latest_available_widevine_from_repo().get('version')
3333
cdm_os = config.WIDEVINE_OS_MAP[system_os()]
34-
cdm_arch = config.WIDEVINE_ARCH_MAP_X86[arch()]
35-
else: # grab the license from the x86 files
34+
cdm_arch = config.WIDEVINE_ARCH_MAP_REPO[arch()]
35+
else: # Grab the license from the x86 files
3636
log(0, 'Acquiring Widevine EULA from x86 files.')
3737
cdm_version = latest_widevine_version(eula=True)
3838
cdm_os = 'mac'
@@ -51,6 +51,13 @@ def widevine_eula():
5151
return yesno_dialog(localize(30026), eula, nolabel=localize(30028), yeslabel=localize(30027)) # Widevine CDM EULA
5252

5353

54+
def cdm_from_repo():
55+
"""Whether the Widevine CDM is available from Google's library CDM repository"""
56+
# Based on https://source.chromium.org/chromium/chromium/src/+/master:third_party/widevine/cdm/widevine.gni
57+
if 'x86' in arch() or arch() == 'arm64' and system_os() == 'Darwin':
58+
return True
59+
return False
60+
5461
def backup_path():
5562
"""Return the path to the cdm backups"""
5663
path = os.path.join(addon_profile(), 'backup', '')
@@ -64,7 +71,7 @@ def widevine_config_path():
6471
iacdm = ia_cdm_path()
6572
if iacdm is None:
6673
return None
67-
if 'x86' in arch():
74+
if cdm_from_repo():
6875
return os.path.join(iacdm, config.WIDEVINE_CONFIG_NAME)
6976
return os.path.join(iacdm, 'config.json')
7077

@@ -155,7 +162,7 @@ def missing_widevine_libs():
155162

156163
def latest_widevine_version(eula=False):
157164
"""Returns the latest available version of Widevine CDM/Chrome OS."""
158-
if eula or 'x86' in arch():
165+
if eula or cdm_from_repo():
159166
url = config.WIDEVINE_VERSIONS_URL
160167
versions = http_get(url)
161168
return versions.split()[-1]
@@ -174,7 +181,7 @@ def latest_available_widevine_from_repo():
174181
"""Returns the latest available Widevine CDM version and url from Google's library CDM repository"""
175182
cdm_versions = http_get(config.WIDEVINE_VERSIONS_URL).strip('\n').split('\n')
176183
cdm_os = config.WIDEVINE_OS_MAP[system_os()]
177-
cdm_arch = config.WIDEVINE_ARCH_MAP_X86[arch()]
184+
cdm_arch = config.WIDEVINE_ARCH_MAP_REPO[arch()]
178185
available_cdms = []
179186
for cdm_version in cdm_versions:
180187
cdm_url = config.WIDEVINE_DOWNLOAD_URL.format(version=cdm_version, os=cdm_os, arch=cdm_arch)

0 commit comments

Comments
 (0)