101

I have a Youtube playlist, I want to download it but I want youtube-dl to name the files like 1-{name}, 2-{name}, ... n-{name} in order to be able to watch them in the same sequence as original Youtube playlist. In other words I need my downloaded videos to be prefixed with numbers. How can I do that?

5 Answers5

154

The best solution I found is:

youtube-dl -o "%(playlist_index)s-%(title)s.%(ext)s" <playlist_link>
  • 1
    What is the difference between %(playlist_index)s and %(autonumber)s? – Flimm May 23 '18 at 14:11
  • 8
    @Flimm autonumber uses the number in your download queue, if you restart the download it will be reset. playlist_index uses index of video in playlist and is a better option if you want to stop and resume your download later. – Iman Mohamadi May 29 '18 at 05:30
  • Any idea on resolving when playlist index has been changed overtime? I already have alot of downloaded videos but their index is messed up. I don't wish to rename each one of them individually. –  Apr 28 '20 at 13:21
  • 6
    I would even go as far as: %(playlist_index)02d for playlists 10-99 items long. – Tomasz Gandor Sep 29 '21 at 13:53
  • @TomaszGandor Exactly what I was looking for! Though it do add 0 if more then 9 items, I want to have 0N for conformity :) – user3342816 Dec 21 '21 at 20:51
20

I think using

youtube-dl --auto-number url

will do it.

SarpSTA
  • 1,011
17

Use the -o option with playlist_index and the format <n>d like this:

youtube-dl -o "%(playlist_index)02d - %(title)s.%(ext)s" PLaPV8TkYEUV05rhlfVKXKqxvTkQ_3Tqek
#                               .
#                              /|\
#                               |
Nabil Kadimi
  • 2,212
10

Please use the below link to download playlist in numbers in increment at first followed by title of the content

youtube-dl -cio '%(autonumber)s-%(title)s.%(ext)s' 'Paste your playlist link'
Fabby
  • 34,259
3

excellent! but it leaves you with a file called 00001nameoffile
so run:

rename 's/000//g' *

afterwards
to get 01,02,03 etc
For this line below

youtube-dl -cio '%(autonumber)s-%(title)s.%(ext)s' 'Paste your playlist link'

or as one line:

youtube-dl -cio '%(autonumber)s-%(title)s.%(ext)s' url ; rename 's/000//g' *

shantiq
  • 567