Skip to content

Commit

Permalink
Merge pull request rb2k#12 from kl/master
Browse files Browse the repository at this point in the history
Added Veoh plugin
  • Loading branch information
rb2k committed Nov 20, 2011
2 parents 3b21872 + fb530af commit d2d6830
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion helper/download-helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.os_has?(utility, windows = (ENV['OS'] =~ /windows/i))
return `which #{utility}`.include?(utility)
else
begin
`#{utility}` #if running the command does not thow an error, Windows has it
`#{utility}` #if running the command does not throw an error, Windows has it
return true
rescue Errno::ENOENT
return false
Expand Down
2 changes: 1 addition & 1 deletion plugins/blip.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Blip < PluginBase
# this will be called by the main app to check weather this plugin is responsible for the url passed
# this will be called by the main app to check whether this plugin is responsible for the url passed
def self.matches_provider?(url)
url.include?("blip.tv")
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/megavideo.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Megavideo < PluginBase
#this will be called by the main app to check weather this plugin is responsible for the url passed
#this will be called by the main app to check whether this plugin is responsible for the url passed
def self.matches_provider?(url)
url.include?("megavideo.com")
end
Expand Down
46 changes: 46 additions & 0 deletions plugins/veoh.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Veoh < PluginBase
VEOH_API_BASE = "http://www.veoh.com/api/"
PREFERRED_FORMATS = [:mp4, :flash] # mp4 is preferred because it enables downloading full videos and not just previews

#this will be called by the main app to check whether this plugin is responsible for the url passed
def self.matches_provider?(url)
url.include?("veoh.com")
end

def self.get_urls_and_filenames(url)
veoh_id = url[/\/watch\/([\w\d]+)/, 1]
info_url = "#{VEOH_API_BASE}findByPermalink?permalink=#{veoh_id}"
info_doc = Nokogiri::XML(open(info_url))

download_url = get_download_url(info_doc)
file_name = get_file_name(info_doc, download_url)

[{:url => download_url, :name => file_name}]
end

#returns the first valid download url string, in order of the prefered formats, that is found for the video
def self.get_download_url(info_doc)
PREFERRED_FORMATS.each do |format|
a = get_attribute(format)
download_attr = info_doc.xpath('//rsp/videoList/video').first.attributes[a]
return(download_attr.content) unless download_attr.nil? || download_attr.content.empty?
end
end

#the file name string is a combination of the video name and the extension
def self.get_file_name(info_doc, download_url)
name = info_doc.xpath('//rsp/videoList/video').first.attributes['title'].content
name.gsub!(" ", "_") # replace spaces with underscores
extension = download_url[/\/[\w\d]+(\.[\w\d]+)\?ct/, 1]
name + extension
end

def self.get_attribute(format)
case format
when :mp4
"ipodUrl"
when :flash
"previewUrl"
end
end
end
4 changes: 2 additions & 2 deletions plugins/vimeo.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Vimeo < PluginBase
#this will be called by the main app to check weather this plugin is responsible for the url passed
#this will be called by the main app to check whether this plugin is responsible for the url passed
def self.matches_provider?(url)
url.include?("vimeo.com")
end
Expand All @@ -22,4 +22,4 @@ def self.get_urls_and_filenames(url)
puts "downloading to " + file_name
[{:url => download_url, :name => file_name}]
end
end
end
4 changes: 2 additions & 2 deletions plugins/youtube.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Youtube < PluginBase
#this will be called by the main app to check weather this plugin is responsible for the url passed
#this will be called by the main app to check whether this plugin is responsible for the url passed
def self.matches_provider?(url)
url.include?("youtube.com") || url.include?("youtu.be")
end
Expand Down Expand Up @@ -134,7 +134,7 @@ def self.grab_single_url_filename(url)

#video_info_hash.keys.sort.each{|key| puts "#{key} : #{video_info_hash[key]}" }
download_url = video_info_hash["url_encoded_fmt_stream_map"][selected_format]
#if download url ends with a ';' followed by a codec string remove that part because stops URI.parse from working
#if download url ends with a ';' followed by a codec string remove that part because it stops URI.parse from working
download_url = $1 if download_url =~ /(.*?);\scodecs=/
file_name = title.delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + "." + format_ext[selected_format][:extension]
puts "downloading to " + file_name
Expand Down

0 comments on commit d2d6830

Please sign in to comment.