Module: ViddlRb

Defined in:
lib/viddl-rb.rb

Defined Under Namespace

Classes: DownloadError, PluginError

Class Method Summary collapse

Class Method Details

.get_names(url) ⇒ Object

returns an array of filenames for the given video url.



61
62
63
64
# File 'lib/viddl-rb.rb', line 61

def self.get_names(url)
  urls_filenames = get_urls_names(url)
  urls_filenames.nil? ? nil : urls_filenames.map { |uf| uf[:name] }
end

.get_urls(url) ⇒ Object

returns an array of download urls for the given video url.



55
56
57
58
# File 'lib/viddl-rb.rb', line 55

def self.get_urls(url)
  urls_filenames = get_urls_names(url)
  urls_filenames.nil? ? nil : urls_filenames.map { |uf| uf[:url] }
end

.get_urls_exts(url) ⇒ Object

same as get_urls_and_filenames but with the extensions only.



67
68
69
70
71
72
73
# File 'lib/viddl-rb.rb', line 67

def self.get_urls_exts(url)
  urls_filenames = get_urls_names(url)
  urls_filenames.map do |uf|
    ext = File.extname(uf[:name])
    {:url => uf[:url], :ext => ext}
  end
end

.get_urls_names(url) ⇒ Object

returns an array of hashes containing the download url(s) and filenames(s) for the specified video url. if the url does not match any plugin, return nil and if a plugin throws an error, throw PluginError. the reason for returning an array is because some urls will give multiple download urls (for example a Youtube playlist url).



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/viddl-rb.rb', line 36

def self.get_urls_names(url)
  plugin = PluginBase.registered_plugins.find { |p| p.matches_provider?(url) }

  if plugin 
    begin
      #we'll end up with an array of hashes with they keys :url and :name
      urls_filenames = plugin.get_urls_and_filenames(url)
    rescue PluginBase::CouldNotDownloadVideoError => e
      raise_download_error(e)
    rescue StandardError => e
      raise_plugin_error(e, plugin)
    end
    follow_all_redirects(urls_filenames)
  else
    nil
  end
end

.io=(io_object) ⇒ Object



22
23
24
# File 'lib/viddl-rb.rb', line 22

def self.io=(io_object)
  PluginBase.io = io_object
end