[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: youtube video downloader for chrome



On Wed 20 Mar 2019 at 08:08:56 (-0400), Greg Wooledge wrote:
> On Wed, Mar 20, 2019 at 10:34:42AM +0100, Pierre Frenkiel wrote:
> > On Tue, 19 Mar 2019, riveravaldez wrote:
> > 
> > > Maybe worth mentioning: youtube-dl, exceptionally useful and simple CLI tool.
> > 
> >   useful and simple... but it works only for urls with alphanumeric characters
> >   I tried with an url containing ? and &, and I got nothing
> 
> You probably forgot to quote the URL in your shell command.  If you don't
> quote it, the & is special to the shell and will cause the command to
> be split at that point, with the first half being run as a background
> command, and the second half being run as a foreground command.
> 
> >   I tried also by escaping ? and & with \, and it was not better.
> >   I'll send you an example later, if you are not convinced...
> 
> That should work.  An example of the failure would be helpful.
> 
> Generally speaking, though, just wrap the whole URL in single quotes
> and you should be fine.

This is a trick I find very useful too: RightClick on a google hit,
type a, then paste the address into this function on an xterm:

function gy-in-quotes {
    [ -z "$1" ] && printf '%s\n' "Usage:	$FUNCNAME 'URL' (must be in single quotes!)
	strips the google prefix (up to url=) and suffix (from &usg=) from the argument,
	translates various common %nn sequences in the URL, and retrieves it." >&2 && return 1
    youtube-dl $(sed -e 's/http.*url=//;s/&usg=.*$//;s/%2F/\//g;s/%3A/:/g;s/%3D/=/g;s/%3F/?/g;s/%25/%/g' <<<"$1") # % characters must be edited last
}

The same idea works of course for wget:

function wg-in-quotes {
    [ -z "$1" ] && printf '%s\n' "Usage:	$FUNCNAME 'URL' (must be in single quotes!)
	strips the google prefix (up to url=) and suffix (from &usg=) from the argument,
	translates various common %nn sequences in the URL, and retrieves it." >&2 && return 1
    wget $(sed -e 's/http.*url=//;s/&usg=.*$//;s/%2F/\//g;s/%3A/:/g;s/%3D/=/g;s/%3F/?/g;s/%25/%/g' <<<"$1") # % characters must be edited last
}

Of course, I only type gy-<TAB> or wg-<TAB>, but the function name
reminds me to add the quotes, else all hell breaks loose.

Actually I don't call youtube-dl as above, because I have two helper
functions which do things like history logging to prevent me
accidentally downloading the same video twice.

Cheers,
David.


Reply to: