Created
April 21, 2019 17:34
-
-
Save anisayari/b3c189e410ee0b895af284a0eabf1762 to your computer and use it in GitHub Desktop.
get_youtube_music
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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