To address your specific question about xargs
, you need to specify that you want to use the {}
placeholder:
youtube-dl --get-title "Youtube URI" |\
xargs -I{} youtube-dl -o {} "Youtube URI"
See man xargs
for more info, and what switches are also implied by -I
.
Since it's only a single argument, it would be more straightforward to use substitution:
youtube-dl -o "$(youtube-dl --get-title "Youtube URI")" "Youtube URI"
Note that these constructions will give you a file without appropriate file extension.
The most straightforward way to accomplish your actual task would as mentioned be to use the built-in title naming option:
youtube-dl -t "Youtube URI"
as described in man youtube-dl
. This will also produce the correct file extension for the video file.
Xargs can't deal with spaces ' and " unless you pass the -0 flag. Also, I don't know youtube-dl, but maybe it doesn't take standard input, so xargs would be useless. – Bruno9779 – 2012-06-11T23:35:49.363
@Bruno9779 - What do you mean by space ' and "? How would I know whether an application like youtube-dl takes standard input? – PeanutsMonkey – 2012-06-11T23:54:06.187
I mean the space character, quotes and double quotes. Read the man pages of xargs for more on that and stdi/o (I don't want to paste all that here). It looks like youtube-dl takes only URLs as stdin, so your command can't work IMO. Still, try with a -0 flag after xargs first, you never know – Bruno9779 – 2012-06-12T00:56:27.483
@Bruno9779:
-0
would produce a file name with the ending newline character in it, which is allowed, but often annoying. If no other delimiter is given with-d
,xargs
defaults to\n
("newline") which is appropriate in this case. – Daniel Andersson – 2012-06-12T07:06:17.320