Files
VoiceStudio/tests/test_dub_download_mtime.py
T
6819feb8b2 fix(dub): skip yt-dlp mtime stamp to avoid [Errno 22] on Windows (#642) (#644)
Dubbing a URL could fail with 'Unable to download video: [Errno 22] Invalid
argument' on Windows: yt-dlp stamps the downloaded file's mtime with the video's
upload date, and an out-of-range/invalid timestamp makes os.utime raise
[Errno 22], aborting the ingest. We download to a throwaway original.* and never
use its mtime, so set updatetime=False (yt-dlp --no-mtime). Regression test
asserts the opt is set. No version bump.

Co-authored-by: mergetest <test@local>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 11:53:44 +05:30

47 lines
1.3 KiB
Python

"""yt-dlp must not stamp the download's mtime (#642).
On Windows, yt-dlp stamping the temp file with the video's upload date can raise
`[Errno 22] Invalid argument` from os.utime on an out-of-range timestamp, failing
the whole URL ingest. We download to a throwaway file and never use its mtime, so
`updatetime` must be False.
"""
import os
import sys
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "backend"))
from services import dub_pipeline # noqa: E402
def test_download_opts_disable_mtime(tmp_path, monkeypatch):
import yt_dlp
captured = {}
class _FakeYDL:
def __init__(self, opts):
captured.update(opts)
def __enter__(self):
return self
def __exit__(self, *a):
return False
def extract_info(self, url, download=True):
raise RuntimeError("stop after capturing opts")
def prepare_filename(self, info):
return "unused"
monkeypatch.setattr(yt_dlp, "YoutubeDL", _FakeYDL)
with pytest.raises(Exception):
dub_pipeline.yt_download_sync("https://youtu.be/abc", str(tmp_path))
assert captured.get("updatetime") is False, (
"yt-dlp must set updatetime=False so a bad upload-date timestamp can't "
"raise [Errno 22] on Windows (#642)"
)