- My goal: Download podcast as MP3
- Used Python, Flask and Youtube_dl on Ubuntu 18.04 and Nginx
- I followed this tutorial to set up my server: Flask app with uSWGI and Nginx
Point 1: Deployment was successful and running a simple flask app in the browser works.
Point 2: I add the following code to my simple flask route to be rendered.
@app.route('/video', methods=['POST'])
def videoland():
ydl_opts = {
'format': 'bestaudio/best',
'verbose': True,
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'postprocessor_args': [
'-ar', '16000'
],
'prefer_ffmpeg': True,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
return Response('Response test')
Here is the problem: When I render this page, I receive 500 error and 'Response test' is never shown.
However, the MP3 file gets to be downloaded in my project directory without problems (Sounds perfect)
By checking 'journalctl' of my project, I find the following:
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2019.11.28
[debug] Python version 3.6.9 (CPython) - Linux-4.15.0-1051-aws-x86_64-with-Ubuntu-18.04-bionic
[debug] exe versions: none
[debug] Proxy map: {}
[youtube] BaW_jenozKc: Downloading webpage
[youtube] BaW_jenozKc: Downloading video info webpage
[debug] Invoking downloader on 'https://r3---sn-aigl6nl7.googlevideo.com/videoplayback?expire=1579853383&ei=51EqXpe4HZiuxgKiz4SYBw&ip=35.178.16.206&id=o-AP8Cssz7OHlOd6PRswoEVAAVY7kfgYf0ZV-jL_TE9HZH&itag=140&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-aigl6nl7%2Csn-aigzrn7z&ms=au%2Crdu&mv=m&mvi=2&pl=15&initcwndbps=860000&vprv=1&mime=audio%2Fmp4&gir=yes&clen=157753&dur=9.891&lmt=1387961817989105&mt=1579831690&fvip=3&keepalive=yes&fexp=23842630&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=ALgxI2wwRQIgI4XTN3uqTHc10HQcotiqwL8-hSqUwnop-mrrYaIwICsCIQCSeyXDEvxEVafgIOWkMloobolXXoWRYHqzPH3fh2OfOA%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIgZKbNf2W3csHWf1leFuPJHx07S8sRJLL0-luUuXb5BqACIQD7WbHSG0E17nyoq0yTB8udlgt0-1drPysUoYKp0V539w%3D%3D&ratebypass=yes'
[download] youtube-dl test video ''_ä↭-BaW_jenozKc.m4a has already been downloaded
[29B blob data]
WARNING: BaW_jenozKc: writing DASH m4a. Only some players support this container. Install ffmpeg or avconv to fix this automatically.
ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.
Traceback (most recent call last):
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 2064, in post_process
files_to_delete, info = pp.run(info)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/postprocessor/ffmpeg.py", line 272, in run
filecodec = self.get_audio_codec(path)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/postprocessor/ffmpeg.py", line 166, in get_audio_codec
raise PostProcessingError('ffprobe/avprobe and ffmpeg/avconv not found. Please install one.')
youtube_dl.utils.PostProcessingError: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.
[2020-01-24 02:09:44,465] ERROR in app: Exception on /video [POST]
Traceback (most recent call last):
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 2064, in post_process
files_to_delete, info = pp.run(info)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/postprocessor/ffmpeg.py", line 272, in run
filecodec = self.get_audio_codec(path)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/postprocessor/ffmpeg.py", line 166, in get_audio_codec
raise PostProcessingError('ffprobe/avprobe and ffmpeg/avconv not found. Please install one.')
youtube_dl.utils.PostProcessingError: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./mp3d.py", line 54, in videoland
ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 2018, in download
url, force_generic_extractor=self.params.get('force_generic_extractor', False))
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 807, in extract_info
return self.process_ie_result(ie_result, download, extra_info)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 862, in process_ie_result
return self.process_video_result(ie_result, download=download)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 1643, in process_video_result
self.process_info(new_info)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 1999, in process_info
self.post_process(filename, info_dict)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 2066, in post_process
self.report_error(e.msg)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 624, in report_error
self.trouble(error_message, tb)
File "/home/juan/mp3d/mp3denv/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 594, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one.
[pid: 23571|app: 0|req: 4/6] 85.255.232.218 () {58 vars in 1170 bytes} [Fri Jan 24 02:09:43 2020] POST /video => generated 290 bytes in 1047 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)
These are all the logs to a simple request to the route /video
Note I have tried the following:
- sudo apt-get install ffmpeg
- I tested running the same code as simple .py script instead of a flask route (from the environment and outside of it) they both run successfully without errors and downloads the MP3 file.
I am not very familiar with python virtualenv, so I believe it is a configuration error, maybe.
May this Github solution for a similar error be related?
Or this Stackoverflow solution, but it doesn't explain much.
Do you know how to solve it or have a clue on where to start? - Thanks