Skip to content

Instantly share code, notes, and snippets.

@neurotech
Created March 2, 2013 13:39
Show Gist options
  • Select an option

  • Save neurotech/5071025 to your computer and use it in GitHub Desktop.

Select an option

Save neurotech/5071025 to your computer and use it in GitHub Desktop.
require "viddl-rb"
ViddlRb.io = $stdout
Shoes.app :title => 'Viddl', :width => 300, :height => 150, :margin => 10, :resizable => false do
stack do
para "Enter Video URL:"
edit_line do |e|
@url = e.text
end
button "Save to..." do
destination = ask_open_folder
end
end
button "Download!" do
begin
ViddlRb.get_urls(@url)
rescue ViddlRb::DownloadError => e
alert "Could not get download url: #{e.message}"
rescue ViddlRb::PluginError => e
alert "Plugin blew up! #{e.message}\n" + "Backtrace:\n#{e.backtrace.join("\n")}"
end
end
end
@rb2k
Copy link
Copy Markdown

rb2k commented Mar 2, 2013

This will just give you the URLs it found.

require 'rubygems'
require 'viddl-rb'

ViddlRb.io = $stdout
@url = 'http://www.youtube.com/watch?v=IvvFpb2IS2o'
result = ViddlRb.get_urls(@url)
puts result.inspect
$ ruby viddl.rb 
[YOUTUBE] ID FOUND: IvvFpb2IS2o
["http://r5---sn-4g57ln7r.c.youtube.com/videoplayback?sparams=cp,id,ip,ipbits,itag,ratebypass,source,upn,expire&expire=1362256190&id=22fbc5a5bd884b6a&ipbits=8&upn=xPCJwhQo764&ms=au&newshard=yes&ip=84.147.99.23&key=yt1&itag=37&sver=3&mv=m&cp=U0hVR1JQVF9OSkNONV9KSlhCOm1Ka1B2b0J1Y2RB&source=youtube&mt=1362232096&fexp=913807,920704,912806,902000,922403,922405,929901,913605,925006,906938,931202,908529,920201,930101,906834,913570,901451&ratebypass=yes&sig=BD293543EE8B7CAEECDD5F83756559D585FC4E80.4ED4DB2229CC7AE46A05DDB1DDB3BCC78E384A6F&fallback_host=tc.v24.cache1.c.youtube.com&&signature=BD293543EE8B7CAEECDD5F83756559D585FC4E80.4ED4DB2229CC7AE46A05DDB1DDB3BCC78E384A6F"]

@neurotech
Copy link
Copy Markdown
Author

Right. Should I just use Shoes' own Download on the URL returned by ViddlRb.get_urls, or can I do that with viddl-rb?

@rb2k
Copy link
Copy Markdown

rb2k commented Mar 2, 2013

You MIGHT run into problems trying to download this yourself.
Some providers expect certain User-Agents when downloading (and youtube needs a few retries sometimes).

You can certainly give the shoes downloader a try, but depending on what you try to do in the end, shelling out to viddl-rb might not be the worst thing.
The "library"-functionality of viddl-rb is more of an afterthought :)

@neurotech
Copy link
Copy Markdown
Author

This is mainly a personal "hobby" program to make it easy to get YouTube videos as audio files.

Is it possible to call the CLI for viddl-rb from ruby?

@rb2k
Copy link
Copy Markdown

rb2k commented Mar 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment