School of Computing. Dublin City University.
Online coding site: Ancient Brain
There are lots of YouTube downloaders out there, but it is a good exercise to write one yourself from first principles. You may be surprised that one can be written in Shell.
youtube (url)For example:
<script> var ytplayer = ....
There are multiple URLs, and they are found like this:
... url=THEURL ...
THEURL contains googlevideo.com and is
The URLs are delimited by any or all of the following:
arg=`echo "$1" | sed "s|https://|http://|"`
wget -q -O - "$arg" > y.htm
N.B. When debugging the rest of the program, just work with y.htm without going to fetch the page from YouTube again.
(This is just in case large numbers of requests from this class to YouTube in a short time cause problems.)
When you have debugged the program, you can fix it so it fetches the page from Youtube again.
tr '"' '\n'
(Note: "\" has special meaning to sed so I "escaped" it.)
For the meaning of "^" see string matching / regular expressions.
I suggest this one:
#!/usr/bin/perl use URI::Escape; my $encodedurl = $ARGV; my $url = uri_unescape($encodedurl); print "$url\n";
read url newurl=`percentdecode "$url"` echo "$newurl"
This is the URL of the video.
The script can launch the player automatically:
vlc file &