Syntax error by using ruby-youtube-dl - ruby

i'm new to this site and also in programming. Actually i'm learning Ruby.
In my first experiments i would like to download a file from Youtube. I decided to use ruby-youtube-dl.
I parse ARGV0 to $url.
Then i'm using:
FileUtils.cd("#{$musicdir}/#{$folder}") do
YoutubeDL::Downloader.download_audio("#{$url}")
end
But that one produces that output:
sh: -c: Zeile 0: Syntaxfehler beim unerwarteten Wort `('
sh: -c: Zeile 0: `/home/sascha/.rvm/gems/ruby-2.0.0-p353/gems/ruby-youtube-dl-0.0.5/bin/youtube-dl.py --no-progress --extract-audio --audio-format=mp3 --output=/tmp/%(stitle)s-%(uploader)s-%(autonumber)s.mp3'
/home/sascha/.rvm/gems/ruby-2.0.0-p353/gems/ruby-youtube-dl-0.0.5/lib/ruby-youtube-dl/downloader.rb:9:in `download_audio': undefined method `[]' for nil:NilClass (NoMethodError)
from /home/sascha/RubymineProjects/ruby_script_collection/youtube_dlhelper/lib/youtube_dlhelper.rb:86:in `block in <top (required)>'
from /home/sascha/.rvm/rubies/ruby-2.0.0-p353/lib64/ruby/2.0.0/fileutils.rb:125:in `chdir'
from /home/sascha/.rvm/rubies/ruby-2.0.0-p353/lib64/ruby/2.0.0/fileutils.rb:125:in `cd'
from /home/sascha/RubymineProjects/ruby_script_collection/youtube_dlhelper/lib/youtube_dlhelper.rb:84:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
The full sourcefile is placed there: http://pastebin.com/jAwjHanw
Maybe anyone can help out?

I've looked into the log, and it seems to be a bug. You can do the following steps the solve, or partially solve the problem:
Check out gem:
$ cd ~/git
$ git clone https://github.com/bnmrrs/ruby-youtube-dl.git
Specify the path folder in your project's Gemfile that will point to the newly checked out gem:
gem 'ruby-youtube-dl', :path => '~/git/ruby-youtube-dl'
Try to fix the gem locally, for example by removing parentheses, and # chars, and replacing them with constants. Of course it will be a workaround.
In case if you are developing a gem or rails app, you shell to publish you changes to web, and you are able to do that by forking the gem on github, pushing you changed into you version branch:
$ git clone git://github.com/yourname/ruby-youtube-dl.git
$ cd ruby-youtube-dl
$ git branch fixbranch
$ git checkout fixbranch
# do your changes...
$ git push origin fixbranch
Use your changes as the main gem version. In this case you are need to change your Gemfile for example as follows:
gem 'ruby-youtube-dl', :git => 'git://github.com/yourname/ruby-youtube-dl.git', :branch => 'fixbranch'
In case if your changes are not workaround you can open a pull request on github to commit your changes into the mainstream.
If you are unable to solve the problem even with a workaround, it will be beast to report the issue to the gem developers here, supplying the error logs unto them.

Related

Receive syntax error when installing gem on Ruby

I'm trying to install a gem using Ruby. I keep getting a weird syntax error when I do. Using rvm, latest version, to install. The error message is:
/Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse': (<unknown>): mapping values are not allowed in this context at line 2 column 30 (Psych::SyntaxError)
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:318:in `parse'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:245:in `load'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:333:in `load_file'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/config_file.rb:198:in `initialize'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `new'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:74:in `do_configuration'
from /Users/george/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/gem_runner.rb:39:in `run'
from /Users/george/.rvm/rubies/ruby-2.1.5/bin/gem:21:in `<main>'
I also get this error when trying to set rvm to use a different ruby version.
There's an error in your rubygems config file. If you're not using a custom config file, look for a file .gemrc in your home folder. It seems there's incorrect content on line 2.
Psych is a YAML parser, so look for something that is incorrect YAML.
It looks like there was an issue in the .gemrc file as well as some other files created in the root folder that were affecting RVM from installing Ruby correctly.
Re-storing the files to the previous state and removing the junk files with rm -rf got everything working.

Error running executable from gem because another gem is not part of the bundle

I'm creating a gem (see https://github.com/hamchapman/rewinder) that has ruby-git (https://github.com/schacon/ruby-git) as a dependency.
Part of my gem has an executable https://github.com/hamchapman/rewinder/blob/master/bin/rewinder
which basically just requires the main lib file https://github.com/hamchapman/rewinder/blob/master/lib/rewinder.rb
and then runs the method there (all messy at the moment - ignore that for now).
When I install the gem locally and use it in another repo I get the following error:
/Users/Hami/.rvm/gems/ruby-2.1.2/gems/git-1.2.7/lib/git/lib.rb:764:in `command': git checkout '6eef72baf24bed761f753267cce16402e4a947f8' 2>&1:Note: checking out '6eef72baf24bed761f753267cce16402e4a947f8'. (Git::GitExecuteError)
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 6eef72b... Trying another bg-color change for homeboy
/Users/Hami/.rvm/gems/ruby-2.1.2#global/gems/bundler-1.6.2/lib/bundler/rubygems_integration.rb:252:in `block in replace_gem': hookup is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/hookup:22:in `<main>'
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/git-1.2.7/lib/git/lib.rb:528:in `checkout'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/git-1.2.7/lib/git/base.rb:325:in `checkout'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/rewinder-0.0.1/lib/rewinder.rb:11:in `block in heloo'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/rewinder-0.0.1/lib/rewinder.rb:10:in `each'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/rewinder-0.0.1/lib/rewinder.rb:10:in `each_with_index'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/rewinder-0.0.1/lib/rewinder.rb:10:in `heloo'
from /Users/Hami/.rvm/gems/ruby-2.1.2/gems/rewinder-0.0.1/bin/rewinder:4:in `<top (required)>'
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/rewinder:23:in `load'
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/rewinder:23:in `<main>'
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /Users/Hami/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
I don't really understand the error seeing as neither my gem, nor the ruby-git gem have hookup as a dependency. If I load up the file /Users/Hami/.rvm/gems/ruby-2.1.2/bin/hookup
then comment out the bottom two lines like this:
#!/usr/bin/env ruby_executable_hooks
#
# This file was generated by RubyGems.
#
# The application 'hookup' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
#gem 'hookup', version
#load Gem.bin_path('hookup', 'hookup', version)
then the error doesn't occur.
From what I've read it looks like it could be something to do with how oh-my-zsh wraps certain commands - maybe it's wrapping a git one?
Any suggestions?
From the hookup documentation:
Each time your current HEAD changes, hookup checks to see if your Gemfile, Gemfile.lock, or gem spec has changed. If so, it runs bundle check, and if that indicates any dependencies are unsatisfied, it runs bundle install.
From this I gather that the gem listens to git checkout events. Since you do that in your code, the hookup hooks come to life, and get confused (regardless of whether it is part of your ruby application or not).
Try uninstalling the gem and trying again.
If this resolves your problem, you might consider opening an issue to the author of the gem to fix this.

Invalid spec cache file

I have ruby 2.0.0p247 [x64-mingw32] with Gem 2.2.2 installed on Windows 8. I have a persistent problem gem that is making it virtually unusable. Whenever I try to install a new gem, I invariably get:
ERROR: While executing gem ... Invalid spec cache file in C:/Users/...
In the past, I've been able to run gem update or gem update --system and that would clear up the problem for one, single gem install. Subsequent install would fail with the same error. Now even gem update fails with that error message.
I've tried deleting the users/.../.gem directory. When I do that, gem update recreates that directory and promptly fails with the same error message.
I re-installed ruby 1.9.8 with gems several times to try to cure the problem, then upgraded to ruby 2.0.0. Throughout all re-installs and upgrades, the problem persisted.
I'm at my wits end here. Can anyone help me resolve this issue?
Here's the backtrace on the edit"
L:\xampp\htdocs\frameworks\yii2\framework>gem update --backtrace
Updating installed gems
ERROR: While executing gem ... (Gem::Exception)
Invalid spec cache file in C:/Users/Larry/.gem/specs/rubygems.org%443/specs.4.8
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/source.rb:187:in `rescue in load_specs'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/source.rb:179:in `load_specs'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/spec_fetcher.rb:266:in `tuples_for'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/spec_fetcher.rb:228:in `block in available_specs'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/source_list.rb:97:in `each'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/source_list.rb:97:in `each_source'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/spec_fetcher.rb:222:in `available_specs'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/spec_fetcher.rb:102:in `search_for_dependency'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/commands/update_command.rb:113:in `fetch_remote_gems'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/commands/update_command.rb:135:in `highest_remote_version'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/commands/update_command.rb:264:in `block in which_to_update'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/commands/update_command.rb:260:in `each'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/commands/update_command.rb:260:in `which_to_update'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/commands/update_command.rb:96:in `execute'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/command.rb:305:in `invoke_with_build_args'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/command_manager.rb:167:in `process_args'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/command_manager.rb:137:in `run'
C:/Ruby200-x64/lib/ruby/site_ruby/2.0.0/rubygems/gem_runner.rb:54:in `run'
C:/Ruby200-x64/bin/gem:21:in `<main>'
I had the same problem, but was able to fix it this way:
Delete the folder in users/%user%/.gem/ and rerun the command gem sources --update
Hope this helps.

