nyaa_anime 0.6.0 → 0.7.0
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 +4 -4
- data/bin/nyaa_anime +19 -11
- data/lib/nyaa_anime.rb +38 -27
- data/lib/nyaa_anime/list.rb +1 -1
- data/lib/nyaa_anime/remove.rb +2 -1
- data/lib/nyaa_anime/search.rb +31 -13
- data/lib/nyaa_anime/version.rb +1 -1
- data/nyaa_anime.gemspec +1 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e624f06033c4f20b98887562663b271fbd3342d5
|
4
|
+
data.tar.gz: 4912a5bb4e60dca9463ae3682a9d4ced3ab30b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45b2ca6bd017059bfece00d1bbc130e4e3273b2f403c26281bdc091a38243a5a08c52b2ef512c737cb332bac678ffddf8fb75bfc19a6928c4a91b440f385785e
|
7
|
+
data.tar.gz: c3fd3e63b529b7d5c7c936d7333caf08bfc86ee38720bcfbb38c471e12715c35dd8d6fd6ba7bc7a3e21227c1f5c0ca2c9f334546a014bb368151148b59ab3ad2
|
data/bin/nyaa_anime
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
ARGV[1] = "-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
scripts = ["search", "list", "remove"]
|
4
|
+
|
5
|
+
if ARGV[0] == "get"
|
6
|
+
ARGV[0], ARGV[1] = "search", "-naq"
|
7
|
+
elsif ARGV[0] == "help" && ARGV[1]
|
8
|
+
if scripts.include? ARGV[1]
|
9
|
+
ARGV[0], ARGV[1] = ARGV[1], "--help"
|
10
|
+
else
|
11
|
+
puts "Error: No such command \"#{ARGV[1]}\"."
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
script = ARGV[0]
|
17
|
+
if scripts.include? script
|
18
|
+
require "nyaa_anime/#{script}"
|
12
19
|
else
|
13
20
|
puts "Usage: nyaa <command> [<args>]\n" <<
|
14
21
|
" nyaa_anime <command> [<args>]\n\n" <<
|
@@ -16,7 +23,8 @@ else
|
|
16
23
|
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n" <<
|
17
24
|
"Commands:\n" <<
|
18
25
|
" search Search for and download anime\n" <<
|
19
|
-
" get Equivalent to `nyaa search -
|
26
|
+
" get Equivalent to `nyaa search -naq`\n" <<
|
20
27
|
" list List downloaded torrent files\n" <<
|
21
|
-
" remove Delete download torrent files from a series\n"
|
28
|
+
" remove Delete download torrent files from a series\n" <<
|
29
|
+
" help Get help about a command (`nyaa help <command>`)\n"
|
22
30
|
end
|
data/lib/nyaa_anime.rb
CHANGED
@@ -9,6 +9,7 @@ class NyaaAnime
|
|
9
9
|
require 'levenshtein'
|
10
10
|
require 'set'
|
11
11
|
require 'fileutils'
|
12
|
+
require 'parallel'
|
12
13
|
|
13
14
|
NYAA_URI = "http://nyaa.se"
|
14
15
|
NYAA_SEARCH = "#{NYAA_URI}/?page=rss"
|
@@ -19,12 +20,14 @@ class NyaaAnime
|
|
19
20
|
TITLE_TOLERANCE_RANGE = (1..4)
|
20
21
|
NEW_COLOR = :green
|
21
22
|
ALREADY_DOWNLOADED_COLOR = :cyan
|
23
|
+
CL_WIDTH = 70
|
24
|
+
THREAD_COUNT = 20
|
22
25
|
|
23
26
|
attr_reader :downloads, :new_titles
|
24
27
|
|
25
28
|
FileUtils.mkdir_p NYAA_DL_DIR
|
26
29
|
|
27
|
-
def search(title, quiet=
|
30
|
+
def search(title, quiet=false)
|
28
31
|
puts "Searching for \"#{title}\"..." unless quiet
|
29
32
|
@downloads = {}
|
30
33
|
@titles = []
|
@@ -33,7 +36,12 @@ class NyaaAnime
|
|
33
36
|
dl_urls = []
|
34
37
|
offset = 1
|
35
38
|
while true
|
36
|
-
|
39
|
+
begin
|
40
|
+
results = Nokogiri::HTML(open("#{url}#{offset}")).css('item')
|
41
|
+
rescue SocketError
|
42
|
+
puts "Error: Could not connect to NyaaTorrents."
|
43
|
+
exit
|
44
|
+
end
|
37
45
|
titles.concat results.css('title').map { |t| t.content }
|
38
46
|
dl_urls.concat results.css('link').map { |l| l.next.content }
|
39
47
|
break if results.count < NYAA_ENTRIES_PER_PAGE || offset >= MAX_PAGES
|
@@ -46,21 +54,29 @@ class NyaaAnime
|
|
46
54
|
nil
|
47
55
|
end
|
48
56
|
|
49
|
-
def find_new_titles
|
57
|
+
def find_new_titles(quiet=false)
|
50
58
|
search_terms = NyaaAnime.series_of_downloaded_titles
|
51
59
|
new_titles = Set.new
|
52
60
|
new_downloads = {}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
count_s_size = "[/] ".size + search_terms.count.to_s.size * 2
|
62
|
+
line_end_size = "...none found.".size
|
63
|
+
max_entry_size = [search_terms.map { |t| t.size }.max + count_s_size +
|
64
|
+
line_end_size, CL_WIDTH].min - line_end_size
|
65
|
+
index = 1
|
66
|
+
lock = Mutex.new
|
67
|
+
Parallel.each(search_terms, in_threads: THREAD_COUNT) do |t|
|
68
|
+
n = NyaaAnime.new
|
69
|
+
n.search t, true
|
70
|
+
lock.synchronize do
|
71
|
+
new_titles.merge n.new_titles
|
72
|
+
n.new_titles.each { |ti| new_downloads[ti] = n.downloads[ti] }
|
73
|
+
if !quiet
|
74
|
+
msg = "/#{search_terms.count}] #{t[0...max_entry_size-count_s_size]}..." <<
|
75
|
+
("." * [max_entry_size - (count_s_size + t.size), 0].max) <<
|
76
|
+
(n.new_titles.any? ? "#{n.new_titles.count} found!".colorize(:green) : "none found.")
|
77
|
+
puts "[#{index.to_s.rjust(search_terms.count.to_s.size, "0")}#{msg}"
|
78
|
+
index += 1
|
79
|
+
end
|
64
80
|
end
|
65
81
|
end
|
66
82
|
@new_titles = new_titles
|
@@ -69,8 +85,8 @@ class NyaaAnime
|
|
69
85
|
@already_downloaded_titles = Set.new
|
70
86
|
@version_differing_titles = Set.new
|
71
87
|
@other_titles = Set.new
|
72
|
-
if
|
73
|
-
puts "#{
|
88
|
+
if downloads.count > 0
|
89
|
+
puts "#{downloads.count} new episode#{"s" if downloads.count > 1} found!".colorize(:green)
|
74
90
|
end
|
75
91
|
@titles.each_with_index { |t, i| puts "#{i+1}: #{t.colorize(NEW_COLOR)}" }
|
76
92
|
end
|
@@ -167,24 +183,19 @@ class NyaaAnime
|
|
167
183
|
torrent = open @downloads[title]
|
168
184
|
filename = torrent.meta["content-disposition"][/filename="(.+\.torrent)"/, 1]
|
169
185
|
open("#{NYAA_DL_DIR}#{filename}", "w") { |f| f.write torrent.read }
|
170
|
-
puts "#{title}.torrent downloaded."
|
171
186
|
"#{NYAA_DL_DIR}\"#{title}.torrent\""
|
172
187
|
end
|
173
188
|
|
174
|
-
def
|
175
|
-
|
189
|
+
def download_batch(titles)
|
190
|
+
Parallel.map(titles) { |t| download(t) }.sort!
|
176
191
|
end
|
177
192
|
|
178
|
-
def
|
179
|
-
@
|
180
|
-
end
|
181
|
-
|
182
|
-
def download_count
|
183
|
-
@downloads.count
|
193
|
+
def download_all
|
194
|
+
download_batch @titles
|
184
195
|
end
|
185
196
|
|
186
|
-
def
|
187
|
-
@new_titles
|
197
|
+
def download_all_new
|
198
|
+
download_batch @new_titles
|
188
199
|
end
|
189
200
|
|
190
201
|
end
|
data/lib/nyaa_anime/list.rb
CHANGED
@@ -6,7 +6,7 @@ OptionParser.new do |opts|
|
|
6
6
|
" If you like this tool, please donate via PayPal\n" <<
|
7
7
|
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n"
|
8
8
|
|
9
|
-
opts.on("-a", "--all", "List all individual files
|
9
|
+
opts.on("-a", "--all", "List all individual files") do
|
10
10
|
options[:list_all] = true
|
11
11
|
end
|
12
12
|
end.parse!
|
data/lib/nyaa_anime/remove.rb
CHANGED
@@ -14,7 +14,8 @@ OptionParser.new do |opts|
|
|
14
14
|
options[:remove_all] = true
|
15
15
|
end
|
16
16
|
|
17
|
-
opts.on("-n", "--number [N]", "Remove torrents of series as
|
17
|
+
opts.on("-n", "--number [N]", "Remove torrents of series as",
|
18
|
+
"numbered by `nyaa list`") do |n|
|
18
19
|
options[:number] = n.to_i
|
19
20
|
end
|
20
21
|
end.parse!
|
data/lib/nyaa_anime/search.rb
CHANGED
@@ -15,7 +15,7 @@ ARGV[1] ||= "--help"
|
|
15
15
|
options = {}
|
16
16
|
OptionParser.new do |opts|
|
17
17
|
opts.banner = "Usage: nyaa search [options] <anime>\n" <<
|
18
|
-
" nyaa get (equivalent to `nyaa search -
|
18
|
+
" nyaa get (equivalent to `nyaa search -naq`)\n\n" <<
|
19
19
|
" If you like this tool, please donate via PayPal\n" <<
|
20
20
|
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n"
|
21
21
|
|
@@ -24,9 +24,12 @@ OptionParser.new do |opts|
|
|
24
24
|
options[:find_new] = true
|
25
25
|
end
|
26
26
|
|
27
|
-
opts.on("-a", "--all", "Download all
|
27
|
+
opts.on("-a", "--all", "Download all without asking") do
|
28
28
|
options[:download_all] = true
|
29
29
|
end
|
30
|
+
opts.on("-q", "--quiet", "Be quiet (only with -a)") do
|
31
|
+
options[:quiet] = true
|
32
|
+
end
|
30
33
|
|
31
34
|
opts.on("-s", "--small-res", "Add '#{SMALL_RESOLUTION}' to the search term") do
|
32
35
|
options[:resolution] = SMALL_RESOLUTION
|
@@ -39,8 +42,9 @@ OptionParser.new do |opts|
|
|
39
42
|
end
|
40
43
|
|
41
44
|
opts.on("-f", "--fansubber [FANSUBBER]",
|
42
|
-
"Specify [FANSUBBER] to be added
|
43
|
-
"term. [FANSUBBER]
|
45
|
+
"Specify [FANSUBBER] to be added",
|
46
|
+
"to the search term. [FANSUBBER]",
|
47
|
+
"can be abbreviated by",
|
44
48
|
*FANSUBBERS.map {|o, f| "#{o} - #{f}"}) do |f|
|
45
49
|
if FANSUBBERS[f]
|
46
50
|
options[:subber] = FANSUBBERS[f]
|
@@ -52,16 +56,21 @@ OptionParser.new do |opts|
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
|
-
opts.on("-S", "--speedsubs", "Equivalent to
|
59
|
+
opts.on("-S", "--speedsubs", "Equivalent to",
|
60
|
+
"`--fansubber=#{SPEEDSUBBER}`") do
|
56
61
|
options[:subber] = SPEEDSUBBER
|
57
62
|
end
|
58
63
|
end.parse!
|
59
64
|
|
65
|
+
if !options[:download_all]
|
66
|
+
options[:quiet] = false
|
67
|
+
end
|
68
|
+
|
60
69
|
require 'nyaa_anime'
|
61
70
|
nyaa = NyaaAnime.new
|
62
71
|
|
63
72
|
if options[:find_new]
|
64
|
-
nyaa.find_new_titles
|
73
|
+
nyaa.find_new_titles !!options[:quiet]
|
65
74
|
else
|
66
75
|
if ARGV.size == 2
|
67
76
|
search_term = ARGV[1]
|
@@ -74,10 +83,14 @@ else
|
|
74
83
|
if res = options[:resolution]
|
75
84
|
search_term += " #{res}"
|
76
85
|
end
|
77
|
-
|
86
|
+
if search_term == ""
|
87
|
+
puts "Error: No search term provided."
|
88
|
+
exit
|
89
|
+
end
|
90
|
+
nyaa.search search_term, !!options[:quiet]
|
78
91
|
end
|
79
92
|
|
80
|
-
if nyaa.
|
93
|
+
if nyaa.downloads.count == 0
|
81
94
|
puts "No downloads found."
|
82
95
|
exit
|
83
96
|
end
|
@@ -86,6 +99,11 @@ require 'os'
|
|
86
99
|
require 'highline/import'
|
87
100
|
|
88
101
|
def prompt_to_open(torrents)
|
102
|
+
if torrents.count == 1
|
103
|
+
puts "Downloaded #{File.basename torrents[0]}."
|
104
|
+
else
|
105
|
+
puts "Downloaded #{torrents.count} torrent files."
|
106
|
+
end
|
89
107
|
if agree "Open downloaded torrent#{"s" if torrents.count > 1}? (y/n): "
|
90
108
|
if OS.mac?
|
91
109
|
`open #{torrents.join " "}`
|
@@ -102,9 +120,9 @@ if options[:download_all]
|
|
102
120
|
exit
|
103
121
|
end
|
104
122
|
|
105
|
-
if nyaa.
|
106
|
-
prompt = "Download (1-#{nyaa.
|
107
|
-
prompt << ", 'n(ew)'" if nyaa.
|
123
|
+
if nyaa.downloads.count > 1
|
124
|
+
prompt = "Download (1-#{nyaa.downloads.count}, 'a(ll)'"
|
125
|
+
prompt << ", 'n(ew)'" if nyaa.new_titles.count > 0 && !options[:find_new]
|
108
126
|
prompt << ", or [ENTER] to cancel): "
|
109
127
|
else
|
110
128
|
if agree "Download? (y/n): "
|
@@ -120,7 +138,7 @@ while true
|
|
120
138
|
if index == ""
|
121
139
|
exit
|
122
140
|
end
|
123
|
-
if "new".match(/\A#{index}/) && nyaa.
|
141
|
+
if "new".match(/\A#{index}/) && nyaa.new_titles.count > 0 && !options[:find_new]
|
124
142
|
prompt_to_open nyaa.download_all_new
|
125
143
|
exit
|
126
144
|
end
|
@@ -128,7 +146,7 @@ while true
|
|
128
146
|
prompt_to_open nyaa.download_all
|
129
147
|
exit
|
130
148
|
end
|
131
|
-
if (1..nyaa.
|
149
|
+
if (1..nyaa.downloads.count).include?(index.to_i)
|
132
150
|
prompt_to_open [nyaa.download_index(index.to_i-1)]
|
133
151
|
exit
|
134
152
|
end
|
data/lib/nyaa_anime/version.rb
CHANGED
data/nyaa_anime.gemspec
CHANGED
@@ -23,6 +23,7 @@ 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'
|
26
27
|
spec.add_runtime_dependency 'highline', '~> 1.6', '>= 1.6.21'
|
27
28
|
spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.2.1'
|
28
29
|
spec.add_runtime_dependency 'colorize', '~> 0.7', '>= 0.7.3'
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyaa_anime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.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-22 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
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: highline
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|