Class: WGif::Downloader
- Inherits:
-
Object
- Object
- WGif::Downloader
- Defined in:
- lib/wgif/downloader.rb
Instance Method Summary collapse
- #get_video(youtube_url) ⇒ Object
-
#initialize ⇒ Downloader
constructor
A new instance of Downloader.
- #video_id(youtube_url) ⇒ Object
- #video_url(youtube_url) ⇒ Object
Constructor Details
#initialize ⇒ Downloader
Returns a new instance of Downloader.
13 14 15 |
# File 'lib/wgif/downloader.rb', line 13 def initialize @cache = WGif::VideoCache.new end |
Instance Method Details
#get_video(youtube_url) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wgif/downloader.rb', line 32 def get_video(youtube_url) id = video_id youtube_url cached_clip = @cache.get(id) if cached_clip cached_clip else temp = load_clip(id, youtube_url) video = WGif::Video.new(id, temp.path) video end end |
#video_id(youtube_url) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/wgif/downloader.rb', line 24 def video_id(youtube_url) uri = URI(youtube_url) params = CGI.parse(uri.query) params['v'].first rescue raise WGif::InvalidUrlException end |
#video_url(youtube_url) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/wgif/downloader.rb', line 17 def video_url(youtube_url) urls = ViddlRb.get_urls(youtube_url) urls.first rescue raise WGif::VideoNotFoundException end |