phase 1 rework
This commit is contained in:
1 parent
211bfd174d
commit
20054198f3
38 files changed
+5001
-1019
No files matched your search
+49
-40
@@ -1,52 +1,61 @@
|
||||
import sys
|
||||
import argparse
|
||||
from lib.proxer_utils import get_mp4_url, download_mp4, get_embed_url
|
||||
|
||||
# Protect scripts/lib/__pycache__ even when this CLI is invoked without python -B.
|
||||
sys.dont_write_bytecode = True
|
||||
|
||||
from request_validation import (
|
||||
SafeArgumentParser,
|
||||
emit_result,
|
||||
error_result,
|
||||
output_path,
|
||||
token_from_args,
|
||||
validate_auth_cookie,
|
||||
validate_watch_url,
|
||||
verify_output,
|
||||
)
|
||||
|
||||
|
||||
def download_video(url, filename, auth_token, output_dir):
|
||||
"""
|
||||
Downloads a video from Proxer and saves it to the specified directory.
|
||||
"""Run the existing stream pipeline; errors propagate to the CLI result."""
|
||||
url = validate_watch_url(url)
|
||||
auth_token = validate_auth_cookie(auth_token)
|
||||
target = output_path(output_dir, filename)
|
||||
|
||||
:param url: The URL of the Proxer video page
|
||||
:param filename: The desired filename for the downloaded video
|
||||
:param auth_token: A tuple containing (cookie_name, cookie_value) for Proxer authentication
|
||||
:param output_dir: Directory to save the downloaded video
|
||||
"""
|
||||
try:
|
||||
print(f"Fetching embed URL for video: {url}...")
|
||||
embed_url = get_embed_url(url, auth_token)
|
||||
print(f"Embed URL fetched: {embed_url}")
|
||||
# Import only after validation, leaving all protected source and bytecode intact.
|
||||
from lib.proxer_utils import get_embed_url, get_mp4_url, download_mp4
|
||||
|
||||
print(f"Fetching MP4 URL for video: {url}...")
|
||||
mp4_url = get_mp4_url(embed_url)
|
||||
print(f"MP4 URL fetched: {mp4_url}")
|
||||
print("Resolving episode...", flush=True)
|
||||
embed_url = get_embed_url(url, auth_token)
|
||||
print("Resolving media...", flush=True)
|
||||
mp4_url = get_mp4_url(embed_url)
|
||||
print("Downloading video...", flush=True)
|
||||
download_mp4(mp4_url, str(target), label=f"Downloading {filename}")
|
||||
verify_output(target)
|
||||
return target
|
||||
|
||||
# Prepare the output file path
|
||||
output_file = f"{output_dir}/{filename}.mp4"
|
||||
|
||||
# Download the video
|
||||
print(f"Downloading video {filename}...")
|
||||
download_mp4(mp4_url, output_file, label=f"Downloading {filename}")
|
||||
print(f"Video {filename} downloaded successfully!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error downloading video: {e}")
|
||||
|
||||
def parse_args():
|
||||
"""Parse command-line arguments"""
|
||||
parser = argparse.ArgumentParser(description="Download a video from Proxer.me")
|
||||
def parse_args(argv=None):
|
||||
parser = SafeArgumentParser(description="Download a video from Proxer.me")
|
||||
parser.add_argument('-u', '--url', required=True, type=str, help="URL of the Proxer video page")
|
||||
parser.add_argument('-f', '--filename', required=True, type=str, help="Filename for the downloaded video (without extension)")
|
||||
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 save the downloaded video")
|
||||
token = parser.add_mutually_exclusive_group(required=True)
|
||||
token.add_argument('-t', '--token', type=str, help="Proxer authentication token (cookie)")
|
||||
token.add_argument('--token-stdin', action='store_true', help="Read the cookie from standard input instead of process arguments")
|
||||
parser.add_argument('-o', '--output', required=True, type=str, help="Existing directory to save the downloaded video")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
try:
|
||||
args = parse_args(argv)
|
||||
download_video(args.url, args.filename, token_from_args(args), args.output)
|
||||
except Exception as error:
|
||||
result = error_result(error)
|
||||
emit_result(result)
|
||||
return 2 if result["errorCategory"] == "validation" else 1
|
||||
emit_result({"version": 1, "status": "completed"})
|
||||
return 0
|
||||
|
||||
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 the video
|
||||
download_video(args.url, args.filename, auth_token, args.output)
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user