saber 0.0.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +3 -0
  4. data/Gemfile +18 -8
  5. data/Gemfile.lock +72 -33
  6. data/Guardfile +4 -0
  7. data/README.md +192 -52
  8. data/Rakefile +46 -0
  9. data/bin/1saber +5 -3
  10. data/bin/saber +4 -0
  11. data/bin/saber.bib +3 -0
  12. data/bin/saber.what +3 -0
  13. data/extconf.rb +4 -1
  14. data/lib/saber.rb +7 -13
  15. data/lib/saber/autofetcher.rb +8 -0
  16. data/lib/saber/autofetcher/client.rb +66 -0
  17. data/lib/saber/autofetcher/server.rb +78 -0
  18. data/lib/saber/cli.rb +65 -26
  19. data/lib/saber/{downloader.rb → fetcher.rb} +9 -11
  20. data/lib/saber/mechanize_ext.rb +136 -0
  21. data/lib/saber/rc.rb +3 -21
  22. data/lib/saber/task.rb +26 -11
  23. data/lib/saber/task/base.rb +18 -0
  24. data/lib/saber/task/clean.rb +18 -0
  25. data/lib/saber/task/generate.rb +38 -0
  26. data/lib/saber/task/make.rb +44 -0
  27. data/lib/saber/task/send.rb +21 -0
  28. data/lib/saber/task/upload.rb +37 -0
  29. data/lib/saber/tracker.rb +28 -0
  30. data/lib/saber/tracker/base.rb +115 -2
  31. data/lib/saber/tracker/bb.rb +244 -0
  32. data/lib/saber/tracker/bib.rb +225 -0
  33. data/lib/saber/tracker/ptp.rb +100 -0
  34. data/lib/saber/tracker/what.rb +55 -7
  35. data/lib/saber/ui.rb +65 -22
  36. data/lib/saber/version.rb +1 -1
  37. data/rutorrent/init.js +8 -9
  38. data/rutorrent/plugin.info +1 -1
  39. data/saber.gemspec +14 -10
  40. data/spec/data/_saber/.gitkeep +0 -0
  41. data/spec/saber/downloader_spec.rb +5 -2
  42. data/spec/saber/task_spec.rb +16 -0
  43. data/spec/saber/tracker/bib_spec.rb +24 -0
  44. data/spec/spec_helper.rb +25 -0
  45. data/templates/_saberrc +36 -0
  46. data/templates/bb/anime.yml +6 -0
  47. data/templates/bb/application.yml +7 -0
  48. data/templates/bb/audiobook.yml +12 -0
  49. data/templates/bb/comic.yml +7 -0
  50. data/templates/bb/documentary.yml +26 -0
  51. data/templates/bb/ebook.yml +8 -0
  52. data/templates/bb/elearning_video.yml +7 -0
  53. data/templates/bb/game_console.yml +6 -0
  54. data/templates/bb/game_pc.yml +6 -0
  55. data/templates/bb/magazine.yml +6 -0
  56. data/templates/bb/misc.yml +6 -0
  57. data/templates/bb/movie.yml +26 -0
  58. data/templates/bb/music.yml +21 -0
  59. data/templates/bb/tv.yml +6 -0
  60. data/templates/bib/application.yml +9 -0
  61. data/templates/bib/article.yml +18 -0
  62. data/templates/bib/audiobook.yml +17 -0
  63. data/templates/bib/comic.yml +22 -0
  64. data/templates/bib/ebook.yml +20 -0
  65. data/templates/bib/journal.yml +18 -0
  66. data/templates/bib/magazine.yml +18 -0
  67. data/templates/ptp/movie.yml +63 -0
  68. data/templates/ptp/movie_add.yml +35 -0
  69. data/templates/what/ebook.yml +6 -0
  70. data/templates/what/music.yml +2 -0
  71. data/templates/what/music_add.yml +2 -0
  72. metadata +182 -26
  73. data/doc/Development.md +0 -3
  74. data/lib/saber/client.rb +0 -58
  75. data/lib/saber/server.rb +0 -70
  76. data/saber.watchr +0 -23
