Example #1
0
def convert_subtitles(video_guid):
	try:
		file = None
		dialog = xbmcgui.DialogProgress()
        	dialog.create(common.smart_utf8(addon.getLocalizedString(39026)))
		dialog.update(0, common.smart_utf8(addon.getLocalizedString(39027)))
		str_output = ''
		subtitle_data = connection.getURL(CLOSEDCAPTION % video_guid, connectiontype = 0)
		subtitle_data = simplejson.loads(subtitle_data)
		lines_total = len(subtitle_data)
		dialog.update(0, common.smart_utf8(addon.getLocalizedString(39028)))
		for i, subtitle_line in enumerate(subtitle_data):
			if subtitle_line is not None and 'Text' in subtitle_line['metadata']:
				if (dialog.iscanceled()):
					return
				if i % 10 == 0:
					percent = int( (float(i*100) / lines_total) )
					dialog.update(percent, common.smart_utf8(addon.getLocalizedString(30929)))
				sub = common.smart_utf8(subtitle_line['metadata']['Text'])
				start_time = common.smart_utf8(str(subtitle_line['startTime'])).split('.')
				start_minutes, start_seconds = divmod(int(start_time[0]), 60)
				start_hours, start_minutes = divmod(start_minutes, 60)
				start_time = '%02d:%02d:%02d,%02d' % (start_hours, start_minutes, start_seconds, int(start_time[1][0:2]))
				end_time = common.smart_utf8(str(subtitle_line['endTime'])).split('.')
				end_minutes, end_seconds = divmod(int(end_time[0]), 60)
				end_hours, end_minutes = divmod(end_minutes, 60)
				end_time = '%02d:%02d:%02d,%02d' % (end_hours, end_minutes, end_seconds, int(end_time[1][0:2]))
				str_output += str(i + 1) + '\n' + start_time + ' --> ' + end_time + '\n' + sub + '\n\n'
		file = open(ustvpaths.SUBTITLE, 'w')
		file.write(str_output)
		file.close()
	except Exception, e:
		print "Exception: " + unicode(e)
		common.show_exception(NAME, addon.getLocalizedString(39030))
Example #2
0
def convert_subtitles(video_guid):
	try:
		file = None
		dialog = xbmcgui.DialogProgress()
        	dialog.create(common.smart_utf8(xbmcaddon.Addon(id = common.ADDONID).getLocalizedString(39026)))
		dialog.update(0, common.smart_utf8(xbmcaddon.Addon(id = common.ADDONID).getLocalizedString(39027)))
		str_output = ''
		subtitle_data = connection.getURL(CLOSEDCAPTION % video_guid, connectiontype = 0)
		subtitle_data = simplejson.loads(subtitle_data)
		lines_total = len(subtitle_data)
		dialog.update(0, common.smart_utf8(xbmcaddon.Addon(id = common.ADDONID).getLocalizedString(39028)))
		for i, subtitle_line in enumerate(subtitle_data):
			if subtitle_line is not None and 'Text' in subtitle_line['metadata']:
				if (dialog.iscanceled()):
					return
				if i % 10 == 0:
					percent = int( (float(i*100) / lines_total) )
					dialog.update(percent, common.smart_utf8(xbmcaddon.Addon(id = common.ADDONID).getLocalizedString(30929)))
				sub = common.smart_utf8(subtitle_line['metadata']['Text'])
				start_time = common.smart_utf8(str(subtitle_line['startTime'])).split('.')
				start_minutes, start_seconds = divmod(int(start_time[0]), 60)
				start_hours, start_minutes = divmod(start_minutes, 60)
				start_time = '%02d:%02d:%02d,%02d' % (start_hours, start_minutes, start_seconds, int(start_time[1][0:2]))
				end_time = common.smart_utf8(str(subtitle_line['endTime'])).split('.')
				end_minutes, end_seconds = divmod(int(end_time[0]), 60)
				end_hours, end_minutes = divmod(end_minutes, 60)
				end_time = '%02d:%02d:%02d,%02d' % (end_hours, end_minutes, end_seconds, int(end_time[1][0:2]))
				str_output += str(i + 1) + '\n' + start_time + ' --> ' + end_time + '\n' + sub + '\n\n'
		file = open(ustvpaths.SUBTITLE, 'w')
		file.write(str_output)
		file.close()
	except Exception, e:
		print "Exception: " + unicode(e)
		common.show_exception(NAME, xbmcaddon.Addon(id = common.ADDONID).getLocalizedString(39030))
Example #3
0
def list_qualities(M3UURL = None):
	exception = False
	video_url = common.args.url
	video_data = connection.getURL(video_url)
	if 'link.theplatform.com' not in video_url:
		video_tree =  BeautifulSoup(video_data, 'html.parser')
		try:
			player_url = 'http:' + video_tree.find('div', class_ = 'video-player-wrapper').iframe['src']
		except:
			player_url = 'http:' + video_tree.find('div', id = 'pdk-player')['data-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=SCRIPT'
		
		script_data = connection.getURL(video_url)
		script_menu = simplejson.loads(script_data)
		if script_menu['pl1$entitlement'] != 'auth':
			bitrates,exception = smil_bitrates(video_url)
		else:
			captions = script_menu['captions'][0]['src']
			id = re.compile('([0-9]+.[0-9]+.*).tt').findall(captions)[0]
			td = (datetime.datetime.utcnow()- datetime.datetime(1970,1,1))
			unow = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
			master_url = M3UURL % (id, str(unow), str(unow+60))
			bitrates = m3u_bitrates(master_url)
			return bitrates
			#need to set captions on player
	else:
		bitrates,exception = smil_bitrates(video_url)
	if  not exception:
		return bitrates
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
Example #4
0
def login(url):
    if addon.getSetting('cbs_use_login') == 'true':
        username = addon.getSetting('cbs_username')
        password = addon.getSetting('cbs_password')
        #Get token
        data = connection.getURL(url)
        token = re.compile("authToken = '(.*?)';").findall(data)[0]
        login_values = values = {
            'j_username': username,
            'j_password': password,
            '_remember_me': '1',
            'tk_trp': token
        }
        login_response = connection.getURL(LOGIN_URL,
                                           login_values,
                                           savecookie=True)
        response = simplejson.loads(login_response)
        if response['success'] == False:
            print 'Login failed', response
            try:
                msg = response['message']
            except:
                msg = response['messages']
            common.show_exception(NAME, msg)
            return False
        else:
            return True
def play_video(SWFURL, M3UURL = None, BASE = None):
	key_url = None
	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')
		try:
			player_url = 'http:' + video_tree.find('div', class_ = 'video-player-wrapper').iframe['src']
		except:
			player_url = 'http:' + video_tree.find('div', id = 'pdk-player')['data-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=SCRIPT'
		
		script_data = connection.getURL(video_url)
		script_menu = simplejson.loads(script_data)
		if script_menu['pl1$entitlement'] != 'auth':
			finalurl,exception = process_smil(video_url)
		else:
			captions = script_menu['captions'][0]['src']

			id = re.compile('([0-9]+.[0-9]+.*).tt').findall(captions)[0]

			td = (datetime.datetime.utcnow()- datetime.datetime(1970,1,1))
			unow = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
			master_url = M3UURL % (id, str(unow), str(unow+60))
			finalurl = process_m3u(master_url, qbitrate)
	else:
		finalurl, exception = process_smil(video_url)
	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'])
Example #6
0
def list_qualities():
    exception = False
    video_url = common.args.url
    bitrates = []
    video_data = connection.getURL(video_url)
    video_tree = BeautifulSoup(video_data, 'html.parser')
    try:
        video_rtmp = video_tree.meta['base']
    except:
        video_rtmp = None
    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)
    if video_rtmp is not None:
        for video_index in video_rtmp:
            bitrate = int(video_index['system-bitrate'])
            display = int(bitrate)
            bitrates.append((display, bitrate))
    else:
        video_data = connection.getURL(video_url + '&manifest=m3u')
        video_tree = BeautifulSoup(video_data, 'html.parser')
        if video_tree.find('param',
                           attrs={
                               'name': 'isException',
                               'value': 'true'
                           }) is None:
            video_url2 = video_tree.seq.find_all('video')[0]
            video_url3 = video_url2['src']
            video_data2 = connection.getURL(video_url3)
            video_url4 = m3u8.parse(video_data2)
            for video_index in video_url4.get('playlists'):
                bitrate = int(video_index.get('stream_info')['bandwidth'])
                try:
                    codecs = video_index.get('stream_info')['codecs']
                except:
                    codecs = ''
                display = int(bitrate) / 1024
                bitrates.append((display, bitrate))
        else:
            exception = True
    if not exception:
        return bitrates
    else:
        common.show_exception(video_tree.ref['title'],
                              video_tree.ref['abstract'])
Example #7
0
def play_video(video_url = common.args.url):
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	closedcaption = None
	video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
		playpath_url = None
		if qbitrate is None:
			video_url2 = video_tree.switch.find_all('video')
			lbitrate = -1
			hbitrate = -1
			sbitrate = int(addon.getSetting('quality')) * 1024
			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:
			bitrate = qbitrate 
			playpath_url = video_tree.switch.find('video', attrs = {'system-bitrate' : qbitrate})['src']
		try:
			closedcaption = video_tree.find('textstream', type = 'text/srt')['src']
		except:
			pass
		finalurl = playpath_url
		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})
		except:
			pass
		xbmcplugin.setResolvedUrl(pluginHandle, True, item)
		if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
			while not xbmc.Player().isPlaying():
				xbmc.sleep(100)
			xbmc.Player().setSubtitles(closedcaption)
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
Example #8
0
def list_qualities(video_url = common.args.url):
	bitrates = []
	video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
		video_url2 = video_tree.switch.find_all('video')
		for video in video_url2:
			bitrate = video['system-bitrate']
			display = int(bitrate) / 1024
			bitrates.append((display, bitrate))
		return bitrates
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
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').replace('{type}', 'normal').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
Example #10
0
def list_qualities():
	exception = False
	video_url = common.args.url
	bitrates = []
	video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	try:
		video_rtmp = video_tree.meta['base']
	except:
		video_rtmp = None
	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)
	if video_rtmp is not None:
		for video_index in video_rtmp:
			bitrate = int(video_index['system-bitrate'])
			display = int(bitrate)
			bitrates.append((display, bitrate))
	else:
		video_data = connection.getURL(video_url + '&manifest=m3u')
		video_tree = BeautifulSoup(video_data, 'html.parser')
		if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
			video_url2 = video_tree.seq.find_all('video')[0]
			video_url3 = video_url2['src']
			video_data2 = connection.getURL(video_url3)
			video_url4 = m3u8.parse(video_data2)
			for video_index in video_url4.get('playlists'):
				bitrate = int(video_index.get('stream_info')['bandwidth'])
				try:
					codecs =  video_index.get('stream_info')['codecs']
				except:
					codecs = ''
				display = int(bitrate) / 1024
				bitrates.append((display, bitrate))
		else:
			exception = True
	if  not exception:
		return bitrates
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
Example #11
0
def list_qualities(video_url=common.args.url):
    bitrates = []
    if "http://" in video_url:
        pid = lookup_meta(video_url)
    else:
        pid = video_url
    video_url = EPISODE % pid
    video_data = connection.getURL(video_url)
    video_tree = BeautifulSoup(video_data, "html.parser")
    if video_tree.find("param", attrs={"name": "isException", "value": "true"}) is None:
        video_url2 = video_tree.switch.find_all("video")
        for video in video_url2:
            bitrate = video["system-bitrate"]
            display = int(bitrate) / 1024
            bitrates.append((display, bitrate))
        return bitrates
    else:
        common.show_exception(video_tree.ref["title"], video_tree.ref["abstract"])
Example #12
0
def list_qualities(video_url = common.args.url):
	bitrates = []
	if 'http://' in video_url:
		pid = lookup_meta(video_url)
	else:
		pid = video_url
	video_url = EPISODE % pid
	video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
		video_url2 = video_tree.switch.find_all('video')
		for video in video_url2:
			bitrate = video['system-bitrate']
			display = int(bitrate) / 1024
			bitrates.append((display, bitrate))
		return bitrates
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
Example #13
0
def login(url):
    if addon.getSetting("cbs_use_login") == "true":
        username = addon.getSetting("cbs_username")
        password = addon.getSetting("cbs_password")
        # Get token
        data = connection.getURL(url)
        token = re.compile("authToken = '(.*?)';").findall(data)[0]
        login_values = values = {"j_username": username, "j_password": password, "_remember_me": "1", "tk_trp": token}
        login_response = connection.getURL(LOGIN_URL, login_values, savecookie=True)
        response = simplejson.loads(login_response)
        if response["success"] == False:
            print "Login failed", response
            try:
                msg = response["message"]
            except:
                msg = response["messages"]
            common.show_exception(NAME, msg)
            return False
        else:
            return True
Example #14
0
def login(url):
	if  addon.getSetting('cbs_use_login') == 'true':
		username = addon.getSetting('cbs_username')
		password = addon.getSetting('cbs_password')
		#Get token
		data = connection.getURL(url)
		token = re.compile("authToken = '(.*?)';").findall(data)[0]
		login_values = values = {'j_username' : username, 'j_password' : password, '_remember_me' : '1', 'tk_trp' : token }
		login_response = connection.getURL(LOGIN_URL, login_values, savecookie = True)
		response = simplejson.loads(login_response)
		if response['success'] == False:
			print 'Login failed', response
			try:
				msg = response['message']
			except:
				msg = response['messages']
			common.show_exception(NAME, msg)
			return False
		else:
			return True
Example #15
0
def list_qualities(video_url=common.args.url):
    bitrates = []
    try:
        video_data = connection.getURL(video_url)
        video_tree = BeautifulSoup(video_data, 'html.parser')
        if video_tree.find('param',
                           attrs={
                               'name': 'isException',
                               'value': 'true'
                           }) is None:
            video_url2 = video_tree.switch.find_all('video')
            for video in video_url2:
                bitrate = video['system-bitrate']
                display = int(bitrate) / 1024
                bitrates.append((display, bitrate))
            return bitrates
        else:
            common.show_exception(video_tree.ref['title'],
                                  video_tree.ref['abstract'])
    except:
        return [(v, k) for k, v in dict(zip(BITRATES, BITRATES)).iteritems()]
Example #16
0
def convert_subtitles(video_guid):
    try:
        file = None
        dialog = xbmcgui.DialogProgress()
        dialog.create(common.smart_utf8(addon.getLocalizedString(39026)))
        dialog.update(0, common.smart_utf8(addon.getLocalizedString(39027)))
        str_output = ""
        subtitle_data = connection.getURL(CLOSEDCAPTION % video_guid, connectiontype=0)
        subtitle_data = simplejson.loads(subtitle_data)
        lines_total = len(subtitle_data)
        dialog.update(0, common.smart_utf8(addon.getLocalizedString(39028)))
        for i, subtitle_line in enumerate(subtitle_data):
            if subtitle_line is not None and "Text" in subtitle_line["metadata"]:
                if dialog.iscanceled():
                    return
                if i % 10 == 0:
                    percent = int((float(i * 100) / lines_total))
                    dialog.update(percent, common.smart_utf8(addon.getLocalizedString(30929)))
                sub = common.smart_utf8(subtitle_line["metadata"]["Text"])
                start_time = common.smart_utf8(str(subtitle_line["startTime"])).split(".")
                start_minutes, start_seconds = divmod(int(start_time[0]), 60)
                start_hours, start_minutes = divmod(start_minutes, 60)
                start_time = "%02d:%02d:%02d,%02d" % (
                    start_hours,
                    start_minutes,
                    start_seconds,
                    int(start_time[1][0:2]),
                )
                end_time = common.smart_utf8(str(subtitle_line["endTime"])).split(".")
                end_minutes, end_seconds = divmod(int(end_time[0]), 60)
                end_hours, end_minutes = divmod(end_minutes, 60)
                end_time = "%02d:%02d:%02d,%02d" % (end_hours, end_minutes, end_seconds, int(end_time[1][0:2]))
                str_output += str(i + 1) + "\n" + start_time + " --> " + end_time + "\n" + sub + "\n\n"
        file = open(ustvpaths.SUBTITLE, "w")
        file.write(str_output)
        file.close()
    except Exception, e:
        print "Exception: " + unicode(e)
        common.show_exception(NAME, addon.getLocalizedString(39030))
def list_qualities(M3UURL=None):
    exception = False
    video_url = common.args.url
    video_data = connection.getURL(video_url)
    if 'link.theplatform.com' not in video_url:
        video_tree = BeautifulSoup(video_data, 'html.parser')
        try:
            player_url = 'http:' + video_tree.find(
                'div', class_='video-player-wrapper').iframe['src']
        except:
            player_url = 'http:' + video_tree.find('div',
                                                   id='pdk-player')['data-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=SCRIPT'

        script_data = connection.getURL(video_url)
        script_menu = simplejson.loads(script_data)
        if script_menu['pl1$entitlement'] != 'auth':
            bitrates, exception = smil_bitrates(video_url)
        else:
            captions = script_menu['captions'][0]['src']
            id = re.compile('([0-9]+.[0-9]+.*).tt').findall(captions)[0]
            td = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1))
            unow = int((td.microseconds +
                        (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
            master_url = M3UURL % (id, str(unow), str(unow + 60))
            bitrates = m3u_bitrates(master_url)
            return bitrates
            #need to set captions on player
    else:
        bitrates, exception = smil_bitrates(video_url)
    if not exception:
        return bitrates
    else:
        common.show_exception(video_tree.ref['title'],
                              video_tree.ref['abstract'])
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').replace('{type}', 'normal').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 play_video(BASE, video_uri = common.args.url, media_base = VIDEOURL):
	video_url = media_base + video_uri
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	video_url2 = 'stack://'
	closedcaption = []
	exception = False
	queue = PriorityQueue()
	segments = []
	if 'feed' in video_uri:
		feed_url = video_uri
	else:
		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
			uri = urllib.quote_plus(uri)
			feed_url = feed_url.replace('{uri}', uri).replace('&amp;', '&').replace('{device}', DEVICE).replace('{ref}', 'None').replace('{type}', 'network').strip()
		else:
				exception = True
				error_text = config_tree.error.string.split('/')[-1].split('_') 
				if error_text[1] == 'loc':
					params = dict(item.split("=") for item in config_url.split('?')[-1].split('&'))
					common.show_exception('Geo', params['geo'])
	if not exception:
		feed_data = connection.getURL(feed_url,  header = {'X-Forwarded-For' : '12.13.14.15'})
		video_tree = BeautifulSoup(feed_data, 'html.parser', parse_only = SoupStrainer('media:group'))
		video_segments = video_tree.find_all('media:content')
		if not video_segments:
			video_tree = BeautifulSoup(feed_data, 'html.parser')
			common.show_exception(video_tree.find('meta', property = "og:site_name")['content'], video_tree.find('meta', property = "og:url")['content'])
			exception = True
		threads = []
		for i, video_item in enumerate(video_segments):
			try:
				threads.append(Thread(get_videos, queue, i, video_item, qbitrate, False))
			except Exception, e:
				print "Exception: ", e
		[i.start() for i in threads]
		[i.join() for i 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], int(video_data2[0])))
		player._segments_array = segments
		finalurl = video_url2[:-3]
		time.sleep(20)
		if (addon.getSetting('enablesubtitles') == 'true') and closedcaption and detect_format is not None:
			convert_subtitles(closedcaption)
			player._subtitles_Enabled = True
		item = xbmcgui.ListItem(path = finalurl)
		if player._localHTTPServer:
			filestring = 'XBMC.RunScript(' + os.path.join(ustvpaths.LIBPATH,'proxy.py') + ', 12345)'
			xbmc.executebuiltin(filestring)
			finalurl = video_url2[:-3]
			#localhttpserver = True
			time.sleep(20)
		queue.task_done()
		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)
