Class: Youruby::Youtube

Inherits:
Object
  • Object
show all
Defined in:
lib/youruby.rb

Overview

Youtube Class

Examples:

Youruby::Youtube.new(id)

Constant Summary collapse

YT_DL =
File.join(root_path, yt_path)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/youruby.rb', line 16

def id
  @id
end

#locationObject (readonly)

Returns the value of attribute location.



16
17
18
# File 'lib/youruby.rb', line 16

def location
  @location
end

Instance Method Details

#download_videoObject



58
59
60
# File 'lib/youruby.rb', line 58

def download_video
  system(YT_DL, '-o', file_path, url, '--no-progress')
end

#file_pathObject



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

#titleObject



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