def process_m3u(m3u_url, qbitrate=None):
    key_url = None
    sbitrate = int(addon.getSetting('quality')) * 1024
    lbitrate = -1
    hbitrate = -1
    video_data2 = connection.getURL(m3u_url, savecookie=True)
    video_url5 = m3u8.parse(video_data2)
    for video_index in video_url5.get('playlists'):
        bitrate = int(video_index.get('stream_info')['bandwidth'])
        try:
            codecs = video_index.get('stream_info')['codecs']
        except:
            codecs = ''
        if qbitrate is None:
            if (bitrate < lbitrate or lbitrate == -1):
                lbitrate = bitrate
                lplaypath_url = video_index.get('uri')
            if (bitrate > hbitrate and bitrate <= sbitrate):
                hbitrate = bitrate
                playpath_url = video_index.get('uri')
        elif bitrate == qbitrate:
            playpath_url = video_index.get('uri')
    if playpath_url is None:
        playpath_url = lplaypath_url
    if not common.use_proxy() and int(addon.getSetting('connectiontype')) == 0:
        player._localHTTPServer = False
        return playpath_url
    else:
        m3u_data = connection.getURL(playpath_url, loadcookie=True)
        try:
            key_url = re.compile('URI="(.*?)"').findall(m3u_data)[0]

            key_data = connection.getURL(key_url, loadcookie=True)
            key_file = open(ustvpaths.KEYFILE % '0', 'wb')
            key_file.write(key_data)
            key_file.close()
        except:
            pass
        video_url5 = re.compile('(http:.*?)\n').findall(m3u_data)
        if int(addon.getSetting('connectiontype')) > 0:
            proxy_config = common.proxyConfig()
            for i, video_item in enumerate(video_url5):
                newurl = base64.b64encode(video_item)
                newurl = urllib.quote_plus(newurl)
                m3u_data = m3u_data.replace(
                    video_item, 'http://127.0.0.1:12345/proxy/' + newurl +
                    '/' + proxy_config)
        filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,
                                                      'proxy.py') + ', 12345)'
        xbmc.executebuiltin(filestring)
        time.sleep(20)
        if key_url is not None:
            m3u_data = m3u_data.replace(key_url,
                                        'http://127.0.0.1:12345/play0.key')
        playfile = open(ustvpaths.PLAYFILE, 'w')
        playfile.write(m3u_data)
        playfile.close()
        return ustvpaths.PLAYFILE
def play_video(video_url=common.args.url):
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    hbitrate = -1
    lbitrate = -1
    sbitrate = int(addon.getSetting('quality')) * 1000
    finalurl = ''
    video_data = connection.getURL(video_url + '&manifest=m3u')
    video_tree = BeautifulSoup(video_data, 'html.parser')
    if (addon.getSetting('enablesubtitles') == 'true'):
        try:
            closedcaption = video_tree.find('textstream',
                                            src=True,
                                            type="text/srt")['src']
            video_closedcaption = 'true'
            player._subtitles_Enabled = True
            player._subtitles_direct = closedcaption
        except:
            video_closedcaption = 'false'
    video_url2 = video_tree.find('video', src=True)['src']
    if addon.getSetting(
            'sel_quality') == 'true' or qbitrate is not None or int(
                xbmc.getInfoLabel("System.BuildVersion")
                [:2]) < 14 or common.use_proxy():
        print "********************************selecion"
        video_data2 = connection.getURL(video_url2, savecookie=True)
        video_url3 = m3u8.parse(video_data2)
        video_url4 = None
        for video_index in video_url3.get('playlists'):
            bitrate = int(video_index.get('stream_info')['bandwidth'])
            if qbitrate is None:
                if (bitrate < lbitrate or lbitrate == -1) and bitrate > 100000:
                    lbitrate = bitrate
                    lvideo_url4 = video_index.get('uri')
                if bitrate > hbitrate and bitrate <= sbitrate and bitrate > 100000:
                    hbitrate = bitrate
                    video_url4 = video_index.get('uri')
                if video_url4 is None:
                    video_url4 = lvideo_url4
            else:
                if qbitrate == bitrate:
                    video_url4 = video_index.get('uri')
        video_data4 = connection.getURL(video_url4, loadcookie=True)
        key_url = re.compile('URI="(.*?)"').findall(video_data4)[0]
        key_data = connection.getURL(key_url, loadcookie=True)
        key_file = open(ustvpaths.KEYFILE % '0', 'wb')
        key_file.write(key_data)
        key_file.close()
        video_url5 = re.compile('(http:.*?)\n').findall(video_data4)
        for i, video_item in enumerate(video_url5):
            newurl = base64.b64encode(video_item)
            newurl = urllib.quote_plus(newurl)
            video_data4 = video_data4.replace(
                video_item, 'http://127.0.0.1:12345/0/foxstation/' + newurl)
        video_data4 = video_data4.replace(key_url,
                                          'http://127.0.0.1:12345/play0.key')
        localhttpserver = True
        filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,
                                                      'proxy.py') + ', 12345)'
        xbmc.executebuiltin(filestring)
        time.sleep(20)
        playfile = open(ustvpaths.PLAYFILE, 'w')
        playfile.write(video_data4)
        playfile.close()
        finalurl = ustvpaths.PLAYFILE
    else:
        print "******************************** bypass selection"
        player._localHTTPServer = False
        finalurl = video_url2
    item = xbmcgui.ListItem(path=finalurl)
    try:
        item.setThumbnailImage(common.args.thumb)
    except:
        pass
    try:
        item.setInfo(
            'Video', {
                'title': common.args.name,
                'season': common.args.season_number,
                'episode': common.args.episode_number,
                'TVShowTitle': common.args.show_title
            })
    except:
        pass
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    while player.is_active:
        player.sleep(250)
def get_videos(queue, i, video_item, qbitrate, rtmp=False):
    try:
        video_mgid = video_item['video']['mgid']
    except:
        try:
            video_mgid = video_item['url'].split('uri=')[1].split('&')[0]
        except:
            try:
                video_mgid = video_item['url'].split('mgid=')[1].split('&')[0]
            except:
                video_mgid = video_item['url'].split('/')[-1].split('?')[0]
    video_data = connection.getURL(VIDEOURLAPI % video_mgid)
    video_tree = BeautifulSoup(video_data, 'html.parser')
    try:
        duration = video_tree.findAll('rendition')[0]['duration']
    except:
        duration = 0
    try:
        closedcaption = video_tree.find('typographic', format='ttml')['src']
    except:
        closedcaption = None
    hbitrate = -1
    lbitrate = -1
    sbitrate = int(addon.getSetting('quality'))
    if rtmp:
        try:
            video_url2 = video_tree.findAll('rendition')
            if qbitrate is None:
                for video_index in video_url2:
                    bitrate = int(video_index['bitrate'])
                    if bitrate < lbitrate or lbitrate == -1:
                        lbitrate = bitrate
                        lplaypath_url = video_index.src.string
                    if bitrate > hbitrate and bitrate <= sbitrate:
                        hbitrate = bitrate
                        playpath_url = video_index.src.string
            else:
                playpath_url = video_tree.find('rendition',
                                               bitrate=qbitrate).src.string
            if playpath_url is None:
                playpath_url = lplaypath_url
            if "gsp.alias" in playpath_url:
                file_name = 'rtmpe://cp10740.edgefcs.net/ondemand/mtvnorigin/gsp.alias' + playpath_url.split(
                    '/gsp.alias')[1]
            else:
                file_name = playpath_url
            queue.put([i, file_name, duration, closedcaption])
        except:
            pass
    else:
        try:
            video_data = connection.getURL(VIDEOURLAPIHLS % video_mgid)
            video_tree = BeautifulSoup(video_data, 'html.parser')
            video_menu = video_tree.src.string
            hbitrate = -1
            lbitrate = -1
            m3u8_url = None
            #can we just pass video_menu

            if addon.getSetting(
                    'sel_quality') == 'true' or qbitrate is not None or int(
                        xbmc.getInfoLabel("System.BuildVersion")
                        [:2]) < 14 or common.use_proxy():
                m3u8_master_data = connection.getURL(video_menu,
                                                     savecookie=True,
                                                     cookiefile=i)
                m3u8_master = m3u8.parse(m3u8_master_data)
                sbitrate = int(addon.getSetting('quality')) * 1024
                for video_index in m3u8_master.get('playlists'):
                    bitrate = int(video_index.get('stream_info')['bandwidth'])
                    if qbitrate is None:
                        if bitrate < lbitrate or lbitrate == -1:
                            lbitrate = bitrate
                            lm3u8_url = video_index.get('uri')
                        if bitrate > hbitrate and bitrate <= sbitrate:
                            hbitrate = bitrate
                            m3u8_url = video_index.get('uri')
                    elif (qbitrate *
                          (100 - BITRATERANGE)) / 100 < bitrate and (
                              qbitrate * (100 + BITRATERANGE)) / 100 > bitrate:
                        m3u8_url = video_index.get('uri')
                if ((m3u8_url is None) and (qbitrate is None)):
                    m3u8_url = lm3u8_url
                m3u8_data = connection.getURL(m3u8_url,
                                              loadcookie=True,
                                              cookiefile=i)
                key_url = re.compile('URI="(.*?)"').findall(m3u8_data)[0]
                key_data = connection.getURL(key_url,
                                             loadcookie=True,
                                             cookiefile=i)
                key_file = open(ustvpaths.KEYFILE % str(i), 'wb')
                key_file.write(key_data)
                key_file.close()
                video_url = re.compile('(http:.*?)\n').findall(m3u8_data)
                for video_item in video_url:
                    newurl = base64.b64encode(video_item)
                    newurl = urllib.quote_plus(newurl)
                    m3u8_data = m3u8_data.replace(
                        video_item, 'http://127.0.0.1:12345/' + str(i) +
                        '/foxstation/' + newurl)
                m3u8_data = m3u8_data.replace(
                    key_url, 'http://127.0.0.1:12345/play%s.key' % str(i))
                file_name = ustvpaths.PLAYFILE.replace('.m3u8',
                                                       str(i) + '.m3u8')
                playfile = open(file_name, 'w')
                playfile.write(m3u8_data)
                playfile.close()
            else:
                print "********************* No sel*****************"
                file_name = video_menu
                player._localHTTPServer = False
            queue.put([i, file_name, duration, closedcaption])
        except:
            pass
Exemple #4
0
def play_video(video_url = common.args.url, tonightshow = False):
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	closedcaption = None
	video_data = connection.getURL(video_url)
	if 'link.theplatform.com' not in video_url:
		print "Getting player link"
		video_tree =  BeautifulSoup(video_data, 'html.parser')
		player_url = video_tree.find('div', class_ = 'video-player-full')['data-mpx-url']
		if 'http' not in player_url:
			player_url = 'http:' + player_url
		player_data = connection.getURL(player_url)
		player_tree =  BeautifulSoup(player_data, 'html.parser')
		try:
			smil_url = player_tree.find('link', type = "application/smil+xml")['href']
		except:
			media_url = player_tree.find('meta', attrs={ 'name' :'twitter:player'})['content']
			pid = re.compile('media.(.*)\?').findall(media_url)[0]
			smil_url = SMILM % pid
		video_data = connection.getURL(smil_url + '&manifest=m3u&format=SMIL')
	smil_tree = BeautifulSoup(video_data, 'html.parser')
	if smil_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
		video_url2 = smil_tree.video['src']	
		try:
			closedcaption = smil_tree.textstream['src']
		except:
			pass
		if addon.getSetting('sel_quality') == 'true' or qbitrate is not None or  int(xbmc.getInfoLabel( "System.BuildVersion" )[:2]) < 14 or common.use_proxy() :
			print "*****************Selection"
			m3u_master_data = connection.getURL(video_url2, savecookie = True)
			m3u_master = m3u8.parse(m3u_master_data)
			hbitrate = -1
			sbitrate = int(addon.getSetting('quality')) * 1024
			for video_index in m3u_master.get('playlists'):
				bitrate = int(video_index.get('stream_info')['bandwidth'])
				if qbitrate is None:
					if bitrate > hbitrate and bitrate <= sbitrate:
						hbitrate = bitrate
						m3u8_url =  video_index.get('uri')
				elif  bitrate == qbitrate:
					m3u8_url =  video_index.get('uri')
			m3u_data = connection.getURL(m3u8_url, loadcookie = True)
			key_url = re.compile('URI="(.*?)"').findall(m3u_data)[0]
			key_data = connection.getURL(key_url, loadcookie = True)		
			key_file = open(ustvpaths.KEYFILE % '0', 'wb')
			key_file.write(key_data)
			key_file.close()
			video_url5 = re.compile('(http:.*?)\n').findall(m3u_data)
			for i, video_item in enumerate(video_url5):
				newurl = base64.b64encode(video_item)
				newurl = urllib.quote_plus(newurl)
				m3u_data = m3u_data.replace(video_item, 'http://127.0.0.1:12345/0/foxstation/' + newurl)
			localhttpserver = True
			filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,'proxy.py') + ', 12345)'
			xbmc.executebuiltin(filestring)
			time.sleep(20)
			m3u_data = m3u_data.replace(key_url, 'http://127.0.0.1:12345/play0.key')
			playfile = open(ustvpaths.PLAYFILE, 'w')
			playfile.write(m3u_data)
			playfile.close()
			finalurl = ustvpaths.PLAYFILE
		else:
			print "******************************** bypass selection"
			player._localHTTPServer = False
			finalurl = video_url2
		if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
			convert_subtitles(closedcaption)
			player._subtitles_Enabled = True
		item = xbmcgui.ListItem(path = finalurl)
		try:

			item.setThumbnailImage(common.args.thumb)
		except:
			pass
		try:
			item.setInfo('Video', {	'title' : common.args.name,
									'season' : common.args.season_number,
									'episode' : common.args.episode_number,
									'TVShowTitle' : common.args.show_title})
		except:
			pass
		xbmcplugin.setResolvedUrl(pluginHandle, True, item)
		while player.is_active:
				player.sleep(250)
	else:
		common.show_exception(smil_tree.ref['title'], smil_tree.ref['abstract'])
