nyaa_anime 0.8.2 → 0.9.2
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 +48 -48
- data/bin/nyaa-get +1 -4
- data/lib/nyaa_anime/entry.rb +40 -0
- data/lib/nyaa_anime/list.rb +4 -4
- data/lib/nyaa_anime/remove.rb +8 -8
- data/lib/nyaa_anime/search.rb +27 -33
- data/lib/nyaa_anime/version.rb +1 -1
- data/lib/nyaa_anime.rb +58 -120
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c4c190239b5baf100c07ba7b8dc5336f63b3dc4
|
|
4
|
+
data.tar.gz: d518e8d14fc44ce129bdd6aa979a088f098059ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b77ba04c27f78adf3e3d82afa411c8034bec2807d875ef14aebf650a6a5297825a197ccbee94565e6ce37705dbd9ed9e100298e6a413e76066bdb58d9634fe42
|
|
7
|
+
data.tar.gz: 012745fb00c81368242a35217c49cbb13ef940eb71db6a2777407cf33508b1529b6b8ddc8ae593f6588630fcd703307a130e5c9763cd2cbfd2308d4bb6f3b61f
|
data/README.md
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
# NyaaAnime
|
|
2
|
-
|
|
3
|
-
`nyaa` (short for `nyaa_anime`) is the painless Nyaa Torrents anime command-line tool.
|
|
4
|
-
Search for and download anime torrents and open them automatically.
|
|
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 get`!
|
|
7
|
-
List downloaded torrent files with `$ nyaa list [-a]`.
|
|
8
|
-
Delete torrents for a series with `$ nyaa remove ...`.
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
$ gem install nyaa_anime
|
|
13
|
-
|
|
14
|
-
That's all!
|
|
15
|
-
|
|
16
|
-
## Usage (
|
|
17
|
-
|
|
18
|
-
Run `$ nyaa` to see the usage text:
|
|
19
|
-
|
|
20
|
-

|
|
21
|
-
|
|
22
|
-
For example, try `$ nyaa -m -f ch no game no life`:
|
|
23
|
-
|
|
24
|
-

|
|
25
|
-
|
|
26
|
-
Downloads are saved to `~/Downloads/nyaa/`. Future queries will check the files there and automatically color-code the search results. Green is for new episodes of previously downloaded torrents, while cyan (blue) is for previously downloaded torrents:
|
|
27
|
-
|
|
28
|
-

|
|
29
|
-
|
|
30
|
-
The `-n` (`--new`) option makes `nyaa` find new episodes of previously downloaded anime (the torrents in `~/Downloads/nyaa/`):
|
|
31
|
-
|
|
32
|
-

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

|
|
37
|
-
|
|
38
|
-
## Donations
|
|
39
|
-
|
|
40
|
-
If you like `nyaa`, please donate via PayPal to wujoshuawu@gmail.com to keep me afloat. Thank you!
|
|
41
|
-
|
|
42
|
-
## Contributing
|
|
43
|
-
|
|
44
|
-
1. Fork it ( https://bitbucket.org/tsubaki/nyaa_anime/fork )
|
|
45
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
46
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
47
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
|
48
|
-
5. Create a new Pull Request
|
|
1
|
+
# NyaaAnime
|
|
2
|
+
|
|
3
|
+
`nyaa` (short for `nyaa_anime`) is the painless Nyaa Torrents anime command-line tool.
|
|
4
|
+
Search for and download anime torrents and open them automatically.
|
|
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 get`!
|
|
7
|
+
List downloaded torrent files with `$ nyaa list [-a]`.
|
|
8
|
+
Delete torrents for a series with `$ nyaa remove ...`.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
$ gem install nyaa_anime
|
|
13
|
+
|
|
14
|
+
That's all!
|
|
15
|
+
|
|
16
|
+
## Usage (very outdated)
|
|
17
|
+
|
|
18
|
+
Run `$ nyaa` to see the usage text:
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
For example, try `$ nyaa -m -f ch no game no life`:
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
Downloads are saved to `~/Downloads/nyaa/`. Future queries will check the files there and automatically color-code the search results. Green is for new episodes of previously downloaded torrents, while cyan (blue) is for previously downloaded torrents:
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
The `-n` (`--new`) option makes `nyaa` find new episodes of previously downloaded anime (the torrents in `~/Downloads/nyaa/`):
|
|
31
|
+
|
|
32
|
+

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

