I would love to see the shellscript equivalent! :))
alias yt='youtube-dl --recode-video mp4'
On my system I have a funky python setup so I need to use this instead: alias yt='unset PYTHONPATH; youtube-dl --recode-video mp4'
I don't see the need for interactivity because the only format I ever want is mp4.For audio, I would just do a separate alias with a different name. For example (edit: tested):
alias yta='youtube-dl --extract-audio --audio-format mp3'
Invoke each with the URL. For example:Video:
yt https://www.youtube.com/watch?v=IFe9wiDfb0E
Audio: yta https://www.youtube.com/watch?v=qKS8KsTC4IU
If a youtube URL has extra parameters separated by &, delete those before invoking. For example the URL below, which has extra parameters because it came from a playlist: https://www.youtube.com/watch?v=7uQuX1sOYk4&list=PLYq_mcte9NvDA2Xi5Qjl1DrH5LuDKDlAI
should be changed to this before using it to attempt a download: https://www.youtube.com/watch?v=7uQuX1sOYk4
Or you can use the full original URL but you need to protect it from interpretation by UNIX by surrounding it with single quotes when invoking. yta 'https://www.youtube.com/watch?v=7uQuX1sOYk4&list=PLYq_mcte9NvDA2Xi5Qjl1DrH5LuDKDlAI'Then this tool isn't for you. If you're gonna skip the whole point of the tool, you can't claim your code suggestions are equivalent.
f=/tmp/youtube-urls;sed 's/^/url=/'|exec curl -K-|exec grep -o "https%3A%2F%2Fr[0-9][a-zA-Z0-9.%_-]*"|exec sed -n 's/%26/\&/g;s/%3D/=/g;s/%3A/:/g;s/%2F/\//g;s/%3F/?/g;s/%25/%/g;w'"$f"'';case $1 in --help|-help|-h|-?)exec echo usage: echo youtube-url\|$0 \[fmt\] \[saveas\];;*) a=$(exec grep "itag=$1"\& $f 2>/dev/null);case ${#a} in 0) echo "the fmt (itag number \""$1"\") is not available. here are the available formats:";exec grep -o "itag=[0-9]*" $f;;*)exec curl -4o ${1-$c} $a;esac;esac
The idea of interactively selecting the format seems like it would become cumbersome after the user learns the formats, i.e., itag numbers, that she can play on her computer.Once she has that knowledge, she will just be looking for the same itag numbers every time, e.g., 18 or 22 are popular for mp4.