Class: Anstaendig::ArteAgent

Inherits:
AbstractAgent show all
Defined in:
lib/anstaendig/agents/arte.rb

Overview

Agent for anstaendig to download videos from the arte media center.

Instance Attribute Summary

Attributes inherited from AbstractAgent

#filename, #url

Instance Method Summary collapse

Methods inherited from AbstractAgent

#recode, #run, #userAgent

Constructor Details

#initialize(uri, quality) ⇒ ArteAgent



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/anstaendig/agents/arte.rb', line 6

def initialize( uri, quality )
  require( 'nokogiri' )
  require( 'open-uri' )

  lang = ENV['LANG'].slice(0..1)

  doc = open( uri.to_s ).readlines

          @swfurl = doc.grep( /^<embed/ )[0].match( /\"(.*)\"/ )[1]

  doc = Nokogiri::XML( open(
    doc.grep( /vars_player\.videorefFileUrl/ )
      .first.match( /(http.*xml)/ )[1]
  ))

  doc.xpath( '//videos/video' ).each do |item|
    if( item.attr( 'lang' ) == lang )
      doc = Nokogiri::XML( open( item.attr( 'ref' ) ) )
    end
  end

  @filename = doc.xpath( '//name' ).first.text + '.flv'

  case( quality )
    when :hd, :high, :default
      @url = doc.xpath( '//urls/url[@quality="hd"]' ).text
    when :sd, :medium, :low
      @url = doc.xpath( '//urls/url[@quality="sd"]' ).text
    else
      raise( NoSuchQualityException )
  end
end

Instance Method Details

#ripObject

Ripping arte clips no longer works with mplayer :(.



40
41
42
# File 'lib/anstaendig/agents/arte.rb', line 40

def rip
  `rtmpdump -W "#{@swfurl}" -r "#{@url}" -o "#{@filename}"`
end