Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the playlist index in reverse order using youtube-dl? [closed]

There's a playlist with 3012 videos. I want to download the first 100 videos of this playlist, which are actually the 100 most recent videos, so I want %(playlist_index)s to start from 3012 to 2913 instead of 1 to 100.

What I have now is just a basic shell script:

youtube-dl --yes-playlist "www.youtube.com/playlist?list=3xAMpLe_iD" -o "%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" --download-archive archive.txt

I'd like to keep track of the video order in reverse because the following week there might be 4 new videos then when I download those, the numbering should be 3016 to 3013 because it will come from the same playlist.

I have no experience with youtube-dl python scripts but you may answer as if I know the basics. Also, how can I get the --download-archive file named to the %(playlist)s value in the same script?

like image 853
ntruter42 Avatar asked Sep 07 '25 11:09

ntruter42


1 Answers

There are multiple ways to do this.

First addressing your reverse problem:
There is a parameter --playlist-reverse.
It will use list comprehension [::-1] to reverse. This will then download files in a reversed order.
However I am not sure how it's stored even if you use %(playlist_index)s.
It may start downloading with let's say 3012 but as this should be the index it will be stored as 3012 but I haven't tested that.
So you may want to use %(autonumber)s as it will number your tracks according to the queue order. Note it will start numbering from 1 then.
To avoid that you can specify the start number with --autonumber-start

Now to your second problem - starting at the right point.
There is --playlist-start.
But you have to tell explicitly where to start. In your case 3012.
There is --playlist-end.
Once again you have to specify it exactly. In your case 2913.
And ultimately there is --playlist-items which is likely what you looking for then.

So your command would look like this

youtube-dl --yes-playlist "www.youtube.com/playlist?list=3xAMpLe_iD" -o "%(playlist)s/%(autonumber)s - %(title)s.%(ext)s" --autonumber-start 3012 --playlist-items 100 --download-archive archive.txt
like image 147
Tom-Oliver Heidel Avatar answered Sep 10 '25 00:09

Tom-Oliver Heidel