Search code examples
rubyherokuyoutube-dl

How to fix YouTube-dl Invalid parameters. on Heroku


When I try to download a song with youtube-dl.rb gem it works locally, but when I do it on Heroku it says this:

Terrapin::ExitStatusError - Command '/app/vendor/bundle/ruby/2.6.0/gems/youtube-dl.rb-0.3.1.2016.09.11.1/vendor/bin/youtube-dl --no-color --no-progress --print-json "ytsearch:notion hooked"' returned 1. Expected 0

It also says something about cocaine being deprecated like this:

DEPRECATION: The cocaine gem is deprecated. Please upgrade to terrapin. See https://github.com/thoughtbot/terrapin/ for further instructions.

This is my code that is running this gem:

song_list.each { |song|
        # formatted_command = 'youtube-dl -o "' + __dir__.to_s + '/' + temp_dir_name + '/%(title)s.%(ext)s" -x --audio-format mp3 "ytsearch:' + song + '"'
        # system formatted_command
        options = {
            audio_format: :mp3,
            extract_audio: true,
            output: "#{__dir__.to_s}/#{temp_dir_name}/%(title)s.%(ext)s",
        }
        YoutubeDL.download "ytsearch:#{song}", options
    }

I commented two lines above that were downloading songs with the CLI tool, that worked as well, but I can't download that tool on a Heroku machine, so I have to use this Ruby wrapper.


Solution

  • Here are some instructions to running youtube-dl on your Heroku server:

    1. create a requirements.txt file in the root of your repo, with content:
    youtube-dl
    
    1. Run the following three commands to set up Python buildpack as well as Ruby buildpack, making sure Ruby is the primary buildpack:
    heroku buildpacks:add heroku/ruby
    heroku buildpacks:add --index 1 heroku/python
    heroku buildpacks:set heroku/ruby
    

    Commit and deploy, test by opening heroku run bash and running youtube-dl. If it works here, you can also call it from Ruby.