#!/usr/bin/env bash # A yt-dlp stand-in for load tests. It never touches the network. Every URL # is its own video (the ID is a checksum of the URL), so the cache only # helps where the load test asks for the same link twice. # # LOAD_SIZE bytes per file (default 2000000) # LOAD_TIME seconds per download (default 2) # LOAD_PROBE seconds per lookup (default 0.2) set -u args=("$@") dir="" probe=0 url="${args[$((${#args[@]} - 1))]}" for ((i = 0; i < ${#args[@]}; i++)); do case "${args[$i]}" in -P) dir="${args[$((i + 1))]}" ;; -J) probe=1 ;; --version) echo "2026.10.26"; exit 0 ;; -U|--update) echo "yt-dlp is up to date"; exit 0 ;; esac done id=$(printf '%s' "$url" | cksum | cut -d' ' -f1) size=${LOAD_SIZE:-2000000} if [[ $probe -eq 1 ]]; then sleep "${LOAD_PROBE:-0.2}" echo '{"id": "v'"$id"'", "title": "Load test '"$id"'", "extractor": "loadtest", "extractor_key": "Loadtest", "webpage_url": "'"$url"'", "duration": 60, "uploader": "Load", "is_live": false, "formats": [{"format_id": "a", "ext": "m4a", "vcodec": "none", "acodec": "mp4a.40.2", "filesize": '"$((size / 4))"'}, {"format_id": "v", "ext": "mp4", "vcodec": "avc1", "acodec": "mp4a.40.2", "height": 720, "width": 1280, "filesize": '"$size"'}]}' exit 0 fi echo 'INFO|{"id": "v'"$id"'", "title": "Load test '"$id"'", "duration": 60, "extractor": "loadtest", "extractor_key": "Loadtest", "uploader": "Load", "is_live": false}' echo "[download] Destination: $dir/media.mp4" steps=4 for ((s = 1; s <= steps; s++)); do sleep "$(awk "BEGIN{print ${LOAD_TIME:-2}/$steps}")" echo "DLP|downloading|$((size * s / steps))|$size|NA" done echo "DLP|finished|$size|$size|NA" head -c "$size" /dev/zero > "$dir/media.mp4" echo 'RESULT|{"width": 1280, "height": 720, "duration": 60, "ext": "mp4", "filepath": "'"$dir/media.mp4"'"}'