@@ -0,0 +1,100 @@
1
+ require "active_support/core_ext/object/try"
2
+
3
+ module Saber
4
+ module Tracker
5
+ class PTP < Base
6
+ @@BASE_URL = "https://tls.passthepopcorn.me"
7
+ @@LOGIN_CHECK_PATH = "/inbox.php"
8
+
9
+ FIELDS = {
10
+ "new" => {
11
+ "file_input" => :file_upload,
12
+ "type" => :select_list,
13
+ "title" => :text,
14
+ "year" => :text,
15
+ "image" => :text,
16
+ "trailer" => :text,
17
+ "special" => :checkbox,
18
+ "remaster" => :checkbox,
19
+ "scene" => :checkbox,
20
+ "source" => :select_list,
21
+ "codec" => :select_list,
22
+ "container" => :select_list,
23
+ "resolution" => :select_list,
24
+ "tags" => :text,
25
+ "album_desc" => :text,
26
+ "release_desc" => :text,
27
+ },
28
+
29
+ "add" => {
30
+ "file_input" => :file_upload,
31
+ "special" => :checkbox,
32
+ "remaster" => :checkbox,
33
+ "scene" => :checkbox,
34
+ "source" => :select_list,
35
+ "codec" => :select_list,
36
+ "container" => :select_list,
37
+ "resolution" => :select_list,
38
+ "release_desc" => :text,
39
+ },
40
+ }
41
+
42
+ def do_upload(file, info)
43
+ info["file_input"] = "#{file}.torrent"
44
+ path = info["group_id"] ? "/upload.php?group_id=#{info['group_id']}" : "/upload.php"
45
+ agent.get(path) {|p|
46
+ ret = p.form_with(action: "") {|f|
47
+ FIELDS[info.type].each {|k,t|
48
+ f.set(t, k, info[k])
49
+ }
50
+
51
+ # subtitles[]
52
+ info["subtitles"].each {|subtitle|
53
+ f.checkboxes("subtitles[]").find {|checkbox|
54
+ checkbox.node.at("following-sibling::label").inner_text == subtitle
55
+ }.check
56
+ }
57
+ }.submit
58
+
59
+ # error
60
+ if ret.uri.path =~ %~^/upload.php~
61
+ errors = ret.search("//*[class='bvalidator_errmsg']")
62
+ msg = errors.map{|e| "- #{ReverseMarkdown.parse(e)}" }.join("\n\n")
63
+ Saber.ui.error "ERROR:\n #{msg}"
64
+ return false
65
+ else
66
+ return true
67
+ end
68
+ }
69
+ end
70
+
71
+ protected
72
+
73
+ def do_login_with_username
74
+ agent.get("/login.php") { |p|
75
+ ret = p.form_with(action: "login.php" ) {|f|
76
+ # error
77
+ unless f
78
+ Saber.ui.error! p.at("//body").inner_html
79
+ end
80
+
81
+ f.username = username || ask("Username: ")
82
+ f.password = ask("Password: "){|q| q.echo = false}
83
+ f.checkbox(name: "keeplogged").check
84
+ }.submit
85
+
86
+ # error
87
+ if ret.uri.path == "/login.php"
88
+ msg = ret.at("//*[@id='loginfail']/p[1]").inner_text
89
+ Saber.ui.error "Faild. #{msg}"
90
+ return false
91
+ else
92
+ return true
93
+ end
94
+ }
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ # vim: fdn=4
@@ -1,20 +1,68 @@
1
1
  module Saber
2
- class Tracker
2
+ module Tracker
3
+ # DON'T WORK for mechanize does not support javascript.
3
4
  class What < Base
4
- include HTTParty
5
- base_uri "http://what.cd"
5
+ @@BASE_URL = "https://what.cd"
6
+ @@LOGIN_CHECK_PATH = "/inbox.php"
6
7
 
7
- def login(username, password)
8
- self.post "/login.php", :body => {username: "SaberSalv", password: "futell2w"}
9
-
8
+ FIELDS = {
9
+ "E-Books" => {
10
+ "file_input" => :file_upload,
11
+ "type" => :select_list,
12
+ "title" => :text,
13
+ "tags" => :text,
14
+ "image" => :text,
15
+ "desc" => :text
16
+ }
17
+ }
18
+
19
+ def do_upload(file, info)
20
+ info["file_input"] = "#{file}.torrent"
21
+ path = info["group_id"] ? "/upload.php?group_id=#{info['group_id']}" : "/upload.php"
10
22
 
23
+ agent.get(path) {|p|
24
+ ret = p.form_with(action: "") {|f|
25
+ FIELDS[info.type].each {|k,t|
26
+ f.set(t, k, info[k])
27
+ }
28
+ }.submit
11
29
 
30
+ # error
31
+ if ret.uri.path =~ %r~^/upload.php~
32
+ msg = ReverseMarkdown.parse(ret.at("//*[@id='content']/div[2]/p[2]"))
33
+ Saber.ui.error "ERROR:\n#{msg}"
34
+ return false
35
+ else
36
+ return true
37
+ end
38
+ }
39
+ end
12
40
 
41
+ protected
13
42
 
43
+ def do_login_with_username(username)
44
+ agent.get("/login.php") {|p|
45
+ ret = p.form_with(action: "login.php" ) {|f|
46
+ # error
47
+ unless f
48
+ Saber.ui.error! p.at("//body").inner_text
49
+ end
14
50
 
51
+ f.username = username || ask("Username: ")
52
+ f.password = ask("Password: "){|q| q.echo = false}
53
+ f.checkbox(name: "keeplogged").check
54
+ }.submit
15
55
 
56
+ # error
57
+ if ret.uri.path == "/login.php"
58
+ msg = ret.at("//*[@id='loginform']/span[2]").inner_text
59
+ Saber.ui.error "Failed. You have #{msg} attempts remaining."
60
+ return false
61
+ else
62
+ return true
63
+ end
64
+ }
16
65
  end
