Class: Anstaendig::ArdAgent

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

Overview

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

Instance Attribute Summary

Attributes inherited from AbstractAgent

#filename, #url

Instance Method Summary collapse

Methods inherited from AbstractAgent

#recode, #rip, #run, #userAgent

Constructor Details

#initialize(uri, quality) ⇒ ArdAgent

Returns a new instance of ArdAgent.



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
# File 'lib/anstaendig/agents/ard.rb', line 6

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

	doc = Nokogiri::HTML( open( uri.to_s ) )
	raw = doc.content.split( "\r\n" ).grep( /rtmp/ )

	@url = case( quality )
		when :high, :default
			conjure( raw.last )
		when :medium
			begin
				conjure( raw[1] )
			rescue( NoMethodError )
				raise( NoSuchQualityException )
			end
		when :low
			conjure( raw.first )
		else
			raise( NoSuchQualityException )
	end

	title = doc.xpath( '//title' ).inner_text
	title = title.gsub( 'ARD Mediathek: ', '' )
	n = title.index( /\ -\ [A-Za-z]*,/ ) - 1

	@filename = title[0..n] + '.flv'
end

Instance Method Details

#conjure(string) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/anstaendig/agents/ard.rb', line 35

def conjure( string )
	a = string.index( '"' ) + 1
	b = string.index( '", "' ) - 1
	c = string.index( '")' ) - 1

	string.slice( a..b ) + string.slice( b+5..c )
end