Skip to content

video_dl: skip download if video exceeds 500MB#146

Merged
psykzz merged 1 commit into
mainfrom
copilot/check-file-size-before-download
Apr 30, 2026
Merged

video_dl: skip download if video exceeds 500MB#146
psykzz merged 1 commit into
mainfrom
copilot/check-file-size-before-download

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

Previously, oversized videos were only detected after a full download completed. This adds a pre-flight size check using yt-dlp metadata to abort before wasting bandwidth and disk I/O.

Changes

  • New constant MAX_DOWNLOAD_SIZE = 500 * 1024 * 1024 on the cog class
  • Pre-download probe in _download_video(): calls extract_info(download=False) and checks filesize / filesize_approx against the limit before starting the actual download
  • Fail-open on probe errors — if metadata fetch fails, a warning is logged and the download proceeds as before
  • Explicit is not None guard rather than truthiness check, so a reported size of 0 doesn't bypass the limit
probe_info = ydl.extract_info(url, download=False)
file_size_estimate = probe_info.get('filesize') or probe_info.get('filesize_approx')
if file_size_estimate is not None and file_size_estimate > self.MAX_DOWNLOAD_SIZE:
    return False, None, f"Video is too large ({size_mb:.1f}MB). Maximum allowed size is {max_mb:.0f}MB."

The error propagates through the existing flow: silent in on_message, surfaced as a reply in the /download command.

@psykzz psykzz marked this pull request as ready for review April 30, 2026 20:44
@psykzz psykzz merged commit ea9d43e into main Apr 30, 2026
3 checks passed
@psykzz psykzz deleted the copilot/check-file-size-before-download branch April 30, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants