Class: RR2Fetcher

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

Constant Summary collapse

VERSION =
"0.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RR2Fetcher

Returns a new instance of RR2Fetcher.



7
8
9
10
11
# File 'lib/rr2fetcher.rb', line 7

def initialize(options)
  @download_list = []
  @app = options[:backend]
  @options = options
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



5
6
7
# File 'lib/rr2fetcher.rb', line 5

def app
  @app
end

#download_listObject

Returns the value of attribute download_list.



4
5
6
# File 'lib/rr2fetcher.rb', line 4

def download_list
  @download_list
end

Instance Method Details

#add_download(*links) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rr2fetcher.rb', line 13

def add_download(*links)
  links.each do |link|
    if File.exist?(link)
      File.open(link) do |f|
        @download_list += f.readlines
      end
    else
      @download_list << link
    end
  end
end

#download(to_download) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rr2fetcher.rb', line 33

def download(to_download)
  parser = RSSParser.new(to_download)

  wait_until_ready(parser)
  agent = "Mozilla Firefox 1.5"

  cmd = "wget -U '#{agent}' '#{parser.download_link}' --post-data='mirror=on&x=67&y=50'"
  file = parser.filename # FIXME: check if download_link is valid

  case @app
    when :curl
      cmd = "curl -A '#{agent}' --url '#{parser.download_link}' --data 'mirror=on&x=67&y=50' > #{file}"
    when :kget4
      url = %@'#{parser.download_link}?mirror=on&x=67&y=50'@
      cmd = "qdbus org.kde.kget /kget/MainWindow_1 org.kde.kget.addTransfer '#{parser.download_link}' ./#{file} true"
  end

  system(cmd)
end

#start_dowloadObject



25
26
27
28
29
30
31
# File 'lib/rr2fetcher.rb', line 25

def start_dowload
  while !@download_list.empty?
    url = @download_list.pop.strip
    next if url.empty? || downloaded?(url)
    download url
  end
end