nyaa_anime 0.4.3 → 0.6.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/README.md +5 -3
- data/bin/nyaa-get +3 -1
- data/bin/nyaa_anime +18 -157
- data/lib/nyaa_anime.rb +30 -16
- data/lib/nyaa_anime/list.rb +23 -0
- data/lib/nyaa_anime/remove.rb +60 -0
- data/lib/nyaa_anime/search.rb +138 -0
- data/lib/nyaa_anime/version.rb +1 -1
- data/nyaa_anime.gemspec +2 -1
- metadata +27 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 721bcf93f8c04147dcbedef8a0293e0af7f295ec
|
|
4
|
+
data.tar.gz: f537048e7e23959fc25afe59f3fe1a9b201fb145
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e61f73f40b2aa9618818ea9780ce3012b9144bd5ca59ad28da737b55d093369fdfd6c4a4abbef585b210fd6a90f4ce442988ad72e833b14bb733b935453489a5
|
|
7
|
+
data.tar.gz: 261ea3c57b28c8098556f06d0c9d25db8790bdd7c7499f88e50e5877002d1f92ce3efdd9245cafe69b3c60d8252548ffcfd3f5a6bb99fe52d0f23310713a0ed0
|
data/README.md
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
`nyaa` (short for `nyaa_anime`) is the painless Nyaa Torrents anime command-line tool.
|
|
4
4
|
Search for and download anime torrents and open them automatically.
|
|
5
5
|
Results are color-coded - green for new episodes of previously downloaded torrents, cyan (blue) for previously downloaded torrents.
|
|
6
|
-
Automatically find and downloaded new episodes of previously downloaded anime with `$ nyaa
|
|
6
|
+
Automatically find and downloaded new episodes of previously downloaded anime with `$ nyaa get`!
|
|
7
|
+
List downloaded torrent files with `$ nyaa list [-a]`.
|
|
8
|
+
Delete torrents for a series with `$ nyaa remove ...`.
|
|
7
9
|
|
|
8
10
|
## Installation
|
|
9
11
|
|
|
@@ -11,7 +13,7 @@ Automatically find and downloaded new episodes of previously downloaded anime wi
|
|
|
11
13
|
|
|
12
14
|
That's all!
|
|
13
15
|
|
|
14
|
-
## Usage
|
|
16
|
+
## Usage (a bit outdated)
|
|
15
17
|
|
|
16
18
|
Run `$ nyaa` to see the usage text:
|
|
17
19
|
|
|
@@ -29,7 +31,7 @@ The `-n` (`--new`) option makes `nyaa` find new episodes of previously downloade
|
|
|
29
31
|
|
|
30
32
|

|
|
31
33
|
|
|
32
|
-
You can also run `$ nyaa
|
|
34
|
+
You can also run `$ nyaa get` which is equivalent to `$ nyaa -na`:
|
|
33
35
|
|
|
34
36
|

