How to bulk download videos and rename them simultaneously using youtube-dl?

5,968

If you are only renaming files because you don't like the style by which youtube-dl names them, then you can use --output (or -o) with a template to customize the way it names all the files from Youtube metadata.

For example, -o %(title)s.%(ext)s will cause it to leave out the Youtube IDs from all of the filenames.

There are a lot of options, which may depend on your version of youtube-dl, so full details on this can be found at the terminal by typing:

man youtube-dl
/OUTPUT

However if you do want to name each file individually, you could instead run youtube-dl once for each line in the text file like this:

(while read URL NAME; do [ "$URL" ] && youtube-dl --format mp4 -o "$NAME" "$URL"; done) < data.txt

For each line, split it at the first run of one or more tabs and spaces into a URL and NAME, then if the line is not blank, pass them to youtube-dl. If the line just has a URL, the file will not be renamed.

Share:
5,968

Related videos on Youtube

ddas
Author by

ddas

Updated on September 18, 2022

Comments

  • ddas
    ddas over 1 year

    I am using Ubuntu 16.04 LTS. I want to download some YouTube videos. I came to know about the command line tool youtube-dl from this question. As mentioned by Yasser, using the command,

    youtube-dl youtube.com/videolink --format mp4
    

    I am able to download those video files in mp4 format.

    Now I want to download ten videos from different channels. I have a text file with the YouTube links and the names by which I want to save them. The text file with name data.txt looks like,

    http://youtube.com/link1    name1
    http://youtube.com/link2    name2
    http://youtube.com/link3    name3 
    .........                   ......
    .........                   ......
    http://youtube.com/link10    name10
    

    Now I want to run the youtube-dl command only once so that it takes the arguments from that text file automatically and save them with the required names.

    If I have only the links in data.txt, i.e.,

    http://youtube.com/link1
    http://youtube.com/link2
    http://youtube.com/link3 
    .........
    .........
    http://youtube.com/link10
    

    I am able to download the videos using the command only once with option -a,

    youtube-dl --format mp4 -a data.txt
    

    But I could not rename them simultaneously. From man page of youtube-dl I found that there is an option --output to set the filename.

    How could I do that?

    • Noosrep
      Noosrep about 7 years
      Can't you just place every url one after another? Like youtube-dl youtube.com/videolink youtube.com/videolink2 youtube.com/videolink3
    • M. Becerra
      M. Becerra about 7 years
      It's manpage reads: SYNOPSIS: youtube-dl [OPTIONS] URL [URL...], so yes, it should be possible to simple write one after the other.
    • M. Becerra
      M. Becerra about 7 years
      Im writing a script to accomplish what you asked, do you want to be able to set the location where the file is gonna be stored?
    • ddas
      ddas about 7 years
      Yes. It would be nice to set the location.
    • ddas
      ddas about 7 years
      @Becerra, do you have any positive news?
    • karel
      karel about 7 years
      My youtube-dl rename script is posted in this answer: askubuntu.com/questions/857989/… if you want to customize the rename part for your situation. The rename part of the script is this string: 'y/A-Z/a-z/'