yt-dl command to download audio files - in a python script

1.3k Views Asked by At

I want to convert this command into a python call:

yt-dlp --continue --no-overwrites --extract-audio --audio-format mp3 -o "ST_%(upload_date)s_%(title).50s.%(ext)s" https://www.youtube.com/channel/UCYt3jqP4rRP2rr5Ye8fs0LQ/videos --playlist-reverse --restrict-filenames   --add-metadata --postprocessor-args "-metadata albumartist=rAmAnuja-dayA" --download-archive ./ytdl-archive.txt 

The python call will look something like:

  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    error_code = ydl.download([url])

What should my options dict look like? Here is a start (not sure if it is right):

ydl_opts_base = {
  'format': 'm4a/bestaudio/best',
  # ℹ️ See help(yt_dlp.postprocessor) for a list of available Postprocessors and their arguments
  'postprocessors': [{  # Extract audio using ffmpeg
    'key': 'FFmpegExtractAudio',
    'preferredcodec': 'm4a',
  }],
  'verbose': True, # Useful for checking if we have the latest version.
  'playlistreverse': True,
  'restrictfilenames': True,
  "nooverwrites": True,
  "continuedl": True,
  "outtmpl": {"default": "ST_%(upload_date)s_%(title).50s.mp3"}
}
ydl_opts = copy(ydl_opts_base)
ydl_opts.update(options_dict)
ydl_opts["paths"] = {"home": dest_dir}
ydl_opts["download_archive"] = os.path.join(dest_dir, "ytdl-archive.txt")

ydl_opts['postprocessor_args'] = {"metadata": {"albumartist": "rAmAnuja-dayA"}}


(This works with the latest version of yt-dl - downloads an mp3.)

0

There are 0 best solutions below