nyaa_anime 0.3.1 → 0.3.4

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: d114871e4368e1d3fbee2e706f31592009178192
4
- data.tar.gz: f5716d1fbf597abc7a6de8872672ca53472696aa
3
+ metadata.gz: 191e2a8c93ed5c404ab58f017d08e192a12f3e9d
4
+ data.tar.gz: cd648da31060aa478eb1417f41c3f19a20baf597
5
5
  SHA512:
6
- metadata.gz: d4d325d829bd96a04090c6719e4064f31dbbb59713e9c1e4d6f00bc654ef1cb5d515859b44bb40ee40e291b3518dc28030821b0a4f5d4ced559413b94874c5f3
7
- data.tar.gz: 7a1b51b5b736fc67164e523009a59432189ede39f474167f1e7d298664d1188e5d38e98ee7fd7b293c0e0eef7a5a245f92e61172c4381563ca26f97b76014142
6
+ metadata.gz: ede45cd7c81d8464047177e24da368ce2d2ac73d98bfbf124ba6ae83ce8ba8436612cc223ca1ed359bc8ba2d68b5df29d139f43ca53af58ee0dab143dad2e9da
7
+ data.tar.gz: 5167320aa3994fa16423dd84845f8ad9b1ac97fe281c93fb0abfbbe35ff5df3775e43000d26043d3060e0969eff3ab1c06f568d907a30e6b6feab1ad237ce884
data/lib/nyaa_anime.rb CHANGED
@@ -11,68 +11,53 @@ class NyaaAnime
11
11
  require 'set'
12
12
 
13
13
  NYAA_URI = "http://nyaa.se"
14
- NYAA_SEARCH = "#{NYAA_URI}/?page=search"
14
+ NYAA_SEARCH = "#{NYAA_URI}/?page=rss"
15
15
  NYAA_SEARCH_DEFAULT = "#{NYAA_SEARCH}&cats=1_37&filter=2&term="
16
16
  NYAA_DL_DIR = "#{Dir.home}/Downloads/nyaa/"
17
- MAX_PAGE_COUNT = 29
17
+ MAX_PAGE_COUNT = 30
18
18
  TITLE_TOLERANCE_RANGE = (1..4)
19
19
  NEW_COLOR = :green
20
20
  ALREADY_DOWNLOADED_COLOR = :cyan
21
+ THREAD_COUNT = 10
22
+
23
+ attr_reader :downloads, :new_titles
21
24
 
22
25
  def search(title, quiet=true)
23
26
  puts "Searching for \"#{title}\"..." unless quiet
24
27
  @downloads = {}
25
- noko_doc = Nokogiri::HTML(open("#{NYAA_SEARCH_DEFAULT}#{CGI.escape(title)}"))
26
- results = noko_doc.css('.tlistrow')
27
- if results.any?
28
- titles = results.css('.tlistname a').map { |a| a.content }
29
- dl_urls = results.css('.tlistdownload a').map { |a| a.attr('href') }
30
- page_urls = noko_doc.css('.pages').first.css('a').map { |a| a.attr('href') }
31
- if page_urls.count == MAX_PAGE_COUNT - 1
32
- puts "Truncating at #{MAX_PAGE_COUNT} pages." unless quiet
33
- end
34
- if page_urls.count > 1
35
- page_titles = [nil] * (page_urls.count - 1)
36
- page_dl_urls = [nil] * (page_urls.count - 1)
37
- Parallel.each_with_index(page_urls, in_threads: 10) do |url, i|
38
- r = Nokogiri::HTML(open(url)).css('.tlistrow')
39
- page_titles[i] = r.css('.tlistname a').map { |a| a.content }
40
- page_dl_urls[i] = r.css('.tlistdownload a').map { |a| a.attr('href') }
41
- print "."
42
- end
43
- print "\n"
44
- page_titles.each { |pt| titles.concat pt }
45
- page_dl_urls.each { |pd| dl_urls.concat pd }
46
- end
47
- titles.each_with_index { |t, i| @downloads[t] = dl_urls[i] }
48
- @titles = titles.sort!
49
- else
50
- if title_element = noko_doc.css('.viewtorrentname').first
51
- title = title_element.content
52
- @titles = [title]
53
- @downloads[title] = noko_doc.css('.viewdownloadbutton a').first.attr('href')
54
- else
55
- return
28
+ @titles = []
29
+ 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
56
37
  end
57
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?
42
+ titles.each_with_index { |t, i| @downloads[t] = dl_urls[i] }
43
+ @titles = titles.sort!
58
44
  categorize_titles
59
45
  colorized_titles.each_with_index { |t, i| puts "#{i+1}: #{t}" } unless quiet
60
46
  nil
61
47
  end
62
48
 
63
49
  def find_new_titles
64
- new_titles = Set.new
65
- new_downloads = {}
66
- idx = 1
67
- stripped_episodeless_downloaded_titles.each do |t|
68
- search t
69
- new_titles.merge @new_titles
70
- @new_titles.each do |ti|
71
- new_downloads[ti] = @downloads[ti]
72
- puts "#{idx}: #{ti.colorize(NEW_COLOR)}"
73
- idx += 1
74
- end
50
+ 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 }
75
58
  end
59
+ new_titles = new_titles.reduce { |a, b| b ? a.merge(b) : a }
60
+ new_downloads = new_downloads.reduce { |a, b| b ? a.merge(b) : a }
76
61
  @new_titles = new_titles
77
62
  @titles = new_titles.to_a.sort!
78
63
  @downloads = new_downloads
@@ -82,6 +67,7 @@ class NyaaAnime
82
67
  if download_count > 0
83
68
  puts "#{download_count} new episode#{"s" if download_count > 1} found!"
84
69
  end
70
+ @titles.each_with_index { |t, i| puts "#{i+1}: #{t.colorize(NEW_COLOR)}" }
85
71
  end
86
72
 
87
73
  def colorized_titles
@@ -169,11 +155,11 @@ class NyaaAnime
169
155
  end
170
156
 
171
157
  def download_all
172
- Parallel.map(@titles, in_threads: 10) { |t| download(t) }
158
+ Parallel.map(@titles, in_threads: THREAD_COUNT) { |t| download(t) }
173
159
  end
174
160
 
175
161
  def download_all_new
176
- Parallel.map(@new_titles, in_threads: 10) { |t| download(t) }
162
+ Parallel.map(@new_titles, in_threads: THREAD_COUNT) { |t| download(t) }
177
163
  end
178
164
 
179
165
  def download_count
@@ -1,3 +1,3 @@
1
1
  class NyaaAnime
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.4"
3
3
  end
data/nyaa_anime.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = NyaaAnime::VERSION
9
9
  spec.authors = ["Joshua Tsubaki Wu"]
10
10
  spec.email = ["wujoshuawu@gmail.com"]
11
- spec.summary = %q{the painless Nyaa Torrents anime command-line tool}
11
+ spec.summary = %q{the painless NyaaTorrents anime command-line tool}
12
12
  spec.description = "`nyaa` (short for `nyaa_anime`) is the painless Nyaa Torrents anime " <<
13
13
  "command-line tool. Search for and download anime torrents and open " <<
14
14
  "them automatically. Results are color-coded - green for new episodes of " <<
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyaa_anime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Tsubaki Wu
@@ -180,5 +180,5 @@ rubyforge_project:
180
180
  rubygems_version: 2.4.2
181
181
  signing_key:
182
182
  specification_version: 4
183
- summary: the painless Nyaa Torrents anime command-line tool
183
+ summary: the painless NyaaTorrents anime command-line tool
184
184
  test_files: []