def play(url): try: params = utils.get_url(url) if params.has_key('id'): video_id = params['id'] v = comm.get_video(video_id) elif params.has_key('url'): # New style v = classes.Video() v.parse_xbmc_url(url) # Show a dialog d = xbmcgui.DialogProgress() d.create(config.NAME, '') d.update(50, 'Starting video...') listitem = xbmcgui.ListItem(label=v.get_title(), iconImage=v.get_thumbnail(), thumbnailImage=v.get_thumbnail()) listitem.addStreamInfo('video', v.get_xbmc_stream_info()) listitem.setInfo('video', v.get_xbmc_list_item()) xbmc.Player().play(v.get_url(), listitem) except: # user cancelled dialog or an error occurred d = xbmcgui.Dialog() message = utils.dialog_error("Unable to play video") d.ok(*message) utils.log_error()
def parse_json_video_new(video_data): """ Parse the JSON data and construct a video object from it for a list of videos """ # Find our quality setting and fetch the URL __addon__ = xbmcaddon.Addon() qual = __addon__.getSetting('QUALITY') video = classes.Video() video.title = video_data['title'] video.description = video_data['description'] video.thumbnail = video_data['thumbnailPath'] timestamp = time.mktime( time.strptime(video_data['customPublishDate'], '%Y-%m-%dT%H:%M:%S.%f+0000')) video.date = datetime.date.fromtimestamp(timestamp) video_format = None for v in video_data['mediaFormats']: if int(v['bitRate']) == config.VIDEO_QUALITY[qual]: video_format = v break video.url = video_format['sourceUrl'] video.duration = video_format['duration'] return video
def play(url): # Show a dialog d = xbmcgui.DialogProgress() d.create(config.NAME, '') d.update(20, 'Fetching video parameters...') v = classes.Video() v.parse_xbmc_url(url) try: d.update(40, 'Fetching video URL...') base_url = get_url(v.id) d.update(60, 'Fetching video URL...') video_url = quality_url(base_url) d.update(80, 'Building playlist...') listitem = xbmcgui.ListItem(label=v.get_title(), iconImage=v.get_thumbnail(), thumbnailImage=v.get_thumbnail()) listitem.setInfo('video', v.get_xbmc_list_item()) d.update(99, 'Starting video...') xbmc.Player().play(video_url, listitem) except: # user cancelled dialog or an error occurred d = xbmcgui.Dialog() message = utils.dialog_error("Unable to play video") d.ok(*message) utils.log_error()
def play(url): try: params = utils.get_url(url) v = classes.Video() v.parse_xbmc_url(url) if 'ooyalaid' in params: login_token = None if params.get('subscription_required') == 'True': login_token = ooyalahelper.get_user_token() stream_url = ooyalahelper.get_m3u8_playlist( params['ooyalaid'], v.live, login_token) else: stream_url = v.get_url() listitem = xbmcgui.ListItem(label=v.get_title(), iconImage=v.get_thumbnail(), thumbnailImage=v.get_thumbnail(), path=stream_url) listitem.addStreamInfo('video', v.get_kodi_stream_info()) listitem.setInfo('video', v.get_kodi_list_item()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error('Unable to play video')
def get_upcoming(): """Make a dummy file list for users to see upcoming matches/times""" season_data = json.loads(fetch_url(config.SEASONS_URL, request_token=True)) current_season = season_data.get('currentSeasonId') current_round = None for s in season_data.get('seasons'): if s.get('id') == current_season: current_round = s.get('currentRoundId') break if not current_round: return None fixture_url = config.FIXTURE_URL.format(current_season, current_round) fixture_data = json.loads(fetch_url(fixture_url, request_token=True)) listing = [] for match in fixture_data.get('fixtures'): if match.get('status') in [ 'SCHEDULED', 'UNCONFIRMED_TEAMS', 'CONFIRMED_TEAMS' ]: v = classes.Video() try: home = match['homeTeam'].get('teamName') away = match['awayTeam'].get('teamName') except KeyError: continue match_time = get_airtime(match.get('utcStartTime')) title = '{home} vs {away} - {time}' v.title = title.format(home=home, away=away, time=match_time) v.isdummy = True v.url = 'null' listing.append(v) return listing
def list_live(params): data = json.loads(fetch_url(config.HOME_URL)) listing = [] for match in data.get('upcoming_matches'): match_data = match.get('match') if not match: continue if match_data.get('status') == 'FullTime': continue broadcasters = match_data.get('broadcasters') if not broadcasters: continue v = classes.Video() v.home = match_data.get('home_team').get('name') v.away = match_data.get('away_team').get('name') v.start_date = match_data.get('start_date') v.status = match_data.get('status') if v.status == 'PreMatch' and v.is_near_live(): v.status = 'Live' if v.status == 'Live': v.live = True v.title = v.get_live_title() for broadcast in broadcasters: if 'Telstra' in broadcast.get('name'): v.ooyala_id = broadcast.get('stream_name') break else: v.dummy = True v.title = v.get_upcoming_title() listing.append(v) return listing
def get_aflw_upcoming(): """ similar to get_score but this time we are searching for upcoming live match info """ data = fetch_url(config.AFLW_SCORE_URL) tree = ET.fromstring(data) listing = [] for elem in tree.findall("Day"): for subelem in elem.findall("Game"): if subelem.find('GameState').text == 'COMPLETE': continue v = classes.Video() home = subelem.find('HomeTeam').attrib['FullName'] away = subelem.find('AwayTeam').attrib['FullName'] timestamp = subelem.find('Timestamp').text # convert zulu to local time airtime = get_airtime(timestamp, aflw=True) title = ('[COLOR red]AFLW:[/COLOR] ' '{0} vs {1} - {2}') v.title = title.format(home, away, airtime) v.dummy = True listing.append(v) return listing
def play(url): try: params = utils.get_url(url) v = classes.Video() v.parse_xbmc_url(url) if params.get('isdummy'): xbmcgui.Dialog().ok( 'Dummy item', 'This item is not playable, it is used only to display ' 'the upcoming schedule. Please check back once the match ' 'has started. Playable matches will have "LIVE NOW" in ' 'green next to the title.') if 'ooyalaid' in params: login_token = None if params.get('subscription_required') == 'True': login_token = ooyalahelper.get_user_token() stream_data = ooyalahelper.get_m3u8_playlist(params['ooyalaid'], v.live, login_token) else: stream_data = {'stream_url': v.get_url()} listitem = xbmcgui.ListItem(label=v.get_title(), iconImage=v.get_thumbnail(), thumbnailImage=v.get_thumbnail(), path=stream_data.get('stream_url')) inputstream = drmhelper.check_inputstream(drm=v.live) if not inputstream: utils.dialog_message( 'Failed to play stream. Please visit our website at ' 'http://aussieaddons.com/addons/afl/ for more ' 'information.') return widevine_url = stream_data.get('widevine_url') if inputstream and (not v.live or not widevine_url): listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') listitem.setProperty('inputstream.adaptive.license_key', stream_data.get('stream_url')) elif v.live: listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'mpd') listitem.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') listitem.setProperty('inputstream.adaptive.license_key', widevine_url + '|Content-Type=application%2F' 'x-www-form-urlencoded|A{SSM}|') listitem.addStreamInfo('video', v.get_kodi_stream_info()) listitem.setInfo('video', v.get_kodi_list_item()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error('Unable to play video')
def parse_json_video(video_data): """ Parse the JSON data and construct a video object from it. """ new_video = classes.Video() new_video.title = video_data['title'] new_video.description = video_data['description'] new_video.thumbnail = video_data['media$thumbnails'][0]['plfile$url'] return new_video
def parse_video(video_item): v = video_item['content'] new_video = classes.Video() new_video.id = v['contentId'] new_video.title = v['title'] new_video.description = v['description'] new_video.duration = v['duration'] new_video.thumbnail = v['imageUrl'] return new_video
def list_videos(params): data = json.loads(fetch_url(config.VIDEOS_URL)) listing = [] for video in data: v = classes.Video() v.title = video.get('name') v.desc = video.get('name') v.thumb = video.get('poster_small').get('url') v.fanart = video.get('poster').get('url') v.video_id = video.get('video_id') v.account_id = video.get('account_id') listing.append(v) return listing
def get_aflw_videos(): data = fetch_url(config.AFLW_LONG_URL) tree = ET.fromstring(data) listing = [] for elem in tree.findall('MediaSection'): for video in elem.findall('Item'): if video.attrib['Type'] == 'V': v = classes.Video() v.title = video.find('Title').text v.thumbnail = video.find('FullImageUrl').text v.ooyalaid = video.find('Video').attrib['Id'] listing.append(v) return listing
def parse_json_live(video_data): """Parse JSON live stream data Parse the JSON data for live match and construct a video object from it for a list of videos """ video_stream = video_data.get('videoStream') if not video_stream: return attrs = video_stream.get('customAttributes') if not attrs: return video = classes.Video() title = utils.ensure_ascii(video_data.get('title')) video.title = '[COLOR green][LIVE NOW][/COLOR] {0}'.format(title) video.thumbnail = video_stream.get('thumbnailURL') if video_stream.get('entitlement'): video.subscription_required = True # Look for 'national' stream (e.g. Foxtel) video_id = get_attr(attrs, 'ooyala embed code') if not video_id: # Look for configured state stream state = ADDON.getSetting('STATE') video_id = get_attr(attrs, 'state-' + state) if not video_id: # Fall back to the VIC stream video_id = get_attr(attrs, 'state-VIC') if not video_id: utils.log( 'Unable to find video ID from stream data: {0}'.format(video_data)) raise exceptions.AussieAddonsException('Unable to find video ' 'ID from stream data.') video.ooyalaid = video_id video.live = True return video
def parse_amf_video(video_item): """ Parse the AMF video item and construct a video object from it. """ v = video_item['content'] new_video = classes.Video() new_video.id = v['contentId'] new_video.title = v['title'] new_video.description = v['description'] # Convert h:m:s to seconds if v.has_key('duration') and v['duration'] is not None: h, m, s = [int(i) for i in v['duration'].split(':')] new_video.duration = 3600 * h + 60 * m + s # Replace to higher res thumbnails if v['imageUrl']: new_video.thumbnail = v['imageUrl'].replace('89x50.jpg', '326x184.jpg') return new_video
def parse_json_video(video_data): """Parse JSON stream data Parse the JSON data and construct a video object from it for a list of videos """ attrs = video_data.get('customAttributes') if not attrs: return video = classes.Video() video.title = utils.ensure_ascii(video_data.get('title')) video.description = utils.ensure_ascii(video_data.get('description')) video.thumbnail = video_data.get('thumbnailPath') try: timestamp = time.mktime( time.strptime(video_data['customPublishDate'], '%Y-%m-%dT%H:%M:%S.%f+0000')) video.date = datetime.date.fromtimestamp(timestamp) except Exception: pass if video_data.get('entitlement'): video.subscription_required = True # Look for 'national' stream (e.g. Foxtel) video_id = get_attr(attrs, 'ooyala embed code') if not video_id: # Look for configured state stream state = ADDON.getSetting('STATE') video_id = get_attr(attrs, 'state-' + state) if not video_id: # Fall back to the VIC stream video_id = get_attr(attrs, 'state-VIC') video.ooyalaid = video_id video.live = False return video
def list_matches(params): comp_id = params.get('id') rnd = params.get('rnd') if params.get('type') == 'team': query = 't{0}/fixture'.format(comp_id) data = json.loads(fetch_url(config.MATCHES_URL.format(query))) listing = [] round_data = [entry.get('match') for entry in data] else: query = 'c{0}/s2018/r{1}/fixture'.format(comp_id, rnd) data = json.loads(fetch_url(config.MATCHES_URL.format(query))) listing = [] round_data = data.get('rounds') for match in round_data: v = classes.Video() v.ooyala_id = match.get('match_replay_embedcode') if not v.ooyala_id: continue v.title = match.get('title') v.desc = match.get('title') v.thumb = params.get('thumb') listing.append(v) return listing