Created
August 10, 2020 00:21
-
-
Save neelriyer/51684a409ba1dd29718f4931e59ce2b1 to your computer and use it in GitHub Desktop.
Download the audio from part of a youtube video
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 os | |
| # download youtube url using ffmpeg | |
| # adapted from: https://github.com/ytdl-org/youtube-dl/issues/622#issuecomment-162337869 | |
| def download_from_url_ffmpeg(url, output, minute_mark = 1): | |
| try: | |
| os.remove(output) | |
| except: | |
| pass | |
| # cmd = 'ffmpeg -loglevel warning -ss 0 -i $(youtube-dl -f 22 --get-url https://www.youtube.com/watch?v=mMZriSvaVP8) -t 11200 -c:v copy -c:a copy react-spot.mp4' | |
| cmd = 'ffmpeg -loglevel warning -ss 0 -i $(youtube-dl -f bestaudio --get-url '+str(url)+') -t '+str(minute_mark*60)+' '+str(output) | |
| os.system(cmd) | |
| return os.getcwd()+'/'+output | |
| url = 'https://www.youtube.com/watch?v=-xY_D8SMNtE' | |
| content_audio_name = download_from_url_ffmpeg(url, 'jre.wav') | |
| url = 'https://www.youtube.com/watch?v=-l88fMJcvWE' | |
| style_audio_name = download_from_url_ffmpeg(url, 'joey_diaz.wav') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment