Class: Video
Constant Summary collapse
- BASE_URI =
"http://confreaks.tv/api/v1"
Instance Attribute Summary collapse
-
#abstract ⇒ Object
Returns the value of attribute abstract.
-
#embed_code ⇒ Object
Returns the value of attribute embed_code.
-
#event_short_code ⇒ Object
Returns the value of attribute event_short_code.
-
#host ⇒ Object
Returns the value of attribute host.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #download ⇒ Object
- #event ⇒ Object
-
#initialize(title, abstract, host, embed_code, event_short_code) ⇒ Video
constructor
A new instance of Video.
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(title, abstract, host, embed_code, event_short_code) ⇒ Video
Returns a new instance of Video.
11 12 13 14 15 16 17 18 |
# File 'lib/get_freaky/video.rb', line 11 def initialize(title, abstract, host, , event_short_code) self.title = title self.abstract = abstract self.host = host self. = # TODO: This feels like a kludge to me--figure out a better way to deal with the event_short_code for featured videos self.event_short_code = event_short_code || nil end |
Instance Attribute Details
#abstract ⇒ Object
Returns the value of attribute abstract.
9 10 11 |
# File 'lib/get_freaky/video.rb', line 9 def abstract @abstract end |
#embed_code ⇒ Object
Returns the value of attribute embed_code.
9 10 11 |
# File 'lib/get_freaky/video.rb', line 9 def @embed_code end |
#event_short_code ⇒ Object
Returns the value of attribute event_short_code.
9 10 11 |
# File 'lib/get_freaky/video.rb', line 9 def event_short_code @event_short_code end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/get_freaky/video.rb', line 9 def host @host end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/get_freaky/video.rb', line 9 def title @title end |
Class Method Details
.find(event_short_code, title) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/get_freaky/video.rb', line 29 def self.find(event_short_code, title) slug = self.create_slug(event_short_code, title) response = get("/videos/#{slug}.json") if response.success? self.create_video(response, event_short_code) else puts slug puts title puts "#{response["status"]} error: #{response["error"]}" end end |
.find_featured ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/get_freaky/video.rb', line 20 def self.find_featured response = get("/featured-video.json") if response.success? self.create_video(response) else raise response.response end end |
Instance Method Details
#download ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/get_freaky/video.rb', line 41 def download puts "downloading #{title}" YoutubeDL.download url, { output: "#{title}.mp4" } rescue Cocaine::ExitStatusError => e regex_errors = [ /YouTube said\: This video does not exist\./, /YouTube said\: Please sign in to view this video\./, /Incomplete YouTube ID/, /HTTP Error 404\: Not Found/, # for vimeo ] case e. when *regex_errors puts $LAST_MATCH_INFO[0] return when /content too short/ puts "#{$LAST_MATCH_INFO[0]} - retry" return download end # raise different uncaught exceptions raise e end |
#event ⇒ Object
65 66 67 |
# File 'lib/get_freaky/video.rb', line 65 def event Event.find(event_short_code) end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/get_freaky/video.rb', line 69 def to_s %Q{\n#{Paint['Title:', :green]} #{title}\n#{Paint["Description:", :green]} #{abstract}\n} end |
#url ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/get_freaky/video.rb', line 73 def url if host == "youtube" "https://www.youtube.com/watch?v=#{}" elsif host == "vimeo" "https://vimeo.com/#{}" end end |