59

I was wondering if it was possible to download a youtube playlist as mp3 using youtube-dl, skipping already existing files. I am using this command:

youtube-dl --continue --ignore-errors --no-overwrites --extract-audio --audio-format mp3 --output "%(title)s.%(ext)s" [path here]

and, even though I set it to not overwrite, it does redownload everything from scratch. Is this possible?

2
  • even though it redownloads it usually skips writing the file by default even without that option set
    – mchid
    Sep 12, 2015 at 21:24
  • 1
    Ok, if I keep the downloaded video along with the mp3 file, the skipping function works properly. Not exactly what I needed but it is ok.
    – Warrior
    Sep 16, 2015 at 9:43

3 Answers 3

103

With the option --download-archive FILE youtube-dl both reads and adds to a list of files not to download again. Every time a file is successfully downloaded, that video id is added to FILE.

You can use it as follows:

youtube-dl --download-archive downloaded.txt --no-post-overwrites -ciwx --audio-format mp3 -o "%(title)s.%(ext)s" [path here]

It will redownload any videos from before that you didn't keep for one last time as it creates the list. You can now delete them.

If your MP3 files had been named with the default format of %(title)s-%(id)s.%(ext)s, you could have avoided the redownload by creating downloaded.txt from the youtube %(id)s in a bash terminal as follows:

for n in *.mp3
do if [[ "$n" =~ -[-_0-9a-zA-Z]{11}.mp3$ ]]
   then echo "youtube ${n: -15: 11}" >> downloaded.txt
   fi
done
5
  • 2
    Valuable answer here. It solves my problem. thank you.
    – Warrior
    Jan 11, 2016 at 10:56
  • 1
    What is -cwix here ?
    – bteo
    Jun 21, 2017 at 18:16
  • 8
    -cwix is a shorter alternative to --continue --no-overwrites --ignore-errors --extract-audio Jun 24, 2017 at 9:05
  • 2
    It's worth mentioning that while this works perfectly for YouTube, youtube-dl also works with other sites (e.g. Soundcloud) where the -x option seems to break the output. You can safely remove that flag if you're downloading from an audio source. Aug 2, 2017 at 18:55
  • What should "youtube" be replace with if I'm downloading from somewhere else, specifically podcast episodes from simplecastcdn.com? Edit: I'm dumb. It's still just youtube. I guess for youtube-dl, not for a video coming from youtube.
    – Marcel
    Jun 17, 2022 at 15:38
12

This is really helpful. If it's of any use to anybody, I modified the code to create the existing downloads list to include all files in the folder. Useful if downloading audio with the --extract-audio and --audio-quality "best" flags

create_download_list.sh:

#!/usr/bin/env bash

for n in *.*
do if [[ "$n" =~ -([-_0-9a-zA-Z]{11}).*$ ]]
   then echo "youtube ${BASH_REMATCH[1]}" 
   fi
done > downloaded.txt

I'm sure most people could have worked that out for themselves, but not everyone is clued-up with bash scripting.

3
  • 1
    You can also redirect from the whole loop to avoid multiple file-writes. Instead of >> downloaded.txt, replace done with done > downloaded.txt (or >> to append, of course). ☺ Nov 10, 2020 at 19:51
  • "youtube ${n: -16: 11}" worked for me.
    – nvd
    Apr 18, 2022 at 2:19
  • if anyone forgot like me, chmod u+x create_download_list.sh
    – 128KB
    Nov 4, 2022 at 19:19
0

I use the following approach:

yt-dlp --download-archive downloaded.txt --no-post-overwrites -ciwx "put format here" "put url here"

And I use the code below for downloading youtube playlist with tons of videos which also requires membership.

yt-dlp --cookies cookies.txt --download-archive downloaded.txt --no-post-overwrites -ciwx "put format here" "put url here"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .