예제 #1
0
def play_uri(video_uri=_common.args.url, video_referer='www.vh1.com'):
    swfUrl = _connection.getRedirect(BASE2 + video_uri, referer=video_referer)
    configurl = urllib.unquote_plus(
        swfUrl.split('CONFIG_URL=')[1].split('&')[0])
    configxml = _connection.getURL(configurl)
    video_tree = BeautifulSoup(configxml)
    feed = video_tree.player.feed
    try:
        mrssurl = feed.string.replace('{uri}', video_uri).replace(
            '{ref}', 'None').replace('&', '&').strip()
        mrssxml = _connection.getURL(mrssurl)
        mrsstree = BeautifulSoup(mrssxml)
    except:
        mrsstree = feed
    segmenturls = mrsstree.find_all('media:content')
    stacked_url = 'stack://'
    for segment in segmenturls:
        surl = segment['url']
        videos = _connection.getURL(surl)
        videos = BeautifulSoup(videos).find_all('rendition')
        hbitrate = -1
        sbitrate = int(_addoncompat.get_setting('quality'))
        for video in videos:
            bitrate = int(video['bitrate'])
            if bitrate > hbitrate and bitrate <= sbitrate:
                hbitrate = bitrate
                rtmpdata = video.src.string
                rtmpurl = MP4URL + rtmpdata.split('viacomvh1strm')[2]
        stacked_url += rtmpurl.replace(',', ',,') + ' , '
    finalurl = stacked_url[:-3]
    xbmcplugin.setResolvedUrl(pluginHandle, True,
                              xbmcgui.ListItem(path=finalurl))
def list_qualities(BASE, video_url = _common.args.url, media_base = VIDEOURL):
	if media_base not in video_url:
		video_url = media_base + video_url
	bitrates = []
	if 'feed' not in video_url:
		swf_url = _connection.getRedirect(video_url, header = {'Referer' : BASE})
		params = dict(item.split("=") for item in swf_url.split('?')[1].split("&"))
		uri = urllib.unquote_plus(params['uri'])
		config_url = urllib.unquote_plus(params['CONFIG_URL'])
		config_data = _connection.getURL(config_url, header = {'Referer' : video_url, 'X-Forwarded-For' : '12.13.14.15'})
		feed_url = BeautifulSoup(config_data, 'html.parser', parse_only = SoupStrainer('feed')).feed.string
		feed_url = feed_url.replace('{uri}', uri).replace('&amp;', '&').replace('{device}', DEVICE).replace('{ref}', 'None').strip()
	else:
		feed_url = video_url
	feed_data = _connection.getURL(feed_url)
	video_tree = BeautifulSoup(feed_data, 'html.parser', parse_only = SoupStrainer('media:group'))
	video_segments = video_tree.find_all('media:content')
	srates = []
	for video_segment in video_segments:
		video_url3 = video_segment['url'].replace('{device}', DEVICE)
		video_data3 = _connection.getURL(video_url3, header = {'X-Forwarded-For' : '12.13.14.15'})
		video_menu = BeautifulSoup(video_data3).findAll('rendition')
		orates = srates
		srates = []	
		for video_index in video_menu:
			bitrate = int(video_index['bitrate'])
			srates.append((bitrate, bitrate))
		if orates != []:
			srates = list(set(srates).intersection(orates))
	bitrates  =srates
	return bitrates
예제 #3
0
def play_uri(video_uri = _common.args.url, video_referer = 'www.vh1.com'):
	swfUrl = _connection.getRedirect(BASE2 + video_uri, referer = video_referer)
	configurl = urllib.unquote_plus(swfUrl.split('CONFIG_URL=')[1].split('&')[0])
	configxml = _connection.getURL(configurl)
	video_tree = BeautifulSoup(configxml)
	feed = video_tree.player.feed
	try:
		mrssurl = feed.string.replace('{uri}', video_uri).replace('{ref}', 'None').replace('&amp;', '&').strip()
		mrssxml = _connection.getURL(mrssurl)
		mrsstree = BeautifulSoup(mrssxml)
	except:
		mrsstree = feed
	segmenturls = mrsstree.find_all('media:content')
	stacked_url = 'stack://'
	for segment in segmenturls:
		surl = segment['url']
		videos = _connection.getURL(surl)
		videos = BeautifulSoup(videos).find_all('rendition')
		hbitrate = -1
		sbitrate = int(_addoncompat.get_setting('quality'))
		for video in videos:
			bitrate = int(video['bitrate'])
			if bitrate > hbitrate and bitrate <= sbitrate:
				hbitrate = bitrate
				rtmpdata = video.src.string
				rtmpurl = MP4URL + rtmpdata.split('viacomvh1strm')[2]
		stacked_url += rtmpurl.replace(',',',,') + ' , '
	finalurl = stacked_url[:-3]
	xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path = finalurl))
