def play_video(params): """ Determine content and pass url to Kodi for playback """ if params['action'] == 'listchannels': json_url = config.BRIGHTCOVE_DRM_URL.format(config.BRIGHTCOVE_ACCOUNT, params['id']) url = comm.get_stream(json_url, live=True) play_item = xbmcgui.ListItem(path=url) elif params['drm'] == 'True': if xbmcaddon.Addon().getSetting('ignore_drm') == 'false': if not drmhelper.check_inputstream(): return acc = config.BRIGHTCOVE_ACCOUNT drm_url = config.BRIGHTCOVE_DRM_URL.format(acc, params['id']) widevine = comm.get_widevine_auth(drm_url) url = widevine['url'] play_item = xbmcgui.ListItem(path=url) play_item.setProperty('inputstream.adaptive.manifest_type', 'mpd') play_item.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') play_item.setProperty( 'inputstream.adaptive.license_key', widevine['key'] + ('|Content-Type=application%2F' 'x-www-form-urlencoded|A{SSM}|')) else: json_url = config.BRIGHTCOVE_DRM_URL.format(config.BRIGHTCOVE_ACCOUNT, params['id']) m3u8 = comm.get_stream(json_url) data = urllib2.urlopen(m3u8).read().splitlines() url = parse_m3u8(data, m3u8_path=m3u8) play_item = xbmcgui.ListItem(path=url) xbmcplugin.setResolvedUrl(_handle, True, play_item)
def play(url): try: addon = xbmcaddon.Addon() p = classes.Program() p.parse_xbmc_url(url) # Some programs don't have protected streams. 'Public' streams are # set in program.url, otherwise we fetch it separately if p.get_url(): stream_info = {} stream_url = p.get_url() else: stream_info = comm.get_stream(p.id) stream_url = stream_info['url'] bandwidth = addon.getSetting('BANDWIDTH') if bandwidth == '0': stream_url = stream_url.replace('&b=0-2000', '&b=400-600') elif bandwidth == '1': stream_url = stream_url.replace('&b=0-2000', '&b=900-1100') elif bandwidth == '2': stream_url = stream_url.replace('&b=0-2000', '&b=1400-1600') listitem = xbmcgui.ListItem(label=p.get_list_title(), iconImage=p.thumbnail, thumbnailImage=p.thumbnail, path=stream_url) listitem.setInfo('video', p.get_kodi_list_item()) # Add subtitles if available if 'subtitles' in stream_info: sub_url = stream_info['subtitles'] profile = addon.getAddonInfo('profile') path = xbmc.translatePath(profile).decode('utf-8') if not os.path.isdir(path): os.makedirs(path) subfile = xbmc.translatePath( os.path.join(path, 'subtitles.eng.srt')) if os.path.isfile(subfile): os.remove(subfile) try: data = urllib2.urlopen(sub_url).read() f = open(subfile, 'w') f.write(data) f.close() if hasattr(listitem, 'setSubtitles'): # This function only supported from Kodi v14+ listitem.setSubtitles([subfile]) except Exception: utils.log('Subtitles not available for this program') if hasattr(listitem, 'addStreamInfo'): listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info()) listitem.addStreamInfo('video', p.get_kodi_video_stream_info()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error("Unable to play video")
def play(params): try: import drmhelper if not drmhelper.check_inputstream(drm=False): return except ImportError: utils.log("Failed to import drmhelper") utils.dialog_message('DRM Helper is needed for inputstream.adaptive ' 'playback. For more information, please visit: ' 'http://aussieaddons.com/drm') return try: stream = comm.get_stream(params['video_id']) utils.log('Attempting to play: {0} {1}'.format(stream['name'], stream['url'])) item = xbmcgui.ListItem(label=stream['name'], path=stream['url']) item.setProperty('inputstreamaddon', 'inputstream.adaptive') item.setProperty('inputstream.adaptive.manifest_type', 'hls') item.setMimeType('application/vnd.apple.mpegurl') item.setContentLookup(False) xbmcplugin.setResolvedUrl(pluginhandle, True, listitem=item) except Exception: utils.handle_error('Unable to play video')
def play(url): try: addon = xbmcaddon.Addon() p = classes.Program() p.parse_xbmc_url(url) stream_data = comm.get_stream(p.id) stream_url = [x['url'] for x in stream_data if x['quality'] == 'Auto'][0] """ bandwidth = addon.getSetting('BANDWIDTH') if bandwidth == '0': stream_url = stream_url.replace('&b=0-2000', '&b=400-600') elif bandwidth == '1': stream_url = stream_url.replace('&b=0-2000', '&b=900-1100') elif bandwidth == '2': stream_url = stream_url.replace('&b=0-2000', '&b=1400-1600') """ listitem = xbmcgui.ListItem(label=p.get_list_title(), iconImage=p.thumbnail, thumbnailImage=p.thumbnail, path=stream_url) listitem.setInfo('video', p.get_kodi_list_item()) """# Add subtitles if available if 'subtitles' in stream_info: sub_url = stream_info['subtitles'] profile = addon.getAddonInfo('profile') path = xbmc.translatePath(profile).decode('utf-8') if not os.path.isdir(path): os.makedirs(path) subfile = xbmc.translatePath( os.path.join(path, 'subtitles.eng.srt')) if os.path.isfile(subfile): os.remove(subfile) try: data = urllib2.urlopen(sub_url).read() f = open(subfile, 'w') f.write(data) f.close() if hasattr(listitem, 'setSubtitles'): # This function only supported from Kodi v14+ listitem.setSubtitles([subfile]) except Exception: utils.log('Subtitles not available for this program')""" """ listitem.setProperty('inputstreamaddon', 'inputstream.adaptive') listitem.setProperty('inputstream.adaptive.manifest_type', 'hls') listitem.setProperty('inputstream.adaptive.license_key', stream_url) """ if hasattr(listitem, 'addStreamInfo'): listitem.addStreamInfo('audio', p.get_kodi_audio_stream_info()) listitem.addStreamInfo('video', p.get_kodi_video_stream_info()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) except Exception: utils.handle_error("Unable to play video")
def play(params): try: success = True stream = comm.get_stream(params['video_id']) utils.log('Attempting to play: {0} {1}'.format(stream['name'], stream['url'])) item = xbmcgui.ListItem(label=stream['name'], path=stream['url']) item.setProperty('inputstreamaddon', 'inputstream.adaptive') item.setProperty('inputstream.adaptive.manifest_type', 'hls') item.setMimeType('application/vnd.apple.mpegurl') item.setContentLookup(False) xbmcplugin.setResolvedUrl(pluginhandle, True, listitem=item) except Exception: utils.handle_error('Unable to play video')
def play(url): params = utils.get_url(url) p = classes.Program() p.parse_xbmc_url(url) program_id = comm.get_program_id(params['url_path']) stream = comm.get_stream(program_id) # Plus7 has returned a specific error if stream.has_key('error'): d = xbmcgui.Dialog() msg = utils.dialog_message("Unable to play video:\n%s" % stream['error']) d.ok(*msg) return try: # RTMP URL isn't available if stream.has_key('rtmp_host'): # Build the final RTMP Url. New syntax for external librtmp # http://trac.xbmc.org/ticket/8971 rtmp_url = "%s playpath=%s swfurl=%s swfvfy=true" % ( stream['rtmp_host'], stream['rtmp_path'], config.swf_url) listitem = xbmcgui.ListItem(label=p.title, iconImage=p.thumbnail, thumbnailImage=p.thumbnail) listitem.setInfo('video', p.get_xbmc_list_item()) xbmc.Player().play(rtmp_url, listitem) else: d = xbmcgui.Dialog() msg = utils.dialog_message( "Unable to play video:\nStream URL not found.") d.ok(*msg) return except: # oops print error message d = xbmcgui.Dialog() message = utils.dialog_error("Unable to play video") d.ok(*message) utils.log_error()
def play(url): params = utils.get_url(url) p = classes.Program() p.parse_xbmc_url(url) program_id = comm.get_program_id(params['url_path']) stream = comm.get_stream(program_id) # Plus7 has returned a specific error if stream.has_key('error'): d = xbmcgui.Dialog() msg = utils.dialog_message("Unable to play video:\n%s" % stream['error']) d.ok(*msg) return try: # RTMP URL isn't available if stream.has_key('rtmp_host'): # Build the final RTMP Url. New syntax for external librtmp # http://trac.xbmc.org/ticket/8971 rtmp_url = "%s playpath=%s" % (stream['rtmp_host'], stream['rtmp_path']) listitem=xbmcgui.ListItem(label=p.title, iconImage=p.thumbnail, thumbnailImage=p.thumbnail) listitem.setInfo('video', p.get_xbmc_list_item()) xbmc.Player().play(rtmp_url, listitem) else: d = xbmcgui.Dialog() msg = utils.dialog_message("Unable to play video:\nStream URL not found.") d.ok(*msg) return except: # oops print error message d = xbmcgui.Dialog() message = utils.dialog_error("Unable to play video") d.ok(*message) utils.log_error();
def play(url): addon = xbmcaddon.Addon(config.ADDON_ID) try: p = classes.Program() p.parse_xbmc_url(url) # Some programs don't have protected streams. 'Public' streams are # set in program.url, otherwise we fetch it separately if p.get_url(): stream_url = p.get_url() else: stream_url = comm.get_stream(p.id) listitem = xbmcgui.ListItem(label=p.get_list_title(), iconImage=p.thumbnail, thumbnailImage=p.thumbnail) listitem.setInfo("video", p.get_xbmc_list_item()) if hasattr(listitem, "addStreamInfo"): listitem.addStreamInfo("audio", p.get_xbmc_audio_stream_info()) listitem.addStreamInfo("video", p.get_xbmc_video_stream_info()) xbmc.Player().play(stream_url, listitem) except: utils.handle_error("Unable to play video")
def play_video(params): """ Determine content and pass url to Kodi for playback """ try: json_url = config.BRIGHTCOVE_DRM_URL.format(config.BRIGHTCOVE_ACCOUNT, params['id']) if params['drm'] == 'True': if xbmcaddon.Addon().getSetting('ignore_drm') == 'false': if not drmhelper.check_inputstream(): return widevine = comm.get_widevine_auth(json_url) url = widevine['url'] sub_url = widevine['sub_url'] play_item = xbmcgui.ListItem(path=url) play_item.setProperty('inputstream.adaptive.manifest_type', 'mpd') play_item.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') play_item.setProperty( 'inputstream.adaptive.license_key', widevine['key'] + ('|Content-Type=application%2F' 'x-www-form-urlencoded|A{SSM}|')) else: if params['action'] == 'listchannels': qual = int(xbmcaddon.Addon().getSetting('LIVEQUALITY')) live = True else: qual = int(xbmcaddon.Addon().getSetting('HLSQUALITY')) live = False stream_data = comm.get_stream(json_url, live=live) m3u8 = stream_data.get('url') sub_url = stream_data.get('sub_url') url = parse_m3u8(m3u8, qual=qual, live=live) play_item = xbmcgui.ListItem(path=url) utils.log('Playing {0} - {1}'.format(params.get('title'), url)) if sub_url: try: utils.log("Enabling subtitles: {0}".format(sub_url)) profile = xbmcaddon.Addon().getAddonInfo('profile') subfilename = xbmc.translatePath( os.path.join(profile, 'subtitle.srt')) profiledir = xbmc.translatePath(os.path.join(profile)) if not os.path.isdir(profiledir): os.makedirs(profiledir) with custom_session.Session() as s: webvtt_data = s.get(sub_url).text if webvtt_data: with open(subfilename, 'w') as f: webvtt_subtitle = WebVTTReader().read(webvtt_data) srt_subtitle = SRTWriter().write(webvtt_subtitle) srt_unicode = srt_subtitle.encode('utf-8') f.write(srt_unicode) if hasattr(play_item, 'setSubtitles'): # This function only supported from Kodi v14+ play_item.setSubtitles([subfilename]) except Exception as e: utils.log('Unable to add subtitles: {0}'.format(e)) xbmcplugin.setResolvedUrl(_handle, True, play_item) except Exception: utils.handle_error('Unable to play video')
def play(url): addon = xbmcaddon.Addon(config.ADDON_ID) try: p = classes.Program() p.parse_xbmc_url(url) # Some programs don't have protected streams. 'Public' streams are # set in program.url, otherwise we fetch it separately if p.get_url(): stream_url = p.get_url() else: stream_url = comm.get_stream(p.id) listitem=xbmcgui.ListItem(label=p.get_list_title(), iconImage=p.thumbnail, thumbnailImage=p.thumbnail, path=stream_url) listitem.setInfo('video', p.get_xbmc_list_item()) #add subtitles if available if addon.getSetting('subtitles_enabled') == 'true' and p.get_subfilename(): subtitles = None profile = xbmcaddon.Addon().getAddonInfo('profile') path = xbmc.translatePath(profile).decode('utf-8') if not os.path.isdir(path): os.makedirs(path) subfile = xbmc.translatePath(os.path.join(path, 'subtitles.eng.srt')) if os.path.isfile(subfile): os.remove(subfile) x = stream_url.find('managed')+8 subdate = stream_url[x:x+11] suburl = config.subtitle_url+subdate+p.get_subfilename() try: data = urllib2.urlopen(suburl).read() f = open(subfile, 'w') f.write(data) f.close() if hasattr(listitem, 'setSubtitles'): # This function only supported from Kodi v14+ listitem.setSubtitles([subfile]) else: subtitles = True except: utils.log('Subtitles not available for this program') if hasattr(listitem, 'addStreamInfo'): listitem.addStreamInfo('audio', p.get_xbmc_audio_stream_info()) listitem.addStreamInfo('video', p.get_xbmc_video_stream_info()) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem=listitem) # Enable subtitles for XBMC v13 if addon.getSetting('subtitles_enabled') == "true" and p.get_subfilename(): if subtitles == True: if not hasattr(listitem, 'setSubtitles'): player = xbmc.Player() while not player.isPlaying(): xbmc.sleep(100) # wait until video is being played player.setSubtitles(subfile) except: utils.handle_error("Unable to play video")