diff --git a/cloud/autopilot.py b/cloud/autopilot.py index 06cc559..0b515ce 100644 --- a/cloud/autopilot.py +++ b/cloud/autopilot.py @@ -261,6 +261,25 @@ async def fetch_social_accounts(profile: str) -> dict: return out +async def is_youtube_private(video_id: str) -> bool: + """True when the video is private on YouTube. + + oEmbed answers 401/403 for a private video and 200 for a public or + unlisted one. It has to run BEFORE is_youtube_short: /shorts/ of a + private video also answers 200, so a private upload read as "already a + short". A private video cannot be clipped at all: yt-dlp gets "Private + video", and the YouTube Data API behind Upload-Post lists the owner's + uploads but never serves the media file. + """ + try: + async with httpx.AsyncClient(timeout=10) as client: + resp = await client.get("https://www.youtube.com/oembed", params={ + "url": f"https://www.youtube.com/watch?v={video_id}", "format": "json"}) + return resp.status_code in (401, 403) + except Exception: + return False + + async def is_youtube_short(video_id: str) -> bool: """True when YouTube serves this id as a Short. @@ -450,6 +469,16 @@ async def _start_video(user, video: dict, trigger: str, max_minutes: int) -> dic run_id = await _claim(user.id, video, trigger) if run_id is None: return {"status": "duplicate", "reason": "already_picked", "job_id": None} + if await is_youtube_private(video["id"]): + if trigger != "manual": + # Scheduled uploads are often private until they go live: let the + # next poll pick the video up again instead of skipping it for good. + async with database.session() as s: + async with s.begin(): + await s.execute(delete(AutopilotRun).where(AutopilotRun.id == run_id)) + return {"status": SKIPPED, "reason": "private_video", "job_id": None} + await _update_run(run_id, status=SKIPPED, reason="private_video") + return {"status": SKIPPED, "reason": "private_video", "job_id": None} if await is_youtube_short(video["id"]): await _update_run(run_id, status=SKIPPED, reason="youtube_short") return {"status": SKIPPED, "reason": "youtube_short", "job_id": None} @@ -738,13 +767,12 @@ async def put_autopilot(payload: AutopilotUpdate, request: Request): max_minutes=DEFAULT_MAX_MINUTES, publish_hour=DEFAULT_PUBLISH_HOUR) s.add(prefs) - if payload.rights_ack: + # Connecting the channel through YouTube's own OAuth already proves it + # is theirs, so switching Autopilot on records the attestation + # instead of asking for a checkbox. + if payload.rights_ack or turning_on: prefs.rights_ack_at = prefs.rights_ack_at or datetime.now(timezone.utc) if turning_on: - if not prefs.rights_ack_at: - raise HTTPException(status_code=400, detail={ - "error": "rights_ack_required", - "message": "Confirm you own the content of this channel first."}) if not prefs.enabled: # New baseline: only videos published from now on. prefs.enabled_at = datetime.now(timezone.utc) @@ -812,10 +840,6 @@ async def run_now(payload: ManualRun, request: Request): "error": "plan_required", "message": "Autopilot is included in the Starter, Creator and Pro plans."}) prefs = await _get_settings(user.id) - if not prefs or not prefs.rights_ack_at: - raise HTTPException(status_code=400, detail={ - "error": "rights_ack_required", - "message": "Confirm you own the content of this channel first."}) now = datetime.now(timezone.utc) if await _count_recent(user.id, "manual", now - timedelta(days=1)) >= MANUAL_DAILY_LIMIT: raise HTTPException(status_code=429, detail="Daily limit reached. Try again tomorrow.") @@ -838,7 +862,8 @@ async def run_now(payload: ManualRun, request: Request): AutopilotRun.user_id == user.id, AutopilotRun.video_id == payload.video_id, AutopilotRun.status.in_((FAILED, SKIPPED)))) - result = await _start_video(user, video, "manual", prefs.max_minutes or DEFAULT_MAX_MINUTES) + result = await _start_video(user, video, "manual", + (prefs.max_minutes if prefs else None) or DEFAULT_MAX_MINUTES) if result["status"] == "duplicate": raise HTTPException(status_code=409, detail="This video was already clipped by Autopilot.") if result.get("retry") or result["status"] == QUEUED: diff --git a/dashboard/src/components/AutopilotTab.jsx b/dashboard/src/components/AutopilotTab.jsx index 965100a..3c387d0 100644 --- a/dashboard/src/components/AutopilotTab.jsx +++ b/dashboard/src/components/AutopilotTab.jsx @@ -23,6 +23,7 @@ const ERROR_TEXT = { const REASON_TEXT = { youtube_short: 'already a short', + private_video: 'private on YouTube — set it to Unlisted to clip it', out_of_minutes: 'out of minutes', too_short: 'too short to clip', unavailable: 'not available yet (private or processing)', @@ -90,7 +91,6 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected } const [videosError, setVideosError] = useState(null); const [loadError, setLoadError] = useState(''); const [saving, setSaving] = useState(false); - const [rightsAck, setRightsAck] = useState(false); const [running, setRunning] = useState(null); // video id being submitted const [notice, setNotice] = useState(''); // Feedback for "clip it", shown next to the list: the page-level notice sits @@ -164,16 +164,12 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected } }, []); const toggleEnabled = useCallback(async (on) => { - if (on && !data?.settings?.rights_ack && !rightsAck) { - setNotice('Confirm you own the content of this channel to switch Autopilot on.'); - return; - } const s = await save(on ? { enabled: true, rights_ack: true } : { enabled: false }); if (s) { track(on ? 'AutopilotEnabled' : 'AutopilotDisabled', { props: { autopublish: String(!!s.autopublish) } }); setNotice(on ? 'Autopilot is on. Your next video will be clipped automatically.' : 'Autopilot paused.'); } - }, [data, rightsAck, save]); + }, [save]); const togglePlatform = useCallback((p) => { const cur = data?.settings?.publish_platforms || []; @@ -182,14 +178,9 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected } }, [data, save]); const runNow = useCallback(async (video) => { - if (!data?.settings?.rights_ack && !rightsAck) { - setListNotice('Tick “I own the content…” just above the list first, then clip it again.'); - return; - } setRunning(video.id); setListNotice(''); try { - if (!data?.settings?.rights_ack) await save({ rights_ack: true }); const r = await apiJson('/api/autopilot/run', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -205,7 +196,7 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected } setRunning(null); load(); } - }, [data, rightsAck, save, load]); + }, [load]); const openProject = useCallback(async (jobId) => { if (!onOpenProject || opening) return; @@ -309,18 +300,6 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected } /> - {!s.rights_ack && ( - - )} - {errorText && (

{errorText}

)} @@ -433,18 +412,6 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected } - - {!s.rights_ack && ( - - )} {listNotice && (
{listNotice}
)} diff --git a/main.py b/main.py index 7997931..7e5a022 100644 --- a/main.py +++ b/main.py @@ -802,6 +802,17 @@ def cap_source_duration(input_video, max_minutes, safety=False): raise RuntimeError(f"could not cut the source to its first {float(max_minutes):g} minutes") +def _content_block(error_text): + """User-facing reason when the VIDEO (not the network) can't be fetched.""" + t = error_text.lower() + if "private video" in t: + return ("This video is private on YouTube. Set it to Unlisted (or Public) " + "and try again, or upload the file instead.") + if "members-only" in t or "join this channel" in t: + return "This video is for channel members only. Upload the file instead." + return None + + def download_youtube_video(url, output_dir=".", on_audio=None): """ Downloads a YouTube video using yt-dlp. @@ -1087,6 +1098,14 @@ def download_youtube_video(url, output_dir=".", on_audio=None): time.sleep(3) if sanitized_title is not None: break + # The video itself is off limits: another route (or the paid proxy) + # cannot change that, so stop instead of spending every attempt. + if last_err is not None and _content_block(str(last_err)): + break + + if sanitized_title is None and last_err is not None and _content_block(str(last_err)): + print(f"❌ {_content_block(str(last_err))}") + raise last_err if sanitized_title is None: import sys