Skip to content
Browse files

Added Veoh.com plugin

  • Loading branch information...
1 parent 5664ac6 commit 06fba743ea3a06dda5e2cd4e1d976fc6e182c220 @kl kl committed Nov 20, 2011
Showing with 46 additions and 0 deletions.
  1. +46 −0 plugins/veoh.rb
View
46 plugins/veoh.rb
@@ -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

0 comments on commit 06fba74

Please sign in to comment.
Something went wrong with that request. Please try again.