|
|
37
|
+
|
|
38
|
+
## Donations
|
|
39
|
+
|
|
40
|
+
If you like `nyaa`, please donate via PayPal to wujoshuawu@gmail.com to keep me afloat. Thank you!
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
1. Fork it ( https://bitbucket.org/tsubaki/nyaa_anime/fork )
|
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
48
|
+
5. Create a new Pull Request
|
data/bin/nyaa-get
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class Entry
|
|
2
|
+
|
|
3
|
+
require 'nyaa_anime'
|
|
4
|
+
|
|
5
|
+
attr_reader :title, :link, :hashless, :distro_episode, :distro_meta, :subber, :series, :episode, :last_ep, :meta
|
|
6
|
+
|
|
7
|
+
def initialize(title, link=nil)
|
|
8
|
+
@title = title
|
|
9
|
+
@link = link
|
|
10
|
+
match = @title.scan(/\A(\[[^\[\]]+\])?[_\s]*(.+?)[_\s]*-?[_\s]*(\d+(\.\d+)?(v\d+)?|\d+-\d+)[_\s]*(.+?)[_\s]*(\[\w{8,}\])?[_\s]*(\.\w+)*\z/)
|
|
11
|
+
@subber, @series, @episode, @meta = match[0].values_at(0, 1, 2, 5)
|
|
12
|
+
@episode, @last_ep = @episode.split("-").map { |ep| ep.to_i }
|
|
13
|
+
@last_ep ||= @episode
|
|
14
|
+
@distro_episode = "#{@subber} #{@series} #{@episode}"
|
|
15
|
+
@distro_meta = "#{@subber} #{@series} #{@meta}"
|
|
16
|
+
@hashless = "#{@subber} #{@series} #{@episode} #{@meta}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def ==(other)
|
|
20
|
+
@title == other.title &&
|
|
21
|
+
@link == other.link
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def <=>(other)
|
|
25
|
+
if @title == other.title
|
|
26
|
+
@link <=> other.link
|
|
27
|
+
else
|
|
28
|
+
@title <=> other.title
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_s
|
|
33
|
+
@hashless
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def first_ep
|
|
37
|
+
@episode
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
data/lib/nyaa_anime/list.rb
CHANGED
|
@@ -21,11 +21,11 @@ end
|
|
|
21
21
|
|
|
22
22
|
require 'nyaa_anime'
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
de_ds = NyaaAnime.downloaded_entries_by_distro
|
|
25
|
+
de_ds.each_with_index do |distro_entries, idx|
|
|
26
|
+
distro, entries = distro_entries
|
|
27
27
|
puts "#{idx+1}: #{distro}"
|
|
28
28
|
if options[:list_all]
|
|
29
|
-
|
|
29
|
+
entries.each { |entry| puts " #{e.title}" }
|
|
30
30
|
end
|
|
31
31
|
end
|
data/lib/nyaa_anime/remove.rb
CHANGED
|
@@ -31,9 +31,9 @@ end
|
|
|
31
31
|
require 'nyaa_anime'
|
|
32
32
|
|
|
33
33
|
TORRENTS_BY_DISTRO = NyaaAnime.downloaded_torrents_by_distro
|
|
34
|
-
|
|
34
|
+
distros = TORRENTS_BY_DISTRO.keys.sort!
|
|
35
35
|
|
|
36
|
-
if
|
|
36
|
+
if distros.size == 0
|
|
37
37
|
puts "No files in #{NyaaAnime::NYAA_DL_DIR}."
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -56,19 +56,19 @@ end
|
|
|
56
56
|
|
|
57
57
|
if options[:number]
|
|
58
58
|
num = options[:number]
|
|
59
|
-
if (1..
|
|
60
|
-
delete_distro
|
|
59
|
+
if (1..distros.size).include? num
|
|
60
|
+
delete_distro distros[num-1]
|
|
61
61
|
else
|
|
62
|
-
warn "Error: Number (#{num}) out of range 1-#{
|
|
62
|
+
warn "Error: Number (#{num}) out of range 1-#{distros.size}."
|
|
63
63
|
exit 1
|
|
64
64
|
end
|
|
65
65
|
exit
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
term = ARGV[1..-1].join " "
|
|
69
|
-
|
|
70
|
-
if
|
|
69
|
+
distros = TORRENTS_BY_DISTRO.keys.select { |distro| !!distro[/#{term}/i] }
|
|
70
|
+
if distros.count == 0
|
|
71
71
|
warn "Error: No torrent files matching \"#{term}\"."
|
|
72
72
|
exit 1
|
|
73
73
|
end
|
|
74
|
-
|
|
74
|
+
distros.each { |distro| delete_distro distro }
|
data/lib/nyaa_anime/search.rb
CHANGED
|
@@ -16,6 +16,7 @@ options = {}
|
|
|
16
16
|
option_parser = OptionParser.new do |opts|
|
|
17
17
|
opts.banner = "Usage: nyaa search [options] <anime>\n" <<
|
|
18
18
|
" nyaa s [options] <anime>\n" <<
|
|
19
|
+
" nyaa search -n [-a [-q]]\n" <<
|
|
19
20
|
" nyaa get (equivalent to `nyaa search -naq`)\n\n" <<
|
|
20
21
|
" If you like this tool, please donate via PayPal\n" <<
|
|
21
22
|
" to wujoshuawu@gmail.com to keep the developer afloat.\n\n"
|
|
@@ -80,16 +81,15 @@ end
|
|
|
80
81
|
|
|
81
82
|
require 'nyaa_anime'
|
|
82
83
|
require 'colorize'
|
|
83
|
-
nyaa = NyaaAnime.new
|
|
84
84
|
|
|
85
85
|
if options[:find_new]
|
|
86
|
-
|
|
87
|
-
if
|
|
86
|
+
entries = NyaaAnime.find_new_titles(!!options[:quiet]).sort!
|
|
87
|
+
if entries.count == 0
|
|
88
88
|
puts "No new episodes found."
|
|
89
89
|
exit
|
|
90
90
|
else
|
|
91
|
-
puts "#{
|
|
92
|
-
|
|
91
|
+
puts "#{entries.count} new episode#{"s" if entries.count > 1} found!".colorize(NyaaAnime::NEW_COLOR)
|
|
92
|
+
entries.each_with_index { |entry, i| puts "#{i+1}: #{entry.to_s.colorize(NyaaAnime::NEW_COLOR)}" }
|
|
93
93
|
end
|
|
94
94
|
else
|
|
95
95
|
search_term = ARGV[1..-1].join " "
|
|
@@ -100,33 +100,29 @@ else
|
|
|
100
100
|
exit 1
|
|
101
101
|
end
|
|
102
102
|
puts "Searching for \"#{search_term}\"..." unless options[:quiet]
|
|
103
|
-
|
|
103
|
+
colorized_entries = NyaaAnime.colorized_entries NyaaAnime.search(search_term).sort!
|
|
104
|
+
new_entries = colorized_entries[:new]
|
|
105
|
+
entries = colorized_entries.values.flatten!
|
|
104
106
|
if options[:list_individually]
|
|
105
|
-
|
|
107
|
+
entries.each_with_index { |entry, i| puts "#{i+1}: #{entry}" } unless options[:quiet]
|
|
106
108
|
else
|
|
107
|
-
|
|
109
|
+
entries = NyaaAnime.entries_by_distro(entries).to_a
|
|
108
110
|
unless options[:quiet]
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
entries.each_with_index do |d_e, i|
|
|
112
|
+
distro, ents = d_e
|
|
113
|
+
if ents.count == 1
|
|
114
|
+
puts "#{i+1}: #{ents.first}"
|
|
112
115
|
next
|
|
113
116
|
end
|
|
114
|
-
|
|
115
|
-
last_ep = NyaaAnime.episode_of_title(results[ds].last)
|
|
116
|
-
if first_ep && last_ep
|
|
117
|
-
ep_tag = "(#{first_ep.first}~#{last_ep.last})"
|
|
118
|
-
else
|
|
119
|
-
ep_tag = "(#{results[ds].count} torrent#{"s" if results[ds].count > 1})"
|
|
120
|
-
end
|
|
121
|
-
puts "#{i+1}: #{ep_tag.bold} #{ds}"
|
|
117
|
+
puts "#{i+1}: #{"([#{ents.count}] #{ents.first.first_ep}~#{ents.last.last_ep})".bold} #{distro}"
|
|
122
118
|
end
|
|
123
119
|
end
|
|
124
120
|
end
|
|
125
|
-
if
|
|
121
|
+
if entries.count == 0
|
|
126
122
|
puts "No results for \"#{search_term}\"."
|
|
127
123
|
exit
|
|
128
124
|
else
|
|
129
|
-
puts "#{
|
|
125
|
+
puts "#{entries.count} result#{"s" if entries.count > 1}, #{new_entries.count} new."
|
|
130
126
|
end
|
|
131
127
|
end
|
|
132
128
|
|
|
@@ -152,37 +148,35 @@ def prompt_to_open(torrents)
|
|
|
152
148
|
end
|
|
153
149
|
|
|
154
150
|
if options[:download_all]
|
|
155
|
-
prompt_to_open
|
|
151
|
+
prompt_to_open NyaaAnime.download entries
|
|
156
152
|
exit
|
|
157
153
|
end
|
|
158
154
|
|
|
159
|
-
if
|
|
160
|
-
prompt = "Download (1-#{
|
|
161
|
-
"#{", 'n(ew)'" if
|
|
155
|
+
if entries.count > 1
|
|
156
|
+
prompt = "Download (1-#{entries.count}, 'a(ll)'" <<
|
|
157
|
+
"#{", 'n(ew)'" if new_entries.count > 0 && !options[:find_new]}" <<
|
|
162
158
|
", or [ENTER] to cancel): "
|
|
163
159
|
choice = ask(prompt) do |q|
|
|
164
160
|
q.validate = Proc.new do |input|
|
|
165
161
|
input == "" ||
|
|
166
|
-
("new"[/\A#{input}/i] &&
|
|
162
|
+
("new"[/\A#{input}/i] && new_entries.count > 0 && !options[:find_new]) ||
|
|
167
163
|
"all"[/\A#{input}/i] ||
|
|
168
|
-
(1..
|
|
164
|
+
(1..entries.count).include?(input.to_i)
|
|
169
165
|
end
|
|
170
166
|
q.responses[:not_valid] = ""
|
|
171
167
|
end
|
|
172
168
|
|
|
173
169
|
if choice == ""
|
|
174
170
|
elsif choice[/\An/i]
|
|
175
|
-
prompt_to_open
|
|
171
|
+
prompt_to_open NyaaAnime.download new_entries
|
|
176
172
|
elsif choice[/\Aa/i]
|
|
177
|
-
prompt_to_open
|
|
173
|
+
prompt_to_open NyaaAnime.download entries
|
|
178
174
|
else
|
|
179
|
-
|
|
180
|
-
prompt_to_open nyaa.download(torrent)
|
|
175
|
+
prompt_to_open NyaaAnime.download(entries.first.is_a?(Array) ? entries[choice.to_i-1][1] : entries[choice.to_i-1])
|
|
181
176
|
end
|
|
182
177
|
|
|
183
178
|
else
|
|
184
179
|
if agree "Download? (y/n): "
|
|
185
|
-
|
|
186
|
-
prompt_to_open nyaa.download(torrent)
|
|
180
|
+
prompt_to_open NyaaAnime.download(entries.first.is_a?(Array) ? entries.first[1].first : entries.first)
|
|
187
181
|
end
|
|
188
182
|
end
|
data/lib/nyaa_anime/version.rb
CHANGED
data/lib/nyaa_anime.rb
CHANGED
|
@@ -2,6 +2,7 @@ require "nyaa_anime/version"
|
|
|
2
2
|
|
|
3
3
|
class NyaaAnime
|
|
4
4
|
|
|
5
|
+
require 'nyaa_anime/entry'
|
|
5
6
|
require 'open-uri'
|
|
6
7
|
require 'nokogiri'
|
|
7
8
|
require 'cgi'
|
|
@@ -21,16 +22,11 @@ class NyaaAnime
|
|
|
21
22
|
CL_WIDTH = 70
|
|
22
23
|
THREAD_COUNT = 20
|
|
23
24
|
|
|
24
|
-
attr_reader :downloads, :new_titles
|
|
25
|
-
|
|
26
25
|
FileUtils.mkdir_p NYAA_DL_DIR
|
|
27
26
|
|
|
28
|
-
def search(title)
|
|
29
|
-
|
|
30
|
-
@titles = []
|
|
27
|
+
def self.search(title)
|
|
28
|
+
entries = []
|
|
31
29
|
url = "#{NYAA_SEARCH_DEFAULT}#{CGI.escape(title)}&offset="
|
|
32
|
-
titles = []
|
|
33
|
-
dl_urls = []
|
|
34
30
|
offset = 1
|
|
35
31
|
loop do
|
|
36
32
|
begin
|
|
@@ -39,158 +35,100 @@ class NyaaAnime
|
|
|
39
35
|
$stderr.print "Error: Could not connect to NyaaTorrents.\n"
|
|
40
36
|
exit 1
|
|
41
37
|
end
|
|
42
|
-
|
|
43
|
-
dl_urls.concat results.css('link').map { |l| l.next.content }
|
|
38
|
+
entries.concat results.map { |r| Entry.new r.css('title')[0].content, r.css('link')[0].next.content }
|
|
44
39
|
break if results.count < NYAA_ENTRIES_PER_PAGE || offset >= MAX_PAGES
|
|
45
40
|
offset += 1
|
|
46
41
|
end
|
|
47
|
-
|
|
48
|
-
@titles = titles.sort!
|
|
49
|
-
categorize_titles!
|
|
50
|
-
colorized_titles
|
|
42
|
+
entries
|
|
51
43
|
end
|
|
52
44
|
|
|
53
|
-
def find_new_titles(quiet=false)
|
|
54
|
-
search_terms = NyaaAnime.
|
|
55
|
-
|
|
56
|
-
new_downloads = {}
|
|
45
|
+
def self.find_new_titles(quiet=false)
|
|
46
|
+
search_terms = NyaaAnime.downloaded_entries.map { |e| e.distro_meta }
|
|
47
|
+
search_terms.uniq!
|
|
57
48
|
count_s_size = "[/] ".size + search_terms.count.to_s.size * 2
|
|
58
49
|
line_end_size = "...none found.".size
|
|
59
50
|
max_entry_size = [search_terms.map { |t| t.size }.max + count_s_size +
|
|
60
51
|
line_end_size, CL_WIDTH].min - line_end_size
|
|
61
52
|
index = 1
|
|
62
53
|
lock = Mutex.new
|
|
54
|
+
all_results = []
|
|
63
55
|
Parallel.each(search_terms, in_threads: THREAD_COUNT) do |t|
|
|
64
|
-
|
|
65
|
-
n.search t
|
|
56
|
+
results = NyaaAnime.categorize_entries(NyaaAnime.search t)[:new]
|
|
66
57
|
lock.synchronize do
|
|
67
|
-
new_titles.merge n.new_titles
|
|
68
|
-
n.new_titles.each { |ti| new_downloads[ti] = n.downloads[ti] }
|
|
69
58
|
if !quiet
|
|
70
59
|
msg = "/#{search_terms.count}] #{t[0...max_entry_size-count_s_size]}..." <<
|
|
71
60
|
("." * [max_entry_size - (count_s_size + t.size), 0].max) <<
|
|
72
|
-
(
|
|
61
|
+
(results.any? ? "#{results.count} found!".colorize(NEW_COLOR) : "none found.")
|
|
73
62
|
puts "[#{index.to_s.rjust(search_terms.count.to_s.size, "0")}#{msg}"
|
|
74
63
|
index += 1
|
|
75
64
|
end
|
|
76
65
|
end
|
|
66
|
+
all_results.concat results
|
|
77
67
|
end
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
downloaded_distros = NyaaAnime.distros_of_downloaded_titles
|
|
105
|
-
stripped_dls = NyaaAnime.stripped_downloaded_titles
|
|
106
|
-
@titles.each do |t|
|
|
107
|
-
if dls.include? "#{t}.torrent"
|
|
108
|
-
@already_downloaded_titles.add t
|
|
109
|
-
elsif stripped_dls.include? NyaaAnime.stripped_title(t)
|
|
110
|
-
@version_differing_titles.add t
|
|
111
|
-
elsif downloaded_distros.include? NyaaAnime.distro_of_title(t)
|
|
112
|
-
@new_titles.add t
|
|
68
|
+
all_results.uniq!
|
|
69
|
+
all_results.sort!
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.colorized_entries(entries)
|
|
73
|
+
c = self.categorize_entries entries
|
|
74
|
+
c[:downloaded] = c[:downloaded].map { |e| Entry.new e.title.colorize(ALREADY_DOWNLOADED_COLOR), e.link }
|
|
75
|
+
c[:new] = c[:new].map { |e| Entry.new e.title.colorize(NEW_COLOR), e.link }
|
|
76
|
+
c
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.categorize_entries(entries)
|
|
80
|
+
result = { downloaded: [], new: [], version: [], other: [] }
|
|
81
|
+
dls = NyaaAnime.downloaded_entries
|
|
82
|
+
downloaded_titles = dls.map { |e| e.title }
|
|
83
|
+
downloaded_distro_metas = dls.map { |e| e.distro_meta }
|
|
84
|
+
downloaded_distro_metas.uniq!
|
|
85
|
+
downloaded_distro_episodes = dls.map { |e| e.distro_episode }
|
|
86
|
+
downloaded_distro_episodes.uniq!
|
|
87
|
+
entries.each do |e|
|
|
88
|
+
if downloaded_titles.include? "#{e.title}.torrent"
|
|
89
|
+
result[:downloaded].push e
|
|
90
|
+
elsif downloaded_distro_episodes.include? e.distro_episode
|
|
91
|
+
result[:version].push e
|
|
92
|
+
elsif downloaded_distro_metas.include? e.distro_meta
|
|
93
|
+
result[:new].push e
|
|
113
94
|
else
|
|
114
|
-
|
|
95
|
+
result[:other].push e
|
|
115
96
|
end
|
|
116
97
|
end
|
|
117
|
-
|
|
98
|
+
result
|
|
118
99
|
end
|
|
119
100
|
|
|
120
|
-
def self.
|
|
121
|
-
|
|
101
|
+
def self.downloaded_entries
|
|
102
|
+
Dir["#{NYAA_DL_DIR}*"].select { |f| File.file? f }.map { |f| Entry.new File.basename(f) }
|
|
122
103
|
end
|
|
123
104
|
|
|
124
|
-
def self.
|
|
125
|
-
torrent.gsub("_", " ").sub(/(\s*\[\w{8,}\])?(\.\w+)*\z/, "")
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def self.episode_of_title(torrent)
|
|
129
|
-
ep = NyaaAnime.hashless_title(torrent)[/\s+-\s+(\d+(\.\d+)?(v\d+)?-?)+\s*/, 1]
|
|
130
|
-
if ep.nil?
|
|
131
|
-
ep = NyaaAnime.hashless_title(torrent)[/\s+(\d+(\.\d+)?(v\d+)?-?)+\s*/, 1]
|
|
132
|
-
end
|
|
133
|
-
unless ep.nil?
|
|
134
|
-
ep.split("-").map { |e| e[/0*(\d+)/, 1] }
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def self.distro_of_title(torrent)
|
|
139
|
-
distro = NyaaAnime.hashless_title(torrent).sub!(/\s+-\s+(\d+(\.\d+)?(v\d+)?-?)+\s*/, " ")
|
|
140
|
-
if distro
|
|
141
|
-
distro
|
|
142
|
-
else
|
|
143
|
-
NyaaAnime.hashless_title(torrent).sub(/\s+(\d+(\.\d+)?(v\d+)?-?)+\s*/, " ")
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def self.downloaded_torrents
|
|
148
|
-
Dir["#{NYAA_DL_DIR}*"].select { |f| File.file? f }.map { |f| File.basename f }
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def self.stripped_downloaded_titles
|
|
152
|
-
dls = Set.new
|
|
153
|
-
NyaaAnime.downloaded_torrents.each { |t| dls.add NyaaAnime.stripped_title(t) }
|
|
154
|
-
dls
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def self.distros_of_downloaded_titles
|
|
158
|
-
dls = Set.new
|
|
159
|
-
NyaaAnime.downloaded_torrents.each { |t| dls.add NyaaAnime.distro_of_title(t) }
|
|
160
|
-
dls
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def self.torrents_by_distro(torrents)
|
|
105
|
+
def self.entries_by_distro(entries)
|
|
164
106
|
dls = {}
|
|
165
|
-
|
|
107
|
+
entries.each { |e| (dls[e.distro_meta] ||= []) << e }
|
|
166
108
|
dls
|
|
167
109
|
end
|
|
168
110
|
|
|
169
|
-
def self.
|
|
170
|
-
NyaaAnime.
|
|
111
|
+
def self.downloaded_entries_by_distro
|
|
112
|
+
NyaaAnime.entries_by_distro NyaaAnime.downloaded_entries
|
|
171
113
|
end
|
|
172
114
|
|
|
173
|
-
def download_single(
|
|
174
|
-
torrent = open
|
|
175
|
-
|
|
115
|
+
def self.download_single(entry)
|
|
116
|
+
torrent = open entry.link
|
|
117
|
+
if redir = torrent.meta["refresh"]
|
|
118
|
+
torrent = open redir[/url=(.+)\z/, 1]
|
|
119
|
+
end
|
|
120
|
+
filename = "#{entry.title.uncolorize}.torrent"
|
|
121
|
+
#filename = torrent.meta["content-disposition"][/filename="(.+\.torrent)"/, 1]
|
|
176
122
|
open("#{NYAA_DL_DIR}#{filename}", "w") { |f| f.write torrent.read }
|
|
177
|
-
"#{NYAA_DL_DIR}\"#{
|
|
123
|
+
"#{NYAA_DL_DIR}\"#{filename}\""
|
|
178
124
|
end
|
|
179
125
|
|
|
180
|
-
def download(
|
|
181
|
-
if
|
|
182
|
-
Parallel.map(
|
|
126
|
+
def self.download(entries)
|
|
127
|
+
if entries.is_a? Array
|
|
128
|
+
Parallel.map(entries) { |e| self.download_single e }.sort!
|
|
183
129
|
else
|
|
184
|
-
download_single
|
|
130
|
+
self.download_single entries
|
|
185
131
|
end
|
|
186
132
|
end
|
|
187
133
|
|
|
188
|
-
def download_all
|
|
189
|
-
download @titles
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def download_all_new
|
|
193
|
-
download @new_titles
|
|
194
|
-
end
|
|
195
|
-
|
|
196
134
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nyaa_anime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.2
|
|
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:
|
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: parallel
|
|
@@ -162,6 +162,7 @@ files:
|
|
|
162
162
|
- bin/nyaa-get
|
|
163
163
|
- bin/nyaa_anime
|
|
164
164
|
- lib/nyaa_anime.rb
|
|
165
|
+
- lib/nyaa_anime/entry.rb
|
|
165
166
|
- lib/nyaa_anime/list.rb
|
|
166
167
|
- lib/nyaa_anime/main.rb
|
|
167
168
|
- lib/nyaa_anime/remove.rb
|
|
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
188
189
|
version: '0'
|
|
189
190
|
requirements: []
|
|
190
191
|
rubyforge_project:
|
|
191
|
-
rubygems_version: 2.4.
|
|
192
|
+
rubygems_version: 2.4.5
|
|
192
193
|
signing_key:
|
|
193
194
|
specification_version: 4
|
|
194
195
|
summary: the painless NyaaTorrents anime command-line tool
|