Class: RSSParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RSSParser

Returns a new instance of RSSParser.



3
4
5
6
7
8
9
10
# File 'lib/rrs_parser.rb', line 3

def initialize(url)
  @page = Hpricot(Net::HTTP.get(URI.parse(url)))
  @url = url
  @download_link = ""
  @filename = ""

  find_form_action
end

Instance Attribute Details

Returns the value of attribute download_link.



2
3
4
# File 'lib/rrs_parser.rb', line 2

def download_link
  @download_link
end

#filenameObject (readonly)

Returns the value of attribute filename.



2
3
4
# File 'lib/rrs_parser.rb', line 2

def filename
  @filename
end

#form_actionObject (readonly)

Returns the value of attribute form_action.



2
3
4
# File 'lib/rrs_parser.rb', line 2

def form_action
  @form_action
end

#metadataObject (readonly)

Returns the value of attribute metadata.



2
3
4
# File 'lib/rrs_parser.rb', line 2

def 
  @metadata
end

#pageObject (readonly)

Returns the value of attribute page.



2
3
4
# File 'lib/rrs_parser.rb', line 2

def page
  @page
end

#urlObject (readonly)

Returns the value of attribute url.



2
3
4
# File 'lib/rrs_parser.rb', line 2

def url
  @url
end

Instance Method Details

#parse_next_pageObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rrs_parser.rb', line 12

def parse_next_page
  @metadata = {}

  resp = Net::HTTP.post_form(URI.parse(@form_action), {"dl.start"=>"free"})
  body = resp.body

  body.each_line do |line|
    if line =~ /.*name="dlf"\saction="(\S*)"/
      $stderr.puts "-> Downloading #{$1}..."
      @download_link = $1
      @filename = $1.to_s.split("/").last
    end

    if line =~ /var\s*c\s*=\s*(\d+)/
      @metadata[:seconds] = $1.to_i
    elsif line =~ /try\s*again\s*in\s*about\s*(\d+)\s*minutes/
      @metadata[:minutes] = $1.to_i
    end
  end

  @metadata
end