How to fix YouTube-dl Invalid parameters. on Heroku - ruby

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.

Here are some instructions to running youtube-dl on your Heroku server:
create a requirements.txt file in the root of your repo, with content:
youtube-dl
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.

Related

Problems with ruby-appium-cucumber on AWS Device Farm

I'm trying to run my test suite on AWS device farm using a custom environment. The test suite runs fine locally but when I run it on device farm some tests fail randomly, and some other acts as expected. Sometimes it looks like it's skipping the cucumber hooks, or just not running the steps.
Here is my custom environment configuration:
# Phases are collection of commands that get executed on Device Farm.
phases:
# The install phase includes commands that install dependencies that your tests use.
# Default dependencies for testing frameworks supported on Device Farm are already installed.
install:
commands:
# By default the ruby version installed is 2.5.1
- mkdir /tmp/tempdir
- export TMPDIR="/tmp/tempdir"
- export TMP="/tmp/tempdir"
- export TEMP="/tmp/tempdir"
- rvm install "ruby-2.6.5"
- rvm use 2.6.5
# you can switch to an alternate ruby version using below command.
#- rvm install 2.3.1 --autolibs=0
# Unpackage and install the gems
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
# Use a pre-configured ruby environment to run your tests.
# This environment has the following gems pre-installed (appium_lib (9.16.1), test-unit (3.2.9)) along with their dependencies.
# If you are using this env, please make sure you do not upload the Gemfile.lock while packaging your tests.
# If the Gemfile.lock contains different versions for the already installed packages, it will ignore the pre-installed packages.
# Using this env can help you speed up your test set up phase as you wont have to install all the gems.
# This default env is only available for ruby 2.5.3.
- rvm gemset use default-ruby-gemset-env-version-1 --create
# Alternatively, you can create a new virtual ruby env using the command:
#- rvm gemset use env --create
# Install the gems from the local vendor/cache directory
- gem install bundler --no-document
- bundle config set path 'vendor/cache'
- gem update --system
- bundle install
# This test execution environment uses Appium version 1.9.1 by default, however we enable you to change it using the Appium version manager (avm). An
# example "avm" command below changes the version to 1.14.2.
# For your convenience, we have preinstalled the following versions: 1.9.1, 1.10.1, 1.11.1, 1.12.1, 1.13.0, 1.14.1, 1.14.2, 1.15.1 or 1.16.0.
# To use one of these Appium versions, change the version number in the "avm" command below to your desired version:
- ln -s /usr/local/avm/versions/1.9.1/node_modules/.bin/appium /usr/local/avm/versions/1.9.1/node_modules/appium/bin/appium.js
# The pre-test phase includes commands that setup your test environment.
pre_test:
commands:
# We recommend starting appium server process in the background using the command below.
# Appium server log will go to $DEVICEFARM_LOG_DIR directory.
# The environment variables below will be auto-populated during run time.
- echo "Start appium server"
- >-
appium --log-timestamp
--default-capabilities "{\"deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \"platformName\":\"$DEVICEFARM_DEVICE_PLATFORM_NAME\",
\"app\":\"$DEVICEFARM_APP_PATH\", \"udid\":\"$DEVICEFARM_DEVICE_UDID\", \"platformVersion\":\"$DEVICEFARM_DEVICE_OS_VERSION\",
\"chromedriverExecutable\":\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\"}"
>> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
- >-
start_appium_timeout=0;
while [ true ];
do
if [ $start_appium_timeout -gt 60 ];
then
echo "appium server never started in 60 seconds. Exiting";
exit 1;
fi;
grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
if [ $? -eq 0 ];
then
echo "Appium REST http interface listener started on 0.0.0.0:4723";
break;
else
echo "Waiting for appium server to start. Sleeping for 1 second";
sleep 1;
start_appium_timeout=$((start_appium_timeout+1));
fi;
done;
# The test phase includes commands that start your test suite execution.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
- echo "Navigate to test source code"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- echo "Start Appium Ruby test"
# Modify/Enter the command below to start the tests. The comamnd should be similar to what you use to run the tests locally.
# "bundle exec" is a Bundle command to execute a script in the context of the current bundle.
# For e.g. assuming you run your tests locally using command "ruby YOUR_TEST_FILENAME.rb.", to run your ruby tests using bundle exec command you can use:
- bundle exec rake set_environment[amazon]
- bundle exec rake test
# The post test phase includes are commands that are run after your tests are executed.
post_test:
commands:
# The artifacts phase lets you specify the location where your tests logs, device logs will be stored.
# And also let you specify the location of your test logs and artifacts which you want to be collected by Device Farm.
# These logs and artifacts will be available through ListArtifacts API in Device Farm.
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_LOG_DIR
Here are the cucumber logs(I have tried to use backtrace to get more info but for some reason is not working in AWS)
Start Appium Ruby test
[DeviceFarm] bundle exec rake set_environment[amazon]
[DeviceFarm] bundle exec rake test
Using the test, no_bugs and pretty_progress profiles...
F------
Failing Scenarios:
cucumber -p test -p no_bugs -p pretty_progress features/regression/android/games/lightning.feature:45 # Scenario: Top up modal appears for a user without funds on lightning flow purchase attempts on all or nothing
1 scenario (1 failed)
6 steps (6 skipped)
1m1.742s
Cucumbers failed
I discovered that my capabilities for appium weren't correct and they lacked some capabilities, without them appium and cucumber acts up weirdly, here are the capabilities I used:
caps = {
"automationName": "UiAutomator2",
"platformName": ENV['DEVICEFARM_DEVICE_PLATFORM_NAME'],
"deviceName": ENV['DEVICEFARM_DEVICE_NAME'],
"app": ENV['DEVICEFARM_APP_PATH'],
"uuid": ENV['DEVICEFARM_DEVICE_UDID'],
"appPackage": "appPackageOfYourChoice",
"appActivity": "appActivityOfYourChoice",
"autoGrantPermissions": true
}