Example #20
0
def play_video(video_url=common.args.url):
    logged_in = login(video_url)
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    closedcaption = None
    if "http://" in video_url:
        pid = lookup_meta(video_url)
    else:
        pid = video_url
    video_url = EPISODE % pid
    video_data = connection.getURL(video_url)
    video_tree = BeautifulSoup(video_data, "html.parser")
    if video_tree.find("param", attrs={"name": "isException", "value": "true"}) is None:
        video_rtmp = video_tree.meta
        playpath_url = None
        if video_rtmp is not None:
            base_url = video_rtmp["base"]
            if qbitrate is None:
                video_url2 = video_tree.switch.find_all("video")
                lbitrate = -1
                hbitrate = -1
                sbitrate = int(addon.getSetting("quality")) * 1024
                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:
                bitrate = qbitrate
                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", "")
            try:
                closedcaption = video_tree.find("param", attrs={"name": "ClosedCaptionURL"})["value"]
                if closedcaption == "":
                    closedcaption = None
            except:
                pass
            if (addon.getSetting("enablesubtitles") == "true") and (closedcaption is not None):
                convert_subtitles(closedcaption)
            finalurl = base_url + " playpath=" + playpath_url + " swfurl=" + SWFURL + " swfvfy=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},
            )
        except:
            pass
        xbmcplugin.setResolvedUrl(pluginHandle, True, item)
        if (addon.getSetting("enablesubtitles") == "true") and (closedcaption is not None):
            while not xbmc.Player().isPlaying():
                xbmc.sleep(100)
            xbmc.Player().setSubtitles(ustvpaths.SUBTITLE)
    else:
        common.show_exception(video_tree.ref["title"], video_tree.ref["abstract"])
def play_video(BASE, video_uri=common.args.url, media_base=VIDEOURL):
    video_url = media_base + video_uri
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    video_url2 = 'stack://'
    closedcaption = []
    exception = False
    queue = PriorityQueue()
    segments = []
    if 'feed' in video_uri:
        feed_url = video_uri
    else:
        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
            uri = urllib.quote_plus(uri)
            feed_url = feed_url.replace('{uri}', uri).replace(
                '&amp;', '&').replace('{device}', DEVICE).replace(
                    '{ref}', 'None').replace('{type}', 'network').strip()
        else:
            exception = True
            error_text = config_tree.error.string.split('/')[-1].split('_')
            if error_text[1] == 'loc':
                params = dict(
                    item.split("=")
                    for item in config_url.split('?')[-1].split('&'))
                common.show_exception('Geo', params['geo'])
    if not exception:
        feed_data = connection.getURL(
            feed_url, header={'X-Forwarded-For': '12.13.14.15'})
        video_tree = BeautifulSoup(feed_data,
                                   'html.parser',
                                   parse_only=SoupStrainer('media:group'))
        video_segments = video_tree.find_all('media:content')
        if not video_segments:
            video_tree = BeautifulSoup(feed_data, 'html.parser')
            common.show_exception(
                video_tree.find('meta', property="og:site_name")['content'],
                video_tree.find('meta', property="og:url")['content'])
            exception = True
        threads = []
        for i, video_item in enumerate(video_segments):
            try:
                threads.append(
                    Thread(get_videos, queue, i, video_item, qbitrate, False))
            except Exception, e:
                print "Exception: ", e
        [i.start() for i in threads]
        [i.join() for i 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], int(video_data2[0])))
        player._segments_array = segments
        finalurl = video_url2[:-3]
        time.sleep(20)
        if (addon.getSetting('enablesubtitles')
                == 'true') and closedcaption and detect_format is not None:
            convert_subtitles(closedcaption)
            player._subtitles_Enabled = True
        item = xbmcgui.ListItem(path=finalurl)
        if player._localHTTPServer:
            filestring = 'XBMC.RunScript(' + os.path.join(
                ustvpaths.LIBPATH, 'proxy.py') + ', 12345)'
            xbmc.executebuiltin(filestring)
            finalurl = video_url2[:-3]
            #localhttpserver = True
            time.sleep(20)
        queue.task_done()
        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)
Example #22
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'])
Example #23
0
def play_video(video_url=common.args.url):
    try:
        qbitrate = common.args.quality
    except:
        qbitrate = None
    closedcaption = None
    video_url = video_url
    video_data = connection.getURL(video_url)
    video_tree = BeautifulSoup(video_data, 'html.parser')
    sbitrate = int(addon.getSetting('quality'))
    if video_tree.find('param', attrs={
            'name': 'isException',
            'value': 'true'
    }) is None:
        try:
            video_url2 = video_tree.switch.find_all('video')
            lbitrate = -1
            hbitrate = -1
            sbitrate = int(addon.getSetting('quality')) * 1024
            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
            finalurl = playpath_url
        except:
            playpath_url = video_tree.video['src']
            if qbitrate is None:
                hbitrate = 1
                format = video_tree.find('param', attrs={'name':
                                                         'format'})['value']
                if 'SD' in format:
                    bitrates = BITRATES[:5]
                else:
                    bitrates = BITRATES
                for i, bitrate in enumerate(bitrates):
                    if int(bitrate) < sbitrate:
                        hbitrate = i + 1
            else:
                hbitrate = BITRATES.index(qbitrate) + 1
            finalurl = playpath_url.split('_')[0] + '_' + str(
                hbitrate) + '.mp4'
        try:
            closedcaption = video_tree.find('textstream',
                                            type='text/srt')['src']
        except:
            pass
        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
                })
        except:
            pass
        xbmcplugin.setResolvedUrl(pluginHandle, True, item)
        if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption
                                                                is not None):
            while not xbmc.Player().isPlaying():
                xbmc.sleep(100)
            xbmc.Player().setSubtitles(closedcaption)
    else:
        common.show_exception(video_tree.ref['title'],
                              video_tree.ref['abstract'])
Example #24
0
def play_video(video_url = common.args.url):
	if  addon.getSetting('cbs_use_login') == 'true':
		username = addon.getSetting('cbs_username')
		password = addon.getSetting('cbs_password')
		login_values = values = {'j_username' : username, 'j_password' : password, '_remember_me' : '1' }
		login_response = connection.getURL(LOGIN_URL, login_values, savecookie = True)
		response = simplejson.loads(login_response)
		if response['success'] == False:
			common.show_exception(NAME, response['messages'])
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	closedcaption = None
	if 'http://' in video_url:
		pid = lookup_meta(video_url)
	else:
		pid = video_url
	video_url = EPISODE % pid
	video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
		video_rtmp = video_tree.meta
		playpath_url = None
		if video_rtmp is not None:
			base_url = video_rtmp['base']
			if qbitrate is None:
				video_url2 = video_tree.switch.find_all('video')
				lbitrate = -1
				hbitrate = -1
				sbitrate = int(addon.getSetting('quality')) * 1024
				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:
				bitrate = qbitrate 
				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', '')
			try:
				closedcaption = video_tree.find('param', attrs = {'name' : 'ClosedCaptionURL'})['value']
				if closedcaption == '':
					closedcaption = None
			except:
				pass
			if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
					convert_subtitles(closedcaption)
			finalurl = base_url + ' playpath=' + playpath_url + ' swfurl=' + SWFURL + ' swfvfy=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})
		except:
			pass
		xbmcplugin.setResolvedUrl(pluginHandle, True, item)
		if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
			while not xbmc.Player().isPlaying():
				xbmc.sleep(100)
			xbmc.Player().setSubtitles(ustvpaths.SUBTITLE)
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
Example #25
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:
        video_tree = BeautifulSoup(video_data, 'html.parser')
        player_url = video_tree.find(
            'div', class_='video-player-full')['data-mpx-url']
        player_data = connection.getURL(player_url)
        player_tree = BeautifulSoup(player_data, 'html.parser')
        smil_url = player_tree.find('link',
                                    type="application/smil+xml")['href']
        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

        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
        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'])
