REVAMP
This commit is contained in:
1 parent
566a8e5905
commit
cb61ad08c7
12 files changed
+145
-374
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+25
-52
@@ -35,7 +35,7 @@ class NetworkError(ProxerError):
|
||||
|
||||
def get_embed_url(episode_url: str, auth_cookie: tuple[str, str]) -> str:
|
||||
"""
|
||||
Extracts the embed URL from a Proxer episode page using iframe parsing.
|
||||
Extracts the embed URL from a Proxer episode page.
|
||||
|
||||
:param episode_url: URL of the Proxer episode page
|
||||
:param auth_cookie: Tuple containing (cookie_name, cookie_value)
|
||||
@@ -43,48 +43,32 @@ def get_embed_url(episode_url: str, auth_cookie: tuple[str, str]) -> str:
|
||||
:raises NotFoundError: If embed URL is not found
|
||||
:raises NetworkError: If a request fails
|
||||
"""
|
||||
import re
|
||||
from requests import get, RequestException
|
||||
|
||||
HEADERS = {
|
||||
'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'
|
||||
}
|
||||
|
||||
# Strip URL fragment
|
||||
episode_url = episode_url.split("#")[0]
|
||||
|
||||
cookies = {auth_cookie[0]: auth_cookie[1], 'stream_choose': 'proxer-stream'}
|
||||
SEARCH_TOKEN = '"code":"'
|
||||
SEARCH_SERVER = "stream-service.proxer.me"
|
||||
HEADERS = {'User-Agent': 'Mozilla/5.0'}
|
||||
|
||||
try:
|
||||
logging.info(f"[DEBUG] Fetching episode URL: {episode_url} with cookies: {cookies}")
|
||||
response = get(episode_url, headers=HEADERS, cookies=cookies, timeout=15)
|
||||
response = get(episode_url, cookies={auth_cookie[0]: auth_cookie[1], 'stream_choose': 'proxer-stream'}, headers=HEADERS)
|
||||
response.raise_for_status()
|
||||
logging.info(f"[DEBUG] HTTP status: {response.status_code}")
|
||||
|
||||
content = response.text
|
||||
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:
|
||||
raise NetworkError(f"Failed to fetch episode page: {e}")
|
||||
|
||||
# Extract iframe src
|
||||
match = re.search(r'<iframe[^>]+src="([^"]+)"', content)
|
||||
if match:
|
||||
embed_url = match.group(1)
|
||||
logging.info(f"[DEBUG] Found embed URL: {embed_url}")
|
||||
return embed_url
|
||||
else:
|
||||
raise NotFoundError("Embed code not found in page content. Check /tmp/proxer_debug.html for details.")
|
||||
# Extract the embed code
|
||||
code_index = content.find(SEARCH_TOKEN) + len(SEARCH_TOKEN)
|
||||
if code_index < len(SEARCH_TOKEN):
|
||||
raise NotFoundError("Embed code not found in page content.")
|
||||
|
||||
code : str = content[code_index:].partition('"')[0]
|
||||
|
||||
# Detect the correct streaming service
|
||||
host : str = "stream-service" if SEARCH_SERVER in content else "stream"
|
||||
return f"https://{host}.proxer.me/embed-{code}.html"
|
||||
|
||||
|
||||
def get_mp4_url(embed_url: str) -> str:
|
||||
"""
|
||||
Extracts the direct MP4 URL from an embed page with enhanced logging.
|
||||
Extracts the direct MP4 URL from an embed page.
|
||||
|
||||
:param embed_url: URL of the Proxer embed player
|
||||
:returns: Direct MP4 URL
|
||||
@@ -92,33 +76,26 @@ def get_mp4_url(embed_url: str) -> str:
|
||||
:raises NetworkError: If a request fails
|
||||
"""
|
||||
SEARCH_TOKEN = 'video/mp4" src="'
|
||||
HEADERS = {
|
||||
'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'
|
||||
}
|
||||
HEADERS = {'User-Agent': 'Mozilla/5.0'}
|
||||
|
||||
try:
|
||||
logging.info(f"[DEBUG] Fetching embed URL: {embed_url}")
|
||||
response = get(embed_url, headers=HEADERS, timeout=15)
|
||||
response = get(embed_url, headers=HEADERS)
|
||||
response.raise_for_status()
|
||||
logging.info(f"[DEBUG] HTTP status: {response.status_code}")
|
||||
content = response.text
|
||||
logging.debug(f"[DEBUG] Embed snippet: {content[:500].replace(chr(10), ' ')}")
|
||||
except RequestException as e:
|
||||
raise NetworkError(f"Failed to fetch embed page: {e}")
|
||||
|
||||
# Extract the MP4 URL
|
||||
link_index = content.find(SEARCH_TOKEN) + len(SEARCH_TOKEN)
|
||||
if link_index < len(SEARCH_TOKEN):
|
||||
raise NotFoundError("MP4 URL not found in embed page.")
|
||||
|
||||
mp4_url = content[link_index:].partition('"')[0]
|
||||
logging.info(f"[DEBUG] Found MP4 URL: {mp4_url}")
|
||||
return mp4_url
|
||||
return content[link_index:].partition('"')[0]
|
||||
|
||||
|
||||
def download_mp4(mp4_url: str, save_path: str, label: str = "") -> None:
|
||||
"""
|
||||
Downloads an MP4 file from a given URL with enhanced logging.
|
||||
Downloads an MP4 file from a given URL and displays a progress bar.
|
||||
|
||||
:param mp4_url: URL of the MP4 file
|
||||
:param save_path: Path to save the downloaded file
|
||||
@@ -128,25 +105,21 @@ def download_mp4(mp4_url: str, save_path: str, label: str = "") -> None:
|
||||
CHUNK_SIZE = 255
|
||||
MAX_LABEL_LENGTH = 32
|
||||
|
||||
# Adjust label for progress bar
|
||||
if label:
|
||||
label = label[:MAX_LABEL_LENGTH - 3] + "..." if len(label) > MAX_LABEL_LENGTH else label.ljust(MAX_LABEL_LENGTH)
|
||||
|
||||
logging.info(f"[DEBUG] Starting download: {mp4_url} -> {save_path}")
|
||||
|
||||
try:
|
||||
response = get(mp4_url, stream=True, timeout=30)
|
||||
response = get(mp4_url, stream=True)
|
||||
response.raise_for_status()
|
||||
total_length = int(response.headers.get('content-length', 0))
|
||||
except RequestException as e:
|
||||
raise NetworkError(f"Failed to start download: {e}")
|
||||
|
||||
# Download file with progress bar
|
||||
with open(save_path, "wb") as file:
|
||||
if total_length:
|
||||
for chunk in progress.bar(
|
||||
response.iter_content(chunk_size=CHUNK_SIZE),
|
||||
expected_size=total_length / CHUNK_SIZE,
|
||||
label=label
|
||||
):
|
||||
for chunk in progress.bar(response.iter_content(chunk_size=CHUNK_SIZE), expected_size=total_length / CHUNK_SIZE, label=label):
|
||||
if chunk:
|
||||
file.write(chunk)
|
||||
else:
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import sys
|
||||
import argparse
|
||||
from time import sleep
|
||||
from lib.proxer_utils import get_embed_url, get_mp4_url, download_mp4
|
||||
|
||||
def download_series(serie_id, pretty_name, episode_range, language, auth_token, output_dir):
|
||||
"""
|
||||
Downloads all episodes in a specified range of a series.
|
||||
If the range is 'x-x', only a single episode is downloaded.
|
||||
"""
|
||||
start, end = map(int, episode_range.split("-"))
|
||||
for episode_number in range(start, end + 1):
|
||||
episode_url = f"https://proxer.me/watch/{serie_id}/{episode_number}/{language}"
|
||||
try:
|
||||
print(f"Fetching embed URL for episode {episode_number} for {episode_url}...")
|
||||
embed_url = get_embed_url(episode_url, auth_token)
|
||||
print(f"Embed URL fetched for episode {episode_number}: {embed_url}")
|
||||
|
||||
print(f"Fetching MP4 URL for episode {episode_number}...")
|
||||
mp4_url = get_mp4_url(embed_url)
|
||||
print(f"MP4 URL fetched for episode {episode_number}: {mp4_url}")
|
||||
|
||||
# Prepare the output file path
|
||||
output_file = f"{output_dir}/{pretty_name}_Episode_{episode_number}_{language}.mp4"
|
||||
|
||||
# Download the episode
|
||||
print(f"Downloading episode {episode_number}...")
|
||||
download_mp4(mp4_url, output_file, label=f"Episode {episode_number} ({language})")
|
||||
print(f"Episode {episode_number} downloaded successfully!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error downloading episode {episode_number}: {e}")
|
||||
|
||||
# Optional: Sleep between downloads to avoid being rate-limited
|
||||
sleep(1)
|
||||
|
||||
def parse_args():
|
||||
"""Parse command-line arguments"""
|
||||
parser = argparse.ArgumentParser(description="Download a series or a single episode from Proxer.me")
|
||||
parser.add_argument('-i', '--id', required=True, type=str, help="The series ID on Proxer.me")
|
||||
parser.add_argument('-n', '--name', required=True, type=str, help="The pretty name of the series")
|
||||
parser.add_argument('-e', '--episodes', required=True, type=str, help="Episode range (start-end), e.g. 1-10 or 5-5 for a single episode")
|
||||
parser.add_argument('-l', '--language', required=True,
|
||||
choices=['engsub', 'engdub', 'gersub', 'gerdub'],
|
||||
help="Language of the subtitles/audio")
|
||||
parser.add_argument('-t', '--token', required=True, type=str, help="Proxer authentication token (cookie)")
|
||||
parser.add_argument('-o', '--output', required=True, type=str, help="Directory to store downloaded videos")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Parse command-line arguments
|
||||
args = parse_args()
|
||||
|
||||
# Assuming the Proxer authentication token comes as a cookie string (name=value)
|
||||
auth_token = tuple(args.token.split("="))
|
||||
|
||||
# Call the function to download episodes (single or multiple)
|
||||
download_series(args.id, args.name, args.episodes, args.language, auth_token, args.output)
|
||||
Reference in new issue
Block a user