fix(autopilot): no ownership checkbox; private videos said as such

- The connected channel (YouTube's own OAuth) is the proof the content is
  the user's: the "I own the content" checkbox is gone, and switching
  Autopilot on records rights_ack_at by itself. "Clip it" no longer
  requires it either.
- Private videos read as "already a short": /shorts/<id> answers 200 for
  them too. is_youtube_private (oEmbed 401/403) runs first; a manual clip
  says "private on YouTube, set it to Unlisted", and the automatic poll
  leaves the video unclaimed so it is picked up once it goes public
  (scheduled uploads are private until then). They cannot be clipped:
  the YouTube Data API lists the owner's uploads but never serves the file.
- A pasted private video stops downloading as soon as yt-dlp says so
  (before the per-GB proxy) and tells the user why, instead of "YouTube
  blocked the request".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
victorcavero14 2026-09-26 01:51:08 +02:00
parent c26178776f
commit a9818832b3
3 changed files with 57 additions and 46 deletions

View file

@ -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/<id> 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:

View file

@ -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 }
/>
</div>
{!s.rights_ack && (
<label className="flex items-start gap-3 mt-5 text-sm text-ink2 cursor-pointer">
<input
type="checkbox"
checked={rightsAck}
onChange={(e) => setRightsAck(e.target.checked)}
className="mt-0.5 accent-[var(--color-accent)]"
/>
<span>I own the content published on this channel, or have the rights to process it.</span>
</label>
)}
{errorText && (
<p className="text-warn text-sm mt-4 flex items-center gap-2"><AlertTriangle size={14} /> {errorText}</p>
)}
@ -433,18 +412,6 @@ export default function AutopilotTab({ onOpenProject, onUpgrade, justConnected }
</div>
<button onClick={load} className="btn-quiet text-xs" aria-label="refresh"><RefreshCw size={13} /> refresh</button>
</div>
{!s.rights_ack && (
<label className="flex items-start gap-3 mb-4 text-sm text-ink2 cursor-pointer">
<input
type="checkbox"
checked={rightsAck}
onChange={(e) => { setRightsAck(e.target.checked); setListNotice(''); }}
className="mt-0.5 accent-[var(--color-accent)]"
/>
<span>I own the content published on this channel, or have the rights to process it.</span>
</label>
)}
{listNotice && (
<div className="mb-4 rounded-card border border-brass/40 bg-brass/5 px-4 py-3 text-sm text-ink2" role="status">{listNotice}</div>
)}

19
main.py
View file

@ -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