|
|
35
37
|
|
data/bin/nyaa-get
CHANGED
data/bin/nyaa_anime
CHANGED
|
@@ -1,161 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
require 'optparse'
|
|
14
|
-
|
|
15
|
-
if ARGV.size == 0
|
|
16
|
-
ARGV.push "--help"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
options = {}
|
|
20
|
-
OptionParser.new do |opts|
|
|
21
|
-
opts.banner = "Usage: nyaa [options] anime\n" <<
|
|
22
|
-
" nyaa_anime [options] anime\n" <<
|
|
23
|
-
" nyaa-get\n\n" <<
|
|
24
|
-
" `nyaa` is an alias for `nyaa_anime`.\n" <<
|
|
25
|
-
" `nyaa-get` is equivalent to `nyaa -na`.\n\n" <<
|
|
26
|
-
" (If you like this tool, please donate via PayPal\n" <<
|
|
27
|
-
" to wujoshuawu@gmail.com to keep the developer afloat.)\n\n"
|
|
28
|
-
|
|
29
|
-
opts.on("-n", "--new", "Find all new episodes of",
|
|
30
|
-
"previously downloaded anime") do
|
|
31
|
-
options[:find_new] = true
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
opts.on("-a", "--all", "Download all results without asking") do
|
|
35
|
-
options[:download_all] = true
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
opts.on("-s", "--small-res", "Add '#{SMALL_RESOLUTION}' to the search term") do
|
|
39
|
-
options[:resolution] = SMALL_RESOLUTION
|
|
40
|
-
end
|
|
41
|
-
opts.on("-m", "--medium-res", "Add '#{MEDIUM_RESOLUTION}' to the search term") do
|
|
42
|
-
options[:resolution] = MEDIUM_RESOLUTION
|
|
43
|
-
end
|
|
44
|
-
opts.on("-l", "--large-res", "Add '#{LARGE_RESOLUTION}' to the search term") do
|
|
45
|
-
options[:resolution] = LARGE_RESOLUTION
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
opts.on("-f", "--fansubber [FANSUBBER]",
|
|
49
|
-
"Specify [FANSUBBER] to be added to the search",
|
|
50
|
-
"term. [FANSUBBER] can be abbreviated by",
|
|
51
|
-
*FANSUBBERS.map {|o, f| "#{o} - #{f}"}) do |f|
|
|
52
|
-
if FANSUBBERS[f]
|
|
53
|
-
options[:subber] = FANSUBBERS[f]
|
|
54
|
-
elsif f.nil?
|
|
55
|
-
puts "Error: Expected [FANSUBBER] with the -f option"
|
|
56
|
-
ARGV.push "--help"
|
|
57
|
-
else
|
|
58
|
-
options[:subber] = f
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
opts.on("-S", "--speedsubs", "Equivalent to `--fansubber=#{SPEEDSUBBER}`") do
|
|
63
|
-
options[:subber] = SPEEDSUBBER
|
|
64
|
-
end
|
|
65
|
-
end.parse!
|
|
66
|
-
|
|
67
|
-
require 'nyaa_anime'
|
|
68
|
-
nyaa = NyaaAnime.new
|
|
69
|
-
|
|
70
|
-
if options[:find_new]
|
|
71
|
-
nyaa.find_new_titles
|
|
3
|
+
if ARGV[0] == "search"
|
|
4
|
+
require 'nyaa_anime/search'
|
|
5
|
+
elsif ARGV[0] == "get"
|
|
6
|
+
ARGV[1] = "-na"
|
|
7
|
+
require 'nyaa_anime/search'
|
|
8
|
+
elsif ARGV[0] == "list"
|
|
9
|
+
require 'nyaa_anime/list'
|
|
10
|
+
elsif ARGV[0] == "remove"
|
|
11
|
+
require 'nyaa_anime/remove'
|
|
72
12
|
else
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
search_term += " #{res}"
|
|
83
|
-
end
|
|
84
|
-
nyaa.search search_term, false
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
if nyaa.download_count == 0
|
|
88
|
-
puts "No downloads found."
|
|
89
|
-
exit
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
require 'os'
|
|
93
|
-
|
|
94
|
-
def get_y_or_n
|
|
95
|
-
while true
|
|
96
|
-
response = $stdin.gets.chomp.downcase
|
|
97
|
-
begin
|
|
98
|
-
if "yes".match(/\A#{response}/)
|
|
99
|
-
return true
|
|
100
|
-
end
|
|
101
|
-
if "no".match(/\A#{response}/)
|
|
102
|
-
return false
|
|
103
|
-
end
|
|
104
|
-
rescue RegexpError
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def prompt_to_open(torrents)
|
|
110
|
-
print "Open downloaded torrent#{"s" if torrents.count > 1}? (y/n): "
|
|
111
|
-
if get_y_or_n
|
|
112
|
-
if OS.mac?
|
|
113
|
-
`open #{torrents.join " "}`
|
|
114
|
-
elsif OS.windows?
|
|
115
|
-
torrents.each { |torr| `#{torr}` }
|
|
116
|
-
else # POSIX assumed
|
|
117
|
-
torrents.each { |torr| `xdg-open #{torr} &` }
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
if options[:download_all]
|
|
123
|
-
prompt_to_open nyaa.download_all
|
|
124
|
-
exit
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
if nyaa.download_count > 1
|
|
128
|
-
prompt = "Download (1-#{nyaa.download_count}, 'a(ll)'"
|
|
129
|
-
prompt << ", 'n(ew)'" if nyaa.new_count > 0 && !options[:find_new]
|
|
130
|
-
prompt << ", or [ENTER] to cancel): "
|
|
131
|
-
else
|
|
132
|
-
print "Download? (y/n): "
|
|
133
|
-
if get_y_or_n
|
|
134
|
-
prompt_to_open [nyaa.download_index(0)]
|
|
135
|
-
end
|
|
136
|
-
exit
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
while true
|
|
140
|
-
print prompt
|
|
141
|
-
index = $stdin.gets.chomp.downcase
|
|
142
|
-
begin
|
|
143
|
-
if index == ""
|
|
144
|
-
exit
|
|
145
|
-
end
|
|
146
|
-
if "new".match(/\A#{index}/) && nyaa.new_count > 0 && !options[:find_new]
|
|
147
|
-
prompt_to_open nyaa.download_all_new
|
|
148
|
-
exit
|
|
149
|
-
end
|
|
150
|
-
if "all".match(/\A#{index}/)
|
|
151
|
-
prompt_to_open nyaa.download_all
|
|
152
|
-
exit
|
|
153
|
-
end
|
|
154
|
-
if (1..nyaa.download_count).include?(index.to_i)
|
|
155
|
-
prompt_to_open [nyaa.download_index(index.to_i-1)]
|
|
156
|
-
exit
|
|
157
|
-
end
|
|
158
|
-
rescue RegexpError
|
|
159
|
-
next
|
|
160
|
-
end
|
|
13
|
+
puts "Usage: nyaa <command> [<args>]\n" <<
|
|
14
|
+
" nyaa_anime <command> [<args>]\n\n" <<
|
|
15
|
+
" If you like this tool, please donate via PayPal\n" <<
|
|
16
|
+
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n" <<
|
|
17
|
+
"Commands:\n" <<
|
|
18
|
+
" search Search for and download anime\n" <<
|
|
19
|
+
" get Equivalent to `nyaa search -na`\n" <<
|
|
20
|
+
" list List downloaded torrent files\n" <<
|
|
21
|
+
" remove Delete download torrent files from a series\n"
|
|
161
22
|
end
|
data/lib/nyaa_anime.rb
CHANGED
|
@@ -15,14 +15,17 @@ class NyaaAnime
|
|
|
15
15
|
NYAA_SEARCH_DEFAULT = "#{NYAA_SEARCH}&cats=1_37&filter=2&term="
|
|
16
16
|
NYAA_DL_DIR = "#{Dir.home}/Downloads/nyaa/"
|
|
17
17
|
NYAA_ENTRIES_PER_PAGE = 100
|
|
18
|
+
MAX_PAGES = 5
|
|
18
19
|
TITLE_TOLERANCE_RANGE = (1..4)
|
|
19
20
|
NEW_COLOR = :green
|
|
20
21
|
ALREADY_DOWNLOADED_COLOR = :cyan
|
|
21
22
|
|
|
22
23
|
attr_reader :downloads, :new_titles
|
|
23
24
|
|
|
25
|
+
FileUtils.mkdir_p NYAA_DL_DIR
|
|
26
|
+
|
|
24
27
|
def search(title, quiet=true)
|
|
25
|
-
|
|
28
|
+
puts "Searching for \"#{title}\"..." unless quiet
|
|
26
29
|
@downloads = {}
|
|
27
30
|
@titles = []
|
|
28
31
|
url = "#{NYAA_SEARCH_DEFAULT}#{CGI.escape(title)}&offset="
|
|
@@ -30,14 +33,12 @@ class NyaaAnime
|
|
|
30
33
|
dl_urls = []
|
|
31
34
|
offset = 1
|
|
32
35
|
while true
|
|
33
|
-
print "."
|
|
34
36
|
results = Nokogiri::HTML(open("#{url}#{offset}")).css('item')
|
|
35
37
|
titles.concat results.css('title').map { |t| t.content }
|
|
36
38
|
dl_urls.concat results.css('link').map { |l| l.next.content }
|
|
37
|
-
break if results.count < NYAA_ENTRIES_PER_PAGE
|
|
39
|
+
break if results.count < NYAA_ENTRIES_PER_PAGE || offset >= MAX_PAGES
|
|
38
40
|
offset += 1
|
|
39
41
|
end
|
|
40
|
-
print "\n" unless quiet
|
|
41
42
|
titles.each_with_index { |t, i| @downloads[t] = dl_urls[i] }
|
|
42
43
|
@titles = titles.sort!
|
|
43
44
|
categorize_titles
|
|
@@ -46,18 +47,22 @@ class NyaaAnime
|
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def find_new_titles
|
|
49
|
-
search_terms =
|
|
50
|
+
search_terms = NyaaAnime.series_of_downloaded_titles
|
|
50
51
|
new_titles = Set.new
|
|
51
52
|
new_downloads = {}
|
|
52
|
-
search_terms.
|
|
53
|
+
max_title_size = search_terms.map { |t| t.size }.max
|
|
54
|
+
search_terms.each_with_index do |t, idx|
|
|
55
|
+
print "[#{(idx+1).to_s.rjust(search_terms.count.to_s.size, "0")}/#{search_terms.count}] #{t}..."
|
|
53
56
|
search t
|
|
54
57
|
new_titles.merge @new_titles
|
|
55
58
|
@new_titles.each { |ti| new_downloads[ti] = @downloads[ti] }
|
|
59
|
+
print "." * (max_title_size - t.size)
|
|
56
60
|
if @new_titles.any?
|
|
57
|
-
|
|
61
|
+
puts "#{@new_titles.count.to_s.colorize(:green)} found!"
|
|
62
|
+
else
|
|
63
|
+
puts "none found."
|
|
58
64
|
end
|
|
59
65
|
end
|
|
60
|
-
print " - "
|
|
61
66
|
@new_titles = new_titles
|
|
62
67
|
@titles = new_titles.to_a.sort!
|
|
63
68
|
@downloads = new_downloads
|
|
@@ -87,8 +92,8 @@ class NyaaAnime
|
|
|
87
92
|
@new_titles = Set.new
|
|
88
93
|
@other_titles = Set.new
|
|
89
94
|
@version_differing_titles = Set.new
|
|
90
|
-
dls = downloaded_torrents
|
|
91
|
-
stripped_dls = stripped_downloaded_titles
|
|
95
|
+
dls = NyaaAnime.downloaded_torrents
|
|
96
|
+
stripped_dls = NyaaAnime.stripped_downloaded_titles
|
|
92
97
|
hashless_dls = dls.map { |t| NyaaAnime.hashless_title t }
|
|
93
98
|
@titles.each do |t|
|
|
94
99
|
stripped_t = NyaaAnime.stripped_title t
|
|
@@ -126,19 +131,29 @@ class NyaaAnime
|
|
|
126
131
|
torrent.sub(/(\s*\[\w{8}\])?(\.\w+)+\z/, "")
|
|
127
132
|
end
|
|
128
133
|
|
|
129
|
-
def
|
|
134
|
+
def self.series_of_title(torrent)
|
|
135
|
+
NyaaAnime.hashless_title(torrent).sub(/\s+-\s+\d+(\.\d+)?(v\d+)?\s*/, " ")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.downloaded_torrents
|
|
130
139
|
Dir["#{NYAA_DL_DIR}*"].select { |f| File.file? f }.map { |f| File.basename f }
|
|
131
140
|
end
|
|
132
141
|
|
|
133
|
-
def stripped_downloaded_titles
|
|
142
|
+
def self.stripped_downloaded_titles
|
|
134
143
|
dls = Set.new
|
|
135
|
-
downloaded_torrents.each { |t| dls.add NyaaAnime.stripped_title(t) }
|
|
144
|
+
NyaaAnime.downloaded_torrents.each { |t| dls.add NyaaAnime.stripped_title(t) }
|
|
136
145
|
dls
|
|
137
146
|
end
|
|
138
147
|
|
|
139
|
-
def
|
|
148
|
+
def self.series_of_downloaded_titles
|
|
140
149
|
dls = Set.new
|
|
141
|
-
downloaded_torrents.each { |t| dls.add NyaaAnime.
|
|
150
|
+
NyaaAnime.downloaded_torrents.each { |t| dls.add NyaaAnime.series_of_title(t) }
|
|
151
|
+
dls
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def self.downloaded_torrents_by_series
|
|
155
|
+
dls = {}
|
|
156
|
+
NyaaAnime.downloaded_torrents.each { |t| (dls[NyaaAnime.series_of_title(t)] ||= []) << t }
|
|
142
157
|
dls
|
|
143
158
|
end
|
|
144
159
|
|
|
@@ -151,7 +166,6 @@ class NyaaAnime
|
|
|
151
166
|
def download(title)
|
|
152
167
|
torrent = open @downloads[title]
|
|
153
168
|
filename = torrent.meta["content-disposition"][/filename="(.+\.torrent)"/, 1]
|
|
154
|
-
FileUtils.mkdir_p NYAA_DL_DIR
|
|
155
169
|
open("#{NYAA_DL_DIR}#{filename}", "w") { |f| f.write torrent.read }
|
|
156
170
|
puts "#{title}.torrent downloaded."
|
|
157
171
|
"#{NYAA_DL_DIR}\"#{title}.torrent\""
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
options = {}
|
|
4
|
+
OptionParser.new do |opts|
|
|
5
|
+
opts.banner = "Usage: nyaa list [-a]\n\n" <<
|
|
6
|
+
" If you like this tool, please donate via PayPal\n" <<
|
|
7
|
+
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n"
|
|
8
|
+
|
|
9
|
+
opts.on("-a", "--all", "List all individual files as well") do
|
|
10
|
+
options[:list_all] = true
|
|
11
|
+
end
|
|
12
|
+
end.parse!
|
|
13
|
+
|
|
14
|
+
require 'nyaa_anime'
|
|
15
|
+
|
|
16
|
+
dt_s = NyaaAnime.downloaded_torrents_by_series
|
|
17
|
+
ss = dt_s.keys.sort!
|
|
18
|
+
ss.each_with_index do |series, idx|
|
|
19
|
+
puts "#{idx+1}: #{series}"
|
|
20
|
+
if options[:list_all]
|
|
21
|
+
dt_s[series].each { |torrent| puts " #{torrent}" }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
ARGV[1] ||= "--help"
|
|
4
|
+
|
|
5
|
+
options = {}
|
|
6
|
+
OptionParser.new do |opts|
|
|
7
|
+
opts.banner = "Usage: nyaa remove <anime>\n" <<
|
|
8
|
+
" nyaa remove -n <index>\n" <<
|
|
9
|
+
" nyaa remove -a\n\n" <<
|
|
10
|
+
" If you like this tool, please donate via PayPal\n" <<
|
|
11
|
+
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n"
|
|
12
|
+
|
|
13
|
+
opts.on("-a", "--all", "Remove all files") do
|
|
14
|
+
options[:remove_all] = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
opts.on("-n", "--number [N]", "Remove torrents of series as numbered by `nyaa list`") do |n|
|
|
18
|
+
options[:number] = n.to_i
|
|
19
|
+
end
|
|
20
|
+
end.parse!
|
|
21
|
+
|
|
22
|
+
require 'nyaa_anime'
|
|
23
|
+
|
|
24
|
+
TORRENTS_BY_SERIES = NyaaAnime.downloaded_torrents_by_series
|
|
25
|
+
ss = TORRENTS_BY_SERIES.keys.sort!
|
|
26
|
+
|
|
27
|
+
if ss.size == 0
|
|
28
|
+
puts "No files in #{NyaaAnime::NYAA_DL_DIR}."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
require 'highline/import'
|
|
32
|
+
|
|
33
|
+
if options[:remove_all]
|
|
34
|
+
ts = NyaaAnime.downloaded_torrents.map { |t| "#{NyaaAnime::NYAA_DL_DIR}#{t}" }
|
|
35
|
+
if agree "Delete all #{ts.size} torrent files? (y/n) "
|
|
36
|
+
File.delete(*ts)
|
|
37
|
+
end
|
|
38
|
+
exit
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def delete_series(series)
|
|
42
|
+
ts = TORRENTS_BY_SERIES[series].map { |t| "#{NyaaAnime::NYAA_DL_DIR}#{t}" }
|
|
43
|
+
if agree "Delete all #{ts.size} torrent files for #{series}? (y/n) "
|
|
44
|
+
File.delete(*ts)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if options[:number]
|
|
49
|
+
num = options[:number]
|
|
50
|
+
if (1..ss.size).include? num
|
|
51
|
+
delete_series ss[num-1]
|
|
52
|
+
else
|
|
53
|
+
puts "Error: Number (#{num}) out of range 1-#{ss.size}."
|
|
54
|
+
end
|
|
55
|
+
exit
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
term = ARGV[1..-1].join " "
|
|
59
|
+
ss = TORRENTS_BY_SERIES.keys.select { |series| !!series[/#{term}/i] }
|
|
60
|
+
ss.each { |series| delete_series series }
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
FANSUBBERS = { "c"=>"Commie",
|
|
2
|
+
"ch"=>"Chihiro",
|
|
3
|
+
"f"=>"FFF",
|
|
4
|
+
"h"=>"Hatsuyuki",
|
|
5
|
+
"hs"=>"HorribleSubs" }
|
|
6
|
+
SPEEDSUBBER = FANSUBBERS["hs"]
|
|
7
|
+
SMALL_RESOLUTION = "480"
|
|
8
|
+
MEDIUM_RESOLUTION = "720"
|
|
9
|
+
LARGE_RESOLUTION = "1080"
|
|
10
|
+
|
|
11
|
+
require 'optparse'
|
|
12
|
+
|
|
13
|
+
ARGV[1] ||= "--help"
|
|
14
|
+
|
|
15
|
+
options = {}
|
|
16
|
+
OptionParser.new do |opts|
|
|
17
|
+
opts.banner = "Usage: nyaa search [options] <anime>\n" <<
|
|
18
|
+
" nyaa get (equivalent to `nyaa search -na`)\n\n" <<
|
|
19
|
+
" If you like this tool, please donate via PayPal\n" <<
|
|
20
|
+
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n"
|
|
21
|
+
|
|
22
|
+
opts.on("-n", "--new", "Find all new episodes of",
|
|
23
|
+
"previously downloaded anime") do
|
|
24
|
+
options[:find_new] = true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
opts.on("-a", "--all", "Download all results without asking") do
|
|
28
|
+
options[:download_all] = true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
opts.on("-s", "--small-res", "Add '#{SMALL_RESOLUTION}' to the search term") do
|
|
32
|
+
options[:resolution] = SMALL_RESOLUTION
|
|
33
|
+
end
|
|
34
|
+
opts.on("-m", "--medium-res", "Add '#{MEDIUM_RESOLUTION}' to the search term") do
|
|
35
|
+
options[:resolution] = MEDIUM_RESOLUTION
|
|
36
|
+
end
|
|
37
|
+
opts.on("-l", "--large-res", "Add '#{LARGE_RESOLUTION}' to the search term") do
|
|
38
|
+
options[:resolution] = LARGE_RESOLUTION
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
opts.on("-f", "--fansubber [FANSUBBER]",
|
|
42
|
+
"Specify [FANSUBBER] to be added to the search",
|
|
43
|
+
"term. [FANSUBBER] can be abbreviated by",
|
|
44
|
+
*FANSUBBERS.map {|o, f| "#{o} - #{f}"}) do |f|
|
|
45
|
+
if FANSUBBERS[f]
|
|
46
|
+
options[:subber] = FANSUBBERS[f]
|
|
47
|
+
elsif f.nil?
|
|
48
|
+
puts "Error: Expected [FANSUBBER] with the -f option"
|
|
49
|
+
ARGV.push "--help"
|
|
50
|
+
else
|
|
51
|
+
options[:subber] = f
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
opts.on("-S", "--speedsubs", "Equivalent to `--fansubber=#{SPEEDSUBBER}`") do
|
|
56
|
+
options[:subber] = SPEEDSUBBER
|
|
57
|
+
end
|
|
58
|
+
end.parse!
|
|
59
|
+
|
|
60
|
+
require 'nyaa_anime'
|
|
61
|
+
nyaa = NyaaAnime.new
|
|
62
|
+
|
|
63
|
+
if options[:find_new]
|
|
64
|
+
nyaa.find_new_titles
|
|
65
|
+
else
|
|
66
|
+
if ARGV.size == 2
|
|
67
|
+
search_term = ARGV[1]
|
|
68
|
+
else
|
|
69
|
+
search_term = ARGV[1..-1].join " "
|
|
70
|
+
end
|
|
71
|
+
if subber = options[:subber]
|
|
72
|
+
search_term = "[#{subber}] #{search_term}"
|
|
73
|
+
end
|
|
74
|
+
if res = options[:resolution]
|
|
75
|
+
search_term += " #{res}"
|
|
76
|
+
end
|
|
77
|
+
nyaa.search search_term, false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
if nyaa.download_count == 0
|
|
81
|
+
puts "No downloads found."
|
|
82
|
+
exit
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
require 'os'
|
|
86
|
+
require 'highline/import'
|
|
87
|
+
|
|
88
|
+
def prompt_to_open(torrents)
|
|
89
|
+
if agree "Open downloaded torrent#{"s" if torrents.count > 1}? (y/n): "
|
|
90
|
+
if OS.mac?
|
|
91
|
+
`open #{torrents.join " "}`
|
|
92
|
+
elsif OS.windows?
|
|
93
|
+
torrents.each { |torr| `#{torr}` }
|
|
94
|
+
else # POSIX assumed
|
|
95
|
+
torrents.each { |torr| `xdg-open #{torr} &` }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
if options[:download_all]
|
|
101
|
+
prompt_to_open nyaa.download_all
|
|
102
|
+
exit
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
if nyaa.download_count > 1
|
|
106
|
+
prompt = "Download (1-#{nyaa.download_count}, 'a(ll)'"
|
|
107
|
+
prompt << ", 'n(ew)'" if nyaa.new_count > 0 && !options[:find_new]
|
|
108
|
+
prompt << ", or [ENTER] to cancel): "
|
|
109
|
+
else
|
|
110
|
+
if agree "Download? (y/n): "
|
|
111
|
+
prompt_to_open [nyaa.download_index(0)]
|
|
112
|
+
end
|
|
113
|
+
exit
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
while true
|
|
117
|
+
print prompt
|
|
118
|
+
index = $stdin.gets.chomp.downcase
|
|
119
|
+
begin
|
|
120
|
+
if index == ""
|
|
121
|
+
exit
|
|
122
|
+
end
|
|
123
|
+
if "new".match(/\A#{index}/) && nyaa.new_count > 0 && !options[:find_new]
|
|
124
|
+
prompt_to_open nyaa.download_all_new
|
|
125
|
+
exit
|
|
126
|
+
end
|
|
127
|
+
if "all".match(/\A#{index}/)
|
|
128
|
+
prompt_to_open nyaa.download_all
|
|
129
|
+
exit
|
|
130
|
+
end
|
|
131
|
+
if (1..nyaa.download_count).include?(index.to_i)
|
|
132
|
+
prompt_to_open [nyaa.download_index(index.to_i-1)]
|
|
133
|
+
exit
|
|
134
|
+
end
|
|
135
|
+
rescue RegexpError
|
|
136
|
+
next
|
|
137
|
+
end
|
|
138
|
+
end
|
data/lib/nyaa_anime/version.rb
CHANGED
data/nyaa_anime.gemspec
CHANGED
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
"them automatically. Results are color-coded - green for new episodes of " <<
|
|
15
15
|
"previously downloaded torrents, cyan (blue) for previously downloaded " <<
|
|
16
16
|
"torrents. Automatically find and downloaded new episodes of previously " <<
|
|
17
|
-
"downloaded anime with `$ nyaa
|
|
17
|
+
"downloaded anime with `$ nyaa get`. List and manage downloaded torrent files."
|
|
18
18
|
spec.homepage = "https://bitbucket.org/tsubaki/nyaa_anime"
|
|
19
19
|
spec.license = "MIT"
|
|
20
20
|
|
|
@@ -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 'highline', '~> 1.6', '>= 1.6.21'
|
|
26
27
|
spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.2.1'
|
|
27
28
|
spec.add_runtime_dependency 'colorize', '~> 0.7', '>= 0.7.3'
|
|
28
29
|
spec.add_runtime_dependency 'levenshtein-ffi', '~> 1.1'
|
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.6.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-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: highline
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.6.21
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.6'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.6.21
|
|
13
33
|
- !ruby/object:Gem::Dependency
|
|
14
34
|
name: nokogiri
|
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -116,7 +136,8 @@ description: "`nyaa` (short for `nyaa_anime`) is the painless NyaaTorrents anime
|
|
|
116
136
|
tool. Search for and download anime torrents and open them automatically. Results
|
|
117
137
|
are color-coded - green for new episodes of previously downloaded torrents, cyan
|
|
118
138
|
(blue) for previously downloaded torrents. Automatically find and downloaded new
|
|
119
|
-
episodes of previously downloaded anime with `$ nyaa
|
|
139
|
+
episodes of previously downloaded anime with `$ nyaa get`. List and manage downloaded
|
|
140
|
+
torrent files."
|
|
120
141
|
email:
|
|
121
142
|
- wujoshuawu@gmail.com
|
|
122
143
|
executables:
|
|
@@ -135,6 +156,9 @@ files:
|
|
|
135
156
|
- bin/nyaa-get
|
|
136
157
|
- bin/nyaa_anime
|
|
137
158
|
- lib/nyaa_anime.rb
|
|
159
|
+
- lib/nyaa_anime/list.rb
|
|
160
|
+
- lib/nyaa_anime/remove.rb
|
|
161
|
+
- lib/nyaa_anime/search.rb
|
|
138
162
|
- lib/nyaa_anime/version.rb
|
|
139
163
|
- nyaa_anime.gemspec
|
|
140
164
|
homepage: https://bitbucket.org/tsubaki/nyaa_anime
|