Module: Videoinfo

Defined in:
lib/videoinfo.rb,
lib/videoinfo/cli.rb,
lib/videoinfo/video.rb,
lib/videoinfo/errors.rb,
lib/videoinfo/result.rb,
lib/videoinfo/version.rb,
lib/videoinfo/image_host.rb,
lib/videoinfo/videos/movie.rb,
lib/videoinfo/image_hosts/imgur.rb,
lib/videoinfo/results/movie_result.rb

Defined Under Namespace

Modules: ImageHosts, Results, Videos Classes: CLI, Error, ImageHost, Result, Video

Constant Summary collapse

VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.analyze_movie(name, file, screenshots = 0) ⇒ Object

Helper method to analyze a movie.



21
22
23
# File 'lib/videoinfo.rb', line 21

def self.analyze_movie(name, file, screenshots = 0)
  Videos::Movie.new(name, file, screenshots).populate_result!
end

.ffmpeg_binaryObject

Get the path to the ffmpeg binary, defaulting to ‘ffmpeg’.



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

def self.ffmpeg_binary
  @ffmpeg_binary ||= 'ffmpeg'
end

.ffmpeg_binary=(ffmpeg) ⇒ Object

Set the path of the ffmpeg binary.



53
54
55
# File 'lib/videoinfo.rb', line 53

def self.ffmpeg_binary=(ffmpeg)
  @ffmpeg_binary = ffmpeg.to_s.shellescape
end

.google(term) ⇒ Object

Performs a google search and returns the top 10 results.



26
27
28
29
30
31
32
33
34
35
# File 'lib/videoinfo.rb', line 26

def self.google(term)
  uri = URI("https://www.google.com/search?hl=en&q=#{CGI.escape(term)}")
  begin
    response = Net::HTTP.get_response(uri)
    document = Nokogiri::HTML(response.body.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => ''))
    document.css('cite').map { |node| node.inner_text }
  rescue => e
    raise Error, "could not search google for '#{term}'. #{e.message}"
  end
end

.image_hostObject

Get the image host class, defaulting to ImageHosts::Imgur.new.



68
69
70
# File 'lib/videoinfo.rb', line 68

def self.image_host
  @image_host ||= ImageHosts::Imgur.new
end

.image_host=(host) ⇒ Object

Set the image host class. Must be an object that responds to upload(File) and returns a URL.



63
64
65
# File 'lib/videoinfo.rb', line 63

def self.image_host=(host)
  @image_host = host
end

.interactive=(value) ⇒ Object

Set interactive mode to true or false.



73
74
75
# File 'lib/videoinfo.rb', line 73

def self.interactive=(value)
  @interactive = value
end

.interactive?Boolean

True if interactive mode is enabled, defaulting to false.

Returns:

  • (Boolean)


78
79
80
# File 'lib/videoinfo.rb', line 78

def self.interactive?
  @interactive ||= false
end

.mediainfo_binaryObject

Get the path to the mediainfo binary, defaulting to ‘mediainfo’.



48
49
50
# File 'lib/videoinfo.rb', line 48

def self.mediainfo_binary
  @mediainfo_binary ||= 'mediainfo'
end

.mediainfo_binary=(mediainfo) ⇒ Object

Set the path of the mediainfo binary.



43
44
45
# File 'lib/videoinfo.rb', line 43

def self.mediainfo_binary=(mediainfo)
  @mediainfo_binary = mediainfo.to_s.shellescape
end

.upload_screenshot(image) ⇒ Object

Uploads a screenshot to the currently configured image_host and returns a URL to the image.



38
39
40
# File 'lib/videoinfo.rb', line 38

def self.upload_screenshot(image)
  image_host.upload(image)
end