Skip to content

Instantly share code, notes, and snippets.

@anisayari
Created April 21, 2019 17:34
Show Gist options
  • Save anisayari/b3c189e410ee0b895af284a0eabf1762 to your computer and use it in GitHub Desktop.
Save anisayari/b3c189e410ee0b895af284a0eabf1762 to your computer and use it in GitHub Desktop.
get_youtube_music
import youtube_dl
import pandas as pd
def get_youtube_music(row):
path = 'data/music/{}/{}.mp3'.format(row['style'],str(row['uuid']))
exists = os.path.isfile(path)
if exists:
print('Already exist {}'.format(row['uuid']))
return
if row['videoID_youtube'] != "missing":
videoID = row['videoID_youtube']
ydl_opts = {
'outtmpl': path,
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3'
}]
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v={}'.format(videoID)])
df = pd.read_csv(output_file,sep=";", header=0)
df.progress_apply(get_youtube_music, axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment