Skip to content

Instantly share code, notes, and snippets.

@stegben
Last active August 10, 2017 09:26
Show Gist options
  • Save stegben/dbeef64c9b24b401426cf8b29eed27ca to your computer and use it in GitHub Desktop.
Save stegben/dbeef64c9b24b401426cf8b29eed27ca to your computer and use it in GitHub Desktop.
download audioset
import youtube_dl
meta_data = ... # from somewhere
count = meta_data[0]
info = meta_data[1]
url = 'http://youtu.be/{}'.format(info['YTID'])
output_audio_path = './audio/{}.wav'.format(str(count))
ydl_ops = {
'format': 'bestaudio/best',
# 'postprocessors': [{
# 'key': 'FFmpegExtractAudio',
# 'preferredcodec': 'mp3',
# 'preferredquality': '192',
# }],
'outtmpl':output_audio_path,
'external_downloader': 'ffmpeg',
'external_downloader_args': ['-i', output_audio_path, '-ab', '192k', '-f', 'mp3', '-ss', str(info['start_seconds']), '-t', '10',],
}
with youtube_dl.YoutubeDL(ydl_ops) as ydl:
ydl.download([url])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment