コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
ファイル: main_turner.py プロジェクト: MarkTV/MarkTV
def play_video(SITE, EPISODE, HLSPATH = None):
	localhttpserver = False
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	stack_url = ''
	for v, video_id in enumerate(common.args.url.split(',')):
		if 'http' not in video_id:
			video_url = EPISODE % video_id
		else:
			video_url = video_id
		hbitrate = -1
		sbitrate = int(getSetting('quality'))
		closedcaption = None
		video_data = connection.getURL(video_url)
		video_tree = BeautifulSoup(video_data, 'html.parser')
		hbitrate = -1
		lbitrate = -1
		file_url = None
		if video_tree.find('file', text = re.compile('mp4:')) is not None:
			hasRTMP = False
		else:
			hasRTMP = True
		if (getSetting('preffered_stream_type') == 'RTMP' and int(getSetting('connectiontype')) == 0) or hasRTMP:
			if qbitrate is  None:
				video_menu = video_tree.find_all('file')
				for video_index in video_menu:
					try:
						try:
							play_mode = video_index['play_mode']
						except:
							play_mode = ''
						if play_mode != 'window':
							bitrate = int(video_index['bitrate'])
							if bitrate < lbitrate or lbitrate == -1:
								lbitrate = bitrate,sbitrate
								lfile_url = video_index.string
							if bitrate > hbitrate and bitrate <= sbitrate:
								hbitrate = bitrate
								file_url = video_index.string
					except:
						pass
				if file_url is None:
					file_url = lfile_url 
			else:
				file_url = video_tree.find('file', attrs = {'bitrate' : qbitrate}).string
			if 'mp4:'  in file_url:
				filename = file_url[1:len(file_url)-4]
				serverDetails = video_tree.find('akamai')
				server = serverDetails.find('src').string.split('://')[1]
				tokentype = serverDetails.find('authtokentype').string
				window = serverDetails.find('window').string
				aifp = serverDetails.find('aifp').string
				auth=getAUTH(aifp,window,tokentype,video_id,filename.replace('mp4:',''), SITE) 
				rtmp = 'rtmpe://' + server + '?' + auth + ' playpath=' + filename + ' swfurl=' + SWFURL + ' swfvfy=true'
				segurl = rtmp
			elif 'http' not in file_url:
				segurl = BASE + file_url
			else:
				segurl = file_url
		else:
			video = video_tree.find('file', bitrate = 'androidtablet').string
			video_url = HLSBASE % HLSPATH + video[1:]
			m3u8_data = connection.getURL(video_url)
			m3u8 = m3u8.parse(m3u8_data)
			uri = None
			for video_index in m3u8.get('playlists'):
				if int(video_index.get('stream_info')['bandwidth']) > 64000:
					bitrate = int(video_index.get('stream_info')['bandwidth']) /1024
					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')
			if playpath_url is None:
				playpath_url = lplaypath_url
			master = video_url.split('/')[-1]
			segurl = video_url.replace(master, playpath_url)
			if int(getSetting('connectiontype')) > 0:
				localhttpserver = True
				play_data = connection.getURL(segurl)
				relative_urls = re.compile('(.*ts)\n').findall(play_data)
				relative_k_urls = re.compile('"(.*key)"').findall(play_data)
				proxy_config = common.proxyConfig()
				for i, video_item in enumerate(relative_urls):
					absolueurl =  video_url.replace(master, video_item)
					newurl = base64.b64encode(absolueurl)
					newurl = urllib.quote_plus(newurl)
					newurl = newurl + '/' + proxy_config
					newurl = 'http://127.0.0.1:12345/proxy/' + newurl
					play_data = play_data.replace(video_item,  newurl)
				for i, video_item in enumerate(relative_k_urls):
					absolueurl =  video_url.replace(master, video_item)
					key_data = connection.getURL(absolueurl)        
					key_file = open(ustvpaths.KEYFILE % (str(v) + '-' + str(i)), 'wb')
					key_file.write(key_data)
					key_file.close()
					play_data = play_data.replace(video_item,  'http://127.0.0.1:12345/play%s.key' % (str(v) + '-' + str(i)))
				file_name = ustvpaths.PLAYFILE.replace('.m3u8', str(v) + '.m3u8')
				playfile = open(file_name, 'w')
				playfile.write(play_data)
				playfile.close()
				segurl = 'http://127.0.0.1:12345/' + file_name.split('\\')[-1]
		stack_url += segurl.replace(',', ',,') + ' , '
	if ', ' in stack_url:
		stack_url = 'stack://' + stack_url
	finalurl = stack_url[:-3]
	if localhttpserver:
		filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,'proxy.py') + ', 12345)'
		xbmc.executebuiltin(filestring)
		time.sleep(20)
	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)
	if localhttpserver:
			while player.is_active:
				player.sleep(250)
コード例 #4
0
def play_video(video_url=common.args.url):
    hbitrate = -1
    lbitrate = -1
    playpath_url = None
    if addon.getSetting('enablesubtitles') == 'true':
        convert_subtitles(video_url)
        player._subtitles_Enabled = True
    sbitrate = int(addon.getSetting('quality'))
    video_data = connection.getURL(VIDEOURL % video_url)
    video_tree = simplejson.loads(video_data)
    for video_key in video_tree['videos']:
        try:
            video_index = video_tree['videos'][video_key]
            bitrate = int(video_index['bitrate'])
            if bitrate < lbitrate or lbitrate == -1:
                lbitrate = bitrate
                lplaypath_url = video_index['uri'].split('mp4:')[1].replace(
                    'Level3', '')
            if bitrate > hbitrate and bitrate <= sbitrate:
                hbitrate = bitrate
                playpath_url = video_index['uri'].split('mp4:')[1].replace(
                    'Level3', '')
        except:
            playpathm3u8 = video_index['uri']
    if addon.getSetting('preffered_stream_type') == 'HLS':
        playpath_url = None
        lplaypath_url = None
        m3u8_data = connection.getURL(playpathm3u8)
        m3u8_obj = m3u8.parse(m3u8_data)
        uri = None
        for video_index in m3u8_obj.get('playlists'):
            if int(video_index.get('stream_info')['bandwidth']) > 64000:
                bitrate = int(
                    video_index.get('stream_info')['bandwidth']) / 1024
                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')
    if playpath_url is None:
        playpath_url = lplaypath_url
    if addon.getSetting('preffered_stream_type') == 'RTMP':
        finalurl = RTMPURL + ' playpath=mp4:' + playpath_url + ' swfurl=' + SWFURL + ' swfvfy=true'
        player._localHTTPServer = False
    else:
        play_data = connection.getURL(playpath_url)
        key_url = re.compile('URI="(.*?)"').findall(play_data)[0]
        key_data = connection.getURL(key_url)
        key_file = open(ustvpaths.KEYFILE % '0', 'wb')
        key_file.write(key_data)
        key_file.close()
        relative_urls = re.compile('(.*ts)\n').findall(play_data)
        name = playpath_url.split('/')[-1]
        proxy_config = common.proxyConfig()
        for i, video_item in enumerate(relative_urls):
            absolueurl = playpath_url.replace(name, video_item)
            if int(addon.getSetting('connectiontype')) > 0:
                newurl = base64.b64encode(absolueurl)
                newurl = urllib.quote_plus(newurl)
                newurl = newurl + '/' + proxy_config
                newurl = 'http://127.0.0.1:12345/proxy/' + newurl
            else:
                newurl = absolueurl
            play_data = play_data.replace(video_item, newurl)
        localhttpserver = True
        filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,
                                                      'proxy.py') + ', 12345)'
        xbmc.executebuiltin(filestring)
        time.sleep(20)
        play_data = play_data.replace(key_url,
                                      'http://127.0.0.1:12345/play0.key')
        playfile = open(ustvpaths.PLAYFILE, 'w')
        playfile.write(play_data)
        playfile.close()
        finalurl = ustvpaths.PLAYFILE
    item = xbmcgui.ListItem(path=finalurl)
    try:
        item.setInfo(
            'Video', {
                'title': common.args.name,
                'season': common.args.season_number,
                'episode': common.args.episode_number,
                'TVShowTitle': common.args.show_title
            })
    except:
        try:
            item.setInfo('Video', {'title': common.args.name})
        except:
            pass
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    while player.is_active:
        player.sleep(250)
コード例 #5
0
def play_video(video_url=common.args.url):
    hbitrate = -1
    lbitrate = -1
    playpath_url = None
    if addon.getSetting("enablesubtitles") == "true":
        convert_subtitles(video_url)
        player._subtitles_Enabled = True
    sbitrate = int(addon.getSetting("quality"))
    video_data = connection.getURL(VIDEOURL % video_url)
    video_tree = simplejson.loads(video_data)
    for video_key in video_tree["videos"]:
        try:
            video_index = video_tree["videos"][video_key]
            bitrate = int(video_index["bitrate"])
            if bitrate < lbitrate or lbitrate == -1:
                lbitrate = bitrate
                lplaypath_url = video_index["uri"].split("mp4:")[1].replace("Level3", "")
            if bitrate > hbitrate and bitrate <= sbitrate:
                hbitrate = bitrate
                playpath_url = video_index["uri"].split("mp4:")[1].replace("Level3", "")
        except:
            playpathm3u8 = video_index["uri"]
    if addon.getSetting("preffered_stream_type") == "HLS":
        playpath_url = None
        lplaypath_url = None
        m3u8_data = connection.getURL(playpathm3u8)
        m3u8_obj = m3u8.parse(m3u8_data)
        uri = None
        for video_index in m3u8_obj.get("playlists"):
            if int(video_index.get("stream_info")["bandwidth"]) > 64000:
                bitrate = int(video_index.get("stream_info")["bandwidth"]) / 1024
                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")
    if playpath_url is None:
        playpath_url = lplaypath_url
    if addon.getSetting("preffered_stream_type") == "RTMP":
        finalurl = RTMPURL + " playpath=mp4:" + playpath_url + " swfurl=" + SWFURL + " swfvfy=true"
        player._localHTTPServer = False
    else:
        play_data = connection.getURL(playpath_url)
        key_url = re.compile('URI="(.*?)"').findall(play_data)[0]
        key_data = connection.getURL(key_url)
        key_file = open(ustvpaths.KEYFILE % "0", "wb")
        key_file.write(key_data)
        key_file.close()
        relative_urls = re.compile("(.*ts)\n").findall(play_data)
        name = playpath_url.split("/")[-1]
        proxy_config = common.proxyConfig()
        for i, video_item in enumerate(relative_urls):
            absolueurl = playpath_url.replace(name, video_item)
            if int(addon.getSetting("connectiontype")) > 0:
                newurl = base64.b64encode(absolueurl)
                newurl = urllib.quote_plus(newurl)
                newurl = newurl + "/" + proxy_config
                newurl = "http://127.0.0.1:12345/proxy/" + newurl
            else:
                newurl = absolueurl
            play_data = play_data.replace(video_item, newurl)
        localhttpserver = True
        filestring = "XBMC.RunScript(" + os.path.join(ustvpaths.LIBPATH, "proxy.py") + ", 12345)"
        xbmc.executebuiltin(filestring)
        time.sleep(20)
        play_data = play_data.replace(key_url, "http://127.0.0.1:12345/play0.key")
        playfile = open(ustvpaths.PLAYFILE, "w")
        playfile.write(play_data)
        playfile.close()
        finalurl = ustvpaths.PLAYFILE
    item = xbmcgui.ListItem(path=finalurl)
    try:
        item.setInfo(
            "Video",
            {
                "title": common.args.name,
                "season": common.args.season_number,
                "episode": common.args.episode_number,
                "TVShowTitle": common.args.show_title,
            },
        )
    except:
        try:
            item.setInfo("Video", {"title": common.args.name})
        except:
            pass
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    while player.is_active:
        player.sleep(250)
コード例 #6
0
ファイル: main_nbcu.py プロジェクト: MarkTV/MarkTV
def play_video():
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	exception = False
	video_url = common.args.url
	hbitrate = -1
	lbitrate = -1
	sbitrate = int(addon.getSetting('quality')) * 1024
	closedcaption = None
	video_data = connection.getURL(video_url)
	if 'link.theplatform.com' not in video_url:
		video_tree =  BeautifulSoup(video_data, 'html.parser')
		player_url = 'http:' + video_tree.find('div', class_ = 'video-player-wrapper').iframe['src']
		player_data = connection.getURL(player_url)
		player_tree =  BeautifulSoup(player_data, 'html.parser')
		video_url = player_tree.find('link', type = "application/smil+xml")['href']
		video_url = video_url + '&format=SMIL'
		video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	video_rtmp = video_tree.meta
	playpath_url = None
	lplaypath_url = None
	try:
		base_url = video_rtmp['base']
	except:
		base_url = None
	if base_url is not None:
		if qbitrate is None:
			video_url2 = video_tree.switch.find_all('video')
			for video_index in video_url2:
				bitrate = int(video_index['system-bitrate'])
				if bitrate < lbitrate or lbitrate == -1:
					lbitrate = bitrate
					lplaypath_url = video_index['src']	
				if bitrate > hbitrate and bitrate <= sbitrate:
					hbitrate = bitrate
					playpath_url = video_index['src']	
			if playpath_url is None:
				playpath_url = lplaypath_url
		else:
			playpath_url = video_tree.switch.find('video', attrs = {'system-bitrate' : qbitrate})['src']
		if '.mp4' in playpath_url:
			playpath_url = 'mp4:'+ playpath_url
		else:
			playpath_url = playpath_url.replace('.flv','')
		finalurl = base_url +' playpath=' + playpath_url + ' swfurl=' + SWFURL + ' swfvfy=true'
		player._localHTTPServer = False
	else:
		video_data = connection.getURL(video_url + '&manifest=m3u&Tracking=true&Embedded=true&formats=F4M,MPEG4')
		video_tree = BeautifulSoup(video_data, 'html.parser')
		try:
			closedcaption = video_tree.textstream['src']
			player._subtitles_Enabled = True
		except:
			pass
		if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
				convert_subtitles(closedcaption)
		if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
			video_url2 = video_tree.body.seq.video
			video_url3 = video_url2['src']
			video_data2 = connection.getURL(video_url3, 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 'https' not in playpath_url:
				player._localHTTPServer = False
				finalurl = playpath_url
			else:
				m3u_data = connection.getURL(playpath_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)
				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)
				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:
			exception = True
	
	if  not exception:
		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(video_tree.ref['title'], video_tree.ref['abstract'])
コード例 #7
0
def play_video(SITE, EPISODE, HLSPATH=None):
    localhttpserver = False
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    stack_url = ''
    for v, video_id in enumerate(common.args.url.split(',')):
        if 'http' not in video_id:
            video_url = EPISODE % video_id
        else:
            video_url = video_id
        hbitrate = -1
        sbitrate = int(getSetting('quality'))
        closedcaption = None
        video_data = connection.getURL(video_url)
        video_tree = BeautifulSoup(video_data, 'html.parser')
        hbitrate = -1
        lbitrate = -1
        file_url = None
        if video_tree.find('file', text=re.compile('mp4:')) is not None:
            hasRTMP = False
        else:
            hasRTMP = True
        if (getSetting('preffered_stream_type') == 'RTMP'
                and int(getSetting('connectiontype')) == 0) or hasRTMP:
            if qbitrate is None:
                video_menu = video_tree.find_all('file')
                for video_index in video_menu:
                    try:
                        try:
                            play_mode = video_index['play_mode']
                        except:
                            play_mode = ''
                        if play_mode != 'window':
                            bitrate = int(video_index['bitrate'])
                            if bitrate < lbitrate or lbitrate == -1:
                                lbitrate = bitrate, sbitrate
                                lfile_url = video_index.string
                            if bitrate > hbitrate and bitrate <= sbitrate:
                                hbitrate = bitrate
                                file_url = video_index.string
                    except:
                        pass
                if file_url is None:
                    file_url = lfile_url
            else:
                file_url = video_tree.find('file', attrs={
                    'bitrate': qbitrate
                }).string
            if 'mp4:' in file_url:
                filename = file_url[1:len(file_url) - 4]
                serverDetails = video_tree.find('akamai')
                server = serverDetails.find('src').string.split('://')[1]
                tokentype = serverDetails.find('authtokentype').string
                window = serverDetails.find('window').string
                aifp = serverDetails.find('aifp').string
                auth = getAUTH(aifp, window, tokentype, video_id,
                               filename.replace('mp4:', ''), SITE)
                rtmp = 'rtmpe://' + server + '?' + auth + ' playpath=' + filename + ' swfurl=' + SWFURL + ' swfvfy=true'
                segurl = rtmp
            elif 'http' not in file_url:
                segurl = BASE + file_url
            else:
                segurl = file_url
        else:
            video = video_tree.find('file', bitrate='androidtablet').string
            video_url = HLSBASE % HLSPATH + video[1:]
            m3u8_data = connection.getURL(video_url)
            m3u8 = m3u8.parse(m3u8_data)
            uri = None
            for video_index in m3u8.get('playlists'):
                if int(video_index.get('stream_info')['bandwidth']) > 64000:
                    bitrate = int(
                        video_index.get('stream_info')['bandwidth']) / 1024
                    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')
            if playpath_url is None:
                playpath_url = lplaypath_url
            master = video_url.split('/')[-1]
            segurl = video_url.replace(master, playpath_url)
            if int(getSetting('connectiontype')) > 0:
                localhttpserver = True
                play_data = connection.getURL(segurl)
                relative_urls = re.compile('(.*ts)\n').findall(play_data)
                relative_k_urls = re.compile('"(.*key)"').findall(play_data)
                proxy_config = common.proxyConfig()
                for i, video_item in enumerate(relative_urls):
                    absolueurl = video_url.replace(master, video_item)
                    newurl = base64.b64encode(absolueurl)
                    newurl = urllib.quote_plus(newurl)
                    newurl = newurl + '/' + proxy_config
                    newurl = 'http://127.0.0.1:12345/proxy/' + newurl
                    play_data = play_data.replace(video_item, newurl)
                for i, video_item in enumerate(relative_k_urls):
                    absolueurl = video_url.replace(master, video_item)
                    key_data = connection.getURL(absolueurl)
                    key_file = open(
                        ustvpaths.KEYFILE % (str(v) + '-' + str(i)), 'wb')
                    key_file.write(key_data)
                    key_file.close()
                    play_data = play_data.replace(
                        video_item, 'http://127.0.0.1:12345/play%s.key' %
                        (str(v) + '-' + str(i)))
                file_name = ustvpaths.PLAYFILE.replace('.m3u8',
                                                       str(v) + '.m3u8')
                playfile = open(file_name, 'w')
                playfile.write(play_data)
                playfile.close()
                segurl = 'http://127.0.0.1:12345/' + file_name.split('\\')[-1]
        stack_url += segurl.replace(',', ',,') + ' , '
    if ', ' in stack_url:
        stack_url = 'stack://' + stack_url
    finalurl = stack_url[:-3]
    if localhttpserver:
        filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,
                                                      'proxy.py') + ', 12345)'
        xbmc.executebuiltin(filestring)
        time.sleep(20)
    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)
    if localhttpserver:
        while player.is_active:
            player.sleep(250)
コード例 #8
0
def play_video():
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    exception = False
    video_url = common.args.url
    hbitrate = -1
    lbitrate = -1
    sbitrate = int(addon.getSetting('quality')) * 1024
    closedcaption = None
    video_data = connection.getURL(video_url)
    if 'link.theplatform.com' not in video_url:
        video_tree = BeautifulSoup(video_data, 'html.parser')
        player_url = 'http:' + video_tree.find(
            'div', class_='video-player-wrapper').iframe['src']
        player_data = connection.getURL(player_url)
        player_tree = BeautifulSoup(player_data, 'html.parser')
        video_url = player_tree.find('link',
                                     type="application/smil+xml")['href']
        video_url = video_url + '&format=SMIL'
        video_data = connection.getURL(video_url)
    video_tree = BeautifulSoup(video_data, 'html.parser')
    video_rtmp = video_tree.meta
    playpath_url = None
    lplaypath_url = None
    try:
        base_url = video_rtmp['base']
    except:
        base_url = None
    if base_url is not None:
        if qbitrate is None:
            video_url2 = video_tree.switch.find_all('video')
            for video_index in video_url2:
                bitrate = int(video_index['system-bitrate'])
                if bitrate < lbitrate or lbitrate == -1:
                    lbitrate = bitrate
                    lplaypath_url = video_index['src']
                if bitrate > hbitrate and bitrate <= sbitrate:
                    hbitrate = bitrate
                    playpath_url = video_index['src']
            if playpath_url is None:
                playpath_url = lplaypath_url
        else:
            playpath_url = video_tree.switch.find(
                'video', attrs={'system-bitrate': qbitrate})['src']
        if '.mp4' in playpath_url:
            playpath_url = 'mp4:' + playpath_url
        else:
            playpath_url = playpath_url.replace('.flv', '')
        finalurl = base_url + ' playpath=' + playpath_url + ' swfurl=' + SWFURL + ' swfvfy=true'
        player._localHTTPServer = False
    else:
        video_data = connection.getURL(
            video_url +
            '&manifest=m3u&Tracking=true&Embedded=true&formats=F4M,MPEG4')
        video_tree = BeautifulSoup(video_data, 'html.parser')
        try:
            closedcaption = video_tree.textstream['src']
            player._subtitles_Enabled = True
        except:
            pass
        if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption
                                                                is not None):
            convert_subtitles(closedcaption)
        if video_tree.find('param',
                           attrs={
                               'name': 'isException',
                               'value': 'true'
                           }) is None:
            video_url2 = video_tree.body.seq.video
            video_url3 = video_url2['src']
            video_data2 = connection.getURL(video_url3, 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 'https' not in playpath_url:
                player._localHTTPServer = False
                finalurl = playpath_url
            else:
                m3u_data = connection.getURL(playpath_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)
                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)
                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:
            exception = True

    if not exception:
        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(video_tree.ref['title'],
                              video_tree.ref['abstract'])
