up
This commit is contained in:
1 parent
c92b7c6d96
commit
8022548d37
1 file changed
+23
-20
+23
-20
@@ -32,9 +32,10 @@ class NotFoundError(ProxerError):
|
|||||||
class NetworkError(ProxerError):
|
class NetworkError(ProxerError):
|
||||||
"""Raised when there is a network-related error"""
|
"""Raised when there is a network-related error"""
|
||||||
|
|
||||||
|
|
||||||
def get_embed_url(episode_url: str, auth_cookie: tuple[str, str]) -> str:
|
def get_embed_url(episode_url: str, auth_cookie: tuple[str, str]) -> str:
|
||||||
"""
|
"""
|
||||||
Extracts the embed URL from a Proxer episode page with enhanced logging.
|
Extracts the embed URL from a Proxer episode page using iframe parsing.
|
||||||
|
|
||||||
:param episode_url: URL of the Proxer episode page
|
:param episode_url: URL of the Proxer episode page
|
||||||
:param auth_cookie: Tuple containing (cookie_name, cookie_value)
|
:param auth_cookie: Tuple containing (cookie_name, cookie_value)
|
||||||
@@ -42,8 +43,9 @@ def get_embed_url(episode_url: str, auth_cookie: tuple[str, str]) -> str:
|
|||||||
:raises NotFoundError: If embed URL is not found
|
:raises NotFoundError: If embed URL is not found
|
||||||
:raises NetworkError: If a request fails
|
:raises NetworkError: If a request fails
|
||||||
"""
|
"""
|
||||||
SEARCH_TOKEN = '"code":"'
|
import re
|
||||||
SEARCH_SERVER = "stream-service.proxer.me"
|
from requests import get, RequestException
|
||||||
|
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
|
||||||
'(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
'(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||||
@@ -52,31 +54,32 @@ def get_embed_url(episode_url: str, auth_cookie: tuple[str, str]) -> str:
|
|||||||
# Strip URL fragment
|
# Strip URL fragment
|
||||||
episode_url = episode_url.split("#")[0]
|
episode_url = episode_url.split("#")[0]
|
||||||
|
|
||||||
|
cookies = {auth_cookie[0]: auth_cookie[1], 'stream_choose': 'proxer-stream'}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info(f"[DEBUG] Fetching episode URL: {episode_url}")
|
logging.info(f"[DEBUG] Fetching episode URL: {episode_url} with cookies: {cookies}")
|
||||||
response = get(
|
response = get(episode_url, headers=HEADERS, cookies=cookies, timeout=15)
|
||||||
episode_url,
|
|
||||||
cookies={auth_cookie[0]: auth_cookie[1], 'stream_choose': 'proxer-stream'},
|
|
||||||
headers=HEADERS,
|
|
||||||
timeout=15
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
logging.info(f"[DEBUG] HTTP status: {response.status_code}")
|
logging.info(f"[DEBUG] HTTP status: {response.status_code}")
|
||||||
|
|
||||||
content = response.text
|
content = response.text
|
||||||
logging.debug(f"[DEBUG] Page snippet: {content[:500].replace(chr(10), ' ')}")
|
logging.debug(f"[DEBUG] Page snippet: {content[:500].replace(chr(10), ' ')}")
|
||||||
|
|
||||||
|
# Optional: dump full page to file for debugging
|
||||||
|
with open("/tmp/proxer_debug.html", "w", encoding="utf-8") as f:
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
raise NetworkError(f"Failed to fetch episode page: {e}")
|
raise NetworkError(f"Failed to fetch episode page: {e}")
|
||||||
|
|
||||||
# Extract the embed code
|
# Extract iframe src
|
||||||
code_index = content.find(SEARCH_TOKEN) + len(SEARCH_TOKEN)
|
match = re.search(r'<iframe[^>]+src="([^"]+)"', content)
|
||||||
if code_index < len(SEARCH_TOKEN):
|
if match:
|
||||||
raise NotFoundError("Embed code not found in page content.")
|
embed_url = match.group(1)
|
||||||
|
logging.info(f"[DEBUG] Found embed URL: {embed_url}")
|
||||||
code: str = content[code_index:].partition('"')[0]
|
return embed_url
|
||||||
host: str = "stream-service" if SEARCH_SERVER in content else "stream"
|
else:
|
||||||
embed_url = f"https://{host}.proxer.me/embed-{code}.html"
|
raise NotFoundError("Embed code not found in page content. Check /tmp/proxer_debug.html for details.")
|
||||||
logging.info(f"[DEBUG] Found embed URL: {embed_url}")
|
|
||||||
return embed_url
|
|
||||||
|
|
||||||
|
|
||||||
def get_mp4_url(embed_url: str) -> str:
|
def get_mp4_url(embed_url: str) -> str:
|
||||||
|
|||||||
Reference in new issue
Block a user