Deploying PhantomJS 2.5 beta on Heroku. How can I see what's failing?

I'm trying to make a custom buildpack to deploy PhantomJS 2.5 beta version on Heroku. This is my buildpack based on Stomita's Phantomjs Buildpack which runs version 2.1.1 and works fine.
This is what I get in the building process:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PhantomJS app detected
remote: -----> Fetching PhantomJS 2.5.0-beta binaries at https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.5.0-beta-linux-ubuntu-trusty-x86_64.tar.gz
remote: ! Push rejected, failed to compile PhantomJS app.
remote:
remote: ! Push failed
remote: Verifying deploy....
remote:
remote: ! Push rejected to rp-phantom.
remote:
As you can see, not much information. The binary is downloaded fine, I checked that omitting the -s flag in the curl command, but can't figure out what's failing.
This is my compile file:
#!/bin/sh
set -e
BUILD_DIR=$1
CACHE_DIR=$2
# config
VERSION="2.5.0-beta"
# Buildpack URL
ARCHIVE_NAME=phantomjs-${VERSION}-linux-ubuntu-trusty-x86_64
FILE_NAME=${ARCHIVE_NAME}.tar.gz
BUILDPACK_PHANTOMJS_PACKAGE=https://bitbucket.org/ariya/phantomjs/downloads/${FILE_NAME}
mkdir -p $CACHE_DIR
if ! [ -e $CACHE_DIR/$FILE_NAME ]; then
echo "-----> Fetching PhantomJS ${VERSION} binaries at ${BUILDPACK_PHANTOMJS_PACKAGE}"
curl $BUILDPACK_PHANTOMJS_PACKAGE -L -s -O $CACHE_DIR/$FILE_NAME
fi
echo "-----> Extracting PhantomJS ${VERSION} binaries to ${BUILD_DIR}/vendor/phantomjs"
mkdir -p $CACHE_DIR/$ARCHIVE_NAME
mkdir -p $BUILD_DIR/vendor
tar -xvf $CACHE_DIR/$FILE_NAME -C $CACHE_DIR
mv $CACHE_DIR/$ARCHIVE_NAME $BUILD_DIR/vendor/phantomjs
echo "-----> exporting PATH and LIBRARY_PATH"
PROFILE_PATH="$BUILD_DIR/.profile.d/phantomjs.sh"
mkdir -p $(dirname $PROFILE_PATH)
echo 'export PATH="$PATH:$HOME/vendor/phantomjs/bin"' >> $PROFILE_PATH
echo 'export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:vendor/phantomjs/lib"' >> $PROFILE_PATH
Thanks in advance!
I was able to get 2.5.0 beta working on Heroku. Here is my answer from my own post:
Ultimately, I was able to figure it out! There are a few things that you have to do...
Dependencies: You have to use the Heroku Apt buildpack to install the missing dependencies. First, you need to add the buildpack to your app:
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
Next, you'll create a file in your project root called Aptfile. Here's where we add the missing dependencies for PhantomJS 2.5.0 Beta. 2.5.0 introduces webp support, so we need that. libhyphen0 is required as well, though I'm not sure how it us used. Finally, we use gcc-5 and the latest libstdc++6. Contents should look like this:
webp
libhyphen0
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.1-8ubuntu1_amd64.deb
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
PhantomJS: Next we grab the latest version of PhantomJS. I've created a fork of the most popular PhantomJS buildpack and updated it for use with 2.5.0 beta. 2.5.0 beta has builds for trusty as well as xenial, so the build pack will detect the Heroku stack and use the appropriate one (though the cedar-16 stack is still in beta at the time of this post). So, add it to your app:
heroku buildpacks:add https://github.com/lookitsatravis/heroku-buildpack-phantomjs.git
Deploy: All that's left is deployment! Commit the Aptfile to your repo, make sure the build packs are setup, and then push to Heroku.
Took a bit of trial and error, but ultimately I was able to get it up and running. Hope this helps others until the final candidate is released.