17
-
18
66
  end
19
67
  end
20
68
  end
@@ -1,60 +1,103 @@
1
1
  module Saber
2
2
  class UI
3
- def warn(message)
3
+ def initialize
4
+ @quiet = false
5
+ @debug = ENV["DEBUG"]
4
6
  end
5
7
 
6
- def debug(message)
8
+ def info(msg)
9
+ do_info(msg) if !@quiet
7
10
  end
8
11
 
9
- def error(message)
12
+ def debug(msg)
13
+ do_debug(msg) if @debug && !@quiet
10
14
  end
11
15
 
12
- def info(message)
16
+ def warn(msg)
17
+ do_warn(msg)
13
18
  end
14
19
 
15
- def confirm(message)
20
+ def error(msg)
21
+ do_error(msg)
16
22
  end
17
23
 
18
- # alias to info
19
- def say(message)
20
- info(message)
24
+ # error with exit
25
+ def error!(msg)
26
+ error(msg)
27
+ exit 1
28
+ end
29
+
30
+ def confirm(msg)
31
+ do_confirm(msg) if !@quiet
32
+ end
33
+
34
+ def say(msg)
35
+ info(msg)
36
+ end
37
+
38
+ def be_quiet!
39
+ @quiet = true
40
+ end
41
+
42
+ def debug!
43
+ @debug = true
21
44
  end
22
45
 
23
46
  class Shell < UI
24
47
  attr_writer :shell
25
48
 
26
49
  def initialize(shell)
50
+ super()
27
51
  @shell = shell
28
- @quiet = false
29
- @debug = ENV['DEBUG']
30
52
  end
31
53
 
32
- def debug(msg)
54
+ def do_info(msg)
55
+ @shell.say(msg) if !@quiet
56
+ end
57
+
58
+ def do_debug(msg)
33
59
  @shell.say(msg) if @debug && !@quiet
34
60
  end
35
61
 
36
- def info(msg)
37
- @shell.say(msg) if !@quiet
62
+ def do_warn(msg)
63
+ @shell.say(msg, :yellow)
64
+ end
65
+
66
+ def do_error(msg)
67
+ @shell.say(msg, :red)
38
68
  end
39
69
 
40
- def confirm(msg)
70
+ def do_confirm(msg)
41
71
  @shell.say(msg, :green) if !@quiet
42
72
  end
73
+ end
43
74
 
44
- def warn(msg)
45
- @shell.say(msg, :yellow)
75
+ class Logger < UI
76
+ attr_accessor :logger
77
+
78
+ def initialize(logger)
79
+ super()
80
+ @logger = logger
46
81
  end
47
82
 
48
- def error(msg)
49
- @shell.say(msg, :red)
83
+ def do_debug(msg)
84
+ @logger.debug(msg)
85
+ end
86
+
87
+ def do_info(msg)
88
+ @logger.info(msg)
89
+ end
90
+
91
+ def do_confirm(msg)
92
+ @logger.confirm(msg)
50
93
  end
51
94
 
52
- def be_quiet!
53
- @quiet = true
95
+ def do_warn(msg)
96
+ @logger.warn(msg)
54
97
  end
55
98
 
56
- def debug!
57
- @debug = true
99
+ def do_error(msg)
100
+ @logger.error(msg)
58
101
  end
59
102
  end
60
103
  end
@@ -1,3 +1,3 @@
1
1
  module Saber
2
- VERSION = "0.0.7"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,28 +1,27 @@
1
- pd = console.log;
1
+ pd = function(){ console.log.apply(console, arguments) }
2
2
 
3
3
  if(plugin.canChangeMenu())
4
4
  {
5
- theWebUI.saberDownload = function(id){
6
- theWebUI.perform("saberDownload");
5
+ theWebUI.saberFetch = function(id){
6
+ theWebUI.perform("saberFetch");
7
7
  }
8
8
 
9
9
  plugin.createMenu = theWebUI.createMenu;
10
10
  theWebUI.createMenu = function( e, id )
11
11
  {
12
12
  plugin.createMenu.call(this, e, id);
13
- if(plugin.enabled)
13
+ if (plugin.enabled)
14
14
  {
15
- var el = theContextMenu.get("Update trackers")
16
- if( el )
17
- theContextMenu.add( el, ["Saber Download", "theWebUI.saberDownload('"+id+"')"]);
15
+ theContextMenu.add(["Saber Fetch", "theWebUI.saberFetch('"+id+"')"]);
18
16
  }
19
17
  }
20
18
  }
21
19
 
22
- rTorrentStub.prototype.saberDownload = function()
20
+ rTorrentStub.prototype.saberFetch = function()
23
21
  {
24
22
  var cmd = new rXMLRPCCommand("execute");
25
- cmd.addParameter("string", "/usr/bin/saber-drb_add");
23
+ cmd.addParameter("string", "saber-drb_add");
26
24
  cmd.addParameter("string", this.hashes.join(","));
25
+ cmd.addParameter("string", "saber");
27
26
  this.commands.push(cmd);
28
27
  }
@@ -1,4 +1,4 @@
1
1
  plugin.description: a rutorrent plugin to auto download files into home laptop.
2
2
  plugin.author: Guten
3
3
  plugin.version: 0.1
4
- plugin.help: https://github.com/GutenYe/rutorrent-saber-download
4
+ plugin.help: https://github.com/GutenYe/saber
@@ -1,12 +1,11 @@
1
- $: << "lib"
2
- require "saber/version"
1
+ Kernel.load File.expand_path("../lib/saber/version.rb", __FILE__)
3
2
 
4
3
  spec = Gem::Specification.new do |s|
5
4
  s.name = "saber"
6
5
  s.version = Saber::VERSION
7
- s.summary = "the saber"
6
+ s.summary = "A complete solution for PT users."
8
7
  s.description = <<-EOF
9
- the saber
8
+ A complete solution for PT users.
10
9
  EOF
11
10
 
12
11
  s.author = "GutenYe"
@@ -18,10 +17,15 @@ the saber
18
17
  s.executables = ["saber"]
19
18
  s.extensions << "extconf.rb"
20
19
 
21
- s.add_dependency "optimism", "~>3.1.2"
22
- s.add_dependency "pa", "~>1.2.3"
23
- s.add_dependency "retort","~>0.0.6"
24
- s.add_dependency "thor", "~>0.14.6"
25
- s.add_dependency "net-ssh", "~>2.3.0"
26
- s.add_dependency "xmpp4r", "~>0.5"
20
+ s.add_dependency "pd", ">= 0"
21
+ s.add_dependency "tagen", "~> 2.0.1"
22
+ s.add_dependency "optimism", "~> 3.3.1"
23
+ s.add_dependency "pa", "~> 1.3.2"
24
+ s.add_dependency "retort", "~> 0.0.6"
25
+ s.add_dependency "thor", "~> 0.16.0"
26
+ s.add_dependency "net-ssh", "~> 2.5.2"
27
+ s.add_dependency "xmpp4r", "~> 0.5"
28
+ s.add_dependency "mechanize", "~> 2.5.1"
29
+ s.add_dependency "highline", "~> 1.6.14"
30
+ s.add_dependency "reverse_markdown", "~> 0.3.0"
27
31
  end
File without changes
@@ -2,7 +2,11 @@ require "spec_helper"
2
2
 
3
3
  Downloader = Saber::Downloader
4
4
 
5
- describe Downloader do
5
+
6
+ uri="Microsoft Office 2010 Professional Plus (Activator Included)/KMS Activator for Microsoft Office 2010 Applications x86 x64 Multilingual-FIXISO~DiBYA/mini-KMS_Activator_v1.053.exe"
7
+
8
+
9
+ xdescribe Downloader do
6
10
  describe "test everyting" do
7
11
  it "works" do
8
12
  XMLRPC::Client.stub(:new2)
@@ -14,4 +18,3 @@ describe Downloader do
14
18
  end
15
19
  end
16
20
  end
17
-
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ Task = Saber::Task
4
+
5
+ class Task::HelloTest < Task::Base
6
+ def invoke(*args)
7
+ args
8
+ end
9
+ end
10
+
11
+ describe Task do
12
+ it "(complete example)" do
13
+ expect(Task["hello_test"]).to be(Task::HelloTest)
14
+ expect(Task["hello_test"].invoke(1, 2)).to eq([1, 2])
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ =begin
2
+ require "spec_helper"
3
+ require "saber/tracker/bib"
4
+
5
+ BIB = Saber::Tracker::BIB
6
+
7
+ describe BIB do
8
+ it do
9
+ VCR.use_cassette("bib", record: :new_episodes) do
10
+ #VCR.use_cassette("bib", record: :all) do
11
+ a = Mechanize.new
12
+ #a.get "http://www.google.com"
13
+ #ret = a.get "http://www.g.cn"
14
+ #a.get "http://bibliotik.org/"
15
+ #ret = a.get "http://bibliotik.org/login"
16
+ #ret = a.get "http://what.cd/"
17
+ #pd ret.uri
18
+
19
+ bib = BIB.new
20
+ bib.login
21
+ end
22
+ end
23
+ end
24
+ =end