4 ms·
below is (edited for hn) the script i use instead of youtube-dl. the ffmpeg option is added; need to test it. this script works with all non-commercial videos,
by 1vuio0pswjnm7 5y ago
below is (edited for hn) the script i use instead of youtube-dl.
the ffmpeg option is added; need to test it.
this script works with all non-commercial videos, like the one in the parent comment.
for commercial videos that restrict downloads, a browser with limited DNS and request blocking or youtube-dl or
a headless browser will work.
if use m.youtube.com with minimum headers then should always get mp4 urls with 1-2 quality options: itag=18 or itag=22.
run the script with no arguments to see what quality options are available.
then run it again with 1 argument to download or
run it with 3 arguments to download an excerpt.
if script is called "yt" usage is
echo https://www.youtube.com/watch?v=Qf2tplcb6eE |yt
echo https://www.youtube.com/watch?v=Qf2tplcb6eE |yt 22
echo https://www.youtube.com/watch?v=Qf2tplcb6eE |yt 22 00:15:34 00:16:09
x3(){ # youtube url variations, adjust as needed
sed '
/youtube.googleapis.com/{s//www.youtube.com/;s>/v/>/watch?v=>;};
s/youtu\.be./www.youtube.com\/watch?v=/;
s/embed./watch?v=/;s/&.*//;
';};
case $# in :)
;;0)
x3|(read x;curl -LHUser-Agent: -sv4 "$x"|grep -o "https://r[^\"]*"|sed 's/\\u0026/\&/g;s/%3D/=/g;s/%2C/,/g;s/%2F/\//g') >.yt;
grep -o "itag=[^&%]*" .yt||exec echo video removed;
exit
;;1)
x1=$(x3|sed 's/.*watch?v=//;s/[&%].*//')
x2=$(sed -n "/itag=$1/p" .yt)
esac;
test "${x1}"||exit;
case $# in :)
;;1) exec curl -LHUser-Agent: -sv4Ro "${x1}".mp4 "${x2}"
;;3) exec ffmpeg -ss $2 -to $3 -i "${x2}" -vf "crop=(iw*0.75):(ih*0.80):(iw*0.20):(ih*0.08)" "${x1}".mp4
esac
- 1vuio0pswjnm7 5y agodont forget about cookies. disable them, block them or scrub them with a forward proxy. note the googlevideo.com domain does not serve cookies, only video. theres no video on youtube.com. plenty of javascript and telemetry, though.
- 1vuio0pswjnm7 5y agoCorrection x3|(read x;curl -LHUser-Agent: -sv4 "$x"|grep -o "https://r[^\"]*"|sed 's/%26/\&/g;s/%25/%/g;s/%3F/?/g;s/\\u0026/\&/g;s/%3D/=/g;s/%2C/,/g;s/%2F/\//g') >.yt;
- 1vuio0pswjnm7 5y agox3|(read x;curl -LHUser-Agent: -sv4 "$x"|grep -o "https://r[^\"]*"|sed 's/%26/\&/g;s/%25/%/g;s/%3F/?/g;s/\\u0026/\&/g;s/%2C/,/g;s/%2F/\//g') >.yt;