Class: Saber::Tracker::PTP

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

Constant Summary collapse

BASE_URL =
"https://tls.passthepopcorn.me"
LOGIN_CHECK_PATH =
"/inbox.php"
FIELDS =
{ 
  "new" => {
    "file_input" => :file_upload,
    "type" => :select_list,
    "title" => :text,
    "year" => :text,
    "image" => :text,
    "trailer" => :text,
    "special" => :checkbox,
    "remaster" => :checkbox,
    "scene" => :checkbox,
    "source" => :select_list,
    "codec" =>  :select_list,
    "container" => :select_list,
    "resolution" => :select_list,
    "tags" => :text,
    "album_desc" => :text,
    "release_desc" => :text,
  },

  "add" => {
    "file_input" => :file_upload,
    "special" => :checkbox,
    "remaster" => :checkbox,
    "scene" => :checkbox,
    "source" => :select_list,
    "codec" =>  :select_list,
    "container" => :select_list,
    "resolution" => :select_list,
    "release_desc" => :text,
  },
}

Constants inherited from Base

Base::DELEGATE_METHODS, Base::POPULATE_TYPES

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

#do_upload(file, info) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/saber/tracker/ptp.rb', line 42

def do_upload(file, info)
  info["file_input"] = "#{file}.torrent"
  path = info["group_id"] ? "/upload.php?group_id=#{info['group_id']}" : "/upload.php"
  agent.get(path) {|p|
    ret = p.form_with(action: "") {|f|
      FIELDS[info.type].each {|k,t|
        f.set(t, k, info[k])
      }

      # subtitles[]
      info["subtitles"].each {|subtitle|
        f.checkboxes("subtitles[]").find {|checkbox|
          checkbox.node.at("following-sibling::label").inner_text == subtitle
        }.check
      }
    }.submit

    # error
    if ret.uri.path =~ %~^/upload.php~
      errors = ret.search("//*[class='bvalidator_errmsg']")
      msg = errors.map{|e| "- #{ReverseMarkdown.parse(e)}" }.join("\n\n")
      Saber.ui.error "ERROR:\n #{msg}"
      return false
    else
      return true
    end
  }
end