fix(downloads): E11.5 epic-end review round 1
A refused Facebook cookie on a group post is no longer "no video in this post":
measured on dev, Facebook answers with its login page (no post id at all), so the
adapter now raises its own POST_NOT_SHOWN verdict and the catalog explains it as
the refused cookie. The adapter owns both post verdicts and the "cannot parse
data" wall wording, so the Chrome retry and the catalog read one constant. The
group-post "no formats" entry is cookie-scoped (with a cookie yt-dlp only gets the
post's video link) and uses the adapter's own group-post test instead of a
"/groups/" substring.
Job transitions that move an asset's ref count (resume, cancel, delete,
redownload) re-read the job under a row lock, asset first, so two overlapping
requests can no longer release the same hold. get_or_create_asset loses an insert
race inside a SAVEPOINT instead of rolling back the caller's pending writes (Retry
lost its cleared error). Every worker-side job failure goes through
finalize_if_running and writes error_detail, so a cancel that landed first is kept
and a failure never shows an earlier one's copy. The worker asks the download
child's own cookie gate (credentials.usable_cookie) when a job inherits a failed
asset.
UI: the Facebook copy no longer points at a Retry button the failure window does
not have, says "paste" like Settings, and the HU wording is fixed
("Újraletöltés" on the re-download confirm). A category this client has no copy
for falls back to the generic sentence instead of a raw key.
Tests: route serialization of error_detail, the probed duration through a real
_download, the page-read cap and a failed read, a Retry off a pending asset, the
confirm-button labels, the lock and savepoint races.
This commit is contained in:
@@ -15,6 +15,7 @@ page holds ~10 other videos), and its watch link downloads.
|
||||
|
||||
import pytest
|
||||
import yt_dlp
|
||||
from yt_dlp.networking.exceptions import TransportError
|
||||
from yt_dlp.networking.impersonate import ImpersonateTarget
|
||||
|
||||
from app.downloads import adapters, pipeline
|
||||
@@ -59,10 +60,11 @@ def test_the_locked_curl_cffi_can_impersonate_chrome():
|
||||
@pytest.fixture
|
||||
def ydl(monkeypatch):
|
||||
"""Fake `yt_dlp.YoutubeDL`: records each attempt's options and plays back `outcomes` in order;
|
||||
`web["page"]` is what a page read returns, and `web` records the pages opened and links extracted."""
|
||||
`web["page"]` is what a page read returns (`web["fail"]`, when set, is raised instead), and `web`
|
||||
records the pages opened, the byte cap each read asked for, and the links extracted."""
|
||||
seen: list[dict] = []
|
||||
outcomes: list = []
|
||||
web: dict = {"page": "", "opened": [], "extracted": []}
|
||||
web: dict = {"page": "", "fail": None, "opened": [], "reads": [], "extracted": []}
|
||||
|
||||
class FakeYDL:
|
||||
def __init__(self, opts):
|
||||
@@ -76,10 +78,13 @@ def ydl(monkeypatch):
|
||||
|
||||
def urlopen(self, url):
|
||||
web["opened"].append(url)
|
||||
if web["fail"] is not None:
|
||||
raise web["fail"]
|
||||
body = web["page"].encode()
|
||||
|
||||
class Response:
|
||||
def read(self, amt=None):
|
||||
web["reads"].append(amt)
|
||||
return body
|
||||
|
||||
return Response()
|
||||
@@ -145,6 +150,8 @@ def test_a_cookie_group_post_downloads_the_posts_own_video(ydl, tmp_path):
|
||||
assert _run(tmp_path, "/cookies.txt", _GROUP_LINK) == {"id": _POST_VIDEO}
|
||||
|
||||
assert web["opened"] == [_GROUP_LINK]
|
||||
# Never an unbounded read.
|
||||
assert web["reads"] == [adapters.FacebookAdapter._POST_PAGE_MAX_BYTES]
|
||||
assert seen[0]["cookiefile"] == "/cookies.txt" # the post page is read signed in
|
||||
watch = f"https://www.facebook.com/watch/?v={_POST_VIDEO}"
|
||||
# Never the post link: that is where the feed video comes from.
|
||||
@@ -166,6 +173,37 @@ def test_a_group_post_without_a_single_video_fails_saying_so(ydl, tmp_path):
|
||||
)
|
||||
|
||||
|
||||
def test_a_group_post_page_without_the_post_is_the_refused_cookie(ydl, tmp_path):
|
||||
# Measured with a refused cookie (E11.5 review): Facebook answers the post link with its login page —
|
||||
# a login form, no post id anywhere. Saying "this post has no video" would blame the post.
|
||||
_, _, web = ydl
|
||||
web["page"] = '<html><title>ChatGPT magyarul</title><form id="login_form"></form></html>'
|
||||
|
||||
with pytest.raises(RuntimeError) as exc:
|
||||
_run(tmp_path, "/cookies.txt", _GROUP_LINK)
|
||||
|
||||
assert web["extracted"] == []
|
||||
assert dlerrors.diagnose(str(exc.value), url=_GROUP_LINK, cookie_attached=True) == (
|
||||
"login_required",
|
||||
"facebook.cookie_rejected",
|
||||
)
|
||||
|
||||
|
||||
def test_a_failed_post_page_read_fails_the_download_as_itself(ydl, tmp_path):
|
||||
# A read that failed says nothing about the post: it must not turn into "no video in this post".
|
||||
_, _, web = ydl
|
||||
web["fail"] = TransportError("Connection reset by peer")
|
||||
|
||||
with pytest.raises(TransportError) as exc:
|
||||
_run(tmp_path, "/cookies.txt", _GROUP_LINK)
|
||||
|
||||
assert web["extracted"] == []
|
||||
assert dlerrors.diagnose(str(exc.value), url=_GROUP_LINK, cookie_attached=True) == (
|
||||
"network",
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def test_without_a_cookie_the_group_post_link_goes_to_ytdlp_unchanged(ydl, tmp_path):
|
||||
_, outcomes, web = ydl
|
||||
outcomes += [_NO_FORMATS]
|
||||
|
||||
Reference in New Issue
Block a user