--watch arg is unsupported on Windows

I'm new to jekyll so first I follow this tutorial Jekyll on Windows and setup jekyll 3.3.0.I got an error about the certificate this tutorial SSL CERTIFICATE UPDATES
and by using this cacert.pem certificate solve the problem.
However,when start jekyll server I get:
--watch arg is unsupported on Windows.
If you are on Windows Bash, please see: https://github.com/Microsoft/BashOnWindows/issues/216
I try to solve this problem using Let Jekyll --watch without any luck.
If I use jekyll 3.2.1 every things work okay but the problem with jekyll 3.3.0.
So how to solve this problem ?
Edit
I Solve my problem reading this and comment some code in the build.rb file at C:\tools\ruby23\lib\ruby\gems\2.3.0\gems\jekyll-3.3.0\lib\jekyll\commands
To enable autoregeration and now every things work okay.
def watch(site, options)
#if Utils::Platforms.windows?
# Jekyll.logger.warn "", "--watch arg is unsupported on Windows. "
# Jekyll.logger.warn "", "If you are on Windows Bash, please see: " \
# "https://github.com/Microsoft/BashOnWindows/issues/216"
# else
External.require_with_graceful_fail "jekyll-watch"
watch_method = Jekyll::Watcher.method(:watch)
if watch_method.parameters.size == 1
watch_method.call(
options
)
else
watch_method.call(
options, site
)
# end
end
I think you can just type jekyll serve.
It's windows bash error, Jekyll or Windows will fix it soon, till then you can use jekyll 3.2.1 version.
Here I commit my answer.
I solved the problem by installing Ruby 2.3.3, DevKit-mingw64 and jekyll 3.4.3

Capistrano error: 'Could not find form_data-0.1.0 in any of the sources' while deploying

I have a rails application on the dev server and I deleted the shared folder while attempting to make some changes. When I'm trying to redeploy the application, I get the following error on Capistrano.
servers: ["xx.xxx.xxx.223"] [xx.xxx.xxx.223] executing command
** [out :: xx.xxx.xxx.223] Could not find form_data-0.1.0 in any of the sources
command finished in 41821ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/apps/SITENAME/releases/20150507165055; true"
I have tried bundle install --deployment and I still get the same error
Could not find form_data-0.1.0 in any of the sources
Any help would be greatly appreciated.
This could be caused by outdated Gemfile.lock file. Remove Gemfile.lock, run bundle install and try to start your app again.

Node.Js: Trying to access a ruby gem inside node app on heroku

I am trying to use this https://github.com/mooktakim/image_optim_bin on my Heroku application, and I'm really not sure as to how to do it. Right now I have the following code trying to run pngcrush
exec('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB ' + file + ' ' + file, function(error, stdout, stderr) {
console.log('PNGCRUSH OUTPUT: ', error, stdout, stderr);
});
But it results in the following error on my heroku logs output:
PNGCRUSH OUTPUT: { [Error: Command failed: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'image_optim_bin' (>= 0) among 9 total gem(s) (Gem::LoadError)
This is my Gemfile
gem 'image_optim_bin', :git => 'https://github.com/mooktakim/image_optim_bin.git'
This is the first time I've tried using ruby gems inside a nodejs application so I really am unclear of how to do so. Is there a specific directory I need to target to run the gem?
Are you already using Heroku multi buildpacks to support both Node and Ruby? If so, I recommend running heroku run bash and then trying to execute pngcrush from the command line. You should be able to quickly identify the path you need.

Resources