nyaa_anime 0.8.2 → 0.9.2

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: 1ba7aa90f66024323a49d1989fdf783419e8bfd3
4
- data.tar.gz: d6e20d46a46a18ef7545e153b38c34ee27884db6
3
+ metadata.gz: 0c4c190239b5baf100c07ba7b8dc5336f63b3dc4
4
+ data.tar.gz: d518e8d14fc44ce129bdd6aa979a088f098059ad
5
5
  SHA512:
6
- metadata.gz: 5771be98e39ffeb8ebf1f2de2a28f6090bff8428fbc7e992195e301193e6870d42cd105e0f230d299d1e6a577cfb9b91de342f142c3372a64d433798a86fff55
7
- data.tar.gz: 97927ef0ff0c716e27d8ae14cf9b99f9814c66d92e0dd602d01961ed8617934d122850893f94e7f441243133878187f6ae15a8418d5b77c9ca117a45d231c72b
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 (a bit outdated)
17
-
18
- Run `$ nyaa` to see the usage text:
19
-
20
- ![Screenshot 2014-10-16 06.39.22.png](https://bitbucket.org/repo/yn7dbo/images/3610502476-Screenshot%202014-10-16%2006.39.22.png)
21
-
22
- For example, try `$ nyaa -m -f ch no game no life`:
23
-
24
- ![Screenshot 2014-10-16 06.44.21.png](https://bitbucket.org/repo/yn7dbo/images/2797464601-Screenshot%202014-10-16%2006.44.21.png)
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
- ![Screenshot 2014-10-16 06.46.11.png](https://bitbucket.org/repo/yn7dbo/images/157798882-Screenshot%202014-10-16%2006.46.11.png)
29
-
30
- The `-n` (`--new`) option makes `nyaa` find new episodes of previously downloaded anime (the torrents in `~/Downloads/nyaa/`):
31
-
32
- ![Screenshot 2014-10-16 06.47.55.png](https://bitbucket.org/repo/yn7dbo/images/2090162283-Screenshot%202014-10-16%2006.47.55.png)
33
-
34
- You can also run `$ nyaa get` which is equivalent to `$ nyaa -na`:
35
-
36
- ![Screenshot 2014-10-16 06.48.33.png](https://bitbucket.org/repo/yn7dbo/images/3719415092-Screenshot%202014-10-16%2006.48.33.png)
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
+ ![Screenshot 2014-10-16 06.39.22.png](https://bitbucket.org/repo/yn7dbo/images/3610502476-Screenshot%202014-10-16%2006.39.22.png)
21
+
22
+ For example, try `$ nyaa -m -f ch no game no life`:
23
+
24
+ ![Screenshot 2014-10-16 06.44.21.png](https://bitbucket.org/repo/yn7dbo/images/2797464601-Screenshot%202014-10-16%2006.44.21.png)
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
+ ![Screenshot 2014-10-16 06.46.11.png](https://bitbucket.org/repo/yn7dbo/images/157798882-Screenshot%202014-10-16%2006.46.11.png)
29
+
30
+ The `-n` (`--new`) option makes `nyaa` find new episodes of previously downloaded anime (the torrents in `~/Downloads/nyaa/`):
31
+
32
+ ![Screenshot 2014-10-16 06.47.55.png](https://bitbucket.org/repo/yn7dbo/images/2090162283-Screenshot%202014-10-16%2006.47.55.png)
33
+
34
+ You can also run `$ nyaa get` which is equivalent to `$ nyaa -na`:
35
+
36
+ ![Screenshot 2014-10-16 06.48.33.png](https://bitbucket.org/repo/yn7dbo/images/3719415092-Screenshot%202014-10-16%2006.48.33.png)
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
@@ -1,6 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- puts "DEPRECATED: Please use `nyaa get` instead. `nyaa-get` will be removed from future releases."
4
-
5
- ARGV[0] = "get"
6
- load "#{File.dirname(__FILE__)}/nyaa_anime"
3
+ puts "DEPRECATED: Please use `nyaa get` instead."
@@ -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
@@ -21,11 +21,11 @@ end
21
21
 
22
22
  require 'nyaa_anime'
23
23
 
24
- dt_ds = NyaaAnime.downloaded_torrents_by_distro
25
- ds = dt_ds.keys.sort!
26
- ds.each_with_index do |distro, idx|
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
- dt_ds[distro].each { |torrent| puts " #{torrent}" }
29
+ entries.each { |entry| puts " #{e.title}" }
30
30
  end
31
31
  end
@@ -31,9 +31,9 @@ end
31
31
  require 'nyaa_anime'
32
32
 
33
33
  TORRENTS_BY_DISTRO = NyaaAnime.downloaded_torrents_by_distro
34
- ds = TORRENTS_BY_DISTRO.keys.sort!
34
+ distros = TORRENTS_BY_DISTRO.keys.sort!
35
35
 
36
- if ds.size == 0
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..ds.size).include? num
60
- delete_distro ds[num-1]
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-#{ds.size}."
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
- ds = TORRENTS_BY_DISTRO.keys.select { |distro| !!distro[/#{term}/i] }
70
- if ds.count == 0
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
- ds.each { |distro| delete_distro distro }
74
+ distros.each { |distro| delete_distro distro }
@@ -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
- titles = nyaa.find_new_titles !!options[:quiet]
87
- if nyaa.downloads.count == 0
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 "#{nyaa.downloads.count} new episode#{"s" if nyaa.downloads.count > 1} found!".colorize(NyaaAnime::NEW_COLOR)
92
- titles.each_with_index { |t, i| puts "#{i+1}: #{t.colorize(NyaaAnime::NEW_COLOR)}" }
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
- results = nyaa.search search_term
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
- results.each_with_index { |t, i| puts "#{i+1}: #{NyaaAnime.hashless_title t}" } unless options[:quiet]
107
+ entries.each_with_index { |entry, i| puts "#{i+1}: #{entry}" } unless options[:quiet]
106
108
  else
107
- results = NyaaAnime.torrents_by_distro results
109
+ entries = NyaaAnime.entries_by_distro(entries).to_a
108
110
  unless options[:quiet]
109
- results.keys.sort!.each_with_index do |ds, i|
110
- if results[ds].count == 1
111
- puts "#{i+1}: #{NyaaAnime.hashless_title ds}"
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
- first_ep = NyaaAnime.episode_of_title(results[ds].first)
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 nyaa.downloads.count == 0
121
+ if entries.count == 0
126
122
  puts "No results for \"#{search_term}\"."
127
123
  exit
128
124
  else
129
- puts "#{nyaa.downloads.count} result#{"s" if nyaa.downloads.count > 1}, #{nyaa.new_titles.count} new."
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 nyaa.download_all
151
+ prompt_to_open NyaaAnime.download entries
156
152
  exit
157
153
  end
158
154
 
159
- if results.count > 1
160
- prompt = "Download (1-#{results.count}, 'a(ll)'" <<
161
- "#{", 'n(ew)'" if nyaa.new_titles.count > 0 && !options[:find_new]}" <<
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] && nyaa.new_titles.count > 0 && !options[:find_new]) ||
162
+ ("new"[/\A#{input}/i] && new_entries.count > 0 && !options[:find_new]) ||
167
163
  "all"[/\A#{input}/i] ||
168
- (1..results.count).include?(input.to_i)
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 nyaa.download_all_new
171
+ prompt_to_open NyaaAnime.download new_entries
176
172
  elsif choice[/\Aa/i]
177
- prompt_to_open nyaa.download_all
173
+ prompt_to_open NyaaAnime.download entries
178
174
  else
179
- torrent = results.is_a?(Array) ? results[choice.to_i-1] : results[results.keys.sort![choice.to_i-1]]
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
- torrent = results.is_a?(Array) ? results.first : results.values.first
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
@@ -1,3 +1,3 @@
1
1
  class NyaaAnime
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.2"
3
3
  end
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
- @downloads = {}
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
- titles.concat results.css('title').map { |t| t.content }
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
- titles.each_with_index { |t, i| @downloads[t] = dl_urls[i] }
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.distros_of_downloaded_titles
55
- new_titles = Set.new
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
- n = NyaaAnime.new
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
- (n.new_titles.any? ? "#{n.new_titles.count} found!".colorize(NEW_COLOR) : "none found.")
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
- @new_titles = new_titles
79
- @downloads = new_downloads
80
- @already_downloaded_titles = Set.new
81
- @version_differing_titles = Set.new
82
- @other_titles = Set.new
83
- @titles = new_titles.to_a.sort!
84
- end
85
-
86
- def colorized_titles
87
- @titles.map do |t|
88
- if @already_downloaded_titles.include? t
89
- t.colorize ALREADY_DOWNLOADED_COLOR
90
- elsif @new_titles.include? t
91
- t.colorize NEW_COLOR
92
- else
93
- t
94
- end
95
- end
96
- end
97
-
98
- def categorize_titles!
99
- @already_downloaded_titles = Set.new
100
- @new_titles = Set.new
101
- @other_titles = Set.new
102
- @version_differing_titles = Set.new
103
- dls = NyaaAnime.downloaded_torrents
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
- @other_titles.add t
95
+ result[:other].push e
115
96
  end
116
97
  end
117
- nil
98
+ result
118
99
  end
119
100
 
120
- def self.stripped_title(torrent)
121
- torrent.gsub("_", " ").sub(/(\s*\[\w*\])*(\.\w+)*\z/, "")
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.hashless_title(torrent)
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
- torrents.each { |t| (dls[NyaaAnime.distro_of_title(t)] ||= []) << t }
107
+ entries.each { |e| (dls[e.distro_meta] ||= []) << e }
166
108
  dls
167
109
  end
168
110
 
169
- def self.downloaded_torrents_by_distro
170
- NyaaAnime.torrents_by_distro NyaaAnime.downloaded_torrents
111
+ def self.downloaded_entries_by_distro
112
+ NyaaAnime.entries_by_distro NyaaAnime.downloaded_entries
171
113
  end
172
114
 
173
- def download_single(title)
174
- torrent = open @downloads[title]
175
- filename = torrent.meta["content-disposition"][/filename="(.+\.torrent)"/, 1]
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}\"#{title}.torrent\""
123
+ "#{NYAA_DL_DIR}\"#{filename}\""
178
124
  end
179
125
 
180
- def download(titles)
181
- if titles.is_a? Array
182
- Parallel.map(titles) { |t| download_single(t) }.sort!
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 titles
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.8.2
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: 2014-10-23 00:00:00.000000000 Z
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.2
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