Skip to content

Commit

Permalink
Download ARM Widevine for RPis from raspberrypi.org
Browse files Browse the repository at this point in the history
  • Loading branch information
horstle committed Mar 21, 2021
1 parent 636b832 commit c1bea94
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/inputstreamhelper/__init__.py
Expand Up @@ -169,9 +169,8 @@ def _supports_widevine():
return True

@staticmethod
def _install_widevine_x86(bpath):
def _install_widevine_x86(bpath, cdm_version):
"""Install Widevine CDM on x86 based architectures."""
cdm_version = latest_widevine_version()

if not store('download_path'):
cdm_os = config.WIDEVINE_OS_MAP[system_os()]
Expand Down Expand Up @@ -218,10 +217,12 @@ def install_widevine(self):
if not widevine_eula():
return False

cdm_version = latest_widevine_version()

if 'x86' in arch():
result = self._install_widevine_x86(backup_path())
result = self._install_widevine_x86(backup_path(), cdm_version)
else:
result = install_widevine_arm(backup_path())
result = install_widevine_arm(backup_path(), cdm_version)
if not result:
return result

Expand Down
8 changes: 8 additions & 0 deletions lib/inputstreamhelper/config.py
Expand Up @@ -71,6 +71,14 @@

WIDEVINE_DOWNLOAD_URL = 'https://dl.google.com/widevine-cdm/{version}-{os}-{arch}.zip'

RPI_WIDEVINE_URL = 'http://archive.raspberrypi.org/debian/pool/main/w/widevine/'

RPI_WIDEVINE_DOWNLOAD_URL = 'http://archive.raspberrypi.org/debian/pool/main/w/widevine/widevine_{version}.orig.tar.xz'

RPI_WIDEVINE_LIB_PATH = "widevine/opt/WidevineCdm/_platform_specific/linux_arm/"

RPI_WIDEVINE_MANIFEST_PATH = "widevine/opt/WidevineCdm/"

WIDEVINE_LICENSE_FILE = 'LICENSE.txt'

WIDEVINE_MANIFEST_FILE = 'manifest.json'
Expand Down
13 changes: 13 additions & 0 deletions lib/inputstreamhelper/utils.py
Expand Up @@ -187,6 +187,19 @@ def unzip(source, destination, file_to_unzip=None, result=[]): # pylint: disabl
return bool(result)


def untar(source, destination, files_to_extract):
"""Extract files from tar archive to specified path"""
import tarfile

if not exists(destination):
mkdirs(destination)

archive = tarfile.open(source)
for file_to_extract in files_to_extract:
with open(os.path.join(destination, os.path.basename(file_to_extract)), 'wb') as fobj:
fobj.write(archive.extractfile(file_to_extract).read())


def system_os():
"""Get system platform, and remember this information"""

Expand Down
27 changes: 24 additions & 3 deletions lib/inputstreamhelper/widevine/arm.py
Expand Up @@ -8,8 +8,8 @@
from time import time

from .. import config
from ..kodiutils import browsesingle, copy, exists, localize, log, mkdir, ok_dialog, open_file, progress_dialog, yesno_dialog
from ..utils import cmd_exists, diskspace, http_download, http_get, run_cmd, sizeof_fmt, store, system_os, temp_path, update_temp_path
from ..kodiutils import browsesingle, copy, exists, get_setting_bool, localize, log, mkdir, ok_dialog, open_file, progress_dialog, yesno_dialog
from ..utils import cmd_exists, diskspace, http_download, http_get, run_cmd, sizeof_fmt, store, system_os, temp_path, untar, update_temp_path
from ..unicodes import compat_path, to_unicode
from .arm_chromeos import ChromeOSImage

Expand Down Expand Up @@ -122,8 +122,29 @@ def chromeos_config():
return json.loads(http_get(config.CHROMEOS_RECOVERY_URL))


def install_widevine_arm(backup_path):
def install_widevine_rpi(backup_path, cdm_version):
"""Installs Widevine CDM on Raspberry Pis."""
url = config.RPI_WIDEVINE_DOWNLOAD_URL.format(version=cdm_version)
downloaded = http_download(url)

if not downloaded:
return False

progress = progress_dialog()
progress.create(heading=localize(30043), message=localize(30044)) # Extracting Widevine CDM

files_to_extract = [os.path.join(config.RPI_WIDEVINE_LIB_PATH, config.WIDEVINE_CDM_FILENAME[system_os()]),
os.path.join(config.RPI_WIDEVINE_MANIFEST_PATH, config.WIDEVINE_MANIFEST_FILE)]
untar(store('download_path'), os.path.join(backup_path, cdm_version), files_to_extract)

return (progress, cdm_version)


def install_widevine_arm(backup_path, cdm_version):
"""Installs Widevine CDM on ARM-based architectures."""
if get_setting_bool('rpi_widevine_source'):
return install_widevine_rpi(backup_path, cdm_version)

devices = chromeos_config()
arm_device = select_best_chromeos_image(devices)
if arm_device is None:
Expand Down
11 changes: 10 additions & 1 deletion lib/inputstreamhelper/widevine/widevine.py
Expand Up @@ -7,7 +7,8 @@
from time import time

from .. import config
from ..kodiutils import addon_profile, exists, get_setting_int, listdir, localize, log, mkdirs, ok_dialog, open_file, set_setting, translate_path, yesno_dialog
from ..kodiutils import (addon_profile, exists, get_setting_bool, get_setting_int, listdir, localize, log, mkdirs, ok_dialog, open_file,
set_setting, translate_path, yesno_dialog)
from ..utils import arch, cmd_exists, hardlink, http_download, http_get, remove_tree, run_cmd, store, system_os
from ..unicodes import compat_path, to_unicode

Expand Down Expand Up @@ -160,6 +161,14 @@ def latest_widevine_version(eula=False):
versions = http_get(url)
return versions.split()[-1]

if get_setting_bool('rpi_widevine_source'):
import re

url = config.RPI_WIDEVINE_URL
files = http_get(url)
version = re.search(r'[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+', files).group(0)
return version

from .arm import chromeos_config, select_best_chromeos_image
devices = chromeos_config()
arm_device = select_best_chromeos_image(devices)
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Expand Up @@ -4,6 +4,7 @@
<setting id="last_modified" default="0.0" visible="false"/>
<setting id="last_check" default="0.0" visible="false"/>
<setting id="version" default="" visible="false"/>
<setting id="rpi_widevine_source" type="bool" default="false" visible="false"/>
<setting label="30901" help="30902" type="action" action="RunScript(script.module.inputstreamhelper, info)"/>
<setting type="sep"/>
<setting label="30903" help="30904" type="bool" id="disabled" default="false"/>
Expand Down

0 comments on commit c1bea94

Please sign in to comment.