nnmClub_api 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6f9b3f6aea0859c2788fb207456e31c55c47fd
4
- data.tar.gz: 3ac33f004d439412cefbad1caf8360bf50f58ace
3
+ metadata.gz: 4bbb50fc2b0ad999c914a706c40c85ddc9a26ccb
4
+ data.tar.gz: 31a2c9a906ffe9867654a8768bfca844f0165d57
5
5
  SHA512:
6
- metadata.gz: 34791c3ecccc2b80dd15077487061733f5dd2d024ff572fafd38d98e1e86d72ba125c774b968d9df7a36deac03488f610e346e6b62c75a9aad87d29d3df97258
7
- data.tar.gz: fcbc23208435222de5433b0bed3876b98b0050b57ba5c7290dfeb7476c5213a89a38392713c463fc4a96c816fbe7f6bac48b7c7536524a73504a45b288db9bc3
6
+ metadata.gz: 8f0bbdee7d092bc664b5ab298b88354d1925444a3c460a31f900261da17654ae7466c8793c10bc66091edeb9f9fe681c143d2dbd3db2b0cba16cdb661540b1db
7
+ data.tar.gz: 960f2f698b7eb177eef51faf97508409df7e8bf6dd9f29c3f25238c188b1c1b5ed5d2025c251c5099a288b2beff97564bc83f30e7557c91b25afd5eb55c6dcf7
data/README.md CHANGED
@@ -22,26 +22,36 @@ Or install it yourself as:
22
22
 
23
23
  ### Example:Search
24
24
 
25
- NnmClub::Search("Noize MC").torrents
25
+ NnmClub::Search("noize mc").torrents
26
26
 
27
27
  returns an Array of Hashes
28
28
 
29
- { :title => the title of the distribution,
29
+ {
30
+ :title => the title of the distribution,
30
31
  :size => size,
31
32
  :seeders => seeders,
32
- :leechers => leechers,
33
33
  :torrent_id => torrent_id,
34
- :tracker => NnmClub::ID
35
34
  }
36
35
 
37
36
  ### Example:Torrent
38
37
 
39
- NnmClub::Torrent.find "728159"
38
+ NnmClub::Torrent.find "97600"
40
39
 
41
40
  returns an Hash
42
41
 
43
- { :content => "HTML"
44
- :image => "UTL"
42
+ {
43
+ :content => "HTML",
44
+ :image => "URL",
45
+ :magnet => magnet-link or none
46
+ }
47
+
48
+ ### Example:NnmClub_api
49
+
50
+ api = NnmClub:NnmClub_api.new
51
+ api.search("noize mc")
52
+ #=> Array of Hashes { :title => ..., }
53
+ api.find("97600")
54
+ #=> Hash { :content => ..., }
45
55
 
46
56
 
47
57
  ## Contributing
@@ -1,4 +1,36 @@
1
+ require "mechanize"
1
2
  require "nnmClub_api/version"
2
3
  require "nnmClub_api/tracker"
3
4
  require "nnmClub_api/search"
4
- require "nnmClub_api/torrent"
5
+ require "nnmClub_api/torrent"
6
+
7
+ class Mechanize
8
+ def login
9
+ self.post(
10
+ NnmClub::LOGIN_PAGE,
11
+ username: NnmClub::USERNAME,
12
+ password: NnmClub::PASSWORD,
13
+ login: ""
14
+ )
15
+ end
16
+ end
17
+
18
+ module NnmClub
19
+ class NnmClub_api
20
+ attr_reader :agent
21
+ def initialize
22
+ @agent = Mechanize.new
23
+ @agent.get(NnmClub::LOGIN_PAGE)
24
+ @agent.login
25
+ true
26
+ end
27
+
28
+ def search query
29
+ NnmClub::Search.new(query, @agent).torrents
30
+ end
31
+
32
+ def find id
33
+ NnmClub::Torrent.find(id, @agent)
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,3 @@
1
- require "uri"
2
- require "open-uri"
3
- require "nokogiri"
4
-
5
1
  class Hash
6
2
  def any_nil?
7
3
  @result = false
@@ -13,35 +9,25 @@ class Hash
13
9
  end
14
10
  end
15
11
 
16
-
17
12
  module NnmClub
18
-
19
13
  class Search
20
- attr_reader :torrents, :url
21
- def initialize(query, category = nil)
22
- torrents = []
23
- query = URI.escape(query)
24
- @url = NnmClub::URL+"nm=#{query}"+(!category.nil? ? "&c=#{category}" : "")
25
-
26
- document = Nokogiri::HTML(open(@url))
27
- document.css("table.forumline.tablesorter").css(".prow1",".prow2").each { |row|
28
-
29
- size = row.at("td[6]/u").nil? ? nil : row.at("td[6]/u").text.to_i
30
- title = row.css(".topictitle").empty? ? nil : row.css(".topictitle").text.strip
31
- seeders = row.css(".seedmed").empty? ? nil : row.css(".seedmed").text.to_i
32
- leechers = row.css(".leechmed").empty? ? nil : row.css(".leechmed").text.to_i
33
- torrent_id = row.css(".topictitle").empty? ? nil : row.css(".topictitle").first[:href].split("=").last
34
-
35
- torrent = { :title => title,
36
- :size => size,
37
- :seeders => seeders,
38
- :leechers => leechers,
39
- :torrent_id => torrent_id,
40
- :tracker => NnmClub::ID
14
+ attr_reader :torrents
15
+ def initialize(query, agent = Mechanize.new)
16
+ form = agent.get(NnmClub::URL).forms.last
17
+ form.field("nm").value = query
18
+ form.checkbox("sd").check
19
+ form.checkbox("a").check
20
+ torrents = form.submit.search(".prow1",".prow2").collect { |row|
21
+ torrent = {
22
+ :title => row.css(".topictitle").empty? ? (nil and status=true) : row.css(".topictitle").text.strip,
23
+ :size => row.at("td[6]/u").nil? ? nil : row.at("td[6]/u").text.to_i,
24
+ :seeders => row.css(".seedmed").empty? ? nil : row.css(".seedmed").text.to_i,
25
+ :torrent_id => status ? nil : row.css(".topictitle").first[:href].split("=").last
41
26
  }
42
- torrents.push(torrent) unless torrent.any_nil?
27
+ torrent unless torrent.any_nil?
43
28
  }
44
29
  @torrents = torrents
30
+
45
31
  end
46
32
  end
47
33
  end
@@ -1,16 +1,17 @@
1
- require "uri"
2
- require "open-uri"
3
- require "nokogiri"
4
-
5
1
  module NnmClub
6
2
  class Torrent
7
- def self.find(torrent_id)
8
- document = Nokogiri::HTML(open(NnmClub::TorrentURL+torrent_id))
9
- postbody = document.css('.postbody').first
10
- info = {:content => postbody.to_html( encoding: "UTF-8" ),
11
- :image => postbody.css('var.postImg').empty? ? "nil" : postbody.css('var.postImg').first['title']
3
+ def self.find(torrent_id, agent = Mechanize.new)
4
+ document = agent.get(NnmClub::TorrentURL+torrent_id)
5
+ content_xpath = "/html/body/div[@class='wrap']/table//tr[2]/td/table//tr/td/table[@class='forumline']//tr[@class='row1']/td[@class='row1'][2]/table//tr[3]/td"
6
+ link_xpath = "/html/body/div[2]/table//tr[2]/td/table//tr/td/table[5]//tr[2]/td[2]/table//tr[4]/td/table[2]//tr[2]/td[3]/a"
7
+ content = document.search(content_xpath)
8
+ content.search(".//img",".//a").remove
9
+ return {
10
+ :content => content.to_html(encoding: "UTF-8"),
11
+ :magnet => document.search(link_xpath).empty? ? "none" : document.search(link_xpath).first[:href],
12
+ :image => document.search('var.postImg').first[:title]
12
13
  }
13
- return info
14
14
  end
15
15
  end
16
- end
16
+ end
17
+
@@ -1,6 +1,10 @@
1
1
  module NnmClub
2
2
  ID = "nnmclub"
3
3
  IMG = "http://nnm-club.me/favicon.ico"
4
- URL = "http://nnm-club.me/forum/tracker.php?"
4
+ URL = "http://nnm-club.me/forum/tracker.php"
5
5
  TorrentURL = "http://nnm-club.me/forum/viewtopic.php?t="
6
+ DownloadURL = "http://nnm-club.me/forum/"
7
+ LOGIN_PAGE = "http://nnm-club.me/forum/login.php"
8
+ USERNAME = "gettornet"
9
+ PASSWORD = "gettornet"
6
10
  end
@@ -1,3 +1,3 @@
1
1
  module NnmClubApi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'nnmClub_api/version'
4
+ require "nnmClub_api/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "nnmClub_api"
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "guard-rspec"
25
25
 
26
- spec.add_dependency "nokogiri"
26
+ spec.add_dependency "mechanize", "2.7.3"
27
27
  end
@@ -0,0 +1,20 @@
1
+ require "nnmClub_api"
2
+
3
+ describe "NnmClub" do
4
+ describe "NmmClub_api" do
5
+ before {
6
+ @api = NnmClub::NnmClub_api.new
7
+ @query = "ruby on rails"
8
+ @id = "97600"
9
+ }
10
+ it "should not be bad login" do
11
+ expect(@api.nil?).to eq(false)
12
+ end
13
+ it "should return results Array" do
14
+ expect(@api.search(@query).class).to eq([].class)
15
+ end
16
+ it "should return results Array" do
17
+ expect(@api.find(@id).class).to eq({}.class)
18
+ end
19
+ end
20
+ end
@@ -1,26 +1,12 @@
1
1
  require "nnmClub_api"
2
+ require "mechanize"
2
3
 
3
4
  describe "NnmClub" do
4
- describe "Search" do
5
- before {
6
- @query = "ruby on rails"
7
- @search = NnmClub::Search.new @query
8
- @url = NnmClub::URL
9
- }
10
- it "should return correct url without category" do
11
- expect(@search.url).to eq(@url+"nm=#{URI.escape(@query)}")
12
- end
13
-
14
- it "should return correct url with category" do
15
- @search = NnmClub::Search.new(@query,17)
16
- expect(@search.url).to eq(@url+"nm=#{URI.escape(@query)}"+"&c=17")
17
- end
18
- end
19
-
20
5
  describe "#torrents" do
21
6
  before {
22
7
  @query = "ruby on rails"
23
- @search = NnmClub::Search.new @query
8
+ agent = NnmClub::NnmClub_api.new.agent
9
+ @search = NnmClub::Search.new(@query,agent)
24
10
  }
25
11
 
26
12
  it "should return array" do
@@ -34,12 +20,21 @@ describe "NnmClub" do
34
20
 
35
21
  describe "Torrent" do
36
22
  before {
37
- @torrent_id = "97600"
38
- @torrent = NnmClub::Torrent.find @torrent_id
23
+ @torrent_id = "728159"
24
+ agent = NnmClub::NnmClub_api.new.agent
25
+ @torrent = NnmClub::Torrent.find(@torrent_id,agent)
39
26
  }
40
27
  it "should return @description" do
41
28
  expect(@torrent.class).to eq({}.class)
42
29
  end
30
+ it "should return image" do
31
+ expect(@torrent[:image].empty?).to eq(false)
32
+ end
33
+ it "should return content" do
34
+ expect(@torrent[:content].empty?).to eq(false)
35
+ end
36
+ it "should return link" do
37
+ expect(@torrent[:magnet].empty?).to eq(false)
38
+ end
43
39
  end
44
-
45
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nnmClub_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Baranov Sergey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-03 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: nokogiri
70
+ name: mechanize
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.7.3
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.7.3
83
83
  description: Gem for parsing NoNaMe Club torrent-tracker.
84
84
  email:
85
85
  - sergey@drummer.ru
@@ -100,6 +100,7 @@ files:
100
100
  - lib/nnmClub_api/tracker.rb
101
101
  - lib/nnmClub_api/version.rb
102
102
  - nnmClub_api.gemspec
103
+ - spec/nnmclub_spec.rb
103
104
  - spec/nnmcluv_api_spec.rb
104
105
  - spec/spec_helper.rb
105
106
  homepage: https://github.com/gemoroy/nnmClub_api
@@ -127,5 +128,6 @@ signing_key:
127
128
  specification_version: 4
128
129
  summary: NNM-Club torrent-tacker parser.
129
130
  test_files:
131
+ - spec/nnmclub_spec.rb
130
132
  - spec/nnmcluv_api_spec.rb
131
133
  - spec/spec_helper.rb