Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Youtube-dl with Flask and uWSGI #23849

Closed
juanektbb opened this issue Jan 26, 2020 · 2 comments
Closed

Use Youtube-dl with Flask and uWSGI #23849

juanektbb opened this issue Jan 26, 2020 · 2 comments
Labels

Comments

@juanektbb
Copy link

@juanektbb juanektbb commented Jan 26, 2020

Checklist

  • I'm asking a question
  • I've looked through the README and FAQ for similar questions
  • I've searched the bugtracker for similar questions including closed ones

Question

I have got a Flask application with a Virtual Environment using uWSGI in Nginx. (Ubuntu 18.04)
I want to download an MP3 using Youtube-dl when accessing a route /test

Case 1: If I run the same program from the terminal, it executes successfully.
Case 2: If I access the route, the program fails with an error telling me to install ffmpeg
Case 3: If I access another route that contains a subprocess to run a separate .py file, it also fails.

The error given by case 2 and 3:

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

My configuration is very simple as follows:

    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'])

I have done the obvious:

  • sudo apt-get install ffmpeg
  • pip install ffmpeg

I believe it is server / enviroment / uWSGI configuration to access ffmpeg from a route.
Would this be related to the PATH or Permissions? - Any suggestion on what should I look at?

I followed this tutorial to configure my server, may this is useful.
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04

@juanektbb juanektbb added the question label Jan 26, 2020
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jan 26, 2020

As you've already mentioned this is most likely PATH or permissions.

@dstftw dstftw closed this Jan 26, 2020
@juanektbb
Copy link
Author

@juanektbb juanektbb commented Jan 26, 2020

@dstftw Thanks for your reply. I am not really sure how to edit that PATH.

This is my Systemd Unit File for WSGI (/etc/systemd/system/myproject.service):

[Unit]
Description=uWSGI instance to serve myproject
After=network.target

[Service]
User=john
Group=www-data
WorkingDirectory=/home/john/myproject
Environment="PATH=/home/john/myproject/myprojectenv/bin"
ExecStart=/home/john/myproject/myprojectenv/bin/uwsgi --ini myproject.ini

[Install]
WantedBy=multi-user.target

Is this the path I should change?

And this one includes the permissions (~/myproject/myproject.ini):

[uwsgi]
module = wsgi:app

master = true
processes = 5

socket = myproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.