Sha256: 76953278cfa02e6acbc974cffa55927d03505186789f194bba2aa31eed2222ee

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

module Saber
  module Tracker
    class STP < Base
      BASE_URL = "https://stopthepress.es"
      LOGIN_CHECK_PATH = "/inbox.php"

      TAG_MAP = {
        "nonfiction" => "non.fiction"
      }

      def exists?(o={})
        url = "/torrents.php?cataloguenumber=#{o[:isbn]}"
        page = agent.get(url)

        not page.at("//*[@id='content']/div[2]/h2[contains(text(), 'Your search did not match anything.')]")
      end

      def convert_tags(*tags)
        tags.map{|tag|
          tag = tag.downcase.gsub(/&/, "and").gsub(/\s+/, ".").gsub(/'/, "")

          TAG_MAP.fetch(tag, tag)
        }
      end

    protected

      def do_login_with_username(username)
        agent.get("/login.php") {|p|
          ret = p.form_with(action: "login.php" ) {|f|
            # error
            unless f 
              Saber.ui.error! p.at("//body").inner_text
            end

            f.username = username || ask("Username: ")
            f.password = ask("Password: "){|q| q.echo = false}
            f.checkbox(name: "keeplogged").check
          }.submit

          # error
          if ret.uri.path == "/login.php"
            msg = ret.at("//*[@id='loginform']/span[2]").inner_text
            Saber.ui.error "Failed. You have #{msg} attempts remaining."
            return false
          else
            return true
          end
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saber-1.2.3 lib/saber/tracker/stp.rb
saber-1.2.2 lib/saber/tracker/stp.rb
saber-1.2.1 lib/saber/tracker/stp.rb
saber-1.2.0 lib/saber/tracker/stp.rb