nyaa_anime 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cf4a5f4fd7c88e19d9ee161ea0e6184909e71f0
4
- data.tar.gz: bde9b108e3bc7cd07c80c5d387c8459f11dfdcdd
3
+ metadata.gz: db19508ca23a44049cc98752b23f2e8440c52c56
4
+ data.tar.gz: ce9b81cd34a5e276ee9a86fe8e9828d55362e049
5
5
  SHA512:
6
- metadata.gz: 49bc891e22b69b273004482ee14f569578105e0886e9129147edbacd9d57463c27fb716b4be57fb43d0ecbee8710e20cee9417741cc1907cd0eeac5ba767b2bb
7
- data.tar.gz: a4cd398f26d9e87c0d165b9f81dad675fc270160f2e0013c50d3b0895bda6ccc3ddf1ef8d17a8026afdf1b885b5c16b528612ee03cb79c2dd56190a7163757a4
6
+ metadata.gz: 2e77e9d2d0e58bd96b3a3cec04db5f0417e434ee62e9c8ecc18d81799efc141d6c82cb27d33a7c718c7a5ac8300d1bf1ad33ee260f03f1092dd941f1928914e3
7
+ data.tar.gz: b3ab356a57a519d08d1e2444957304b40e5fb790702b8f5ce0d989addec3cb05826b18b392ea142d9f6e43eb3241f61e553eaf8250cd4dce41bc43fb5e70f16a
@@ -2,7 +2,6 @@ require "nyaa_anime/version"
2
2
 
3
3
  class NyaaAnime
4
4
 
5
- require 'parallel'
6
5
  require 'open-uri'
7
6
  require 'nokogiri'
8
7
  require 'cgi'
@@ -14,31 +13,30 @@ class NyaaAnime
14
13
  NYAA_SEARCH = "#{NYAA_URI}/?page=rss"
15
14
  NYAA_SEARCH_DEFAULT = "#{NYAA_SEARCH}&cats=1_37&filter=2&term="
16
15
  NYAA_DL_DIR = "#{Dir.home}/Downloads/nyaa/"
17
- MAX_PAGE_COUNT = 30
16
+ NYAA_ENTRIES_PER_PAGE = 100
18
17
  TITLE_TOLERANCE_RANGE = (1..4)
19
18
  NEW_COLOR = :green
20
19
  ALREADY_DOWNLOADED_COLOR = :cyan
21
- THREAD_COUNT = 5
22
20
 
23
21
  attr_reader :downloads, :new_titles
24
22
 
25
23
  def search(title, quiet=true)
26
- puts "Searching for \"#{title}\"..." unless quiet
24
+ print "Searching for \"#{title}\"..." unless quiet
27
25
  @downloads = {}
28
26
  @titles = []
29
27
  url = "#{NYAA_SEARCH_DEFAULT}#{CGI.escape(title)}&offset="
30
- titles = [nil] * MAX_PAGE_COUNT
31
- dl_urls = [nil] * MAX_PAGE_COUNT
32
- Parallel.each((1..THREAD_COUNT), in_threads: THREAD_COUNT) do |offset|
33
- while offset <= MAX_PAGE_COUNT && (results = Nokogiri::HTML(open("#{url}#{offset}")).css('item')).any?
34
- titles[offset-1] = results.css('title').map { |t| t.content }
35
- dl_urls[offset-1] = results.css('link').map { |l| l.next.content }
36
- offset += THREAD_COUNT
37
- end
28
+ titles = []
29
+ dl_urls = []
30
+ offset = 1
31
+ while true
32
+ print "."
33
+ results = Nokogiri::HTML(open("#{url}#{offset}")).css('item')
34
+ titles.concat results.css('title').map { |t| t.content }
35
+ dl_urls.concat results.css('link').map { |l| l.next.content }
36
+ break if results.count < NYAA_ENTRIES_PER_PAGE
37
+ offset += 1
38
38
  end
39
- titles = titles.reduce([]) { |a, b| b ? a.concat(b) : a }
40
- dl_urls = dl_urls.reduce([]) { |a, b| b ? a.concat(b) : a }
41
- return if titles.empty?
39
+ print "\n" unless quiet
42
40
  titles.each_with_index { |t, i| @downloads[t] = dl_urls[i] }
43
41
  @titles = titles.sort!
44
42
  categorize_titles
@@ -48,16 +46,16 @@ class NyaaAnime
48
46
 
49
47
  def find_new_titles
50
48
  search_terms = stripped_episodeless_downloaded_titles
51
- new_titles = [nil] * search_terms.count
52
- new_downloads = [nil] * search_terms.count
53
- Parallel.each_with_index(search_terms, in_threads: THREAD_COUNT) do |t, i|
54
- n = NyaaAnime.new
55
- n.search t
56
- new_titles[i] = n.new_titles
57
- new_downloads[i] = n.downloads.select { |ti, dl| n.new_titles.include? ti }
49
+ new_titles = Set.new
50
+ new_downloads = {}
51
+ search_terms.each do |t|
52
+ search t
53
+ new_titles.merge @new_titles
54
+ @new_titles.each { |ti| new_downloads[ti] = @downloads[ti] }
55
+ if @new_titles.any?
56
+ puts "#{@new_titles.count} new episode#{"s" if @new_titles.count > 1}!".colorize(:green)
57
+ end
58
58
  end
59
- new_titles = new_titles.reduce(Set.new) { |a, b| b ? a.merge(b) : a }
60
- new_downloads = new_downloads.reduce({}) { |a, b| b ? a.merge(b) : a }
61
59
  @new_titles = new_titles
62
60
  @titles = new_titles.to_a.sort!
63
61
  @downloads = new_downloads
@@ -155,11 +153,11 @@ class NyaaAnime
155
153
  end
156
154
 
157
155
  def download_all
158
- Parallel.map(@titles, in_threads: THREAD_COUNT) { |t| download(t) }
156
+ @titles.map { |t| download(t) }
159
157
  end
160
158
 
161
159
  def download_all_new
162
- Parallel.map(@new_titles, in_threads: THREAD_COUNT) { |t| download(t) }
160
+ @new_titles.map { |t| download(t) }
163
161
  end
164
162
 
165
163
  def download_count
@@ -1,3 +1,3 @@
1
1
  class NyaaAnime
2
- VERSION = "0.3.6"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_runtime_dependency 'parallel', '~> 1.2', '>= 1.2.4'
27
26
  spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.2.1'
28
27
  spec.add_runtime_dependency 'colorize', '~> 0.7', '>= 0.7.3'
29
28
  spec.add_runtime_dependency 'levenshtein-ffi', '~> 1.1'
metadata CHANGED
@@ -1,35 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyaa_anime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Tsubaki Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: parallel
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.2'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.2.4
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.2'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.2.4
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: nokogiri
35
15
  requirement: !ruby/object:Gem::Requirement