Example #26
0
def play_video(video_url = common.args.url):
	logged_in = login(video_url)
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	closedcaption = None
	if 'http://' in video_url:
		pid = lookup_meta(video_url)
	else:
		pid = video_url
	video_url = EPISODE % pid
	video_data = connection.getURL(video_url)
	video_tree = BeautifulSoup(video_data, 'html.parser')
	if  video_tree.find('param', attrs = {'name' : 'isException', 'value' : 'true'}) is None:
		video_rtmp = video_tree.meta
		playpath_url = None
		if video_rtmp is not None:
			base_url = video_rtmp['base']
			if qbitrate is None:
				video_url2 = video_tree.switch.find_all('video')
				lbitrate = -1
				hbitrate = -1
				sbitrate = int(addon.getSetting('quality')) * 1024
				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:
				bitrate = qbitrate 
				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', '')
			try:
				closedcaption = video_tree.find('param', attrs = {'name' : 'ClosedCaptionURL'})['value']
				if closedcaption == '':
					closedcaption = None
			except:
				pass
			if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
					convert_subtitles(closedcaption)
			finalurl = base_url + ' playpath=' + playpath_url + ' swfurl=' + SWFURL + ' swfvfy=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})
		except:
			pass
		xbmcplugin.setResolvedUrl(pluginHandle, True, item)
		if (addon.getSetting('enablesubtitles') == 'true') and (closedcaption is not None):
			while not xbmc.Player().isPlaying():
				xbmc.sleep(100)
			xbmc.Player().setSubtitles(ustvpaths.SUBTITLE)
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])
Example #27
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'])
def play_video(SWFURL, M3UURL=None, BASE=None):
    key_url = None
    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')
        print "Getting plauer url"
        try:
            player_url = 'http:' + video_tree.find(
                'div', class_='video-player-wrapper').iframe['src']
        except:

            player_url = 'http:' + video_tree.find(
                'div', class_='pdk-player')['data-src']
        print player_url
        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=SCRIPT'

        script_data = connection.getURL(video_url)
        script_menu = simplejson.loads(script_data)
        if script_menu['pl1$entitlement'] != 'auth':
            finalurl, exception = process_smil(video_url)
        else:
            captions = script_menu['captions'][0]['src']

            id = re.compile('([0-9]+.[0-9]+.*).tt').findall(captions)[0]

            td = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1))
            unow = int((td.microseconds +
                        (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
            master_url = M3UURL % (id, str(unow), str(unow + 60))
            finalurl = process_m3u(master_url, qbitrate)
    else:
        finalurl, exception = process_smil(video_url)
    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'])
Example #29
0
File: nbc.py Project: MarkTV/MarkTV
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:
		video_tree =  BeautifulSoup(video_data, 'html.parser')
		player_url = video_tree.find('div', class_ = 'video-player-full')['data-mpx-url']
		player_data = connection.getURL(player_url)
		player_tree =  BeautifulSoup(player_data, 'html.parser')
		smil_url = player_tree.find('link', type = "application/smil+xml")['href']
		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

	
		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
		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'])
			except Exception, e:
				print e
			print id
			td = (datetime.datetime.utcnow()- datetime.datetime(1970,1,1))
			unow = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
			print unow
			master_url = M3UURL % (id, str(unow), str(unow+60))
			bitrates = m3u_bitrates(master_url)
			return bitrates
			#need to set captions on player
	else:
		bitrates,exception = smil_bitrates(video_url)
	if  not exception:
		return bitrates
	else:
		common.show_exception(video_tree.ref['title'], video_tree.ref['abstract'])

		

def play_video(SWFURL, M3UURL = None, BASE = None):
	key_url = None
	try:
		qbitrate = common.args.quality
	except:
		qbitrate = None
	exception = False
	video_url = common.args.url
	#if BASE is not None and BASE not in video_url:
	#	video_url = BASE + video_url 
	hbitrate = -1
	lbitrate = -1