Class: Saber::Tracker::BIB

Inherits:
Base
  • Object
show all
Defined in:
lib/saber/tracker/bib.rb

Constant Summary collapse

POPULATE_TYPES =
%w[ebook audiobook]
BASE_URL =
"http://bibliotik.org"
LOGIN_CHECK_PATH =
"/conversations"
FIELDS =
{ 
  "applications" => {
    "TorrentFile" => :file_upload,
    "Scene" => :checkbox,
    "Title" => :text,
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  },

  "articles" => {
    "TorrentFile" => :file_upload,
    "Authors" => :text,
    "Title" => :text,
    "Pages" => :text,
    "Year" => :text,
    "YearTo" => :text,
    "Complete" => :checkbox,
    "Format" => :text,
    "Language" => :text,  
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  },


  "autobooks" => {
    "TorrentFile" => :file_upload, 
    "Authors" => :text,
    "Title" => :text,
    "ISBN" => :text,
    "Publishers" => :text,
    "Year" => :text,
    "Format" => :select_list_text,
    "Language" => :select_list_text,
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  },

  "comics" => {
    "TorrentFile" => :file_upload, 
    "Scene" => :checkbox,
    "Authors" => :text,
    "Artists" => :text,
    "Title" => :text,
    "Publishers" => :text,
    "Pages" => :text,
    "Year" => :text,
    "YearTo" => :text,
    "Complete" => :checkbox,
    "Format" => :select_list_text,
    "Language" => :select_list_text,
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  },

  "ebooks" => {
    "TorrentFile" => :file_upload, 
    "Scene" => :checkbox,
    "Authors" => :text, 
    "Title" => :text,
    "ISBN" => :text,
    "Publishers" => :text,
    "Pages" => :text,
    "Year" => :text,
    "Format" => :select_list_text,
    "Language" => :select_list_text,
    "Retail" => :checkbox,
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  },

  "journals" => {
    "TorrentFile" => :file_upload, 
    "Scene" => :checkbox,
    "Title" => :text,
    "Pages" => :text,
    "Year" => :text,
    "YearTo" => :text,
    "Complete" => :checkbox,
    "Format" => :select_list_text,
    "Language" => :select_list_text,
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  },

  "magazines" => {
    "TorrentFile" => :file_upload, 
    "Scene" => :checkbox,
    "Title" => :text,
    "Pages" => :text,
    "Year" => :text,
    "YearTo" => :text,
    "Complete" => :checkbox,
    "Format" => :select_list_text,
    "Language" => :select_list_text,
    "Tags" => :text,
    "Image" => :text,
    "Description" => :text,
    "Anonymous" => :checkbox,
    "Notify" => :checkbox,
  }
}

Constants inherited from Base

Saber::Tracker::Base::DELEGATE_METHODS

Instance Attribute Summary

Attributes inherited from Base

#agent, #name, #options

Instance Method Summary collapse

Methods inherited from Base

can_populate?, inherited, #initialize, #login, #populate, #upload

Constructor Details

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

Instance Method Details

#browse(page, &blk) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/saber/tracker/bib.rb', line 163

def browse(page, &blk)
  ret = []
  path = "/torrents/advanced/?search=&cat[0]=5&y1=&y2=&p1=&p2=&size1=&size2=&for[0]=15&orderby=added&order=desc&page=#{page}"

  p = agent.get(path) 
  p.search("//td[contains(string(), '[Retail]')]/span[@class='title']/a").each {|a|
    page = agent.get(a["href"])

    title = page.at("//*[@id='title']").inner_text.strip
    tags = page.search("//*[@class='taglist']/a").map{|n| n.inner_text}
    isbn = page.at("//*[@id='details_content_info']").inner_text.match(/\((\d+)\)/).try(:[], 1) || ""
    download_link = page.at("//*[@id='details_links']/a[@title='Download']")["href"]
    filenames = page.search("//*[@id='files']//td[1]").map{|n| n.inner_text}

    torrent = {title: title, tags: tags, isbn: isbn, download_link: download_link, filenames: filenames}
    blk.call(torrent) if blk
    ret << torrent
  }

  ret
end

#convert_tags(*tags) ⇒ Object



185
186
187
# File 'lib/saber/tracker/bib.rb', line 185

def convert_tags(*tags)
  tags
end

#do_upload(file, info) ⇒ Boolean

Upload one torrent file to the site.

Parameters:

  • file (String)

    a filename

  • info (Optimism)

    comes from <file>.yml data file.

Returns:

  • (Boolean)

    result-code



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/saber/tracker/bib.rb', line 136

def do_upload(file, info)
  info["TorrentFile"] = "#{file}.torrent"

  agent.get("/upload/#{info.type}") {|p|
    ret = p.form_with(action: "") {|f|
      FIELDS[info.type].each {|k,t|
        f.set(t, "#{k}Field", info[k])
      }
    }.submit

    # error if return path is "/upload/<type>"
    if ret.uri.path == "/upload/#{info.type}"
      msg = nil
      if (err=ret.at("//*[@id='formerrorlist']"))
        # convert html to markdown for pretty print.
        msg = ReverseMarkdown.parse(err)
      else
        msg = ret.body
      end
      Saber.ui.error "ERROR:\n#{msg}"
      return false
    else
      return true
    end
  }
end