Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, platform, requests, shutil, traceback
- import xbmc, xbmcgui, xbmcaddon
- import wvconfig as config
- def has_hls():
- inpustream = get_inputstream()
- if not inpustream: return False
- return int(inpustream.getAddonInfo('version')[0]) >= 2
- def has_widevine(reinstall=False):
- inpustream = get_inputstream()
- if not inpustream: return False
- if (not reinstall and
- inpustream.getAddonInfo('version') == config.get('version') and
- has_ssd_wv(inpustream, config.get('system')) and
- has_widevinecdm(inpustream, config.get('system'))):
- return True
- system = platform.system()
- arch = platform.machine()
- if system == 'Windows':
- arch = platform.architecture()[0]
- elif arch[:3] == 'arm':
- arch = arch[:5]
- elif arch == 'i686':
- arch = 'i386'
- try:
- kodi_major_version = int(xbmc.getInfoLabel("System.BuildVersion").split('.')[0])
- except Exception:
- kodi_major_version = 0
- if system == 'Linux' and xbmc.getCondVisibility('system.platform.android'):
- system = 'Android'
- supported = kodi_major_version >= 18
- elif system+arch in config.SUPPORTED_PLATFORMS:
- supported = kodi_major_version >= 17
- else:
- supported = False
- if not supported:
- xbmc.log('Widevine Not Supported: {0} KODI v{1}'.format(system+arch, kodi_major_version), xbmc.LOGNOTICE)
- msg = 'This system (%s KODI v%s) is not currently supported for Widevine DRM content playback.' % (system+arch, kodi_major_version)
- if kodi_major_version < 17:
- msg += '\nWidevine DRM playback requires at least KODI 17.'
- if config['system'] == 'Android':
- msg += '\nWidevine DRM support for Android is coming in KODI 18.'
- xbmcgui.Dialog().ok('Widevine Not Supported', msg)
- return False
- try:
- get_ssd_wv(inpustream, system, arch)
- get_widevinecdm(inpustream, system, arch)
- except:
- traceback.print_exc()
- xbmcgui.Dialog().ok('ERROR', 'There was an error installing Widevine. Please restart KODI and try again.')
- return False
- else:
- config.set('version', inpustream.getAddonInfo('version'))
- config.set('system', system)
- config.set('arch', arch)
- config.save()
- xbmcgui.Dialog().ok('Widevine DRM installed OK.', 'If videos still won\'t play - please try restarting KODI.')
- return True
- def get_inputstream():
- try: return xbmcaddon.Addon('inputstream.adaptive')
- except: pass
- try:
- xbmc.executebuiltin('InstallAddon(inputstream.adaptive)', True)
- xbmc.executeJSONRPC('{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{"addonid":"inputstream.adaptive","enabled":true}}')
- return xbmcaddon.Addon('inputstream.adaptive')
- except:
- xbmcgui.Dialog().ok('Missing inputstream.adaptive add-on',
- 'inputstream.adaptive add-on not found or not enabled.\
- This add-on is required to view DRM protected content.')
- return False
- def has_ssd_wv(inpustream, system):
- return os.path.exists(os.path.join(xbmc.translatePath(inpustream.getSetting('DECRYPTERPATH')), config.SSD_WV_DICT[system]))
- # return (int(inpustream.getAddonInfo('version')[0]) > 1 or
- # os.path.exists(os.path.join(xbmc.translatePath(inpustream.getSetting('DECRYPTERPATH')), config.SSD_WV_DICT[system])))
- def has_widevinecdm(inpustream, system):
- return (system == 'Android' or
- os.path.exists(os.path.join(xbmc.translatePath(inpustream.getSetting('DECRYPTERPATH')), config.WIDEVINECDM_DICT[system])))
- def remove_file(file_path):
- if os.path.islink(file_path):
- os.unlink(file_path)
- elif os.path.exists(file_path):
- os.remove(file_path)
- def get_widevinecdm(inpustream, system, arch):
- if system == 'Android':
- return
- cdm_path = xbmc.translatePath(inpustream.getSetting('DECRYPTERPATH'))
- filename = config.WIDEVINECDM_DICT[system]
- download_path = os.path.join(cdm_path, filename)
- if not os.path.isdir(cdm_path):
- os.makedirs(cdm_path)
- else:
- remove_file(download_path)
- url = config.GIT_URL.format(system, arch, filename)
- if not progress_download(url, download_path, filename):
- raise Exception("Failed to download file")
- os.chmod(download_path, 0755)
- def get_ssd_wv(inpustream, system, arch):
- # if int(inpustream.getAddonInfo('version')[0]) > 1:
- # return True
- cdm_path = xbmc.translatePath(inpustream.getSetting('DECRYPTERPATH'))
- filename = config.SSD_WV_DICT[system]
- download_path = os.path.join(cdm_path, filename)
- if not os.path.isdir(cdm_path):
- os.makedirs(cdm_path)
- else:
- remove_file(download_path)
- addon_path = xbmc.translatePath(inpustream.getAddonInfo('path')).decode("utf-8")
- paths = [os.path.join(addon_path, filename), os.path.join(addon_path, 'lib', filename), os.path.join(os.sep, 'usr', 'lib', filename)]
- for path in paths:
- if os.path.exists(path):
- try:
- shutil.copy(path, download_path)
- os.chmod(download_path, 0755)
- return
- except:
- continue
- url = config.GIT_URL.format(system, arch, filename)
- if not progress_download(url, download_path, filename):
- raise Exception("Failed to download file")
- os.chmod(download_path, 0755)
- def progress_download(url, download_path, filename):
- xbmc.log('Downloading {0}'.format(url),xbmc.LOGNOTICE)
- try:
- res = requests.get(url, stream=True, verify=False)
- res.raise_for_status()
- except requests.exceptions.HTTPError:
- xbmcgui.Dialog().ok('Download failed', 'HTTP '+str(res.status_code)+' error')
- xbmc.log('Error retrieving {0}'.format(url), level=xbmc.LOGNOTICE)
- return False
- total_length = float(res.headers.get('content-length'))
- dp = xbmcgui.DialogProgress()
- dp.create("Installing DRM", "Downloading", url)
- with open(download_path, 'wb') as f:
- chunk_size = 1024
- downloaded = 0
- for chunk in res.iter_content(chunk_size=chunk_size):
- f.write(chunk)
- downloaded += len(chunk)
- percent = int(downloaded*100/total_length)
- if dp.iscanceled():
- dp.close()
- res.close()
- dp.update(percent)
- xbmc.log('Download {0} bytes complete, saved in {1}'.format(
- int(total_length), download_path),xbmc.LOGNOTICE)
- dp.close()
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement