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(self, response, origin_url=""): self.found_links = [] movie = { 'group': {}, 'episode': [], 'links': [], } soup = BeautifulSoup(response, "html.parser") posts = soup.select( "ol.messageList > li.message > div.messageInfo > div.messageContent > article > blockquote" ) for post in posts: self.extract_links(post) if len(self.found_links) > 0: arequest = AsyncRequest() results = arequest.get(self.found_links) for idx, result in enumerate(results): try: name, size = FShareVN.get_info(content=result) except: print('Link die %s' % self.found_links[idx]) continue if name: movie['links'].append({ 'link': self.found_links[idx], 'title': '[%s] %s' % (size, name), 'intro': name, 'type': 'Unknown', 'resolve': False, 'isFolder': FShareVN.is_folder(self.found_links[idx]), 'originUrl': origin_url }) else: movie['links'].append({ 'link': self.found_links[idx], 'title': self.found_links[idx], 'type': 'Unknown', 'resolve': False, 'isFolder': FShareVN.is_folder(self.found_links[idx]), 'originUrl': origin_url }) return movie
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_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 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
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