Class: Youruby::Youtube
- Inherits:
-
Object
- Object
- Youruby::Youtube
- Defined in:
- lib/youruby.rb
Overview
Youtube Class
Constant Summary collapse
- YT_DL =
File.join(root_path, yt_path)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
- #download_video ⇒ Object
- #file_path ⇒ Object
-
#initialize(id) ⇒ Youtube
constructor
A new instance of Youtube.
- #path(path) ⇒ Object
- #thumbnail(path) ⇒ Object
- #title ⇒ Object
- #url(url = nil) ⇒ Object
Constructor Details
#initialize(id) ⇒ Youtube
Returns a new instance of Youtube.
21 22 23 24 |
# File 'lib/youruby.rb', line 21 def initialize(id) @id = id @location = 'temp/download' end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/youruby.rb', line 16 def id @id end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
16 17 18 |
# File 'lib/youruby.rb', line 16 def location @location end |
Instance Method Details
#download_video ⇒ Object
58 59 60 |
# File 'lib/youruby.rb', line 58 def download_video system(YT_DL, '-o', file_path, url, '--no-progress') end |
#file_path ⇒ Object
31 32 33 |
# File 'lib/youruby.rb', line 31 def file_path File.join(@location, "#{title}-#{id}.mp4") end |
#path(path) ⇒ Object
53 54 55 56 |
# File 'lib/youruby.rb', line 53 def path(path) @location = path true end |
#thumbnail(path) ⇒ Object
49 50 51 |
# File 'lib/youruby.rb', line 49 def thumbnail(path) "http://img.youtube.com/vi/#{@id}/#{path}.jpg" end |
#title ⇒ Object
26 27 28 29 |
# File 'lib/youruby.rb', line 26 def title title = `#{YT_DL} --get-title #{url}` title.delete("\n") end |
#url(url = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/youruby.rb', line 35 def url(url = nil) if url url = URI.parse url url_parse = params(url.query) @id = url_parse['v'].first true else "http://youtube.com/watch?v=#{@id}" end end |