init
This commit is contained in:
1 parent
b9d2f99c3b
commit
ed58376600
18 files changed
+2349
-2
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import sys
|
||||
import argparse
|
||||
from lib.proxer_utils import get_embed_url, get_mp4_url, download_mp4
|
||||
from time import sleep
|
||||
|
||||
def download_series_series(serie_id, pretty_name, episode_range, language, auth_token, output_dir):
|
||||
"""
|
||||
Downloads all episodes in a specified range of a series.
|
||||
|
||||
:param serie_id: The ID of the series (Proxer)
|
||||
:param pretty_name: Pretty name for the series used in file names
|
||||
:param episode_range: A string in the format of "start-end" (inclusive range of episodes)
|
||||
:param language: The preferred language (e.g., 'engsub', 'gerdub')
|
||||
:param auth_token: A tuple containing (cookie_name, cookie_value)
|
||||
:param output_dir: Directory to store downloaded videos
|
||||
"""
|
||||
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 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")
|
||||
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")
|
||||
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 the series
|
||||
download_series_series(args.id, args.name, args.episodes, args.language, auth_token, args.output)
|
||||
@@ -0,0 +1,52 @@
|
||||
import sys
|
||||
import argparse
|
||||
from lib.proxer_utils import get_mp4_url, download_mp4, get_embed_url
|
||||
|
||||
def download_video(url, filename, auth_token, output_dir):
|
||||
"""
|
||||
Downloads a video from Proxer and saves it to the specified directory.
|
||||
|
||||
: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}")
|
||||
|
||||
print(f"Fetching MP4 URL for video: {url}...")
|
||||
mp4_url = get_mp4_url(embed_url)
|
||||
print(f"MP4 URL fetched: {mp4_url}")
|
||||
|
||||
# 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")
|
||||
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")
|
||||
|
||||
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)
|
||||
@@ -0,0 +1,135 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from pymongo import MongoClient
|
||||
from dotenv import load_dotenv # <-- import dotenv
|
||||
|
||||
# ========================
|
||||
# LOAD .env
|
||||
# ========================
|
||||
|
||||
# .env is one directory up
|
||||
env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")
|
||||
load_dotenv(dotenv_path=env_path)
|
||||
|
||||
# ========================
|
||||
# CONFIG
|
||||
# ========================
|
||||
|
||||
MONGO_URI = os.environ.get("MONGO_URI")
|
||||
DB_NAME = os.environ.get("MONGO_DB", "downloads")
|
||||
OUTPUT_DIR = os.environ.get("OUTPUT_DIR", "/mnt/media/WIP/")
|
||||
|
||||
client = MongoClient(MONGO_URI)
|
||||
db = client[DB_NAME]
|
||||
|
||||
queue_col = db["queue"]
|
||||
done_col = db["done"]
|
||||
failed_col = db["failed"]
|
||||
|
||||
# ========================
|
||||
# RUN A JOB
|
||||
# ========================
|
||||
|
||||
def run_job(job):
|
||||
"""Runs proxer-dl-video.py with job parameters."""
|
||||
|
||||
url = job["url"]
|
||||
filename = job["filename"]
|
||||
token = job["token"]
|
||||
|
||||
# Only filename *without extension* must be passed to script.
|
||||
clean_name = filename.replace(".mp4", "")
|
||||
|
||||
script_path = os.path.join(os.path.dirname(__file__), "proxer-dl-video.py")
|
||||
|
||||
cmd = [
|
||||
"python",
|
||||
script_path,
|
||||
"-u", url,
|
||||
"-f", f'"{clean_name}"', # wrap filename in quotes
|
||||
"-t", f'"{token}"', # wrap token in quotes
|
||||
"-o", OUTPUT_DIR
|
||||
]
|
||||
|
||||
|
||||
print("Running:", " ".join(cmd))
|
||||
|
||||
try:
|
||||
proc = subprocess.run(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
)
|
||||
|
||||
stdout = proc.stdout.strip()
|
||||
stderr = proc.stderr.strip()
|
||||
|
||||
# Merge for logs
|
||||
output_log = (stdout + "\n" + stderr).strip()
|
||||
|
||||
# Return code determines success/failure
|
||||
if proc.returncode == 0:
|
||||
print("SUCCESS:", clean_name)
|
||||
|
||||
done_col.insert_one({
|
||||
"filename": filename,
|
||||
"url": url,
|
||||
"finished_at": datetime.utcnow(),
|
||||
"output_log": output_log,
|
||||
"result": "success"
|
||||
})
|
||||
|
||||
# Remove from queue
|
||||
queue_col.delete_one({"_id": job["_id"]})
|
||||
else:
|
||||
print("FAILED:", clean_name)
|
||||
failed_col.insert_one({
|
||||
"filename": filename,
|
||||
"url": url,
|
||||
"failed_at": datetime.utcnow(),
|
||||
"output_log": output_log,
|
||||
"return_code": proc.returncode
|
||||
})
|
||||
|
||||
# Remove or mark as failed
|
||||
queue_col.delete_one({"_id": job["_id"]})
|
||||
|
||||
except Exception as e:
|
||||
|
||||
failed_col.insert_one({
|
||||
"filename": filename,
|
||||
"url": url,
|
||||
"failed_at": datetime.utcnow(),
|
||||
"output_log": str(e),
|
||||
"exception": True
|
||||
})
|
||||
|
||||
queue_col.delete_one({"_id": job["_id"]})
|
||||
|
||||
|
||||
# ========================
|
||||
# MAIN LOOP
|
||||
# ========================
|
||||
|
||||
def main():
|
||||
print("Worker started. Watching queue...")
|
||||
|
||||
while True:
|
||||
job = queue_col.find_one_and_update(
|
||||
{},
|
||||
{"$set": {"processing": True}},
|
||||
sort=[("created_at", 1)]
|
||||
)
|
||||
|
||||
if job:
|
||||
run_job(job)
|
||||
else:
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Binary file not shown.
Reference in new issue
Block a user