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 +4 -4
- data/lib/nyaa_anime.rb +24 -26
- data/lib/nyaa_anime/version.rb +1 -1
- data/nyaa_anime.gemspec +0 -1
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db19508ca23a44049cc98752b23f2e8440c52c56
|
4
|
+
data.tar.gz: ce9b81cd34a5e276ee9a86fe8e9828d55362e049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e77e9d2d0e58bd96b3a3cec04db5f0417e434ee62e9c8ecc18d81799efc141d6c82cb27d33a7c718c7a5ac8300d1bf1ad33ee260f03f1092dd941f1928914e3
|
7
|
+
data.tar.gz: b3ab356a57a519d08d1e2444957304b40e5fb790702b8f5ce0d989addec3cb05826b18b392ea142d9f6e43eb3241f61e553eaf8250cd4dce41bc43fb5e70f16a
|
data/lib/nyaa_anime.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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 = [
|
31
|
-
dl_urls = [
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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 =
|
52
|
-
new_downloads =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
new_titles[
|
57
|
-
|
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
|
-
|
156
|
+
@titles.map { |t| download(t) }
|
159
157
|
end
|
160
158
|
|
161
159
|
def download_all_new
|
162
|
-
|
160
|
+
@new_titles.map { |t| download(t) }
|
163
161
|
end
|
164
162
|
|
165
163
|
def download_count
|
data/lib/nyaa_anime/version.rb
CHANGED
data/nyaa_anime.gemspec
CHANGED
@@ -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.
|
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-
|
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
|