@cupcakezealot@piefed.blahaj.zone
Post #2176234
2026-02-23 15:31 UTC
this isn't perfect but i made one when i wanted to fetch a video for a specific resolution (because i prefer 480)
```bash
ytgrab() {
local id="$1"
local res="${2:-480}" # default to 480
local url="https://www.youtube.com/watch?v=%24id"
# fetch formats
local fmt
fmt=$(yt-dlp -F --cookies-from-browser vivaldi "$url")
# printing the format output
echo "$fmt"
# pick video format matching the requested resolution
local vfmt
vfmt=$(echo "$fmt" | awk -v r="${res}p" '$0 ~ r && /video/ {print $1}' | head -n1)
# pick best m4a audio
local afmt
afmt=$(echo "$fmt" | awk '/m4a/ && /audio/ {print $1}' | head -n1)
# safety check
if [ -z "$vfmt" ] || [ -z "$afmt" ]; then
echo "Could not find matching formats (video ${res}p or m4a audio)."
return 1
fi
echo fetching: yt-dlp -f ${vfmt}+${afmt} --cookies-from-browser vivaldi --write-subs --no-write-auto-subs --sub-lang "en.*" $url
yt-dlp -f "${vfmt}+${afmt}" --write-subs --cookies-from-browser vivaldi --no-write-auto-subs --sub-lang "en.*" "$url"
}
```
Replies (1)
-
@ExperimentalGuy@programming.dev 2026-02-23 19:32
Just curious, but why 480?