def getLinksForVideo(self, cItem): printDBG("1TvRu.getLinksForVideo [%s]" % cItem) linksTab = [] if cItem.get('category', '') == 'live': #live #linksTab.extend(getMPDLinksWithMeta(self.LIVE_URL, False, sortWithMaxBandwidth=999999999)) playerUrl = strwithmeta( self.LIVE_URL, { 'User-Agent': self.HTTP_HEADER['User-Agent'], 'iptv_proto': 'dash' }) linksTab.extend( getMPDLinksWithMeta(playerUrl, False, sortWithMaxBandwidth=99999999)) #linksTab.append({'name': 'mpd', 'url': playerUrl}) url = cItem.get("url", "") if url: if ".m3u8" in url: linksTab.extend( getDirectM3U8Playlist(url, checkExt=False, variantCheck=True, checkContent=True, sortWithMaxBitrate=99999999)) elif ".mpd" in url: linksTab.extend(getMPDLinksWithMeta(url, False)) return linksTab
def getLinksForVideo(self, cItem): url = cItem['url'] printDBG("RtlMostHU.getLinksForVideo url[%s]" % url) videoUrls = [] if not self.tryTologin(): return videoUrls sts, data = self.cm.getPage(self.VIDEO_URL.format( url), self.apiParams) if not sts: return videoUrls try: data = json_loads(data) assets = data['clips'][0].get('assets') url = assets[0].get('full_physical_path'); except Exception: printExc() uri = urlparser.decorateParamsFromUrl(url) protocol = uri.meta.get('iptv_proto', '') printDBG("PROTOCOL [%s] " % protocol) if protocol == 'm3u8': retTab = getDirectM3U8Playlist(uri, checkExt=False, checkContent=True) videoUrls.extend(retTab) elif protocol == 'f4m': retTab = getF4MLinksWithMeta(uri) videoUrls.extend(retTab) elif protocol == 'mpd': retTab = getMPDLinksWithMeta(uri, False) videoUrls.extend(retTab) else: videoUrls.append({'name':'direct link', 'url':uri}) return videoUrls
def getLinksForVideo(self, cItem): url = cItem['url'] url2 = cItem['url2'] md = cItem['md'] if md == 'elo': self.susn('2', '11', 'm4_elo') videoUrls = [] turl = self.kvlva(url) if len(turl) == 0: turl = self.kvlva(url2) uri = urlparser.decorateParamsFromUrl(turl) protocol = uri.meta.get('iptv_proto', '') if protocol == 'm3u8': retTab = getDirectM3U8Playlist(uri, checkExt=False, checkContent=True) videoUrls.extend(retTab) elif protocol == 'f4m': retTab = getF4MLinksWithMeta(uri) videoUrls.extend(retTab) elif protocol == 'mpd': retTab = getMPDLinksWithMeta(uri, False) videoUrls.extend(retTab) else: videoUrls.append({'name': 'direct link', 'url': uri}) return videoUrls
def getVideoLinks(self, videoUrl): printDBG("MediasetPlay.getVideoLinks [%s]" % videoUrl) # mark requested link as used one if len(self.cacheLinks.keys()): for key in self.cacheLinks: for idx in range(len(self.cacheLinks[key])): if videoUrl in self.cacheLinks[key][idx]['url']: if not self.cacheLinks[key][idx]['name'].startswith( '*'): self.cacheLinks[key][idx][ 'name'] = '*' + self.cacheLinks[key][idx][ 'name'] type = strwithmeta(videoUrl).meta.get('priv_type', '') if type == 'DASH/MPD': return getMPDLinksWithMeta(videoUrl, checkExt=False, sortWithMaxBandwidth=999999999) elif type == 'HLS/M3U8': return getDirectM3U8Playlist(videoUrl, checkExt=False, variantCheck=True, checkContent=True, sortWithMaxBitrate=999999999) return []
def getLinksForVideo(self, cItem): printDBG("Urllist.getLinksForVideo url[%s]" % cItem['url']) videoUrls = [] uri = urlparser.decorateParamsFromUrl(cItem['url']) protocol = uri.meta.get('iptv_proto', '') printDBG("PROTOCOL [%s] " % protocol) urlSupport = self.up.checkHostSupport(uri) if 1 == urlSupport: retTab = self.up.getVideoLinkExt(uri) videoUrls.extend(retTab) elif 0 == urlSupport and self._uriIsValid(uri): if protocol == 'm3u8': retTab = getDirectM3U8Playlist(uri, checkExt=False, checkContent=True) videoUrls.extend(retTab) elif protocol == 'f4m': retTab = getF4MLinksWithMeta(uri) videoUrls.extend(retTab) elif protocol == 'mpd': retTab = getMPDLinksWithMeta(uri, False) videoUrls.extend(retTab) else: videoUrls.append({'name': 'direct link', 'url': uri}) return videoUrls
def getLinksForVideo(self, cItem): printDBG("LuxVeritatisPL.getLinksForVideo [%s]" % cItem) linksTab = [] url = cItem['url'] if 'radiomaryja.pl' in url and url.endswith('/live/'): sts, data = self.getPage(url) if not sts: return url = self.cm.ph.getSearchGroups( data, '''<a[^>]+?href=['"](https?://[^>]+?\.m3u8(?:\?[^'^"]*?)?)['"]''' )[0] return getDirectM3U8Playlist(url, checkContent=True) elif 'tv-trwam' in url: sts, data = self.getPage(url) if not sts: return data = self.cm.ph.getSearchGroups( data, '''sources\s*?:\s*?(\[[^\]]+?\])''')[0] try: data = byteify(json.loads(data)) hlsTab = [] dashTab = [] mp4Tab = [] for item in data: vidUrl = item['src'] type = item['type'].lower() if 'dash' in type: dashTab.extend( getMPDLinksWithMeta( vidUrl, checkExt=False, cookieParams=self.defaultParams, sortWithMaxBandwidth=999999999)) elif 'x-mpegurl' in type: hlsTab.extend( getDirectM3U8Playlist( vidUrl, checkExt=False, checkContent=True, cookieParams=self.defaultParams, sortWithMaxBitrate=999999999)) elif 'mp4' in type: mp4Tab.append({ 'name': '[mp4] %s' % vidUrl.split('/')[-1].split( '_', 1)[-1].split('.', 1)[0], 'url': vidUrl }) linksTab.extend(hlsTab) linksTab.extend(dashTab) linksTab.extend(mp4Tab) except Exception: printExc() elif 1 == self.up.checkHostSupport(url): return self.up.getVideoLinkExt(url) elif url.split('?', 1)[0].endswith('.mp3'): return [{'name': 'MP3', 'url': url}] return linksTab
def getVideoLink(self, cItem): printDBG("KarwanTvApi.getVideoLink") urlsTab = [] params = dict(self.http_params) sts, data = self.cm.getPage(cItem['url'], params) if not sts: return urlsTab params['header'] = dict(params['header']) params['header']['Referer'] = cItem['url'] tmp = self.cm.ph.getDataBeetwenMarkers(data, '<div class="art-article">', '<tbody>', False)[1] if tmp == '': tmp = self.cm.ph.getDataBeetwenMarkers(data, '<div class="video-player">', '</div>', False)[1] url = '' tmp = self.cm.ph.getAllItemsBeetwenMarkers(data, '<iframe', '>', caseSensitive=False) for item in tmp: if 'google' in item: continue url = self.cm.ph.getSearchGroups(item, '<iframe[^>]+?src="([^"]+?)"', ignoreCase=True)[0] if 'karwan24' in self.up.getDomain(cItem['url']): url = self.getFullUrl24(url) else: url = self.getFullUrl(url) break if not self.cm.isValidUrl(url): return urlsTab sts, data = self.cm.getPage(url, params) if not sts: return urlsTab hlsUrl = self.cm.ph.getSearchGroups(data, '''['"]?hls['"]?\s*:\s*['"]([^"^']+?)['"]''')[0] if not self.cm.isValidUrl(hlsUrl) == '': hlsUrl = self.cm.getFullUrl(self.cm.ph.getSearchGroups(data, '''['"]([^'^"]+?\.m3u8(?:\?[^'^"]+?)?)['"]''')[0], self.cm.getBaseUrl(self.cm.meta['url'])) dashUrl = self.cm.ph.getSearchGroups(data, '''['"]?dash['"]?\s*:\s*['"]([^"^']+?)['"]''')[0] if self.cm.isValidUrl(dashUrl): dashUrl = self.cm.getFullUrl(self.cm.ph.getSearchGroups(data, '''['"]([^'^"]+?\.mpd(?:\?[^'^"]+?)?)['"]''')[0], self.cm.getBaseUrl(self.cm.meta['url'])) if self.cm.isValidUrl(hlsUrl): urlsTab.extend( getDirectM3U8Playlist(hlsUrl, checkContent=True) ) if 0 == len(urlsTab) and self.cm.isValidUrl(dashUrl): urlsTab.extend( getMPDLinksWithMeta(dashUrl, checkExt=True) ) if 0 == len(urlsTab): tmp = self.cm.ph.getDataBeetwenMarkers(data, 'playlist:', ']')[1] if tmp != "": tmp = tmp.split('}') else: tmp = self.cm.ph.getDataBeetwenMarkers(data, '.setup(', ';')[1] tmp = [tmp] printDBG(tmp) for item in tmp: url = self.cm.ph.getSearchGroups(item, '''['"]?file['"]?\s*:\s*['"]([^"^']+?)['"]''')[0] name = self.cm.ph.getSearchGroups(item, '''['"]?title['"]?\s*:\s*['"]([^"^']+?)['"]''')[0] printDBG(">>> url[%s]" % url) printDBG(">>> name[%s]" % name) if self.cm.isValidUrl(url) and url.split('?')[0].endswith('.m3u8'): tmpTab = getDirectM3U8Playlist(url, checkContent=True) for idx in range(len(tmpTab)): tmpTab[idx]['name'] = name + ' ' + tmpTab[idx]['name'] urlsTab.extend(tmpTab) return urlsTab
def getLinksForVideo(self, cItem): printDBG("TVNowDE.getLinksForVideo [%s]" % cItem) retTab = [] cacheTab = self.cacheLinks.get(cItem['url'], []) if len(cacheTab): return cacheTab urlDashClear = '' #cItem.get('dashclear', '') if not self.cm.isValidUrl(urlDashClear): try: seoUrlItem = cItem['f_seo_url_format'] seoUrlFormat = cItem['f_seo_url_item'] station = cItem['f_station'] url = self.getFullUrl( '/movies/{0}/{1}?fields=*,format,files,manifest,breakpoints,paymentPaytypes,trailers,packages&station={2}' .format(seoUrlItem, seoUrlFormat, station)) sts, data = self.getPage(url) if not sts: return [] try: data = json_loads(data) except Exception: data = 'error' if 'error' in data: data = cItem['orig_item'] urlDashClear = data['manifest']['dashclear'] if data.get('isDrm', False): SetIPTVPlayerLastHostError(_("Video with DRM protection.")) if not self.cm.isValidUrl(urlDashClear): return [] except Exception: printExc() if self.cm.isValidUrl(urlDashClear): urlHlsClear = urlDashClear.replace('/vodnowusodash.', '/vodnowusohls.').split('?', 1) urlHlsClear[0] = urlHlsClear[0][:-3] + 'm3u8' urlHlsClear = '?'.join(urlHlsClear) hlsTab = getDirectM3U8Playlist(urlHlsClear, checkContent=True) dashTab = getMPDLinksWithMeta(urlDashClear, False) try: hlsTab = sorted( hlsTab, key=lambda item: -1 * int(item.get('bitrate', 0))) dashTab = sorted( dashTab, key=lambda item: -1 * int(item.get('bandwidth', 0))) except Exception: printExc() if config.plugins.iptvplayer.tvnowde_prefered_format.value == 'hls': retTab.extend(hlsTab) retTab.extend(dashTab) else: retTab.extend(dashTab) retTab.extend(hlsTab) if len(retTab): self.cacheLinks[cItem['url']] = retTab return retTab
def getVideoLinks(self, videoUrl): printDBG("RTBFBE.getVideoLinks [%s]" % videoUrl) self.tryTologin() # mark requested link as used one if len(self.cacheLinks.keys()): for key in self.cacheLinks: for idx in range(len(self.cacheLinks[key])): if videoUrl in self.cacheLinks[key][idx]['url']: if not self.cacheLinks[key][idx]['name'].startswith('*'): self.cacheLinks[key][idx]['name'] = '*' + self.cacheLinks[key][idx]['name'] break if 1 == self.up.checkHostSupport(videoUrl): videoUrl = videoUrl.replace('youtu.be/', 'youtube.com/watch?v=') return self.up.getVideoLinkExt(videoUrl) retTab = [] meta = dict(videoUrl.meta) type = meta.pop('iptv_proto', 'mp4') printDBG("++++++++++++++++++++++++ type[%s]" % type) if self.loggedIn: urlParams = dict(self.defaultParams) urlParams['header'] = dict(urlParams['header']) urlParams['header']['Referer'] = videoUrl.meta['Referer'] urlParams['raw_post_data'] = True url = 'https://token.rtbf.be/' sts, data = self.getPage(url, urlParams, self.serParams({type:videoUrl}, 'streams')) if not sts: return [] try: data = byteify(json.loads(data)) videoUrl = data['streams'][type] printDBG("+++++++++++++++++++++++++++++++++++++++++++++") printDBG(videoUrl) except Exception: printExc() elif 'token=' not in videoUrl and '?' not in videoUrl: videoUrl += '?token=' + self.getPartnerToken() if type == 'm3u8': retTab = getDirectM3U8Playlist(videoUrl, checkExt=False, checkContent=True, sortWithMaxBitrate=999999999) elif type == 'mpd': retTab = getMPDLinksWithMeta(videoUrl, checkExt=False, sortWithMaxBandwidth=999999999) else: retTab = [{'name':'mp4', 'url':videoUrl}] for idx in range(len(retTab)): retTab[idx]['url'] = strwithmeta(retTab[idx]['url'], meta) return retTab
def getDirectLinks(self, url, formats='flv, mp4', dash=True, dashSepareteList=False, allowVP9=None, allowAgeGate=None): printDBG("YouTubeParser.getDirectLinks") list = [] try: if self.cm.isValidUrl(url) and '/channel/' in url and url.endswith( '/live'): sts, data = self.cm.getPage(url) if sts: videoId = self.cm.ph.getSearchGroups( data, '''<meta[^>]+?itemprop=['"]videoId['"][^>]+?content=['"]([^'^"]+?)['"]''' )[0] if videoId == '': videoId = self.cm.ph.getSearchGroups( data, '''['"]REDIRECT_TO_VIDEO['"]\s*\,\s*['"]([^'^"]+?)['"]''' )[0] if videoId != '': url = 'https://www.youtube.com/watch?v=' + videoId list = YoutubeIE()._real_extract(url, allowVP9=allowVP9, allowAgeGate=allowAgeGate) except Exception: printExc() if dashSepareteList: return [], [] else: return [] reNum = re.compile('([0-9]+)') retHLSList = [] retList = [] dashList = [] # filter dash dashAudioLists = [] dashVideoLists = [] if dash: # separete audio and video links for item in list: if 'mp4a' == item['ext']: dashAudioLists.append(item) elif item['ext'] in ('mp4v', 'webmv'): dashVideoLists.append(item) elif 'mpd' == item['ext']: tmpList = getMPDLinksWithMeta(item['url'], checkExt=False) printDBG(tmpList) for idx in range(len(tmpList)): tmpList[idx]['format'] = "%sx%s" % (tmpList[idx].get( 'height', 0), tmpList[idx].get('width', 0)) tmpList[idx]['ext'] = "mpd" tmpList[idx]['dash'] = True dashList.extend(tmpList) # sort by quality -> format def _key(x): if x['format'].startswith('>'): int(x['format'][1:-1]) else: int(ph.search(x['format'], reNum)[0]) dashAudioLists = sorted(dashAudioLists, key=_key, reverse=True) dashVideoLists = sorted(dashVideoLists, key=_key, reverse=True) for item in list: printDBG(">>>>>>>>>>>>>>>>>>>>>") printDBG(item) printDBG("<<<<<<<<<<<<<<<<<<<<<") if -1 < formats.find(item['ext']): if 'yes' == item['m3u8']: format = re.search('([0-9]+?)p$', item['format']) if format != None: item['format'] = format.group(1) + "x" item['ext'] = item['ext'] + "_M3U8" item['url'] = decorateUrl(item['url'], {"iptv_proto": "m3u8"}) retHLSList.append(item) else: format = re.search('([0-9]+?x[0-9]+?$)', item['format']) if format != None: item['format'] = format.group(1) item['url'] = decorateUrl(item['url']) retList.append(item) if len(dashAudioLists): # use best audio for item in dashVideoLists: item = dict(item) item["url"] = decorateUrl( "merge://audio_url|video_url", { 'audio_url': dashAudioLists[0]['url'], 'video_url': item['url'] }) dashList.append(item) # try to get hls format with alternative method if 0 == len(retList): try: video_id = YoutubeIE()._extract_id(url) url = 'http://www.youtube.com/watch?v=%s&gl=US&hl=en&has_verified=1' % video_id sts, data = self.cm.getPage( url, { 'header': { 'User-agent': 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10' } }) if sts: data = data.replace('\\"', '"').replace('\\\\\\/', '/') hlsUrl = self.cm.ph.getSearchGroups( data, '''"hlsvp"\s*:\s*"(https?://[^"]+?)"''')[0] hlsUrl = json_loads('"%s"' % hlsUrl) if self.cm.isValidUrl(hlsUrl): hlsList = getDirectM3U8Playlist(hlsUrl) if len(hlsList): dashList = [] for item in hlsList: item['format'] = "%sx%s" % (item.get( 'with', 0), item.get('heigth', 0)) item['ext'] = "m3u8" item['m3u8'] = True retList.append(item) except Exception: printExc() if 0 == len(retList): retList = retHLSList if dash: try: sts, data = self.cm.getPage( url, { 'header': { 'User-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36' } }) data = data.replace('\\"', '"').replace('\\\\\\/', '/').replace('\\/', '/') dashUrl = self.cm.ph.getSearchGroups( data, '''"dashmpd"\s*:\s*"(https?://[^"]+?)"''')[0] dashUrl = json_loads('"%s"' % dashUrl) if '?' not in dashUrl: dashUrl += '?mpd_version=5' else: dashUrl += '&mpd_version=5' printDBG("DASH URL >> [%s]" % dashUrl) if self.cm.isValidUrl(dashUrl): dashList = getMPDLinksWithMeta(dashUrl, checkExt=False) printDBG(dashList) for idx in range(len(dashList)): dashList[idx]['format'] = "%sx%s" % ( dashList[idx].get('height', 0), dashList[idx].get('width', 0)) dashList[idx]['ext'] = "mpd" dashList[idx]['dash'] = True except Exception: printExc() for idx in range(len(retList)): if retList[idx].get('m3u8', False): retList[idx]['url'] = strwithmeta( retList[idx]['url'], {'iptv_m3u8_live_start_index': -30}) if dashSepareteList: return retList, dashList else: retList.extend(dashList) return retList
def getLinksForVideo(self, cItem): printDBG("SVTPlaySE.getLinksForVideo [%s]" % cItem) videoUrls = [] hlsUrl = cItem.get('hls_url') dashUrl = cItem.get('dash_url') if hlsUrl == None or dashUrl == None: url = self.getFullApiUrl('/title_page;title=' + cItem['url']) sts, data = self.cm.getPage(url, self.defaultParams) if not sts: return subtitlesTab = [] try: data = byteify(json.loads(data)) videoItem = data.get('video', None) if videoItem == None: videoItem = data.get('video', None) for item in videoItem['videoReferences']: if self.cm.isValidUrl(item['url']): if 'dash' in item['playerType']: dashUrl = item['url'] elif 'ios' in item['playerType']: hlsUrl = item['url'] for item in videoItem['subtitles']: format = item['url'][-3:] if format in ['srt', 'vtt']: subtitlesTab.append({'title':item['language'], 'url':self.getFullIconUrl(item['url']), 'lang':item['language'], 'format':format}) except Exception: printExc() tmpTab = [] if config.plugins.iptvplayer.svt_prefered_format.value == 'hls': tmpTab.append(hlsUrl) tmpTab.append(dashUrl) else: tmpTab.append(dashUrl) tmpTab.append(hlsUrl) max_bitrate = int(config.plugins.iptvplayer.svt_default_quality.value) for item in tmpTab: if item == '': continue if item == dashUrl: item = getMPDLinksWithMeta(item, False) elif item == hlsUrl: item = getDirectM3U8Playlist(item, False, checkContent=True) else: continue def __getLinkQuality( itemLink ): try: return int(itemLink['height']) except Exception: return 0 item = CSelOneLink(item, __getLinkQuality, max_bitrate).getSortedLinks() if config.plugins.iptvplayer.svt_use_default_quality.value: videoUrls.append(item[0]) break videoUrls.extend(item) if len(subtitlesTab): for idx in range(len(videoUrls)): videoUrls[idx]['url'] = strwithmeta(videoUrls[idx]['url'], {'external_sub_tracks':subtitlesTab}) videoUrls[idx]['need_resolve'] = 0 return videoUrls
def getLinksForVideo(self, cItem): printDBG("SpiegelTv.getLinksForVideo [%s]" % cItem) cacheKey = cItem['url'] cacheTab = self.cacheLinks.get(cacheKey, []) if len(cacheTab): return cacheTab self.cacheLinks = {} retTab = [] sts, data = self.getPage(cItem['url']) if not sts: return self._fillOneConfig(cItem, data) self._initiSession(cItem) videoId = self.cm.ph.getDataBeetwenMarkers( data, 'video.start(', ')', False)[1].split(',')[0].strip() if videoId == '': videoId = cItem['url'].split('/videos/', 1)[-1].split('-')[0] try: cid = self.oneconfig['session_data']['general']['cid'] clientToken = self.oneconfig['session_data']['device'][ 'clienttoken'] clientId = self.oneconfig['session_data']['general']['clid'] deviceId = self.oneconfig['session_data']['device_id'] secret = clientToken[int(deviceId[0]):] secret = secret[0:len(secret) - int(deviceId[-1])] op = 'byid' requestToken = hashlib.md5(''.join( (op, clientId, secret))).hexdigest() urlParams = dict(self.defaultParams) urlParams['header'] = dict(self.AJAX_HEADER) urlParams['header'].update({ 'Referer': cItem['url'], 'X-Request-Enable-Auth-Fallback': '1', 'X-Request-CID': cid, 'X-Request-Token': requestToken }) post_data = { 'additionalfields': 'language,channel,actors,studio,licenseby,slug,subtitle,teaser,description', 'addInteractionOptions': '1', 'addStatusDetails': '1', 'addStreamDetails': '1', 'addCaptions': '1', 'addScenes': '1', 'addHotSpots': '1', 'addBumpers': '1', 'captionFormat': 'data', } url = 'https://api.nexx.cloud/v3/%s/videos/%s/%s' % (clientId, op, videoId) sts, data = self.getPage(url, urlParams, post_data) if not sts: return data = json_loads(data, '', True)['result'] try: protectionToken = data['protectiondata']['token'] except Exception: protectionToken = None language = data['general'].get('language_raw') or '' printDBG(data) cdn = data['streamdata']['cdnType'] if cdn == 'azure': data = data['streamdata'] azureLocator = data['azureLocator'] AZURE_URL = 'http://nx%s%02d.akamaized.net/' def getCdnShieldBase(shieldType='', prefix='-p'): for secure in ('', 's'): cdnShield = data.get('cdnShield%sHTTP%s' % (shieldType, secure.upper())) if cdnShield: return 'http%s://%s' % (secure, cdnShield) else: return AZURE_URL % (prefix, int(data['azureAccount'].replace( 'nexxplayplus', ''))) azureStreamBase = getCdnShieldBase() isML = ',' in language azureManifestUrl = '%s%s/%s_src%s.ism/Manifest' % ( azureStreamBase, azureLocator, videoId, ('_manifest' if isML else '')) + '%s' if protectionToken: azureManifestUrl += '?hdnts=%s' % protectionToken try: azureProgressiveBase = getCdnShieldBase('Prog', '-d') azureFileDistribution = data.get('azureFileDistribution') if azureFileDistribution: fds = azureFileDistribution.split(',') if fds: for fd in fds: ss = fd.split(':') if len(ss) != 2: continue tbr = int(ss[0] or 0) if not tbr: continue retTab.append({ 'name': '[%s] %s' % (tbr, ss[1]), 'tbr': tbr, 'url': '%s%s/%s_src_%s_%d.mp4' % (azureProgressiveBase, azureLocator, videoId, ss[1], tbr) }) except Exception: printExc() retTab.sort(key=lambda item: item['tbr'], reverse=True) if len(retTab) == 0: retTab = getMPDLinksWithMeta( azureManifestUrl % '(format=mpd-time-csf)', checkExt=False, sortWithMaxBandwidth=999999999) if len(retTab) == 0: retTab = getDirectM3U8Playlist( azureManifestUrl % '(format=m3u8-aapl)', checkExt=False, checkContent=True, sortWithMaxBitrate=999999999) else: streamData = data['streamdata'] hash = data['general']['hash'] ps = streamData['originalDomain'] if streamData['applyFolderHierarchy'] == '1': s = ('%04d' % int(videoId))[::-1] ps += '/%s/%s' % (s[0:2], s[2:4]) ps += '/%s/%s_' % (videoId, hash) t = 'http://%s' + ps azureFileDistribution = streamData[ 'azureFileDistribution'].split(',') cdnProvider = streamData['cdnProvider'] def p0(p): return '_%s' % p if streamData[ 'applyAzureStructure'] == '1' else '' formats = [] if cdnProvider == 'ak': t += ',' for i in azureFileDistribution: p = i.split(':') t += p[1] + p0(int(p[0])) + ',' t += '.mp4.csmil/master.%s' elif cdnProvider == 'ce': k = t.split('/') h = k.pop() httpBase = t = '/'.join(k) httpBase = httpBase % streamData['cdnPathHTTP'] t += '/asset.ism/manifest.%s?dcp_ver=aos4&videostream=' for i in azureFileDistribution: p = i.split(':') tbr = int(p[0]) filename = '%s%s%s.mp4' % (h, p[1], p0(tbr)) retTab.append({ 'name': '[%s] %s' % (tbr, p[1]), 'tbr': tbr, 'url': httpBase + '/' + filename }) a = filename + ':%s' % (tbr * 1000) t += a + ',' t = t[:-1] + '&audiostream=' + a.split(':')[0] else: printDBG("Unknwon cdnProvider [%s]" % cdnProvider) assert False retTab.sort(key=lambda item: item['tbr'], reverse=True) if len(retTab) == 0: retTab.extend( getMPDLinksWithMeta(t % (streamData['cdnPathDASH'], 'mpd'), checkExt=False, sortWithMaxBandwidth=999999999)) if len(retTab) == 0: retTab.extend( getDirectM3U8Playlist( t % (streamData['cdnPathHLS'], 'm3u8'), checkExt=False, checkContent=True, sortWithMaxBitrate=999999999)) except Exception: printExc() if len(retTab): self.cacheLinks[cacheKey] = retTab for idx in range(len(retTab)): retTab[idx]['need_resolve'] = 1 return retTab
def getLinksForVideo(self, cItem): printDBG("SVTPlaySE.getLinksForVideo [%s]" % cItem) videoUrls = [] hlsUrl = cItem.get('hls_url') dashUrl = cItem.get('dash_url') subtitlesTab = [] if hlsUrl == None or dashUrl == None: if 'api' not in self.up.getDomain(cItem['url']): url = self.getFullUrl(cItem['url']) sts, data = self.cm.getPage(url, self.defaultParams) if not sts: return [] videoId = self.cm.ph.getSearchGroups( data, '<video\s+?data-video-id="([^"]+?)"')[0] url = 'https://api.svt.se/video/' + videoId else: url = cItem['url'] sts, data = self.cm.getPage(url, self.defaultParams) if not sts: return [] printDBG(data) try: data = byteify(json.loads(data)) videoItem = data.get('video', None) if videoItem == None: videoItem = data for item in videoItem['videoReferences']: if self.cm.isValidUrl(item['url']): if 'dashhbbtv' in item['format']: dashUrl = item['url'] elif 'hls' in item['format']: hlsUrl = item['url'] for item in videoItem['subtitleReferences']: format = item['url'][-3:] if format in ['srt', 'vtt']: subtitlesTab.append({ 'title': format, 'url': self.getFullIconUrl(item['url']), 'lang': 'n/a', 'format': format }) except Exception: printExc() tmpTab = [] if config.plugins.iptvplayer.svt_prefered_format.value == 'hls': tmpTab.append(hlsUrl) tmpTab.append(dashUrl) else: tmpTab.append(dashUrl) tmpTab.append(hlsUrl) max_bitrate = int(config.plugins.iptvplayer.svt_default_quality.value) for item in tmpTab: if item == '': continue if item == dashUrl: item = getMPDLinksWithMeta(item, False) elif item == hlsUrl: vidTab = [] # item = strwithmeta(item, {'X-Forwarded-For':'83.172.75.170'}) try: tmp = urlparse.urlparse(item) tmp = urlparse.parse_qs(tmp.query)['alt'][0] vidTab = getDirectM3U8Playlist(tmp, False, checkContent=True) except Exception: printExc() if 0 == len(vidTab): item = getDirectM3U8Playlist(item, False, checkContent=True) else: item = vidTab else: continue if len(item): def __getLinkQuality(itemLink): try: return int(itemLink['height']) except Exception: return 0 item = CSelOneLink(item, __getLinkQuality, max_bitrate).getSortedLinks() if config.plugins.iptvplayer.svt_use_default_quality.value: videoUrls.append(item[0]) break videoUrls.extend(item) if len(subtitlesTab): for idx in range(len(videoUrls)): videoUrls[idx]['url'] = strwithmeta( videoUrls[idx]['url'], {'external_sub_tracks': subtitlesTab}) videoUrls[idx]['need_resolve'] = 0 return videoUrls
def exploreItem(self, cItem): printDBG("KinoPodAniolemPL.exploreItem") self.cacheLinks = [] sts, data = self.getPage(cItem['url']) if not sts: return if 'player-trailer' in data: trailer = True else: trailer = False hlsTab = [] dashTab = [] mp4Tab = [] getDirectM3U8Playlist, getMPDLinksWithMeta data = self.cm.ph.getSearchGroups(data, '''data\-opts=[']([^']+?)[']''')[0] try: data = byteify(json.loads(data), '', True) for playlist in data['playlist']: for item in playlist['sources']: vidUrl = item['file'] format = vidUrl.split('?', 1)[0].split('.')[-1].lower() if format == 'm3u8': hlsTab.extend( getDirectM3U8Playlist( vidUrl, checkExt=False, checkContent=True, cookieParams=self.defaultParams, sortWithMaxBitrate=999999999)) elif format == 'mpd': dashTab.extend( getMPDLinksWithMeta( vidUrl, checkExt=False, cookieParams=self.defaultParams, sortWithMaxBandwidth=999999999)) elif format == 'mp4': mp4Tab.append({'name': 'mp4', 'url': vidUrl}) except Exception: printExc() self.cacheLinks.extend(hlsTab) self.cacheLinks.extend(dashTab) self.cacheLinks.extend(mp4Tab) cookieHeader = self.cm.getCookieHeader(self.COOKIE_FILE) for idx in range(len(self.cacheLinks)): self.cacheLinks[idx]['url'] = strwithmeta( self.cacheLinks[idx]['url'], { 'User-Agent': self.USER_AGENT, 'Referer': cItem['url'], 'Cookie': cookieHeader }) if len(self.cacheLinks): title = cItem['title'] if trailer: title += ' - ' + _('TRAILER') params = dict(cItem) params.update({'good_for_fav': False, 'title': title}) self.addVideo(params)
def getVideoLink(self, cItem): printDBG("VideoStarApi.getVideoLink") urlsTab = [] idx = cItem.get('priv_idx', -1) if idx < 0 or idx >= len(self.cacheChannelList): return urlsTab vidItem = self.cacheChannelList[idx] formatId = config.plugins.iptvplayer.videostar_streamprotocol.value tries = 0 while True: tries += 1 try: if self.loggedIn: url = 'v1/channel/%s?format_id=%s&device_type=android_tv' % ( vidItem['id'], formatId) else: url = 'v1/guest/channel/%s?format_id=%s&device_type=android_tv' % ( vidItem['id'], formatId) url = self.getFullUrl(url, 'api') sts, data = self.cm.getPage(url, self.defaultParams) printDBG(data) if not sts and not self.loggedIn and tries == 1: rm(self.COOKIE_FILE) # self.doLogin('guest', 'guest') sts, data = self.cm.getPage( self.getFullUrl('/static/guest/channels/list/web.json', 'static'), self.defaultParams) if sts: continue if not sts: break data = json_loads(data) if data['data'] != None: for item in data['data']['stream_channel']['streams']: if formatId == '2': if 'hls' in item['type']: hslUrl = item['url'][0] # add here random urlsTab.extend( getDirectM3U8Playlist( hslUrl, checkExt=False, cookieParams=self.defaultParams, checkContent=True)) elif formatId in ['3', '4']: if 'dash' in item['type']: dashUrl = item['url'][0] # add here random urlsTab.extend( getMPDLinksWithMeta( dashUrl, checkExt=False, cookieParams=self.defaultParams)) elif data['_meta'] != None: info = data['_meta']['error']['info'] message = [] message.append( 'Oglądasz już kanał %s na urządeniu %s o adresie: %s.' % (info['channel_name'], info['device'], info['user_ip'])) message.append( 'W WP Pilocie nie możesz oglądać większej liczby kanałów jednocześnie.' ) message.append('Czy chcesz kontynować tutaj?') arg1 = self.sessionEx.waitForFinishOpen( MessageBox, '\n'.join(message), type=MessageBox.TYPE_YESNO) if arg1: url = self.getFullUrl('v1/channels/close', 'api') paramsUrl = dict(self.defaultParams) paramsUrl['header'] = dict(paramsUrl['header']) paramsUrl['header']['Referer'] = self.getFullUrl('tv') paramsUrl['header']['Origin'] = self.MAIN_URL[:-1] paramsUrl['header'][ 'content-type'] = 'application/json;charset=UTF-8' paramsUrl['raw_post_data'] = True sts, data = self.cm.getPage( url, paramsUrl, '{"channelId":"%s","t":"%s"}' % (info['channel_id'], self.userToken)) printDBG("==================== token1[%s] token2[%s]" % (self.userToken, info['stream_token'])) printDBG(data) printDBG("====================") continue except Exception: printExc() break if len(urlsTab): cookieHeader = self.cm.getCookieHeader(self.COOKIE_FILE) for idx in range(len(urlsTab)): urlsTab[idx]['url'] = strwithmeta(urlsTab[idx]['url'], { 'Cookie': cookieHeader, 'User-Agent': self.USER_AGENT }) if len(urlsTab): maxBitrate = int( config.plugins.iptvplayer.videostar_defquality.value) * 1.3 def __getLinkQuality(itemLink): try: if 'bitrate' in itemLink: return int(itemLink['bitrate']) elif 'bandwidth' in itemLink: return int(itemLink['bandwidth']) except Exception: printExc() return 0 oneLink = CSelOneLink(urlsTab, __getLinkQuality, maxBitrate) urlsTab = oneLink.getSortedLinks() if config.plugins.iptvplayer.videostar_use_defquality.value: urlsTab = [urlsTab[0]] return urlsTab
def getLinksForVideo(self, cItem): printDBG("SpiegelTv.getLinksForVideo [%s]" % cItem) cacheKey = cItem['url'] cacheTab = self.cacheLinks.get(cacheKey, []) if len(cacheTab): return cacheTab self.cacheLinks = {} retTab = [] sts, data = self.getPage(cItem['url']) if not sts: return self._fillOneConfig(cItem, data) self._initiSession(cItem) videoId = self.cm.ph.getDataBeetwenMarkers(data, 'video.start(', ')', False)[1].split(',')[0].strip() if videoId == '': videoId = cItem['url'].split('/videos/', 1)[-1].split('-')[0] try: cid = self.oneconfig['session_data']['general']['cid'] clientToken = self.oneconfig['session_data']['device']['clienttoken'] clientId = self.oneconfig['session_data']['general']['clid'] deviceId = self.oneconfig['session_data']['device_id'] secret = clientToken[int(deviceId[0]):] secret = secret[0:len(secret) - int(deviceId[-1])] op = 'byid' requestToken = hashlib.md5(''.join((op, clientId, secret))).hexdigest() urlParams = dict(self.defaultParams) urlParams['header'] = dict(self.AJAX_HEADER) urlParams['header'].update({'Referer':cItem['url'], 'X-Request-Enable-Auth-Fallback':'1', 'X-Request-CID':cid, 'X-Request-Token':requestToken}) post_data = {'additionalfields': 'language,channel,actors,studio,licenseby,slug,subtitle,teaser,description', 'addInteractionOptions': '1', 'addStatusDetails': '1', 'addStreamDetails': '1', 'addCaptions': '1', 'addScenes': '1', 'addHotSpots': '1', 'addBumpers': '1', 'captionFormat': 'data',} url = 'https://api.nexx.cloud/v3/%s/videos/%s/%s' % (clientId, op, videoId) sts, data = self.getPage(url, urlParams, post_data) if not sts: return data = byteify(json.loads(data), '', True)['result'] try: protectionToken = data['protectiondata']['token'] except Exception: protectionToken = None language = data['general'].get('language_raw') or '' data = data['streamdata'] printDBG(data) cdn = data['cdnType'] azureLocator = data['azureLocator'] AZURE_URL = 'http://nx%s%02d.akamaized.net/' def getCdnShieldBase(shieldType='', prefix='-p'): for secure in ('', 's'): cdnShield = data.get('cdnShield%sHTTP%s' % (shieldType, secure.upper())) if cdnShield: return 'http%s://%s' % (secure, cdnShield) else: return AZURE_URL % (prefix, int(data['azureAccount'].replace('nexxplayplus', ''))) azureStreamBase = getCdnShieldBase() isML = ',' in language azureManifestUrl = '%s%s/%s_src%s.ism/Manifest' % (azureStreamBase, azureLocator, videoId, ('_manifest' if isML else '')) + '%s' if protectionToken: azureManifestUrl += '?hdnts=%s' % protectionToken try: azureProgressiveBase = getCdnShieldBase('Prog', '-d') azureFileDistribution = data.get('azureFileDistribution') if azureFileDistribution: fds = azureFileDistribution.split(',') if fds: for fd in fds: ss = fd.split(':') if len(ss) != 2: continue tbr = int(ss[0] or 0) if not tbr: continue retTab.append({'name':'[%s] %s' % (tbr, ss[1]), 'tbr':tbr, 'url': '%s%s/%s_src_%s_%d.mp4' % (azureProgressiveBase, azureLocator, videoId, ss[1], tbr)}) except Exception: printExc() retTab.sort(key=lambda item: item['tbr'], reverse=True) if len(retTab) == 0: retTab = getMPDLinksWithMeta(azureManifestUrl % '(format=mpd-time-csf)', checkExt=False, sortWithMaxBandwidth=999999999) if len(retTab) == 0: retTab = getDirectM3U8Playlist(azureManifestUrl % '(format=m3u8-aapl)', checkExt=False, checkContent=True, sortWithMaxBitrate=999999999) except Exception: printExc() if len(retTab): self.cacheLinks[cacheKey] = retTab for idx in range(len(retTab)): retTab[idx]['need_resolve'] = 1 return retTab