class Video

Constants

BASE_URI

Attributes

abstract[RW]
embed_code[RW]
event_short_code[RW]
host[RW]
title[RW]

Public Class Methods

find(event_short_code, title) click to toggle source
# 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
new(title, abstract, host, embed_code, event_short_code) click to toggle source
# File lib/get_freaky/video.rb, line 11
def initialize(title, abstract, host, embed_code, event_short_code)
  self.title = title
  self.abstract = abstract
  self.host = host
  self.embed_code = embed_code
  # 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

Private Class Methods

create_slug(event_short_code, title) click to toggle source

TODO: That's WAY too many lines of code to do something relatively simple. I'm sure I can do better with some time spent cooking up a regular expression Also I may come up against more situations in which slugify isn't consistent with the way ConFreaks creates slugs–perhaps look into what gem they-re using! For now though…it works!

# File lib/get_freaky/video.rb, line 98
def self.create_slug(event_short_code, title)
  _i = "#{event_short_code} #{title}"
  _i = _i.gsub('/', '-').gsub("'", '-')
  _i = _i.gsub('’', '-')
  _i = _i.slugify
  _i = _i.gsub('---', '-').gsub('--', '-')
  _i = _i.chomp('-').chomp(',')
end
create_video(response, event_short_code=nil) click to toggle source
# File lib/get_freaky/video.rb, line 83
def self.create_video(response, event_short_code=nil)
  Video.new(
    response["title"],
    response["abstract"],
    response["host"],
    response["embed_code"],
    event_short_code
  )
end

Public Instance Methods

download() click to toggle source
# 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.message
  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() click to toggle source
# File lib/get_freaky/video.rb, line 65
def event
  Event.find(event_short_code)
end
to_s() click to toggle source
# 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() click to toggle source
# File lib/get_freaky/video.rb, line 73
def url
  if host == "youtube"
    "https://www.youtube.com/watch?v=#{embed_code}"
  elsif host == "vimeo"
    "https://vimeo.com/#{embed_code}"
  end
end