예제 #4
0
def play_video(video_url=_common.args.url):
    video_url9 = 'stack://'
    sbitrate = int(_addoncompat.get_setting('quality'))
    closedcaption = None
    video_data = _connection.getURL(video_url, forwardheader='12.13.14.15')
    try:
        video_url2 = re.compile(
            '<meta content="http://media.mtvnservices.com/fb/(.+?).swf" property="og:video"/>'
        ).findall(video_data)[0]
    except:
        video_url2 = re.compile("NICK.unlock.uri = '(.+?)';").findall(
            video_data)[0]
    video_url3 = _connection.getRedirect('http://media.mtvnservices.com/fb/' +
                                         video_url2 + '.swf',
                                         referer=BASE)
    video_url4 = urllib.unquote_plus(
        video_url3.split('CONFIG_URL=')[1].split('&')[0]).strip()
    video_data2 = _connection.getURL(
        video_url4,
        referer='http://media.mtvnservices.com/fb/' + video_url2 + '.swf')
    video_tree = BeautifulSoup(video_data2)
    video_url5 = video_tree.feed.string.replace('{uri}', video_url2).replace(
        '&amp;', '&').replace('{type}', 'network')
    video_data3 = _connection.getURL(video_url5)
    video_tree2 = BeautifulSoup(video_data3)
    video_segments = video_tree2.find_all('media:content')
    for video_segment in video_segments:
        hbitrate = -1
        video_url6 = video_segment['url']
        video_data4 = _connection.getURL(video_url6)
        video_menu = BeautifulSoup(video_data4).find_all('rendition')
        for video_index in video_menu:
            bitrate = int(video_index['bitrate'])
            if bitrate > hbitrate and bitrate <= sbitrate:
                hbitrate = bitrate
                video_url7 = video_index.find('src').string
                video_url8 = video_url7 + ' swfurl=' + video_url3.split(
                    '?')[0] + ' pageUrl=' + BASE + ' swfvfy=true'
        video_url9 += video_url8.replace(',', ',,') + ' , '
    finalurl = video_url9[:-3]
    try:
        closedcaption = video_tree2.find_all('media:text')
    except:
        pass
    if (_addoncompat.get_setting('enablesubtitles')
            == 'true') and (closedcaption is not None):
        convert_subtitles(closedcaption)
    xbmcplugin.setResolvedUrl(pluginHandle, True,
                              xbmcgui.ListItem(path=finalurl))
    if (_addoncompat.get_setting('enablesubtitles')
            == 'true') and (closedcaption is not None):
        while not xbmc.Player().isPlaying():
            xbmc.sleep(100)
        for count in range(1, len(closedcaption)):
            xbmc.Player().setSubtitles(
                os.path.join(_common.CACHEPATH,
                             'subtitle-%s.srt' % str(count)))
            while xbmc.Player().isPlaying():
                xbmc.sleep(10)
def list_qualities(BASE, video_url=_common.args.url, media_base=VIDEOURL):
    if media_base not in video_url:
        video_url = media_base + video_url
    bitrates = []
    if 'feed' not in video_url:
        swf_url = _connection.getRedirect(video_url, header={'Referer': BASE})
        params = dict(
            item.split("=") for item in swf_url.split('?')[1].split("&"))
        uri = urllib.unquote_plus(params['uri'])
        config_url = urllib.unquote_plus(params['CONFIG_URL'])
        config_data = _connection.getURL(config_url,
                                         header={
                                             'Referer': video_url,
                                             'X-Forwarded-For': '12.13.14.15'
                                         })
        feed_url = BeautifulSoup(config_data,
                                 'html.parser',
                                 parse_only=SoupStrainer('feed')).feed.string
        feed_url = feed_url.replace('{uri}', uri).replace(
            '&amp;', '&').replace('{device}',
                                  'Other').replace('{ref}', 'None').strip()
    else:
        feed_url = video_url
    feed_data = _connection.getURL(feed_url)
    video_tree = BeautifulSoup(feed_data,
                               'html.parser',
                               parse_only=SoupStrainer('media:group'))
    video_segments = video_tree.find_all('media:content')
    srates = []
    for video_segment in video_segments:
        video_url3 = video_segment['url'].replace('{device}', 'Other')
        video_data3 = _connection.getURL(
            video_url3, header={'X-Forwarded-For': '12.13.14.15'})
        video_menu = BeautifulSoup(video_data3).findAll('rendition')
        orates = srates
        srates = []
        for video_index in video_menu:
            bitrate = int(video_index['bitrate'])
            print bitrate
            srates.append((bitrate, bitrate))
        print srates
        if orates != []:
            srates = list(set(srates).intersection(orates))
    bitrates = srates
    return bitrates
def play_video(video_url = _common.args.url):
	video_url9 = 'stack://'
	sbitrate = int(_addoncompat.get_setting('quality'))
	closedcaption = None
	video_data = _connection.getURL(video_url, forwardHeader = True)
	try:
		video_url2 = re.compile('<meta content="http://media.nick.com/(.+?)" itemprop="embedURL"/>').findall(video_data)[0]
	except:
		video_url2 = re.compile("NICK.unlock.uri = '(.+?)';").findall(video_data)[0]
	video_url3 = _connection.getRedirect('http://media.nick.com/' + video_url2, referer = BASE, forwardHeader = True)
	video_url4 = urllib.unquote_plus(video_url3.split('CONFIG_URL=')[1].split('&')[0]).strip()
	video_data2 = _connection.getURL(video_url4, referer = 'http://media.nick.com/' + video_url2, forwardHeader = True)
	video_tree = BeautifulSoup(video_data2)
	video_url5 = video_tree.feed.string.replace('{uri}', video_url2).replace('&amp;', '&').replace('{type}', 'network').replace('mode=episode', 'mode=clip')
	video_data3 = _connection.getURL(video_url5,forwardHeader=True)
	video_tree2 = BeautifulSoup(video_data3)
	video_segments = video_tree2.find_all('media:content')
	for video_segment in video_segments:
		hbitrate = -1
		video_url6 = video_segment['url']
		video_data4 = _connection.getURL(video_url6, forwardHeader = True)
		video_menu = BeautifulSoup(video_data4).find_all('rendition')
		for video_index in video_menu:
			bitrate = int(video_index['bitrate'])
			if bitrate > hbitrate and bitrate <= sbitrate:
				hbitrate = bitrate
				video_url7 = video_index.find('src').string
				video_url8 = video_url7 + ' swfurl=' + video_url3.split('?')[0] + ' pageUrl=' + BASE + ' swfvfy=true'
		video_url9 += video_url8.replace(',',',,') + ' , '
	finalurl = video_url9[:-3]
	try:
		closedcaption = video_tree2.find_all('media:text')
	except:
		pass
	if (_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None):
		convert_subtitles(closedcaption)
	xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path = finalurl))
	if (_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None):
		while not xbmc.Player().isPlaying():
			xbmc.sleep(100)
		for count in range(1, len(closedcaption)):
			xbmc.Player().setSubtitles(os.path.join(_common.CACHEPATH,'subtitle-%s.srt' % str(count)))
			while xbmc.Player().isPlaying():
				xbmc.sleep(10)
예제 #7
0
def list_qualities(BASE, video_url = _common.args.url, media_base = VIDEOURL):
	bitrates = []
	if media_base not in video_url:
		video_url = media_base + video_url
	exception = False
	if 'feed' not in video_url:
		swf_url = _connection.getRedirect(video_url, header = {'Referer' : BASE})
		params = dict(item.split("=") for item in swf_url.split('?')[1].split("&"))
		uri = urllib.unquote_plus(params['uri'])
		config_url = urllib.unquote_plus(params['CONFIG_URL'].replace('Other', DEVICE))
		config_data = _connection.getURL(config_url, header = {'Referer' : video_url, 'X-Forwarded-For' : '12.13.14.15'})
		config_tree = BeautifulSoup(config_data, 'html.parser')
		if not config_tree.error:
			feed_url = config_tree.feed.string
			feed_url = feed_url.replace('{uri}', uri).replace('&amp;', '&').replace('{device}', DEVICE).replace('{ref}', 'None').strip()
		else:
			exception = True
			error_text = config_tree.error.string.split('/')[-1].split('_') 
			_common.show_exception(error_text[1], error_text[2])
	else:
		feed_url = video_url
	if not exception:
		feed_data = _connection.getURL(feed_url)
		video_tree = BeautifulSoup(feed_data, 'html.parser', parse_only = SoupStrainer('media:group'))
		video_segments = video_tree.find_all('media:content')
		video_segment = video_segments[0]
		video_url3 = video_segment['url'].replace('{device}', DEVICE)
		video_data3 = _connection.getURL(video_url3, header = {'X-Forwarded-For' : '12.13.14.15'})
		video_tree3 = BeautifulSoup(video_data3, 'html.parser')
		video_menu = video_tree3.find('src').string
		m3u8_url = None
		m3u_master_data = _connection.getURL(video_menu, savecookie = True)
		m3u_master = _m3u8.parse(m3u_master_data)
		for video_index in m3u_master.get('playlists'):
			bitrate = int(video_index.get('stream_info')['bandwidth'])
			display = int(bitrate) / 1024
			bitrates.append((display, bitrate))
		return bitrates
def list_qualities(BASE, video_url=_common.args.url, media_base=VIDEOURL):
    if media_base not in video_url:
        video_url = media_base + video_url
    bitrates = []
    if "feed" not in video_url:
        swf_url = _connection.getRedirect(video_url, header={"Referer": BASE})
        params = dict(item.split("=") for item in swf_url.split("?")[1].split("&"))
        uri = urllib.unquote_plus(params["uri"])
        config_url = urllib.unquote_plus(params["CONFIG_URL"])
        config_data = _connection.getURL(config_url, header={"Referer": video_url, "X-Forwarded-For": "12.13.14.15"})
        feed_url = BeautifulSoup(config_data, "html.parser", parse_only=SoupStrainer("feed")).feed.string
        feed_url = (
            feed_url.replace("{uri}", uri)
            .replace("&amp;", "&")
            .replace("{device}", DEVICE)
            .replace("{ref}", "None")
            .strip()
        )
    else:
        feed_url = video_url
    feed_data = _connection.getURL(feed_url)
    video_tree = BeautifulSoup(feed_data, "html.parser", parse_only=SoupStrainer("media:group"))
    video_segments = video_tree.find_all("media:content")
    srates = []
    for video_segment in video_segments:
        video_url3 = video_segment["url"].replace("{device}", DEVICE)
        video_data3 = _connection.getURL(video_url3, header={"X-Forwarded-For": "12.13.14.15"})
        video_menu = BeautifulSoup(video_data3).findAll("rendition")
        orates = srates
        srates = []
        for video_index in video_menu:
            bitrate = int(video_index["bitrate"])
            srates.append((bitrate, bitrate))
        if orates != []:
            srates = list(set(srates).intersection(orates))
    bitrates = srates
    return bitrates
def play_video(BASE, video_url = _common.args.url, media_base = VIDEOURL):
	if media_base not in video_url:
		video_url = media_base + video_url
	try:
		qbitrate = _common.args.quality
	except:
		qbitrate = None
	video_url6 = 'stack://'
	sbitrate = int(_addoncompat.get_setting('quality'))
	closedcaption = []
	if 'feed' not in video_url:
		swf_url = _connection.getRedirect(video_url, header = {'Referer' : BASE})
		params = dict(item.split("=") for item in swf_url.split('?')[1].split("&"))
		uri = urllib.unquote_plus(params['uri'])
		config_url = urllib.unquote_plus(params['CONFIG_URL'].replace('Other',DEVICE))
		config_data = _connection.getURL(config_url, header = {'Referer' : video_url, 'X-Forwarded-For' : '12.13.14.15'})
		feed_url = BeautifulSoup(config_data, 'html.parser', parse_only = SoupStrainer('feed')).feed.string
		feed_url = feed_url.replace('{uri}', uri).replace('&amp;', '&').replace('{device}', DEVICE).replace('{ref}', 'None').strip()
	else:
		feed_url = video_url
	feed_data = _connection.getURL(feed_url)
	video_tree = BeautifulSoup(feed_data, 'html.parser', parse_only = SoupStrainer('media:group'))
	video_segments = video_tree.find_all('media:content')
	

	for act, video_segment in enumerate(video_segments):
		video_url3 = video_segment['url'].replace('{device}', DEVICE)
		video_data3 = _connection.getURL(video_url3, header = {'X-Forwarded-For' : '12.13.14.15'})
		video_tree3 = BeautifulSoup(video_data3)
		try:
			closedcaption.append(video_tree3.find('typographic', format = 'ttml'))
		except:
			pass

		video_menu = video_tree3.find('src').string
		hbitrate = -1
		lbitrate = -1

		m3u_master_data = _connection.getURL(video_menu, savecookie = True)
		m3u_master = _m3u8.parse(m3u_master_data)
		hbitrate = -1
		sbitrate = int(_addoncompat.get_setting('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(_common.KEYFILE + str(act), '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/foxstation/' + newurl)
		
		m3u_data = m3u_data.replace(key_url, 'http://127.0.0.1:12345/play.key' + str(act))


		playfile = open(_common.PLAYFILE.replace('.m3u8',  '_' + str(act)  + '.m3u8'), 'w')
		playfile.write(m3u_data)
		playfile.close()
		video_url6 +=  _common.PLAYFILE.replace('.m3u8',  '_' + str(act)  + '.m3u8') + ' , '
		
	filestring = 'XBMC.RunScript(' + os.path.join(_common.LIBPATH,'_proxy.py') + ', 12345)'
	xbmc.executebuiltin(filestring)
	finalurl = video_url6[:-3]
	localhttpserver = True
	time.sleep(20)

	if (_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None):
		convert_subtitles(closedcaption)
	item = xbmcgui.ListItem(path = finalurl)
	if qbitrate is not None:
		item.setThumbnailImage(_common.args.thumb)
		item.setInfo('Video', {	'title' : _common.args.name,
						'season' : _common.args.season_number,
						'episode' : _common.args.episode_number,
						'TVShowTitle' : _common.args.show_title})
	xbmcplugin.setResolvedUrl(pluginHandle, True, item)
	if ((_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None))  or localhttpserver is True:
		while not xbmc.Player().isPlaying():
			xbmc.sleep(200)
	if (_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None) and closedcaption !=[]:
		for count in range(1, len(closedcaption)):
			xbmc.Player().setSubtitles(os.path.join(_common.CACHEPATH, 'subtitle-%s.srt' % str(count)))
			while xbmc.Player().isPlaying():
				xbmc.sleep(10)
	if localhttpserver is True:
		while xbmc.Player().isPlaying():
			xbmc.sleep(10)
		_connection.getURL('http://localhost:12345/stop', connectiontype = 0)
def play_video(BASE, video_url=_common.args.url, media_base=VIDEOURL):
    if media_base not in video_url:
        video_url = media_base + video_url
    try:
        qbitrate = _common.args.quality
    except:
        qbitrate = None
    video_url6 = 'stack://'
    sbitrate = int(_addoncompat.get_setting('quality'))
    closedcaption = []
    if 'southparkstudios' in video_url:
        sp_id = video_url.split(':')
        sp_id = sp_id[len(sp_id) - 1]
        feed_url = 'http://www.southparkstudios.com/feeds/video-player/mrss/mgid%3Aarc%3Aepisode%3Asouthparkstudios.com"%3A' + sp_id
    elif 'feed' not in video_url:
        swf_url = _connection.getRedirect(video_url, header={'Referer': BASE})
        params = dict(
            item.split("=") for item in swf_url.split('?')[1].split("&"))
        uri = urllib.unquote_plus(params['uri'])
        config_url = urllib.unquote_plus(params['CONFIG_URL'])
        config_data = _connection.getURL(config_url,
                                         header={
                                             'Referer': video_url,
                                             'X-Forwarded-For': '12.13.14.15'
                                         })
        feed_url = BeautifulSoup(config_data,
                                 'html.parser',
                                 parse_only=SoupStrainer('feed')).feed.string
        feed_url = feed_url.replace('{uri}', uri).replace(
            '&amp;', '&').replace('{device}',
                                  'Other').replace('{ref}', 'None').strip()
    else:
        feed_url = video_url
    feed_data = _connection.getURL(feed_url)
    video_tree = BeautifulSoup(feed_data,
                               'html.parser',
                               parse_only=SoupStrainer('media:group'))
    video_segments = video_tree.find_all('media:content')
    for video_segment in video_segments:
        video_url3 = video_segment['url'].replace('{device}', 'Other')
        video_data3 = _connection.getURL(
            video_url3, header={'X-Forwarded-For': '12.13.14.15'})
        video_tree3 = BeautifulSoup(video_data3)
        try:
            closedcaption.append(video_tree3.find('typographic',
                                                  format='ttml'))
        except:
            pass
        if qbitrate is None:
            video_menu = video_tree3.findAll('rendition')
            hbitrate = -1
            lbitrate = -1
            video_url4 = None
            for video_index in video_menu:
                bitrate = int(video_index['bitrate'])
                if bitrate < lbitrate or lbitrate == -1:
                    lbitrate = bitrate
                    video_url4 = video_index.find('src').string
                if bitrate > hbitrate and bitrate <= sbitrate:
                    hbitrate = bitrate
                    video_url4 = video_index.find('src').string

            if video_url4 is None:
                video_url4 = lvideo_url4
        else:
            video_url4 = video_tree3.find('rendition',
                                          attrs={
                                              'bitrate': qbitrate
                                          }).src.string

        video_url5 = MP4URL + '/gsp.' + video_url4.split('/gsp.')[1]
        print video_url5
        video_url6 += video_url5.replace(',', ',,') + ' , '
    finalurl = video_url6[:-3]
    if not closedcaption:
        try:
            closedcaption = video_tree.find_all('media:text')
        except:
            pass
    if (_addoncompat.get_setting('enablesubtitles')
            == 'true') and (closedcaption is not None) and closedcaption != []:
        convert_subtitles(closedcaption)
    item = xbmcgui.ListItem(path=finalurl)
    if qbitrate is not None:
        item.setThumbnailImage(_common.args.thumb)
        item.setInfo(
            'Video', {
                'title': _common.args.name,
                'season': _common.args.season_number,
                'episode': _common.args.episode_number
            })
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    if (_addoncompat.get_setting('enablesubtitles')
            == 'true') and (closedcaption is not None) and closedcaption != []:
        while not xbmc.Player().isPlaying():
            xbmc.sleep(200)
        for count in range(1, len(closedcaption)):
            xbmc.Player().setSubtitles(
                os.path.join(_common.CACHEPATH,
                             'subtitle-%s.srt' % str(count)))
            while xbmc.Player().isPlaying():
                xbmc.sleep(10)
def play_video(BASE, video_url=_common.args.url, media_base=VIDEOURL):
    if media_base not in video_url:
        video_url = media_base + video_url
    try:
        qbitrate = _common.args.quality
    except:
        qbitrate = None
    video_url6 = "stack://"
    sbitrate = int(_addoncompat.get_setting("quality"))
    closedcaption = []
    if "feed" not in video_url:
        swf_url = _connection.getRedirect(video_url, header={"Referer": BASE})
        params = dict(item.split("=") for item in swf_url.split("?")[1].split("&"))
        uri = urllib.unquote_plus(params["uri"])
        config_url = urllib.unquote_plus(params["CONFIG_URL"].replace("Other", DEVICE))
        config_data = _connection.getURL(config_url, header={"Referer": video_url, "X-Forwarded-For": "12.13.14.15"})
        feed_url = BeautifulSoup(config_data, "html.parser", parse_only=SoupStrainer("feed")).feed.string
        feed_url = (
            feed_url.replace("{uri}", uri)
            .replace("&amp;", "&")
            .replace("{device}", DEVICE)
            .replace("{ref}", "None")
            .strip()
        )
    else:
        feed_url = video_url
    feed_data = _connection.getURL(feed_url)
    video_tree = BeautifulSoup(feed_data, "html.parser", parse_only=SoupStrainer("media:group"))
    video_segments = video_tree.find_all("media:content")

    for act, video_segment in enumerate(video_segments):
        video_url3 = video_segment["url"].replace("{device}", DEVICE)
        video_data3 = _connection.getURL(video_url3, header={"X-Forwarded-For": "12.13.14.15"})
        video_tree3 = BeautifulSoup(video_data3, "html5lib")
        try:
            closedcaption.append(video_tree3.find("typographic", format="ttml"))
        except:
            pass

        video_menu = video_tree3.find("src").string
        hbitrate = -1
        lbitrate = -1

        m3u_master_data = _connection.getURL(video_menu, savecookie=True)
        m3u_master = _m3u8.parse(m3u_master_data)
        hbitrate = -1
        sbitrate = int(_addoncompat.get_setting("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(_common.KEYFILE + str(act), "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/foxstation/" + newurl)

        m3u_data = m3u_data.replace(key_url, "http://127.0.0.1:12345/play.key" + str(act))

        playfile = open(_common.PLAYFILE.replace(".m3u8", "_" + str(act) + ".m3u8"), "w")
        playfile.write(m3u_data)
        playfile.close()
        video_url6 += _common.PLAYFILE.replace(".m3u8", "_" + str(act) + ".m3u8") + " , "

    filestring = "XBMC.RunScript(" + os.path.join(_common.LIBPATH, "_proxy.py") + ", 12345)"
    xbmc.executebuiltin(filestring)
    finalurl = video_url6[:-3]
    localhttpserver = True
    time.sleep(20)

    if (_addoncompat.get_setting("enablesubtitles") == "true") and (closedcaption is not None):
        convert_subtitles(closedcaption)
    item = xbmcgui.ListItem(path=finalurl)
    if qbitrate is not None:
        item.setThumbnailImage(_common.args.thumb)
        item.setInfo(
            "Video",
            {
                "title": _common.args.name,
                "season": _common.args.season_number,
                "episode": _common.args.episode_number,
                "TVShowTitle": _common.args.show_title,
            },
        )
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    if (
        (_addoncompat.get_setting("enablesubtitles") == "true") and (closedcaption is not None)
    ) or localhttpserver is True:
        while not xbmc.Player().isPlaying():
            xbmc.sleep(200)
    if (_addoncompat.get_setting("enablesubtitles") == "true") and (closedcaption is not None) and closedcaption != []:
        for count in range(1, len(closedcaption)):
            xbmc.Player().setSubtitles(os.path.join(_common.CACHEPATH, "subtitle-%s.srt" % str(count)))
            while xbmc.Player().isPlaying():
                xbmc.sleep(10)
    if localhttpserver is True:
        while xbmc.Player().isPlaying():
            xbmc.sleep(10)
        _connection.getURL("http://localhost:12345/stop", connectiontype=0)
def play_video(BASE, video_url=_common.args.url, media_base=VIDEOURL):
    if media_base not in video_url:
        video_url = media_base + video_url
    try:
        qbitrate = _common.args.quality
    except:
        qbitrate = None
    video_url6 = 'stack://'
    sbitrate = int(_addoncompat.get_setting('quality'))
    closedcaption = []
    if 'feed' not in video_url:
        swf_url = _connection.getRedirect(video_url, header={'Referer': BASE})
        params = dict(
            item.split("=") for item in swf_url.split('?')[1].split("&"))
        uri = urllib.unquote_plus(params['uri'])
        config_url = urllib.unquote_plus(params['CONFIG_URL'].replace(
            'Other', DEVICE))
        config_data = _connection.getURL(config_url,
                                         header={
                                             'Referer': video_url,
                                             'X-Forwarded-For': '12.13.14.15'
                                         })
        feed_url = BeautifulSoup(config_data,
                                 'html.parser',
                                 parse_only=SoupStrainer('feed')).feed.string
        feed_url = feed_url.replace('{uri}', uri).replace(
            '&amp;', '&').replace('{device}', DEVICE).replace('{ref}',
                                                              'None').strip()
    else:
        feed_url = video_url
    feed_data = _connection.getURL(feed_url)
    video_tree = BeautifulSoup(feed_data,
                               'html.parser',
                               parse_only=SoupStrainer('media:group'))
    video_segments = video_tree.find_all('media:content')

    for act, video_segment in enumerate(video_segments):
        video_url3 = video_segment['url'].replace('{device}', DEVICE)
        video_data3 = _connection.getURL(
            video_url3, header={'X-Forwarded-For': '12.13.14.15'})
        video_tree3 = BeautifulSoup(video_data3, 'html5lib')
        try:
            closedcaption.append(video_tree3.find('typographic',
                                                  format='ttml'))
        except:
            pass

        video_menu = video_tree3.find('src').string
        hbitrate = -1
        lbitrate = -1

        m3u_master_data = _connection.getURL(video_menu, savecookie=True)
        m3u_master = _m3u8.parse(m3u_master_data)
        hbitrate = -1
        sbitrate = int(_addoncompat.get_setting('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(_common.KEYFILE + str(act), '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/foxstation/' + newurl)

        m3u_data = m3u_data.replace(
            key_url, 'http://127.0.0.1:12345/play.key' + str(act))

        playfile = open(
            _common.PLAYFILE.replace('.m3u8', '_' + str(act) + '.m3u8'), 'w')
        playfile.write(m3u_data)
        playfile.close()
        video_url6 += _common.PLAYFILE.replace(
            '.m3u8', '_' + str(act) + '.m3u8') + ' , '

    filestring = 'XBMC.RunScript(' + os.path.join(_common.LIBPATH,
                                                  '_proxy.py') + ', 12345)'
    xbmc.executebuiltin(filestring)
    finalurl = video_url6[:-3]
    localhttpserver = True
    time.sleep(20)

    if (_addoncompat.get_setting('enablesubtitles')
            == 'true') and (closedcaption is not None):
        convert_subtitles(closedcaption)
    item = xbmcgui.ListItem(path=finalurl)
    if qbitrate is not None:
        item.setThumbnailImage(_common.args.thumb)
        item.setInfo(
            'Video', {
                'title': _common.args.name,
                'season': _common.args.season_number,
                'episode': _common.args.episode_number,
                'TVShowTitle': _common.args.show_title
            })
    xbmcplugin.setResolvedUrl(pluginHandle, True, item)
    if ((_addoncompat.get_setting('enablesubtitles') == 'true') and
        (closedcaption is not None)) or localhttpserver is True:
        while not xbmc.Player().isPlaying():
            xbmc.sleep(200)
    if (_addoncompat.get_setting('enablesubtitles')
            == 'true') and (closedcaption is not None) and closedcaption != []:
        for count in range(1, len(closedcaption)):
            xbmc.Player().setSubtitles(
                os.path.join(_common.CACHEPATH,
                             'subtitle-%s.srt' % str(count)))
            while xbmc.Player().isPlaying():
                xbmc.sleep(10)
    if localhttpserver is True:
        while xbmc.Player().isPlaying():
            xbmc.sleep(10)
        _connection.getURL('http://localhost:12345/stop', connectiontype=0)
예제 #13
0
def play_video(BASE, video_url = _common.args.url, media_base = VIDEOURL):
	if media_base not in video_url:
		video_url = media_base + video_url
	try:
		qbitrate = _common.args.quality
	except:
		qbitrate = None
	video_url2 = 'stack://'
	threads = []
	closedcaption = []
	exception = False
	queue = PriorityQueue()
	segments = []
	if 'feed' not in video_url:
		swf_url = _connection.getRedirect(video_url, header = {'Referer' : BASE})
		try:
			params = dict(item.split("=") for item in swf_url.split('?')[1].split("&"))
			uri = urllib.unquote_plus(params['uri'])
			config_url = urllib.unquote_plus(params['CONFIG_URL'].replace('Other', DEVICE))
			config_data = _connection.getURL(config_url, header = {'Referer' : video_url, 'X-Forwarded-For' : '12.13.14.15'})
			config_tree = BeautifulSoup(config_data, 'html.parser')
			if not config_tree.error:
				feed_url = config_tree.feed.string
				feed_url = feed_url.replace('{uri}', uri).replace('&amp;', '&').replace('{device}', DEVICE).replace('{ref}', 'None').strip()
			else:
				exception = True
				error_text = config_tree.error.string.split('/')[-1].split('_') 
				_common.show_exception(error_text[1], error_text[2])
		except:
			_common.show_exception("Viacomm", swf_url)
	else:
		feed_url = video_url
	if not exception:
		feed_data = _connection.getURL(feed_url)
		video_tree = BeautifulSoup(feed_data, 'html.parser', parse_only = SoupStrainer('media:group'))
		video_segments = video_tree.find_all('media:content')
		for i, video_item in enumerate(video_segments):
			worker = Thread(target = get_videos, args = (queue, i, video_item, qbitrate))
			worker.setDaemon(True)
			worker.start()
			threads.append(worker)
		[x.join() for x in threads]
		while not queue.empty():
			video_data2 = queue.get()
			video_url2 += video_data2[1] + ' , '
			segments.append(video_data2[2])
			closedcaption.append((video_data2[3], video_data2[2], video_data2[0]))
		player._segments_array = segments
		filestring = 'XBMC.RunScript(' + os.path.join(_common.LIBPATH,'_proxy.py') + ', 12345)'
		xbmc.executebuiltin(filestring)
		finalurl = video_url2[:-3]
		localhttpserver = True
		time.sleep(20)
		if (_addoncompat.get_setting('enablesubtitles') == 'true') and closedcaption:
			convert_subtitles(closedcaption)
			player._subtitles_Enabled = True
		item = xbmcgui.ListItem(path = finalurl)

		queue.task_done()
		if qbitrate is not None:
			item.setThumbnailImage(_common.args.thumb)
			item.setInfo('Video', {	'title' : _common.args.name,
									'season' : _common.args.season_number,
									'episode' : _common.args.episode_number,
									'TVShowTitle' : _common.args.show_title })
		xbmcplugin.setResolvedUrl(pluginHandle, True, item)
		while player.is_active:
			player.sleep(250)
def play_video(BASE, video_url = _common.args.url, media_base = VIDEOURL):
	if media_base not in video_url:
		video_url = media_base + video_url
	try:
		qbitrate = _common.args.quality
	except:
		qbitrate = None
	video_url6 = 'stack://'
	sbitrate = int(_addoncompat.get_setting('quality'))
	closedcaption = []
	if 'feed' not in video_url:
		swf_url = _connection.getRedirect(video_url, header = {'Referer' : BASE})
		params = dict(item.split("=") for item in swf_url.split('?')[1].split("&"))
		uri = urllib.unquote_plus(params['uri'])
		config_url = urllib.unquote_plus(params['CONFIG_URL'])
		config_data = _connection.getURL(config_url, header = {'Referer' : video_url, 'X-Forwarded-For' : '12.13.14.15'})
		feed_url = BeautifulSoup(config_data, 'html.parser', parse_only = SoupStrainer('feed')).feed.string
		feed_url = feed_url.replace('{uri}', uri).replace('&amp;', '&').replace('{device}', 'Other').replace('{ref}', 'None').strip()
	else:
		feed_url = video_url
	feed_data = _connection.getURL(feed_url)
	video_tree = BeautifulSoup(feed_data, 'html.parser', parse_only = SoupStrainer('media:group'))
	video_segments = video_tree.find_all('media:content')
	for video_segment in video_segments:
		video_url3 = video_segment['url'].replace('{device}', 'Other')
		video_data3 = _connection.getURL(video_url3, header = {'X-Forwarded-For' : '12.13.14.15'})
		video_tree3 = BeautifulSoup(video_data3)
		try:
			closedcaption.append(video_tree3.find('typographic', format = 'ttml'))
		except:
			pass
		if qbitrate is None:
			video_menu = video_tree3.findAll('rendition')
			hbitrate = -1
			lbitrate = -1
			video_url4 = None
			for video_index in video_menu:
				bitrate = int(video_index['bitrate'])
				if bitrate < lbitrate or lbitrate == -1:
					lbitrate = bitrate
					video_url4 = video_index.find('src').string
				if bitrate > hbitrate and bitrate <= sbitrate:
					hbitrate = bitrate
					video_url4 = video_index.find('src').string
					
			if video_url4 is None:
				video_url4 = lvideo_url4
		else:
			video_url4 = video_tree3.find('rendition', attrs = {'bitrate' : qbitrate}).src.string
	
		video_url5 =  MP4URL + '/gsp.' + video_url4.split('/gsp.')[1] 
		print video_url5
		video_url6 += video_url5.replace(',', ',,') + ' , '
	finalurl = video_url6[:-3]
	if not closedcaption:
		try:
			closedcaption = video_tree.find_all('media:text')
		except:
			pass
	if (_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None ) and closedcaption !=[]:
		convert_subtitles(closedcaption)
	item = xbmcgui.ListItem(path = finalurl)
	if qbitrate is not None:
		item.setThumbnailImage(_common.args.thumb)
		item.setInfo('Video', {	'title' : _common.args.name,
						'season' : _common.args.season_number,
						'episode' : _common.args.episode_number})
	xbmcplugin.setResolvedUrl(pluginHandle, True, item)
	if (_addoncompat.get_setting('enablesubtitles') == 'true') and (closedcaption is not None) and closedcaption !=[]:
		while not xbmc.Player().isPlaying():
			xbmc.sleep(200)
		for count in range(1, len(closedcaption)):
			xbmc.Player().setSubtitles(os.path.join(_common.CACHEPATH, 'subtitle-%s.srt' % str(count)))
			while xbmc.Player().isPlaying():
				xbmc.sleep(10)