Exemple #5
0
def play_video(SITE, BRANDID, PARTNERID):
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    video_id, video_type = common.args.url.split('#')
    hbitrate = -1
    lbitrate = -1
    sbitrate = int(addon.getSetting('quality'))
    localhttpserver = False
    video_auth = get_authorization(BRANDID, video_id, video_type)
    if video_auth is False:
        video_url = VIDEOLIST % BRANDID + '001/-1/-1/-1/' + video_id + '/-1/-1'
        video_data = connection.getURL(video_url)
        try:
            video_data2 = simplejson.loads(video_data)['videos']['video']
            video_format = video_data2['assets']['asset'][0]['@format']
            video_closedcaption = video_data2['closedcaption']['@enabled']
        except:
            try:
                video_data2 = simplejson.loads(video_data)['videos']['video']
                video_format = video_data2['assets']['asset']['@format']
                video_closedcaption = video_data2['closedcaption']['@enabled']
            except:
                video_format = 'MOV'
                video_closedcaption = 'false'
        video_id = video_id.replace('VDKA', '')
        if video_format != 'MOV':
            if video_format == 'MP4':
                video_url = PLAYLISTMP4 % (PARTNERID, PARTNERID) + video_id
            else:
                video_url = PLAYLISTM3U % (PARTNERID, PARTNERID) + video_id
            video_data = connection.getURL(video_url)
            video_url2 = m3u8.parse(video_data)
            for video_index in video_url2.get('playlists'):
                bitrate = int(video_index.get('stream_info')['bandwidth'])
                print bitrate, sbitrate * 1000
                if qbitrate is None:
                    if bitrate > hbitrate and bitrate <= sbitrate * 1000:
                        hbitrate = bitrate
                        playpath_url = video_index.get('uri')
                else:
                    if bitrate == qbitrate:
                        playpath_url = video_index.get('uri')
            finalurl = playpath_url
        elif video_format == 'MOV':
            player._localHTTPServer = False
            playpath_url = None
            video_url = PLAYLISTMOV % (PARTNERID, PARTNERID) + video_id
            video_data = connection.getURL(video_url)
            video_tree = BeautifulSoup(video_data, 'html.parser')
            base_url = video_tree('baseurl')[0].string
            video_url2 = video_tree.findAll('media')
            if qbitrate is None:
                for video_index in video_url2:
                    bitrate = int(video_index['bitrate'])
                    if bitrate < lbitrate or lbitrate == -1:
                        lbitrate = bitrate
                        lplaypath_url = video_index['url']
                    if bitrate > hbitrate and bitrate <= sbitrate:
                        hbitrate = bitrate
                        playpath_url = video_index['url']
            else:
                playpath_url = video_tree.find('media',
                                               bitrate=qbitrate)['url']
            if playpath_url is None:
                playpath_url = lplaypath_url
            finalurl = base_url + ' playpath=' + playpath_url + ' swfUrl=' + SWFURL + ' swfVfy=true'
        #else:
        #	finalurl = PLAYLISTM3U % (PARTNERID, PARTNERID) + video_id
    else:
        video_url = VIDEOLIST % BRANDID + '002/-1/-1/-1/' + video_id + '/-1/-1'
        video_data = connection.getURL(video_url)
        video_data2 = simplejson.loads(video_data)['videos']['video']
        video_closedcaption = video_data2['closedcaption']['@enabled']
        try:
            video_url2 = video_data2['assets']['asset']['$'] + video_auth
        except:
            video_url2 = video_data2['assets']['asset'][1]['$'] + video_auth
        video_data3 = connection.getURL(video_url2.replace('m3u8', 'json'))
        video_url3 = simplejson.loads(video_data3)
        for video_keys in BITRATETABLE.iterkeys():
            bitrate = int(video_keys)
            if qbitrate is None:
                if bitrate > hbitrate and bitrate <= sbitrate:
                    hbitrate = bitrate
                    video_url4 = video_url3['url'].replace(
                        '__ray__', BITRATETABLE[video_keys])
            else:
                if qbitrate == bitrate:
                    video_url4 = video_url3['url'].replace(
                        '__ray__', BITRATETABLE[video_keys])
        video_url4 = video_url4.replace('https',
                                        'http').replace('json', 'm3u8')
        if common.use_proxy():

            video_data4 = re.sub(r"\#EXT-X-DISCONTINUITY\n", "",
                                 connection.getURL(video_url4))
            key_url = re.compile('URI="(.*?)"').findall(video_data4)[0]
            key_data = connection.getURL(key_url)
            key_file = open(ustvpaths.KEYFILE % '0', 'wb')
            key_file.write(key_data)
            key_file.close()
            localhttpserver = True
            filestring = 'XBMC.RunScript(' + os.path.join(
                ustvpaths.LIBPATH, 'proxy.py') + ', 12345)'
            xbmc.executebuiltin(filestring)
            time.sleep(20)
            video_data4 = video_data4.replace(
                key_url, 'http://127.0.0.1:12345/play0.key')
            playfile = open(ustvpaths.PLAYFILE, 'w')
            playfile.write(video_data4)
            playfile.close()
            finalurl = ustvpaths.PLAYFILE
        else:
            finalurl = video_url4
            player._localHTTPServer = False
    if (video_closedcaption == 'true') and (addon.getSetting('enablesubtitles')
                                            == 'true'):
        try:
            closedcaption = CLOSEDCAPTIONHOST + video_data2['closedcaption'][
                'src']['$'].split('.com')[1]
            convert_subtitles(closedcaption)
            player._subtitles_Enabled = True
        except:
            video_closedcaption = 'false'
    item = xbmcgui.ListItem(path=finalurl)
    try:
        item.setThumbnailImage(common.args.thumb)
    except:
        pass
    try:
        item.setInfo(
            'Video', {
                'title': common.args.name,
                'season': common.args.season_number,
                'episode': common.args.episode_number,
                'TVShowTitle': common.args.show_title
            })
    except:
        pass
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    while player.is_active:
        player.sleep(250)