def resolve_videos(link): product_id = _play_parser.get_productID(link) video = _play_parser.get_video(product_id) # '/playlist.m3u8' baseUrl = video.link[:video.link.index('playlist.m3u8')] manifest = _play_parser.get_manifest(video.link) result = [] for m in re.finditer('#EXT-X-STREAM-INF:.*?ANDWIDTH=(?P<bandwidth>\d+),RESOLUTION=.+\s(?P<chunklist>.+$\s)',manifest, re.MULTILINE): itm = {} bandwidth = int(m.group('bandwidth')) itm['bandwidth'] = bandwidth if bandwidth < 950000: itm['quality'] = "288p" elif bandwidth >= 950000 and bandwidth < 1150000: itm['quality'] = "360p" elif bandwidth >= 1150000 and bandwidth < 1660000: itm['quality'] = "480p" else: itm['quality'] = "720p" itm['title'] = "%s - %s" % (video.title, itm['quality']) itm['url'] = baseUrl + m.group('chunklist').replace('\n', '') itm['surl'] = video.title primalog.logDebug("item=%s" % itm) result.append(itm) result = sorted(result, key=lambda i: i['bandwidth'], reverse=True) result = resolver.filter_by_quality(result, _quality) if len(result) > 0: for videoItem in result: add_video(videoItem['title'],videoItem['url'])
def resolve_videos(link): m3u8_obj = m3u8.load(link) if m3u8_obj.is_variant: streams = [] for i in m3u8_obj.playlists: streams.append((i.uri, i.stream_info.resolution, i.stream_info.bandwidth)) streams.sort(key=lambda x:x[2], reverse=True) streams.sort(key=lambda x:x[1], reverse=True) for idx, (url, resolution, bandwidth) in enumerate(streams): if resolution and bandwidth: title = "%sx%s - %dKB/s" % (resolution[0], resolution[1], bandwidth/1024/8) elif resolution: title = "%sx%s" % (resolution[0], resolution[1]) elif bandwidth: title = "%dKB/s" % (bandwidth/1024/8) else: title = str(idx) add_video(title, url) else: add_video("video", link)
def add_play(title, provider_name, quality, url, subs=None, filename=None, image=None, infoLabels={}, menuItems={}, headers={}, lang=None): if not 'title' in infoLabels: infoLabels['title'] = title settings = {"extra-headers": headers} title = decode_html(title) quality = decode_html(quality) provider_name = decode_html(provider_name) if client_version != 0: if client_version > 1: client.add_video(title, url, subs=subs, quality=quality, provider_name=provider_name, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, lang=lang) else: if lang: name = '[%s][%s] %s - %s' % (quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality, provider_name, title) client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings) else: if lang: name = '[%s][%s] %s - %s' % (quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality, provider_name, title) client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems)
def add_play(title, provider_name, quality, url, subs=None, filename=None, image=None, infoLabels={}, menuItems={},headers={}, lang=None): if not 'title' in infoLabels: infoLabels['title'] = title settings = {"extra-headers":headers} title = decode_html(title) quality = decode_html(quality) provider_name = decode_html(provider_name) if client_version != 0: if client_version > 1: client.add_video(title, url, subs=subs, quality = quality, provider_name = provider_name, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, lang=lang) else: if lang: name = '[%s][%s] %s - %s'%(quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality,provider_name, title) client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings) else: if lang: name = '[%s][%s] %s - %s'%(quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality, provider_name, title) client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems)
def add_play(title, provider_name, quality, url, subs=None, filename=None, image=None, infoLabels={}, menuItems={},headers={}, lang=None, resolveTitle=None, customTitle=None, customFname=None): if customTitle: title = customTitle if customFname: filename = customFname infoLabels['title'] = replace_diacritic2(title) settings = {"extra-headers":headers} title = replace_diacritic2(title) quality = replace_diacritic2(quality) provider_name = replace_diacritic2(provider_name) if lang: lang = replace_diacritic2(lang) if client_version != 0: if client_version > 1: client.add_video(title, url, subs=subs, quality = quality, provider_name = provider_name, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, lang=lang) else: if resolveTitle: name = replace_diacritic2(resolveTitle) else: if lang: name = '[%s][%s] %s - %s'%(quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality,provider_name, title) client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings) else: if resolveTitle: name = replace_diacritic2(resolveTitle) else: if lang: name = '[%s][%s] %s - %s'%(quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality, provider_name, title) client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems)
def addLink(name, url, image, *args, **kwargs): add_video(name, url, None, image)
def add_play(title, provider_name, quality, url, subs=None, filename=None, image=None, infoLabels={}, menuItems={},headers={}, lang=None, resolveTitle=None, customTitle=None, customFname=None, addonDataItem=None): if customTitle: title = customTitle if customFname: filename = customFname infoLabels['title'] = replace_diacritic2(title) settings = {"extra-headers":headers} title = replace_diacritic2(title) quality = replace_diacritic2(quality) provider_name = replace_diacritic2(provider_name) if lang: lang = replace_diacritic2(lang) if client_version != 0: if client_version > 1: if addonDataItem is None: client.add_video(title, url, subs=subs, quality = quality, provider_name = provider_name, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, lang=lang) else: # back compatibility try: client.add_video(title, url, subs=subs, quality = quality, provider_name = provider_name, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, lang=lang, dataItem=addonDataItem) except: # old version archiv using client.add_video(title, url, subs=subs, quality = quality, provider_name = provider_name, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, lang=lang) else: if resolveTitle: name = replace_diacritic2(resolveTitle) else: if lang: name = '[%s][%s] %s - %s'%(quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality,provider_name, title) if addonDataItem is None: client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings) else: # back compatibility try: client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings, dataItem=addonDataItem) except: client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, settings=settings) else: if resolveTitle: name = replace_diacritic2(resolveTitle) else: if lang: name = '[%s][%s] %s - %s'%(quality, lang, provider_name, title) else: name = '[%s] %s - %s' % (quality, provider_name, title) if addonDataItem is None: client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems) else: # back compatibility try: client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems, dataItem=addonDataItem) except: client.add_video(name, url, subs=subs, filename=filename, image=image, infoLabels=infoLabels, menuItems=menuItems)