示例#1
0
 def del_login(self):
     try:
         folder = KodiUtil.translatePath(self.addon.getAddonInfo('profile'))
         self.log("Removing stored session: " + folder + self.addon_id +
                  "_session" + ".ecdata")
         os.remove(folder + self.addon_id + "_session" + ".ecdata")
     except Exception:
         self.log("Delete login error: " + traceback.format_exc())
示例#2
0
 def save_obj(self, obj, name):
     folder = KodiUtil.translatePath(self.addon.getAddonInfo('profile'))
     self.log("Saving: " + folder + name + '.ecdata')
     with open(folder + name + '.ecdata', 'wb') as f:
         try:
             f.write(self.encrypt_credential_v1(json.dumps(obj)))
         except TypeError:
             f.write(
                 bytes(self.encrypt_credential_v1(json.dumps(obj)), 'utf8'))
示例#3
0
 def load_obj(self, name):
     folder = KodiUtil.translatePath(self.addon.getAddonInfo('profile'))
     self.log("Trying to load: " + folder + name + '.ecdata')
     try:
         with open(folder + name + '.ecdata', 'rb') as f:
             return json.loads(self.decrypt_credential_v1(f.read()))
     except Exception:
         self.log("OBJECT RELOAD ERROR")
         self.log("Stack trace: " + traceback.format_exc())
         return None
示例#4
0
 def clean_sub_cache(self, silent=True):
     try:
         import shutil
         subs_folder = KodiUtil.translatePath(
             self.addon.getAddonInfo('profile'))
         subs_folder = subs_folder + 'subs'
         shutil.rmtree(subs_folder, ignore_errors=True)
         if not silent:
             icon = self.get_resource("icon.png")
             xbmcgui.Dialog().notification(self.language(30814),
                                           self.LB_INFO, icon)
     except Exception:
         self.log("Clean subtitle cache error: " + traceback.format_exc())
    def play(self, content_id, retry=0):
        self.log("Initializing playback... " + str(content_id))

        self.login()

        media_item = self.get_from_hbogo(
            self.API_URL_BROWSE + content_id + self.LANGUAGE_CODE, 'xml')
        if media_item is False:
            return
        media_info = self.construct_media_info(media_item.find('.//item'))

        if self.lograwdata:
            self.log("Play Media: ")
            self.log(ET.tostring(media_item, encoding='utf8'))

        mpd_pre_url = media_item.find(
            './/media:content[@profile="HBO-DASH-WIDEVINE"]',
            namespaces=self.NAMESPACES).get('url') + '&responseType=xml'

        mpd = self.get_from_hbogo(mpd_pre_url, 'xml', False)
        if mpd is False:
            return
        if self.lograwdata:
            self.log("Manifest: ")
            self.log(ET.tostring(mpd, encoding='utf8'))

        mpd_url = mpd.find('.//url').text
        self.log("Manifest url: " + str(mpd_url))

        media_guid = media_item.find('.//guid').text

        license_headers = 'X-Clearleap-AssetID=' + media_guid + '&X-Clearleap-DeviceId=' + self.API_DEVICE_ID + \
                          '&X-Clearleap-DeviceToken=' + self.API_DEVICE_TOKEN + '&Content-Type='

        license_url = 'https://' + self.API_HOST + '/cloffice/drm/wv/' + media_guid + '|' + license_headers + '|R{SSM}|'

        li = xbmcgui.ListItem(path=mpd_url)
        li.setArt(media_info["art"])
        li.setInfo(type="Video", infoLabels=media_info["info"])

        protocol = 'mpd'
        drm = 'com.widevine.alpha'
        li.setContentLookup(False)
        li.setMimeType('application/dash+xml')
        from inputstreamhelper import Helper  # type: ignore
        is_helper = Helper(protocol, drm=drm)
        if is_helper.check_inputstream():
            if sys.version_info < (
                    3, 0
            ):  # if python version < 3 is safe to assume we are running on Kodi 18
                li.setProperty(
                    'inputstreamaddon',
                    'inputstream.adaptive')  # compatible with Kodi 18 API
            else:
                li.setProperty('inputstream', 'inputstream.adaptive'
                               )  # compatible with recent builds Kodi 19 API
            li.setProperty('inputstream.adaptive.license_type', drm)
            li.setProperty('inputstream.adaptive.manifest_type', protocol)
            li.setProperty('inputstream.adaptive.license_key', license_url)

            # GET SUBTITLES
            if self.addon.getSetting('forcesubs') == 'true':
                folder = KodiUtil.translatePath(
                    self.addon.getAddonInfo('profile'))
                folder = folder + 'subs'
                self.clean_sub_cache(folder)
                folder = folder + os.sep + media_guid + os.sep
                self.log(
                    "Cache subtitles enabled, downloading and converting subtitles in: "
                    + folder)
                if not os.path.exists(os.path.dirname(folder)):
                    try:
                        os.makedirs(os.path.dirname(folder))
                    except OSError as exc:  # Guard against race condition
                        if exc.errno != errno.EEXIST:
                            raise
                try:
                    subs = media_item.findall('.//media:subTitle',
                                              namespaces=self.NAMESPACES)
                    subs_paths = []
                    for sub in subs:
                        self.log("Processing subtitle language code: " +
                                 sub.get('lang') + " URL: " + sub.get('href'))
                        r = requests.get(sub.get('href'))
                        with open(folder + sub.get('lang') + ".xml",
                                  'wb') as f:
                            f.write(r.content)
                        ttml = Ttml2Srt(
                            py2_encode(folder + sub.get('lang') + ".xml"), 25)
                        srt_file = ttml.write2file(
                            ttml.mfn2srtfn(
                                py2_encode(folder + sub.get('lang')),
                                ttml.lang, False))
                        self.log("Subtitle converted to srt format")
                        subs_paths.append(srt_file)
                        self.log("Subtitle added: " + srt_file)
                    li.setSubtitles(subs_paths)
                    self.log("Local subtitles set")
                except Exception:
                    self.log("Unexpected error in subtitles processing: " +
                             traceback.format_exc())

            self.log("Play url: " + str(li))
            xbmcplugin.setResolvedUrl(self.handle, True, listitem=li)
        else:
            self.log("DRM problem playback not possible")
            xbmcplugin.setResolvedUrl(self.handle, False, listitem=li)
示例#6
0
    def __init__(self, handle, base_url):
        self.addon = xbmcaddon.Addon()
        self.addon_id = self.addon.getAddonInfo('id')
        self.language = self.addon.getLocalizedString
        self.base_url = base_url
        self.handle = handle
        self.DEBUG_ID_STRING = "[" + str(self.addon_id) + "] "
        self.SESSION_VALIDITY = 4  # stored session valid for 4 hours
        self.max_comm_retry = 1  # if unauthorized del session and re-login and try again max times
        self.max_play_retry = 1  # max play retry on soft error
        self.db_version = 1

        self.base_addon_cat = ""
        self.cur_loc = ""

        xbmcplugin.setPluginFanart(self.handle,
                                   image=self.get_resource("fanart.jpg"))

        # LABELS

        self.LB_SEARCH_DESC = py2_encode(self.language(30700))
        self.LB_SEARCH_NORES = py2_encode(self.language(30701))
        self.LB_ERROR = py2_encode(self.language(30702))
        self.LB_INFO = py2_encode(self.language(30713))
        self.LB_SUCESS = py2_encode(self.language(30727))
        self.LB_EPISODE_UNTILL = py2_encode(self.language(30703))
        self.LB_FILM_UNTILL = py2_encode(self.language(30704))
        self.LB_EPISODE = py2_encode(self.language(30705))
        self.LB_SEASON = py2_encode(self.language(30706))
        self.LB_MYPLAYLIST = py2_encode(self.language(30707))
        self.LB_NOLOGIN = py2_encode(self.language(30708))
        self.LB_LOGIN_ERROR = py2_encode(self.language(30709))
        self.LB_NO_OPERATOR = py2_encode(self.language(30710))
        self.LB_SEARCH = py2_encode(self.language(30711))

        self.n_movies = 0
        self.n_tvshows = 0
        self.n_seasons = 0
        self.n_episodes = 0

        self.force_original_names = self.addon.getSetting('origtitles')
        if self.force_original_names == "true":
            self.force_original_names = True
        else:
            self.force_original_names = False

        self.force_scraper_names = self.addon.getSetting('forcescrap')
        if self.force_scraper_names == "true":
            self.force_scraper_names = True
        else:
            self.force_scraper_names = False

        self.sensitive_debug = self.addon.getSetting('sensitivedebug')
        if self.sensitive_debug == "true":
            self.sensitive_debug = True
        else:
            self.sensitive_debug = False

        self.lograwdata = self.addon.getSetting('lograwdata')
        if self.lograwdata == "true":
            self.lograwdata = True
        else:
            self.lograwdata = False

        self.use_cache = self.addon.getSetting('use_req_cache')
        if self.use_cache == "true":
            self.use_cache = True
        else:
            self.use_cache = False

        self.usedevkey = self.addon.getSetting('usedevkey')
        if self.usedevkey == "true":
            self.usedevkey = True
        else:
            self.usedevkey = False

        if self.sensitive_debug:
            ret = xbmcgui.Dialog().yesno(self.LB_INFO, self.language(30712),
                                         self.language(30714),
                                         self.language(30715))
            if not ret:
                sys.exit()

        self.loggedin_headers = None  # DEFINE IN SPECIFIC HANDLER
        self.API_PLATFORM = 'COMP'

        self.log("Starting database connection...")
        self.db = sqlite3.connect(
            KodiUtil.translatePath(self.addon.getAddonInfo('profile')) +
            'hgo.db')
        cur = self.db.cursor()
        try:
            cur.execute("SELECT val_int FROM settings WHERE set_id='db_ver'")
            r = cur.fetchone()
            if r[0] != self.db_version:
                self.log("Database version mismatch updating database.")
                self.ceate_db(r[0])
        except Exception:
            self.log("Database error: " + traceback.format_exc())
            self.ceate_db()
示例#7
0
 def get_media_resource(resourcefile):
     return py2_decode(
         KodiUtil.translatePath(xbmcaddon.Addon().getAddonInfo('path') +
                                '/resources/media/' + resourcefile))