import sys # 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): """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) # 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("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 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)") 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 if __name__ == "__main__": sys.exit(main())