コード例 #9
0
ファイル: thecw.py プロジェクト: MossyTC/plugin.video.ustvvod
def play_video(video_url = common.args.url):
	hbitrate=-1
	lbitrate=-1
	playpath_url = None
	if addon.getSetting('enablesubtitles') == 'true':
		convert_subtitles(video_url)
		player._subtitles_Enabled = True
	sbitrate = int(addon.getSetting('quality'))
	video_data = connection.getURL(VIDEOURL % video_url)
	video_tree = simplejson.loads(video_data)
	for video_key in video_tree['videos']:
		try:
			video_index = video_tree['videos'][video_key]
			bitrate = int(video_index['bitrate'])
			if bitrate < lbitrate or lbitrate == -1:
				lbitrate = bitrate
				lplaypath_url = video_index['uri'].split('mp4:')[1].replace('Level3', '')
			if bitrate > hbitrate and bitrate <= sbitrate:
				hbitrate = bitrate
 				playpath_url = video_index['uri'].split('mp4:')[1].replace('Level3', '')
		except:
			playpathm3u8 = video_index['uri']
	if addon.getSetting('preffered_stream_type') == 'HLS':
		playpath_url = None
		lplaypath_url = None
		m3u8_data = connection.getURL(playpathm3u8)
		m3u8 = m3u8.parse(m3u8_data)
		uri = None
		for video_index in m3u8.get('playlists'):
			if int(video_index.get('stream_info')['bandwidth']) > 64000:
				bitrate = int(video_index.get('stream_info')['bandwidth']) /1024
				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')
	if playpath_url is None:
		playpath_url = lplaypath_url
	if addon.getSetting('preffered_stream_type') == 'RTMP':
		finalurl = RTMPURL + ' playpath=mp4:' + playpath_url + ' swfurl=' + SWFURL + ' swfvfy=true'
		player._localHTTPServer = False
	else:
		play_data = connection.getURL(playpath_url)
		key_url = re.compile('URI="(.*?)"').findall(play_data)[0]
		key_data = connection.getURL(key_url)		
		key_file = open(ustvpaths.KEYFILE, 'wb')
		key_file.write(key_data)
		key_file.close()
		relative_urls = re.compile('(.*ts)\n').findall(play_data)
		name = playpath_url.split('/')[-1]
		proxy_config = common.proxyConfig()
		for i, video_item in enumerate(relative_urls):
			absolueurl =  playpath_url.replace(name, video_item)
			if int(addon.getSetting('connectiontype')) > 0:
				newurl = base64.b64encode(absolueurl)
				newurl = urllib.quote_plus(newurl)
				newurl = newurl + '/' + proxy_config
				newurl = 'http://127.0.0.1:12345/proxy/' + newurl
			else:
				newurl = absolueurl
			play_data = play_data.replace(video_item,  newurl)
		localhttpserver = True
		filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,'proxy.py') + ', 12345)'
		xbmc.executebuiltin(filestring)
		time.sleep(20)
		play_data = play_data.replace(key_url, 'http://127.0.0.1:12345/play.key')
		playfile = open(ustvpaths.PLAYFILE, 'w')
		playfile.write(play_data)
		playfile.close()
		finalurl = ustvpaths.PLAYFILE
	xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path = finalurl))
	while player.is_active:
		player.sleep(250)