Class: Anstaendig::AbstractAgent

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

Overview

This interface describes download agents.

Defined Under Namespace

Classes: NoSuchQualityException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, quality = :high) ⇒ AbstractAgent

If an agent does not set @filename, it would be the current time and date.



15
16
17
# File 'lib/anstaendig/abstractagent.rb', line 15

def initialize( url, quality = :high )
  @filename = Time.now.to_i
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/anstaendig/abstractagent.rb', line 6

def filename
  @filename
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/anstaendig/abstractagent.rb', line 6

def url
  @url
end

Instance Method Details

#recodeObject

Contains the subshell command to recode the video to a Vorbis/Theora encoded video in an OGG container. Meant to be overloaded by the agent if necessary.



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

def recode
  `ffmpeg -i "#{@filename}" -acodec libvorbis -vcodec libtheora "#{@filename}.ogg"`
end

#ripObject

Contains the subshell command to rip the video stream. mplayer by default. Meant to be overloaded by the agent if necessary.



31
32
33
# File 'lib/anstaendig/abstractagent.rb', line 31

def rip
  `mplayer -user-agent "#{userAgent}" -dumpstream -dumpfile "#{@filename}" "#{@url}"`
end

#runObject

Calls the ripping process after substitution of certain characters in the filename generated by the agent.



21
22
23
24
25
26
27
# File 'lib/anstaendig/abstractagent.rb', line 21

def run
  [ '/', '"', "'" ].each do |char|
    @filename = @filename.gsub( char, '?' )
  end

  rip
end

#userAgentObject

Return the user agent which is sent on stream retrieval. Meant to be overloaded by the agent if necessary.



44
45
46
# File 'lib/anstaendig/abstractagent.rb', line 44

def userAgent
  "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2) Gecko/20100323 Namoroka/3.6.2"
end