Heroku: No Rake File Found

I am giving Heroku a spin for the first time, but am having quite a bit of difficulty even getting my app to open without crashing. When searching for the answer to this problem, the nice people on stack overflow suggest that I run
heroku run rake db:migrate
However, when I do this I consistently get this error back
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
When I run the trace with it I get back this
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:598:in `raw_load_rakefile'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:89:in `block in load_rakefile'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:88:in `load_rakefile'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:72:in `block in run'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rake/application.rb:70:in `run'
/app/bin/rake:41:in `<main>'
I have been searching for the answer for hours but I cannot seem to find one that solves this problem. It is possible I just do not know where to look. Any sort of leads would be exponentially helpful. Thank you!
EDIT
Steps already taken:
git init
git add .
git commit -m "init"
heroku create
git push heroku master
and this is where I tried to run
heroku open
received an error, and to remedy this tried
heroku run rake bd:migrate
Make sure you can run it locally. cd your project and type:
bundle exec gem list rake
if you can not see it here try adding it to your Gemfile by typeing:
echo "gem 'rake'" >> Gemfile
then bundle && git push heroku master

SUPPORTED_TYPE error when setting up a net-ssh connection

Has anyone out there seen this error before? I haven't been able to find any reference to SUPPORTED_TYPE in the source...
irb(main):013:0> connection = Net::SSH.start('host', 'user', :password => 'password')
NameError: uninitialized constant Net::SSH::KnownHosts::SUPPORTED_TYPE
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:117:in `keys_for'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:105:in `each_line'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:105:in `keys_for'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:103:in `open'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:103:in `keys_for'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:33:in `search_in'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:33:in `map'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:33:in `search_in'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/known_hosts.rb:27:in `search_for'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/transport/algorithms.rb:237:in `prepare_preferred_algorithms!'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/transport/algorithms.rb:120:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/transport/session.rb:79:in `new'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh/transport/session.rb:79:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh.rb:186:in `new'
from /usr/lib/ruby/gems/1.8/gems/net-ssh-2.5.1/lib/net/ssh.rb:186:in `start'
from (irb):13
from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:1313
The easier solution is to use this forked version of net-ssh which fixes that issue (the next release of the official net-ssh gem should fix it as well) as described here.
If you have that issue while deploying through capistrano (which I had today), you can install this net-ssh version from github through the Gemfile and then call cap by using bundle exec cap deploy.
Put in the Gemfile gem 'net-ssh', :git => 'git://github.com/nessche/net-ssh.git'.
This is a problem that seems to have been introduced by the May 24th updates 2.5.0 or 2.5.1 to the net-ssh gem. You can find the constant SUPPORTED_TYPE here:
http://net-ssh.github.com/net-ssh/classes/Net/SSH/KnownHosts.html
I don't know all the details, but there have been a couple solutions to this issue so far. One is to remove your known_hosts file (or the particular host you're trying to connect to from that file), and you might be able to connect until that host is added to known_hosts again -- it will return the same error if it's in there, for some reason.
The second option I've found is to revert to version 2.4.0 of the gem. I've submitted a ticket for the issue at:
http://net-ssh.lighthouseapp.com/projects/36253-net-ssh/tickets/58-nameerror-uninitialized-constant-netsshknownhostssupported_type
Hope it helps!
EDIT: Clarif's solution to this looks like a more acceptable one. Thanks, Clarif!
After following the issues on github and also applying what clarif suggested, I came up with this that fixed my problem.
http://tinyurl.com/cxr2xa3

Resources