def playlive(self, id, meta): if id is None: return info = resourceshelper.get_video_info(id) control.log("INFO: %s" % repr(info)) if not info or info is None or 'channel' not in info: return try: hash, user, credentials = self.sign_resource(info['provider_id'], info['resource_id'], id, info['player'], info['version']) except Exception as ex: control.log("ERROR: %s" % repr(ex)) return encrypted = 'encrypted' in info and info['encrypted'] if encrypted and not control.is_inputstream_available(): control.infoDialog(message=control.lang(34103).encode('utf-8'), icon='Wr') return title = info['channel'] query_string = re.sub(r'{{(\w*)}}', r'%(\1)s', info['query_string_template']) query_string = query_string % { 'hash': hash, 'key': 'app', 'openClosed': 'F' if info['subscriber_only'] else 'A', 'user': user if info['subscriber_only'] else '' } url = '?'.join([info['url'], query_string]) control.log("live media url: %s" % url) try: meta = json.loads(meta) except: meta = { "playcount": 0, "overlay": 6, "title": title, "thumb": info["thumbUri"], "mediatype": "video", "aired": info["exhibited_at"] } meta.update({ "genre": info["category"], "plot": info["title"], "plotoutline": info["title"] }) poster = meta['poster'] if 'poster' in meta else control.addonPoster() thumb = meta['thumb'] if 'thumb' in meta else info["thumbUri"] self.offset = float(meta['milliseconds_watched']) / 1000.0 if 'milliseconds_watched' in meta else 0 self.isLive = 'livefeed' in meta and meta['livefeed'] == 'true' parsed_url = urlparse(url) if parsed_url.path.endswith(".m3u8"): self.url, mime_type, stopEvent, cookies = hlshelper.pick_bandwidth(url) else: self.url = url mime_type, stopEvent, cookies = 'video/mp4', None, None if self.url is None: if stopEvent: control.log("Setting stop event for proxy player") stopEvent.set() control.infoDialog(control.lang(34100).encode('utf-8'), icon='ERROR') return control.log("Resolved URL: %s" % repr(self.url)) control.log("Parsed URL: %s" % repr(parsed_url)) item = control.item(path=self.url) item.setArt({'icon': thumb, 'thumb': thumb, 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster}) item.setProperty('IsPlayable', 'true') item.setInfo(type='Video', infoLabels=meta) item.setContentLookup(False) if parsed_url.path.endswith(".mpd"): mime_type = 'application/dash+xml' item.setProperty('inputstream.adaptive.manifest_type', 'mpd') elif parsed_url.path.endswith(".ism/manifest"): mime_type = 'application/vnd.ms-sstr+xml' item.setProperty('inputstream.adaptive.manifest_type', 'ism') else: item.setProperty('inputstream.adaptive.manifest_type', 'hls') if encrypted: control.log("DRM: %s" % info['drm_scheme']) licence_url = info['protection_url'] item.setProperty('inputstream.adaptive.license_type', info['drm_scheme']) if info['drm_scheme'] == 'com.widevine.alpha' or info['drm_scheme'] == 'com.microsoft.playready': item.setProperty('inputstream.adaptive.license_key', licence_url + "||R{SSM}|") if mime_type: item.setMimeType(mime_type) control.log("MIME TYPE: %s" % repr(mime_type)) if not cookies and not control.disable_inputstream_adaptive: item.setProperty('inputstreamaddon', 'inputstream.adaptive') if 'subtitles' in info and info['subtitles'] and len(info['subtitles']) > 0: control.log("FOUND SUBTITLES: %s" % repr([sub['url'] for sub in info['subtitles']])) item.setSubtitles([sub['url'] for sub in info['subtitles']]) control.resolve(int(sys.argv[1]), True, item) self.stopPlayingEvent = threading.Event() self.stopPlayingEvent.clear() self.token = auth_helper.get_globosat_token() self.video_id = info['id'] if 'id' in info else None first_run = True last_time = 0.0 while not self.stopPlayingEvent.isSet(): if control.monitor.abortRequested(): control.log("Abort requested") break if self.isPlaying(): if first_run: self.showSubtitles(False) first_run = False if not self.isLive: current_time = self.getTime() if current_time - last_time > 5 or (last_time == 0 and current_time > 1): last_time = current_time self.save_video_progress(self.token, self.video_id, current_time) control.sleep(1000) if stopEvent: control.log("Setting stop event for proxy player") stopEvent.set() control.log("Done playing. Quitting...")
def playlive(self, id, meta): meta = meta or {} control.log("Globosat Play - play_stream: id=%s | meta=%s" % (id, meta)) if id is None: return self.isLive = meta.get('livefeed', False) cdn = control.setting('globosat_cdn') if cdn: cdn = cdn.lower() if cdn.lower() != 'auto' else None if meta.get('geofencing') and meta.get('lat') and meta.get('long'): info = resourceshelper.get_geofence_video_info( id, meta.get('lat'), meta.get('long'), auth_helper.get_credentials(), cdn) elif not meta.get('router', True) or cdn: info = resourceshelper.get_video_info(id, cdn=cdn) else: info = resourceshelper.get_video_router(id, self.isLive, cdn) if not info: info = resourceshelper.get_video_info(id, cdn=cdn) control.log("INFO: %s" % repr(info)) if not info or info is None or 'channel' not in info: return try: hash_token = info.get('hash_token') user = info.get('user') if not hash_token: control.log('Signing resource: %s' % info['resource_id']) hash_token, user, credentials = self.sign_resource( info['provider_id'], info['resource_id'], id, info['player'], info['version'], cdn) except Exception as ex: control.log(traceback.format_exc(), control.LOGERROR) control.log("PLAYER ERROR: %s" % repr(ex)) return encrypted = 'encrypted' in info and info['encrypted'] if encrypted and not control.is_inputstream_available(): control.okDialog(control.lang(31200), control.lang(34103).encode('utf-8')) return query_string = re.sub(r'{{(\w*)}}', r'%(\1)s', info['query_string_template']) query_string = query_string % { 'hash': hash_token, 'key': 'app', 'openClosed': 'F' if info['subscriber_only'] and user else 'A', 'user': user if info['subscriber_only'] and user else '', 'token': hash_token } url = '?'.join([info['url'], query_string]) control.log("live media url: %s" % url) self.offset = float(meta['milliseconds_watched'] ) / 1000.0 if 'milliseconds_watched' in meta else 0 parsed_url = urlparse(url) if parsed_url.path.endswith(".m3u8"): self.url, mime_type, stop_event, cookies = hlshelper.pick_bandwidth( url) elif parsed_url.path.endswith(".mpd") and not self.isLive: proxy_handler = MediaProxy() self.url = proxy_handler.resolve(url) stop_event = proxy_handler.stop_event mime_type = None cookies = None else: self.url = url mime_type, stop_event, cookies = 'video/mp4', None, None if self.url is None: if stop_event: control.log("Setting stop event for proxy player") stop_event.set() control.infoDialog(control.lang(34100).encode('utf-8'), icon='ERROR') return control.log("Resolved URL: %s" % repr(self.url)) control.log("Parsed URL: %s" % repr(parsed_url)) if control.supports_offscreen: item = control.item(path=self.url, offscreen=True) else: item = control.item(path=self.url) item.setArt(meta.get('art', {})) item.setProperty('IsPlayable', 'true') item.setInfo(type='Video', infoLabels=control.filter_info_labels(meta)) item.setContentLookup(False) if parsed_url.path.endswith(".mpd"): mime_type = 'application/dash+xml' item.setProperty('inputstream.adaptive.manifest_type', 'mpd') if self.isLive: item.setProperty( 'inputstream.adaptive.manifest_update_parameter', 'full') elif parsed_url.path.endswith(".ism/manifest"): mime_type = 'application/vnd.ms-sstr+xml' item.setProperty('inputstream.adaptive.manifest_type', 'ism') else: item.setProperty('inputstream.adaptive.manifest_type', 'hls') if encrypted: control.log("DRM: %s" % info['drm_scheme']) licence_url = info['protection_url'] item.setProperty('inputstream.adaptive.license_type', info['drm_scheme']) if info['drm_scheme'] == 'com.widevine.alpha' or info[ 'drm_scheme'] == 'com.microsoft.playready': item.setProperty('inputstream.adaptive.license_key', licence_url + "||R{SSM}|") if mime_type: item.setMimeType(mime_type) control.log("MIME TYPE: %s" % repr(mime_type)) if not cookies and control.is_inputstream_available(): item.setProperty('inputstreamaddon', 'inputstream.adaptive') # reqCookies = client.request(url=self.url,output='cookiejar',headRequest=True) # cookie_string = "; ".join([str(x) + "=" + str(y) for x, y in reqCookies.items()]) # item.setProperty('inputstream.adaptive.stream_headers', 'cookie=%s' % cookie_string) # control.log("COOKIE STRING: %s" % cookie_string) if 'subtitles' in info and info['subtitles'] and len( info['subtitles']) > 0: control.log("FOUND SUBTITLES: %s" % repr([sub['url'] for sub in info['subtitles']])) item.setSubtitles([sub['url'] for sub in info['subtitles']]) control.resolve(int(sys.argv[1]), True, item) self.stopPlayingEvent = threading.Event() self.stopPlayingEvent.clear() self.token = auth_helper.get_globosat_token() self.video_id = info['id'] if 'id' in info else None first_run = True last_time = 0.0 while not self.stopPlayingEvent.isSet(): if control.monitor.abortRequested(): control.log("Abort requested") break if self.isPlaying(): if first_run: self.showSubtitles(False) first_run = False if not self.isLive: current_time = self.getTime() if current_time - last_time > 5 or (last_time == 0 and current_time > 1): last_time = current_time self.save_video_progress(self.token, self.video_id, current_time) control.sleep(1000) if stop_event: control.log("Setting stop event for proxy player") stop_event.set() control.log("Done playing. Quitting...")
def play_stream(self, id, meta, children_id=None): if id is None: return try: meta = json.loads(meta) except: meta = { "playcount": 0, "overlay": 6, "mediatype": "video", "aired": None } self.isLive = False if 'livefeed' in meta and meta['livefeed'] == 'true': control.log("PLAY LIVE!") self.isLive = True info = self.__getLiveVideoInfo( id, meta['affiliate'] if 'affiliate' in meta else None) if info is None: return item, self.url, stopEvent = self.__get_list_item(meta, info) else: info = resourceshelper.get_video_info(id, children_id) if info is None: return if 'resource_id' not in info: control.log("PLAY CHILDREN!") items = [] xbmc.PlayList(1).clear() first = True for i in info: hash, user, self.credentials = self.sign_resource( i['resource_id'], i['id'], i['player'], i['version']) i['hash'] = hash i['user'] = user item, url, stopEvent = self.__get_list_item(meta, i, False) if first: self.url = url first = False items.append(item) control.log("PLAYLIST ITEM URL: %s" % url) xbmc.PlayList(1).add(url, item) item = items[0] else: control.log("PLAY SINGLE RESOURCE!") hash, user, self.credentials = self.sign_resource( info['resource_id'], info["id"], info['player'], info['version'], meta['anonymous'] if 'anonymous' in meta else False) info['hash'] = hash info['user'] = user item, self.url, stopEvent = self.__get_list_item(meta, info) self.offset = float(meta['milliseconds_watched'] ) / 1000.0 if 'milliseconds_watched' in meta else 0 self.isLive = 'live' in meta and meta['live'] syshandle = int(sys.argv[1]) control.resolve(syshandle, True, item) self.stopPlayingEvent = threading.Event() self.stopPlayingEvent.clear() self.program_id = info['program_id'] if 'program_id' in info else None self.video_id = id first_run = True last_time = 0.0 while not self.stopPlayingEvent.isSet(): if control.monitor.abortRequested(): control.log("Abort requested") break if self.isPlaying(): if first_run: self.showSubtitles(False) first_run = False if not self.isLive: total_time = self.getTotalTime() current_time = self.getTime() if current_time - last_time > 5 or (last_time == 0 and current_time > 1): last_time = current_time percentage_watched = current_time / total_time if total_time > 0 else 1.0 / 1000000.0 self.save_video_progress( self.credentials, self.program_id, self.video_id, current_time * 1000, fully_watched=0.9 < percentage_watched <= 1) control.sleep(500) if stopEvent: control.log("Setting stop event for proxy player") stopEvent.set() control.log("Done playing. Quitting...")
def play_stream(self, id, meta, children_id=None): meta = meta or {} control.log( "GloboPlay - play_stream: id=%s | children_id=%s | meta=%s" % (id, children_id, meta)) if id is None: return self.isLive = meta.get('livefeed', False) stop_event = None if self.isLive and meta.get('lat') and meta.get('long'): control.log("PLAY LIVE!") latitude = meta.get('lat') longitude = meta.get('long') if not latitude or not longitude: code, latitude, longitude = control.get_coordinates( control.get_affiliates_by_id(-1)) info = self.__getLiveVideoInfo(id, latitude, longitude) if info is None: return item, self.url, stop_event = self.__get_list_item(meta, info) else: if not meta.get('router', True): info = resourceshelper.get_video_info(id, children_id) else: info = resourceshelper.get_video_router(id, self.isLive) if not info: info = resourceshelper.get_video_info(id, children_id) if info is None: return if 'resource_id' not in info: control.log("PLAY CHILDREN!") items = [] xbmc.PlayList(1).clear() first = True for i in info: hash_token, user, self.credentials = self.sign_resource( i['resource_id'], i['id'], i['player'], i['version']) i['hash'] = hash_token i['user'] = user item, url, stop_event = self.__get_list_item( meta, i, False) if first: self.url = url first = False items.append(item) control.log("PLAYLIST ITEM URL: %s" % url) xbmc.PlayList(1).add(url, item) item = items[0] else: control.log("PLAY SINGLE RESOURCE!") hash_token, user, self.credentials = self.sign_resource( info['resource_id'], info["id"], info['player'], info['version'], meta['anonymous'] if 'anonymous' in meta else False) info['hash'] = hash_token info['user'] = user item, self.url, stop_event = self.__get_list_item(meta, info) self.offset = float(meta['milliseconds_watched'] ) / 1000.0 if 'milliseconds_watched' in meta else 0 self.stop_playing_event = threading.Event() self.stop_playing_event.clear() self.program_id = info[ 'program_id'] if 'program_id' in info else meta.get('program_id') self.video_id = id syshandle = int(sys.argv[1]) control.resolve(syshandle, True, item) first_run = True last_time = 0.0 while not self.stop_playing_event.isSet(): if control.monitor.abortRequested(): control.log("Abort requested") break if self.isPlaying(): if first_run: self.showSubtitles(False) first_run = False if not self.isLive: total_time = self.getTotalTime() current_time = self.getTime() if current_time - last_time > 5 or (last_time == 0 and current_time > 1): last_time = current_time percentage_watched = current_time / total_time if total_time > 0 else 1.0 / 1000000.0 self.save_video_progress( self.credentials, self.program_id, self.video_id, current_time * 1000, fully_watched=0.9 < percentage_watched <= 1) control.sleep(500) if stop_event: control.log("Setting stop event for proxy player") stop_event.set() control.log("Done playing. Quitting...")