diff --git a/resources/lib/helperobjects.py b/resources/lib/helperobjects.py index 648e2699..38adacad 100644 --- a/resources/lib/helperobjects.py +++ b/resources/lib/helperobjects.py @@ -20,11 +20,12 @@ def __init__(self, client, media_api_url, video_id, publication_id, is_live_stre class StreamURLS: """This helper object holds all information to be used when playing streams""" - def __init__(self, stream_url, subtitle_url=None, license_key=None, use_inputstream_adaptive=False): + def __init__(self, stream_url, subtitle_url=None, license_url=None, license_headers=None, use_inputstream_adaptive=False): """The constructor for the StreamURLS class""" self.stream_url = stream_url self.subtitle_url = subtitle_url - self.license_key = license_key + self.license_url = license_url + self.license_headers = license_headers self.use_inputstream_adaptive = use_inputstream_adaptive self.video_id = None diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py index d86e1c67..c8a1ad9e 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -20,9 +20,11 @@ from utils import from_unicode, to_unicode try: # Python 3 + from urllib.parse import quote, urlencode from urllib.request import HTTPErrorProcessor except ImportError: # Python 2 - from urllib2 import HTTPErrorProcessor + from urllib import urlencode + from urllib2 import quote, HTTPErrorProcessor ADDON = Addon() DEFAULT_CACHE_DIR = 'cache' @@ -309,12 +311,13 @@ def play(stream, video=None): play_item.setProperty('inputstream.adaptive.manifest_type', 'hls') play_item.setMimeType('application/vnd.apple.mpegurl') - if stream.license_key is not None: + if stream.license_url is not None: import inputstreamhelper is_helper = inputstreamhelper.Helper('mpd', drm='com.widevine.alpha') if is_helper.check_inputstream(): play_item.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') - play_item.setProperty('inputstream.adaptive.license_key', stream.license_key) + license_key = generate_ia_license_key(stream.license_url, license_headers=stream.license_headers) + play_item.setProperty('inputstream.adaptive.license_key', license_key) subtitles_visible = get_setting_bool('showsubtitles', default=True) # Separate subtitle url for hls-streams @@ -339,6 +342,21 @@ def get_search_string(search_string=None): return search_string +def generate_ia_license_key(license_url, license_headers='', postdata_type='R', postdata_value='', response_type=''): + """Generates an InputStream Adaptive license_key""" + if license_headers: + license_headers = urlencode(license_headers) + + if postdata_type in ('A', 'R', 'B'): + postdata_value = postdata_type + '{SSM}' + elif postdata_type == 'D': + if 'D{SSM}' not in postdata_value: + raise ValueError('Missing D{SSM} placeholder') + postdata_value = quote(postdata_value) + + return '{}|{}|{}|{}'.format(license_url, license_headers, postdata_value, response_type) + + def ok_dialog(heading='', message=''): """Show Kodi's OK dialog""" from xbmcgui import Dialog diff --git a/resources/lib/streamservice.py b/resources/lib/streamservice.py index 6c34488a..e05f1cf8 100644 --- a/resources/lib/streamservice.py +++ b/resources/lib/streamservice.py @@ -6,9 +6,8 @@ try: # Python 3 from urllib.error import HTTPError - from urllib.parse import quote, urlencode + from urllib.parse import quote except ImportError: # Python 2 - from urllib import urlencode from urllib2 import quote, HTTPError from helperobjects import ApiData, StreamURLS @@ -56,46 +55,6 @@ def _create_settings_dir(): if not exists(settingsdir): mkdir(settingsdir) - @staticmethod - def _get_license_key(key_url, key_type='R', key_headers=None, key_value=None): - """Generates a proper Widevine license key value - - # A{SSM} -> not implemented - # R{SSM} -> raw format - # B{SSM} -> base64 format - # D{SSM} -> decimal format - - The generic format for a LicenseKey is: - |||