Skip to content

Instantly share code, notes, and snippets.

@cjLGH
Created July 4, 2022 00:24
Show Gist options
  • Save cjLGH/841683f3366f0875a65ca22dc981f15c to your computer and use it in GitHub Desktop.
Save cjLGH/841683f3366f0875a65ca22dc981f15c to your computer and use it in GitHub Desktop.
yt-dlp python script to download audio files of asmr videos, depends on yt-dlp and python-slugify
import argparse, yt_dlp
from slugify import slugify
parser = argparse.ArgumentParser()
parser.add_argument('url', metavar='URL|ID', nargs='+', help='a YouTube URL or ID (example: https://www.youtube.com/watch?v=dQw4w9WgXcQ or dQw4w9WgXcQ)')
args = parser.parse_args()
for url in args.url:
class slugifyPP(yt_dlp.postprocessor.PostProcessor):
def run(self, info):
info['title'] = slugify(info['title'])
self.to_screen('slugify title: ' + info['title'])
return [], info
# print(url)
ydl_opts = {
# 'simulate': True,
'format': 'm4a/bestaudio/best',
'outtmpl': '%(channel)s/%(id)s-%(title)s.%(ext)s',
'ignoreerrors': True
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.add_post_processor(slugifyPP(), when='pre_process')
ydl.download([url])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment