import base64 import re from typing import Dict, Any from urllib.parse import urljoin from mediaflow_proxy.extractors.base import BaseExtractor, ExtractorError class VoeExtractor(BaseExtractor): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.mediaflow_endpoint = "hls_manifest_proxy" async def extract(self, url: str, redirected: bool = False, **kwargs) -> Dict[str, Any]: response = await self._make_request(url) # See https://github.com/Gujal00/ResolveURL/blob/master/script.module.resolveurl/lib/resolveurl/plugins/voesx.py redirect_pattern = r'''window\.location\.href\s*=\s*'([^']+)''' redirect_match = re.search(redirect_pattern, response.text, re.DOTALL) if redirect_match: if redirected: raise ExtractorError("VOE: too many redirects") return await self.extract(redirect_match.group(1)) code_and_script_pattern = r'json">\["([^"]+)"]\s* Dict[str, Any]: import json lut = [''.join([('\\' + x) if x in '.*+?^${}()|[]\\' else x for x in i]) for i in luts[2:-2].split("','")] txt = '' for i in ct: x = ord(i) if 64 < x < 91: x = (x - 52) % 26 + 65 elif 96 < x < 123: x = (x - 84) % 26 + 97 txt += chr(x) for i in lut: txt = re.sub(i, '', txt) ct = base64.b64decode(txt).decode('utf-8') txt = ''.join([chr(ord(i) - 3) for i in ct]) txt = base64.b64decode(txt[::-1]).decode('utf-8') return json.loads(txt)