Mayank Mittal Mayank Mittal - 11 months ago 59
Linux Question

Add id to the downloaded youtube playlist

I've downloaded a youtube playlist with youtube-dl is there any way i can rename the files i've downloaded to the appended id of the file in playlist.
e.g. now - xyz.mp4, abc.mkv,
want - 1 - xyz.mp4, 2 - abc.mkv(which is according to the number in the youtube playlist)


If the files are sortable by date (check if the following produces the right output):

i=1; ls -1trd * | while read -r filename; do echo $i' - '"$filename"; i="$(( i + 1 ))"; done

Then this will rename them. NO UNDO FUNCTION FOR THIS

i=1; ls -1trd * | while read -r filename; do mv -vb "$filename" $i' - '"$filename"; i="$(( i + 1 ))"; done