Class: Saber::Task::FindUploads

Inherits:
Base
  • Object
show all
Defined in:
lib/saber/task/find_uploads.rb

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize, invoke

Constructor Details

This class inherits a constructor from Saber::Task::Base

Instance Method Details

#find_uploads(page = "1") ⇒ Object



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
38
39
40
# File 'lib/saber/task/find_uploads.rb', line 8

def find_uploads(page="1")
  bib = Tracker["bib"].new(options)
  stp = Tracker["stp"].new(options)
  dir = Rc._fetch("find_uploads.dir", ".")
  bib.agent.pluggable_parser["application/x-bittorrent"] = Mechanize::DirectorySaver.save_to(dir.to_s)
  bib.
  stp.

  bib.browse(page) {|torrent|
    title, isbn, download_link, filenames, tags = torrent[:title], torrent[:isbn], 
      torrent[:download_link], torrent[:filenames], torrent[:tags]

    generic_tags = convert_bibtags(tags)

    begin
      isbn = ISBN.thirteen(torrent[:isbn])
    rescue ISBN::Invalid13DigitISBN # empty
      next
    end

    if not stp.exists?(isbn: isbn)
      bib.get(download_link)

      Saber.ui.say "#{isbn} #{title}\n    #{filenames.join("\n    ")}"
      File.append("list", "#{filenames[0]}:#{isbn}\n")

      # local data
      local_data = Pa.exists?("#{Rc.p.database}/#{isbn}.yml") ? YAML.load_file("#{Rc.p.database}/#{isbn}.yml") : {}
      local_data.merge!({"tags" => generic_tags.join(", "), "bib.tags" => tags.join(", ")})
      File.write "#{Rc.p.database}/#{isbn}.yml", YAML.dump(local_data)
    end
  }
end