def get_link_deprecated(url, originURL): req = Request() response = req.get(url) # found playlist if re.search('EXT-X-STREAM-INF', response): resolutions = re.findall('RESOLUTION=\d+x(\d+)', response) matches = re.findall('(http.*)\r', response) if '1080' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '1080' == i), -1) url = matches[idx] elif '720' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '720' == i), -1) url = matches[idx] elif '480' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '480' == i), -1) url = matches[idx] response = Request().get(url, headers={'origin': 'http://www.phimmoi.net'}) links = re.findall('(https?://(?!so-trym).*)\r', response) if links: media_type = 'hls4' arequest = AsyncRequest(request=req, retry=2) results = arequest.head(links, headers={ 'origin': 'http://www.phimmoi.net', 'referer': originURL }, redirect=False) for i in range(len(links)): try: response = response.replace(links[i], results[i].headers['location']) except: print(links[i], results[i].headers) else: media_type = 'hls3' stream_url = PasteBin().dpaste(response, name=url, expire=60) playlist = "#EXTM3U\n#EXT-X-VERSION:3\n" playlist += "#EXT-X-STREAM-INF:BANDWIDTH=3998000,RESOLUTION=9999x9999\n" playlist += "%s\n" % stream_url url = PasteBin().dpaste(playlist, name=url, expire=60) if 'hls' == media_type: url += '|referer=' + urllib.quote_plus(originURL) return url, media_type
def get_link(url): print "*********************** Apply fptplay url %s" % url header = { 'Origin': 'https://fptplay.vn', 'User-Agent': "Chrome/59.0.3071.115 Safari/537.36" } return str(url) + "|%s" % urlencode(header), 'hls3' return url, 'hls3' r = re.search('streamFPT\?url=(.*)', url) if r: url = urllib.unquote(r.group(1)) base_url = url.rpartition('/')[0] response = Request().get(url) matches = re.findall('(chunklist.*)', response) for m in matches: stream_url = base_url + '/' + m response = response.replace(m, __get_fptplay_stream(stream_url, base_url)) url = PasteBin().dpaste(response, name=url, expire=60) return url, 'hls3'
def get_link(url, media): # https://play.playoffsite.xyz/play/v1/5f753b4889b8c5269a591e29 # https://play.playoffsite.xyz/apiv1/playhq/5f6581f43036707a6803e61c m_id = re.search(r'v1/(.*)', url) header = {'Referer': url} req = Request() if m_id: m_id = m_id.group(1) # get domain list https://play.playoffsite.xyz/play/v1/5f6581f43036707a6803e61c # var DOMAIN_LIST = response = req.get( "https://play.playoffsite.xyz/play/v1/{}".format(m_id), headers=header) domains = re.search(r'var DOMAIN_LIST = (\[.*\])', response).group(1) idfile = re.search(r'var idfile = "(.*)";', response).group(1) response = req.post( "https://play.playoffsite.xyz/apiv1/playhq/{}".format(m_id), headers=header, data="") playlist = create_playlist(response, idfile, domains) url = PasteBin().dpaste(playlist, name='playoffsite', expire=60) # url = helper.write_file('playlist.strm', url) return url, 'Tvhay'
def get_link(url, movie): request = Request() response = request.get(url) response = response.replace('/redirect/hls', '/hls') url = PasteBin().dpaste(response, name='movie3s', expire=60) return url, 'movie3s_hls'
def calculate_stream(content, origin, referer): # get all links content = content.replace('//immortal.hydrax.net', 'http://immortal.hydrax.net') reg = re.findall('(http://immortal.hydrax.net/.*/.*/(.*)/(.*))/.*\n', content) if reg: ms = list() for i in range(len(reg)): link = 'http://immortal.hydrax.net/%s/%s' % (reg[i][1], reg[i][2]) if link not in ms: ms.append(link) content = content.replace(reg[i][0], link) else: ms = re.findall('(http://immortal.hydrax.net/.*/.*)/.*\n', content) ms = list(dict.fromkeys(ms)) arequest = AsyncRequest() results = arequest.get(ms, headers={'Origin': origin, 'Referer': referer}) max_targetduration = 12 play_list = "#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-TARGETDURATION:12\n#EXT-X-MEDIA-SEQUENCE:0\n" hash = re.search("(#EXT-X-KEY.*?)\n", content) if hash: play_list += hash.group(0) for i in range(len(ms)): link = ms[i] slashlink = link.replace('-', '\\-') slashlink = slashlink.replace('*', '\\*') slashlink = slashlink.replace('?', '\\?') duration = 0 lengthbyte = 0 startbyte = 999999999 segments = re.findall( r"(#EXTINF:([0-9]*\.?[0-9]+),\n#EXT-X-BYTERANGE:([0-9]+)@([0-9]+)(?:(?!#EXTINF).)*" + slashlink + ").*?\n", content, re.DOTALL) for segment in segments: duration += float(segment[1]) startbyte = int(segment[3]) < startbyte and int( segment[3]) or startbyte lengthbyte += int(segment[2]) play_list += "#EXTINF:%s,\n" % duration play_list += "#EXT-X-BYTERANGE:%s@%s\n" % (lengthbyte, startbyte) play_list += "%s\n" % json.loads(results[i])['url'] if duration > max_targetduration: max_targetduration = duration play_list = play_list.replace( "TARGETDURATION:12", "TARGETDURATION:" + str(int(math.ceil(max_targetduration)))) play_list += "#EXT-X-ENDLIST\n" url = PasteBin().dpaste(play_list, name=referer, expire=60) return url
def get_link(url, media): header = { 'Referer': media.get('originUrl'), 'Origin': 'https://fimfast.com', 'User-Agent': "Chrome/59.0.3071.115 Safari/537.36" } return url + "|%s" % urlencode(header) play_list = "" base_url = urlparse(url) base_url = base_url.scheme + '://' + base_url.netloc resp = Request().get(url) resolutions = re.findall('RESOLUTION=\d+x(\d+)', resp) matches = re.findall('(/[a-zA-z]+/.*)', resp) if len(resolutions) > 1: play_list += "#EXTM3U\n" if '2048' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '1080' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url + "|%s" % urlencode(header) elif '1080' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '1080' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url + "|%s" % urlencode(header) return create_imacdn_stream(stream_url, base_url) # play_list += "#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1920x1080\n" # play_list += "%s\n" % create_imacdn_stream(stream_url, base_url) elif '720' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '720' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url + "|%s" % urlencode(header) return create_imacdn_stream(stream_url, base_url) # play_list += "#EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=1280x720\n" # play_list += "%s\n" % create_imacdn_stream(stream_url, base_url) elif '480' in resolutions: idx = next( (resolutions.index(i) for i in resolutions if '480' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url + "|%s" % urlencode(header) return create_imacdn_stream(stream_url, base_url) # play_list += "#EXT-X-STREAM-INF:BANDWIDTH=750000,RESOLUTION=854x480\n" # play_list += "%s\n" % create_imacdn_stream(stream_url, base_url) else: play_list = resp for m in matches: stream_url = base_url + m play_list = play_list.replace( m, create_imacdn_stream(stream_url, base_url)) url = PasteBin().dpaste(play_list, name=url, expire=60) return url
def __get_fptplay_stream(url, base_url): response = Request().get(url) matches = re.findall('(media_.*)', response) for m in matches: stream_url = base_url + '/' + m response = response.replace(m, stream_url) url = PasteBin().dpaste(response, name=url, expire=60) return url
def get_stream(url, header, base_path=None, action="HEAD"): req = Request() r = req.get(url, headers=header) if not base_path: base_url = urlparse(url) base_url = base_url.scheme + '://' + base_url.netloc else: base_url= base_path if re.search('EXT-X-STREAM-INF', r): ad_url = get_adaptive_link(r) if 'http' not in ad_url: ad_url = base_url + ad_url r = req.get(ad_url, headers=header) playlist = "" links = [] is_redirect = True lines = r.splitlines() for line in lines: if len(line) > 0: # guess link if '#' not in line[0]: if 'http' in line: path = line elif '//' in line[0:2]: path = "{}{}".format("https:", line) elif '/' in line[0]: path = "{}/{}".format(base_url, line) else: path = "{}/{}".format(base_url, line) if 'vdacdn.com' in path: is_redirect = False path = path.replace('https://', 'http://') if 'cdnplay.xyz' in path: is_redirect = False # path += "|%s" % urlencode(header) links.append({'url': path, 'parser': parse_link, 'responseHeader': True}) else: path = line playlist += '%s\n' % path if is_redirect and len(playlist) > 0: arequest = AsyncRequest(request=req) results = arequest.get(links, redirect=False, headers=header, verify=False) for i in range(len(links)): playlist = playlist.replace(links[i].get('url'), results[i]) url = PasteBin().dpaste(playlist, name='adaptivestream', expire=60) return url
def get_link(url): r = re.search('streamFPT\?url=(.*)', url) if r: url = urllib.unquote(r.group(1)) base_url = url.rpartition('/')[0] response = Request().get(url) matches = re.findall('(chunklist.*)', response) for m in matches: stream_url = base_url + '/' + m response = response.replace(m, __get_fptplay_stream(stream_url, base_url)) url = PasteBin().dpaste(response, name=url, expire=60) return url, 'hls3'
def get_vip_hydrax(url, media): global origin response = Request().get(url) token = re.search('"key":"(.*?)",', response).group(1) params = { 'key': token, 'type': 'slug', 'value': re.search('#slug=(.*)', url).group(1) } if re.search('vtv16', media['link']): origin = "http://live.vtv16.com" response = Request().post('https://multi.hydrax.net/vip', params, {'Origin': origin}) response = json.loads(response) r = "#EXTM3U\n#EXT-X-VERSION:3\n" if 'fullhd' in response: return get_hydrax_phimmoi_stream(response['fullhd'], response['servers']), 'hls4' # r += "#EXT-X-STREAM-INF:BANDWIDTH=2998000,RESOLUTION=1920x1080\n" # r += "%s\n" % get_hydrax_phimmoi_stream(response['fullhd'], response['servers']) elif 'hd' in response: return get_hydrax_phimmoi_stream(response['hd'], response['servers']), 'hls4' # r += "#EXT-X-STREAM-INF:BANDWIDTH=1998000,RESOLUTION=1280x720\n" # r += "%s\n" % get_hydrax_phimmoi_stream(response['hd'], response['servers']) elif 'mhd' in response: return get_hydrax_phimmoi_stream(response['mhd'], response['servers']), 'hls4' # r += "#EXT-X-STREAM-INF:BANDWIDTH=996000,RESOLUTION=640x480\n" # r += "%s\n" % get_hydrax_phimmoi_stream(response['mhd'], response['servers']) elif 'sd' in response: return get_hydrax_phimmoi_stream(response['sd'], response['servers']), 'hls4' # r += "#EXT-X-STREAM-INF:BANDWIDTH=394000,RESOLUTION=480x360\n" # r += "%s\n" % get_hydrax_phimmoi_stream(response['sd'], response['servers']) elif 'origin' in response: return get_hydrax_phimmoi_stream(response['origin'], response['servers']), 'hls4' # r += "#EXT-X-STREAM-INF:BANDWIDTH=3998000,RESOLUTION=9999x9999\n" # r += "%s\n" % get_hydrax_phimmoi_stream(response['origin'], response['servers']) url = PasteBin().dpaste(r, name=url, expire=60) return url, 'hls4'
def get_vip_hydrax(url, media): global origin response = Request().get(url) token = re.search('"key":"(.*?)",', response).group(1) params = { 'key': token, 'type': 'slug', 'value': re.search('#slug=(.*)', url).group(1) } if re.search('vtv16', media['link']): origin = "http://live.vtv16.com" response = Request().post('https://multi.hydrax.net/vip', params, {'Origin': origin}) response = json.loads(response) r = "#EXTM3U\n#EXT-X-VERSION:3\n" if 'fullhd' in response: stream_url = get_hydrax_phimmoi_stream(response['fullhd'], response['servers']) if stream_url: return stream_url, 'hls4' if 'hd' in response: stream_url = get_hydrax_phimmoi_stream(response['hd'], response['servers']) if stream_url: return stream_url, 'hls4' if 'mhd' in response: stream_url = get_hydrax_phimmoi_stream(response['mhd'], response['servers']) if stream_url: return stream_url, 'hls4' if 'sd' in response: stream_url = get_hydrax_phimmoi_stream(response['sd'], response['servers']) if stream_url: return stream_url, 'hls4' if 'origin' in response: stream_url = get_hydrax_phimmoi_stream(response['origin'], response['servers']) if stream_url: return stream_url, 'hls4' url = PasteBin().dpaste(r, name=url, expire=60) return url, 'hls4'
def get_stream(url, header): req = Request() r = req.get(url, headers=header) base_url = urlparse(url) base_url = base_url.scheme + '://' + base_url.netloc if re.search('EXT-X-STREAM-INF', r): r = get_adaptive_link(r, req, base_url, header) playlist = "" links = [] is_redirect = True for line in r.splitlines(): if len(line) > 0: # guess link if line[0] not in '#': if re.match('http', line): path = line else: path = "{}{}".format(base_url, line) if 'vdacdn.com' in path: is_redirect = False path = path.replace('https://', 'http://') # path += "|%s" % urlencode(header) links.append({ 'url': path, 'parser': parse_link, 'responseHeader': True }) else: path = line playlist += '%s\n' % path if is_redirect and len(playlist) > 0: arequest = AsyncRequest(request=req) results = arequest.get(links, redirect=False, headers=header) for i in range(len(links)): playlist = playlist.replace(links[i].get('url'), results[i]) url = PasteBin().dpaste(playlist, name='dongphim', expire=60) return url
def create_stream(stream, base_url): txt = "#EXTM3U\n#EXT-X-VERSION:5\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-TARGETDURATION:" + str( stream['td']) + "\n#EXT-X-MEDIA-SEQUENCE:0\n" for i in range(len(stream['data'][0])): extif = stream['data'][0][i] byterange = stream['data'][1][i] chunk = stream['data'][2][i] txt += "#EXTINF:%s,\n" % extif txt += "#EXT-X-BYTERANGE:%s\n" % byterange l, s = byterange.split('@') # /drive/hls/8ee495cd1565893812e9b5708ed50d03/8ee495cd1565893812e9b5708ed50d030.html?ch=8ee495cd1565893812e9b5708ed50d03-chunk-0.txt&s=18&l=2431404 txt += "%s/drive/hls/%s/%s.html?ch=%s-chunk-%s.txt&s=%s&l=%s\n" % \ (base_url, stream['md5'], stream['md5'], stream['md5'], chunk, s, l) txt += "#EXT-X-ENDLIST" url = PasteBin().dpaste(txt, name='movie3s', expire=60) return url, 'hls5'
def get_link(url): play_list = "" base_url = urlparse(url) base_url = base_url.scheme + '://' + base_url.netloc resp = Request().get(url) resolutions = re.findall('RESOLUTION=\d+x(\d+)', resp) matches = re.findall('(/drive/.*)', resp) if len(resolutions) > 1: play_list += "#EXTM3U\n" if '1080' in resolutions: idx = next((resolutions.index(i) for i in resolutions if '1080' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url return create_imacdn_stream(stream_url, base_url) # play_list += "#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1920x1080\n" # play_list += "%s\n" % create_imacdn_stream(stream_url, base_url) elif '720' in resolutions: idx = next((resolutions.index(i) for i in resolutions if '720' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url return create_imacdn_stream(stream_url, base_url) # play_list += "#EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=1280x720\n" # play_list += "%s\n" % create_imacdn_stream(stream_url, base_url) elif '480' in resolutions: idx = next((resolutions.index(i) for i in resolutions if '480' == i), -1) url = matches[idx] stream_url = base_url + url return stream_url return create_imacdn_stream(stream_url, base_url) # play_list += "#EXT-X-STREAM-INF:BANDWIDTH=750000,RESOLUTION=854x480\n" # play_list += "%s\n" % create_imacdn_stream(stream_url, base_url) else: play_list = resp for m in matches: stream_url = base_url + m play_list = play_list.replace(m, create_imacdn_stream(stream_url, base_url)) url = PasteBin().dpaste(play_list, name=url, expire=60) return url
def create_effective_playlist(self, sources): r = "#EXTM3U\n#EXT-X-VERSION:3\n" for key, value in sources.items(): if '720' in key: return self.get_stream(value) r += "#EXT-X-STREAM-INF:BANDWIDTH=1998000,RESOLUTION=1280x720\n" r += "%s\n" % self.get_stream(value) break if '480' in key: return self.get_stream(value) r += "#EXT-X-STREAM-INF:BANDWIDTH=996000,RESOLUTION=640x480\n" r += "%s\n" % value break if '360' in key: return self.get_stream(value) r += "#EXT-X-STREAM-INF:BANDWIDTH=394000,RESOLUTION=480x360\n" r += "%s\n" % value break url = PasteBin().dpaste(r, name='animiehay', expire=60) return url
def get_stream(self, url): req = Request() r = req.get(url) str = "" links = [] for line in r.splitlines(): if len(line) > 0: if re.match('http', line): links.append(line) str += '%s\n' % line arequest = AsyncRequest(request=req) results = arequest.head(links) for i in range(len(links)): try: str = str.replace(links[i], results[i].headers['Location ']) except: pass url = PasteBin().dpaste(str, name='animiehay', expire=60) return url
def create_imacdn_stream(url, base_url): retry = 5 res = Request() response = None while retry >= 0: try: print('Retry %d' % retry) response = res.get(url) if response != 'error': break except: pass finally: retry -= 1 if response: matches = re.findall('(/drive/hls/.*)', response) for m in matches: stream_url = base_url + m response = response.replace(m, stream_url) url = PasteBin().dpaste(response, name=url, expire=60) print("------------------------------------ %s") % url return url
def create_stream(self, url, base_url): retry = 5 res = Request() response = None while retry >= 0: try: print('Retry %d' % retry) response = res.get(url) if response != 'error': break except: pass finally: retry -= 1 if response: matches = re.findall('(/drive/hls/.*)', response) for m in matches: stream_url = base_url + m response = response.replace(m, stream_url) response - response.replace('EXT-X-VERSION:5', 'EXT-X-VERSION:3') url = PasteBin().dpaste(response, name=url, expire=60) return url + "|User-Agent: Chrome/59.0.3071.115 Safari/537.36"
def get_hydrax_phimmoi_stream(stream, n): global origin txt = "#EXTM3U\n#EXT-X-VERSION:4\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-TARGETDURATION:" + stream[ 'duration'] + "\n#EXT-X-MEDIA-SEQUENCE:0\n" if 'hash' in stream: txt += "#EXT-X-HASH:%s\n" % stream['hash'] txt += "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\",IV=%s\n" % ( stream['hash'], stream['iv']) links = [] r = len(stream['range']) o = len(n) a = 'expired' in stream and stream['expired'] or None s = 0 l = stream['multiRange'] h = len(l) if stream['type'] == 2: r = 0 for t in range(h): u = stream['multiData'][t]['file'] f = 0 p = 0 for d in range(len(l[t])): if s < o: c = n[s] s += 1 else: s = 1 c = n[0] txt += "#EXTINF:%s,\n" % stream['extinf'][r] txt += "#EXT-X-BYTERANGE:%s\n" % l[t][d] y = l[t][d] c = "http://" + c # c += stream['id'] and "/" + stream['id'] + "/" + stream['range'][t] or "" if '@' in l[t][d]: if l[t][d].find('@') == -1: continue g, y = l[t][d].split('@') g, y = int(g), int(y) f = d and p + 1 or y p = y and f + g - 1 or g - 1 y = '%s-%s' % (f, p) if a: url = a and c + "/" + a + "/" + u else: url = c + "/" + str(r) + "/" + str(u) # url += stream['id'] and "/" + y + ".js" or "/" + y + ".jpg" if url not in links: links.append(url) txt += url + "\n" r += 1 if h == t + 1: txt += "#EXT-X-ENDLIST" elif stream['type'] == 3: for t in range(h): u = stream['multiData'][t]['file'] if s < o: c = n[s] s += 1 else: s = 1 c = n[0] txt += "#EXTINF:" + stream['extinf'][t] + ",\n" c = "http://" + c # e.id && (c = c + "/" + e.id) c += stream['id'] and "/" + stream['id'] or "" url = a and c + "/basic/" + a + "/" + u + "." + ( stream['id'] and "js" or "jpg") or c + "/basic/" + r + "/" + u + "." + ( stream['id'] and "js" or "jpg") if url not in links: links.append(url) txt += url + "\n" r += 1 if h == t + 1: txt += "#EXT-X-ENDLIST" arequest = AsyncRequest() results = arequest.get(links, headers={'origin': origin}) media_urls = [] for i in range(len(links)): try: media_url = json.loads(results[i])['url'] txt = txt.replace(links[i], media_url) if media_url not in media_urls: media_urls.append(media_url) except: print(links[i]) if stream['type'] == 2: max_targetduration = 12 play_list = "#EXTM3U\n#EXT-X-VERSION:4\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-TARGETDURATION:12\n#EXT-X-MEDIA-SEQUENCE:0\n" if 'hash' in stream: path = helper.write_file('hydrax.m3u8', stream['hash'].encode(), binary=True) path = path.replace('\\', '/') # url = PasteBin().dpaste(stream['hash'], name='hydrax.key', expire=60) play_list += "#EXT-X-KEY:METHOD=AES-128,URI=\"file://%s\",IV=%s\n" % ( path, stream['iv']) for link in media_urls: slashlink = link.replace('-', '\\-') slashlink = slashlink.replace('*', '\\*') slashlink = slashlink.replace('?', '\\?') segments = re.findall( r"(#EXTINF:([0-9]*\.?[0-9]+),\n#EXT-X-BYTERANGE:([0-9]+)@([0-9]+)(?:(?!#EXTINF).)*" + slashlink + ")", txt, re.DOTALL) duration = 0 lengthbyte = 0 startbyte = 999999999 for segment in segments: duration += float(segment[1]) startbyte = int(segment[3]) < startbyte and int( segment[3]) or startbyte lengthbyte += int(segment[2]) play_list += "#EXTINF:%s,\n" % duration play_list += "#EXT-X-BYTERANGE:%s@%s\n" % (lengthbyte, startbyte) play_list += "%s\n" % link if duration > max_targetduration: max_targetduration = duration play_list = play_list.replace( "TARGETDURATION:12", "TARGETDURATION:" + str(int(math.ceil(max_targetduration)))) play_list += "#EXT-X-ENDLIST" elif stream['type'] == 3: play_list = txt url = PasteBin().dpaste(play_list, name=stream['id'], expire=60) return url
def get_hydrax_phimmoi_stream(stream, n): global origin txt = "#EXTM3U\n#EXT-X-VERSION:4\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-TARGETDURATION:" + str( stream['duration']) + "\n#EXT-X-MEDIA-SEQUENCE:0\n" if 'hash' in stream: txt += "#EXT-X-HASH:%s\n" % stream['hash'] txt += "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\",IV=%s\n" % ( stream['hash'], stream['iv']) # helper.message('Encrypt not supported', 'Hydrax') # return "" links = [] hashlist = [] r = s = 0 a = 'expired' in stream and stream['expired'] or None if stream['type'] == 2: o = len(n) l = stream['multiRange'] h = len(l) for t in range(h): u = stream['multiData'][t]['file'] f = 0 p = 0 for d in range(len(l[t])): if s < o: c = n[s] s += 1 else: s = 1 c = n[0] txt += "#EXTINF:%s,\n" % stream['extinf'][r] txt += "#EXT-X-BYTERANGE:%s\n" % l[t][d] y = l[t][d] c = "http://" + c # c += stream['id'] and "/" + stream['id'] + "/" + stream['range'][t] or "" if '@' in l[t][d]: if l[t][d].find('@') == -1: continue g, y = l[t][d].split('@') g, y = int(g), int(y) f = d and p + 1 or y p = y and f + g - 1 or g - 1 y = '%s-%s' % (f, p) if a: url = a and c + "/" + a + "/" + u else: url = c + "/" + str(r) + "/" + str(u) # url += stream['id'] and "/" + y + ".js" or "/" + y + ".jpg" if url not in links: # find has match = re.search(r"immortal.hydrax.net/\d+/(.*?)$", url) if match and match.group(1) not in hashlist: links.append(url) hashlist.append(match.group(1)) elif not match: links.append(url) txt += url + "\n" r += 1 if h == t + 1: txt += "#EXT-X-ENDLIST" elif stream['type'] == 3: d = stream['ranges'] l = len(d) o = stream['expired'] a = s = 0 u = stream['datas'] for t in range(l): f = u[t]['file'] for p in range(len(d[t])): if a < r: c = n[a] a += 1 else: a = 1 c = n[0] y = d[t][p] c = "http://" + c txt += "#EXTINF:%s,\n" % stream['extinfs'][s] txt += "#EXT-X-BYTERANGE:%s\n" % y if o: url = c + "/" + o + "/" + f + "/" + y else: url = c + "/" + s + "/" + f + "/" + y txt += "%s\n" % url s += 1 if l == t + 1: txt += "#EXT-X-ENDLIST" # for t in range(l): # u = stream['datas'][t]['file'] # if s < o: # c = n[s] # s += 1 # else: # s = 1 # c = n[0] # # txt += "#EXTINF:" + stream['extinfs'][t] + ",\n" # c = "http://" + c # # e.id && (c = c + "/" + e.id) # c += stream['id'] and "/" + stream['id'] or "" # url = a and c + "/basic/" + a + "/" + u + "." + ( # stream['id'] and "js" or "jpg") or c + "/basic/" + r + "/" + u + "." + ( # stream['id'] and "js" or "jpg") # # if url not in links: # links.append(url) # # txt += url + "\n" # r += 1 # if h == t + 1: # txt += "#EXT-X-ENDLIST" arequest = AsyncRequest() results = arequest.get(links, headers={'origin': origin}) media_urls = [] for i in range(len(links)): try: media_url = json.loads(results[i])['url'] txt = txt.replace(links[i], media_url) if media_url not in media_urls: media_urls.append(media_url) except: print(links[i]) if stream['type'] == 2: max_targetduration = 12 play_list = "#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-PLAYLIST-TYPE:VOD\n#EXT-X-TARGETDURATION:12\n#EXT-X-MEDIA-SEQUENCE:0\n" if 'hash' in stream: # path = helper.write_file('hydrax.m3u8', stream['hash'], binary=True) # path = path.replace('\\', '/') # path = "http://localhost/portal/hydrax.m3u8" path = "encrypted-file://" + stream['hash'] # url = PasteBin().dpaste(stream['hash'], name='hydrax.key', expire=60) play_list += "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\",IV=%s\n" % ( path, stream['iv']) for index, link in enumerate(media_urls): if len(hashlist) > 0: slashlink = hashlist[index] else: slashlink = link.replace('-', '\\-') slashlink = slashlink.replace('*', '\\*') slashlink = slashlink.replace('?', '\\?') segments = re.findall( r"(#EXTINF:([0-9]*\.?[0-9]+),\n#EXT-X-BYTERANGE:([0-9]+)@([0-9]+)(?:(?!#EXTINF).)*" + slashlink + ")", txt, re.DOTALL) duration = 0 lengthbyte = 0 startbyte = 999999999 for segment in segments: duration += float(segment[1]) startbyte = int(segment[3]) < startbyte and int( segment[3]) or startbyte lengthbyte += int(segment[2]) play_list += "#EXTINF:%s,\n" % duration play_list += "#EXT-X-BYTERANGE:%s@%s\n" % (lengthbyte, startbyte) play_list += "%s\n" % link if duration > max_targetduration: max_targetduration = duration play_list = play_list.replace( "TARGETDURATION:12", "TARGETDURATION:" + str(int(math.ceil(max_targetduration)))) play_list += "#EXT-X-ENDLIST" elif stream['type'] == 3: play_list = txt url = PasteBin().dpaste(play_list, name='hydrax', expire=60) return url