Files
a897905955 fix "time in zone" demo and make it use RF-DETR (#1922)
* migrate YT video file download script to use `yt_dlp`; old script didn't work anymore
* RF-DETR file example works
* ultralytics stream example migrated to new inference
* migrate inference scripts to use RF-DETR-Medium
* RF-DETR naive stream example
* RF-DETR stream example
* updated README.md

* fix(pre_commit): 🎨 auto format pre-commit hooks

* Migrate `time_in_zone` examples to use `jsonargparse` and update `--classes` argument format to accept lists
* Add licensing details for `ultralytics` and `supervision` in `README.md`

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: jirka <6035284+Borda@users.noreply.github.com>
2026-02-03 15:57:36 +01:00

64 lines
1.9 KiB
Python

from __future__ import annotations
import os
import sys
from typing import Any
import yt_dlp
from jsonargparse import auto_cli
from yt_dlp.utils import DownloadError
def _build_ydl_opts(output_path: str | None, file_name: str | None) -> dict[str, Any]:
out_dir = output_path or "."
if not os.path.exists(out_dir):
os.makedirs(out_dir)
name_template = file_name if file_name else "%(title)s.%(ext)s"
return {
"format": (
"bestvideo[ext=mp4][vcodec!*=av01][height<=2160]+bestaudio[ext=m4a]/"
"best[ext=mp4][vcodec!*=av01][height<=2160]/"
"bestvideo+bestaudio/best"
),
"merge_output_format": "mp4",
"outtmpl": os.path.join(out_dir, name_template),
"quiet": False,
"noplaylist": True,
}
def main(
url: str, output_path: str = "data/source", file_name: str = "video.mp4"
) -> None:
"""
Download a specific YouTube video by providing its URL.
Args:
url: The full URL of the YouTube video you wish to download.
output_path: Specifies the directory where the video will be saved.
file_name: Sets the name of the saved video file.
"""
# ssl._create_default_https_context = ssl._create_unverified_context
ydl_opts = _build_ydl_opts(output_path, file_name)
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
except DownloadError as err:
print(f"Download failed: {err}", file=sys.stderr)
sys.exit(1)
final_name = file_name if file_name else "the video title"
final_path = output_path if output_path else "current directory"
print(f"Download completed! Video saved as '{final_name}' in '{final_path}'.")
if __name__ == "__main__":
from jsonargparse import auto_cli, set_parsing_settings
set_parsing_settings(parse_optionals_as_positionals=True)
auto_cli(main, as_positional=False)