nyaa 1.0.4 → 1.0.5

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: 9622770089db1b59e44caa99baf401ac01f26886
4
- data.tar.gz: 564720b84300fbbbc007f342cc36ed836aed5e81
3
+ metadata.gz: 5e8be02357f08ca16b78d260bb837ac144cd5dd7
4
+ data.tar.gz: 8e719e1005e106da3bba3c5f43935e324ffdb0d1
5
5
  SHA512:
6
- metadata.gz: 2b3559c0302529a8d6c5f071fa36991bc3e960e07bec51c903b4f2b79a013981c51da6edcf0c3079dfd60fb50339c2838ec4f55aaee753ad90c8c4d36ac7e7d9
7
- data.tar.gz: db3cc7c7e3c56a443737142ee6133fae27b1fe3cd0d2887959fb3f37230cf86e823e7ffde5c5a5b83008d75f141a978bb91170fd8f08703a5e7d0a7635e96001
6
+ metadata.gz: b41ad8e42fabeeea30d142cf60e0d0f8d90efa6d0fa4baedd11d6a724570df7f44cf654f7001e45fe99ca0d64482aea3338c397ca5695935e1f543c0c11de371
7
+ data.tar.gz: 7310f6fc15806f6f37dc54e2e8f9e2edb1fc470c4efe7e1a90df0732d81e066d0f9c2e9cfeedd102a587fd2fa7e7bfcd4ec895b588ad43de6b271ad31024e65d
data/bin/nyaa CHANGED
@@ -5,16 +5,13 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
5
5
  require 'nyaa'
6
6
  include Curses
7
7
 
8
-
9
8
  @opts = Nyaa::CLI.parse(ARGV)
10
- @search = Nyaa::Search.new(@opts[:query], @opts[:category], @opts[:filter])
9
+ @search = Nyaa::Search.new(@opts[:query], @opts[:category], @opts[:filter], @opts[:sort], @opts[:order])
11
10
 
12
11
  def batch_mode
13
12
  results = @search.more.get_results
14
13
  results.each do |r|
15
- puts "o #{r.name}"
16
- puts "#{r.link}"
17
- puts
14
+ puts "#{r.link}\t#{r.name}"
18
15
  end
19
16
  exit
20
17
  end
@@ -33,31 +30,34 @@ if @opts[:batch]
33
30
  batch_mode
34
31
  end
35
32
 
36
- nyaa = Nyaa::UI.new(@opts, @search)
37
- cursor = 1
33
+ nyaa = Nyaa::UI.new(@opts, @search);
34
+ Curses::timeout = 1000;
35
+ cursor = 1;
38
36
 
39
37
  curses_mode do
40
38
  #TODO: Gracefully handle window resizing
41
39
  #Signal.trap('SIGWINCH', nyaa.status("Window size changed!", :failure))
42
- loop do
43
- nyaa.header
44
- nyaa.status
45
- nyaa.footer
46
- nyaa.menu(cursor)
47
- refresh
48
-
49
- case getch
50
- when *[Key::UP,'k'] then cursor = nyaa.move(cursor, -1)
51
- when *[Key::DOWN,'j'] then cursor = nyaa.move(cursor, 1)
52
- when *[Key::NPAGE,'n'] then nyaa.next_page
53
- when *[Key::PPAGE,'p'] then nyaa.prev_page
54
- when *[Key::ENTER,'g'] then nyaa.get(cursor)
55
- when 'i' then nyaa.open(cursor)
56
- when '?' then nyaa.help
57
- when 'q' then @search.purge && break
58
- #when Key::RESIZE then nyaa.status("Window size changed!", :failure)
40
+ begin
41
+ loop do
42
+ nyaa.header
43
+ nyaa.status
44
+ nyaa.footer
45
+ nyaa.menu(cursor)
46
+ refresh
47
+
48
+ case getch
49
+ when *[Key::UP,'k'] then cursor = nyaa.move(cursor, -1)
50
+ when *[Key::DOWN,'j'] then cursor = nyaa.move(cursor, 1)
51
+ when *[Key::NPAGE,'n'] then nyaa.next_page
52
+ when *[Key::PPAGE,'p'] then nyaa.prev_page
53
+ when *[Key::ENTER,'g'] then nyaa.get(cursor)
54
+ when 's' then nyaa.start(cursor);
55
+ when 'i' then nyaa.open(cursor)
56
+ when '?' then nyaa.help
57
+ when 'q' then @search.purge && break
58
+ #when Key::RESIZE then nyaa.status("Window size changed!", :failure)
59
+ end
59
60
  end
60
- end
61
+ rescue Interrupt then end
61
62
  end
62
-
63
63
  exit
@@ -1,50 +1,35 @@
1
- = NYAA
2
-
3
- Nyaa is a command line interface to the nyaa.eu website.
4
-
5
- = COMMANDS
6
-
7
- or k
8
- Scroll up through the list of torrents
9
-
10
- ↓ or j
11
- Scroll down through the list of torrents
12
-
13
- p or PageUp
14
- Skip back a page through the list of torrents
15
-
16
- n or PageDown
17
- Skip forward a page through the list of torrents
18
-
19
- i
20
- Opens the torrent description page in the default web browser.
21
-
22
- g or ENTER
23
- Downloads the torrent into the output directory. This defaults
24
- to the current directory, but can be changed. See `nyaa --help`.
25
-
26
- q
27
- Quits
28
-
29
- ?
30
- Opens this help document
31
-
32
- = VIEW
33
-
34
- The header shows the current category you're browsing (e.g.
35
- "Anime >> English-translated Anime") in addition to:
36
-
37
- * "Size" refers to size of the files in the torrent
38
- * "SE" is the number of seeders
39
- * "LE" is the number of leechers
40
-
41
- In the footer, "view" shows which results are currently being displayed,
42
- and the total results for your search. "recv" shows the number results
43
- currently loaded/fetched. If you page through results too fast, you
44
- might have to wait a second for more results to be fetched. "page" shows
45
- how many pages of results there are.
46
-
47
- You probably also noticed that some torrents are different colors. The
48
- colors correspond to the filters on nyaa.eu. For example, trusted torrents
49
- are green and A+ torrents are blue. These colors depend on your terminal
50
- color settings, so they might different in your terminal.
1
+ NYAA HELP
2
+ =========
3
+
4
+ Keys - Navigation
5
+ -----------------------------------------
6
+ ↑ or k : Move cursor up
7
+ or j : Move cursor down
8
+ p or Page Up : Page up
9
+ n or Page Down : Page down
10
+
11
+ Keys - Actions
12
+ -----------------------------------------
13
+ i : Opens the torrent page in a web browser.
14
+ g or ENTER : Download the torrent to the output directory.
15
+ s : (g)ets the torrent and tries to start it with the installed torrent client.
16
+ q : Quit
17
+ ? : Help screen
18
+
19
+ Interface - View
20
+ -----------------------------------------
21
+ Header
22
+ Size : Torrent size
23
+ SE : Number of seeders
24
+ LE : Number of leechers
25
+
26
+ Torrents
27
+ Blue : A+ status
28
+ Green : Trusted status
29
+ Red : Remake status
30
+ White : Normal status
31
+
32
+ Footer
33
+ view : [displayed results] / total results
34
+ recv : Number fetched (cached) results
35
+ page : Number of pages of results
@@ -19,6 +19,12 @@ module Nyaa
19
19
  @config[:filter] = filter
20
20
  end
21
21
 
22
+ opt.on('-s', '--sort=SORT', 'Sort type for listing') do |sort|
23
+ split = sort.split('_');
24
+ @config[:sort] = Nyaa::SORT.has_key?(split.first.to_sym) ? split.first : 'date'
25
+ @config[:order] = Nyaa::ORDER.has_key?(split.last.to_sym) ? split.last : 'desc'
26
+ end
27
+
22
28
  @config[:output] = Dir.pwd
23
29
  opt.on('-o', '--output-path=PATH', 'Output directory for downloads') do |output|
24
30
  @config[:output] = output
@@ -48,7 +54,14 @@ Categories:
48
54
  all_categories
49
55
 
50
56
  Filters:
51
- show_all, filter_remakes, trusted_only, aplus_only}
57
+ show_all, filter_remakes, trusted_only, aplus_only
58
+
59
+ Sort:
60
+ date, seed, leech, download, size, name
61
+
62
+ Sort Order:
63
+ asc, desc
64
+ Add one of these to the end of Sort as; -s date_asc, -s seed_desc etc.}
52
65
  exit
53
66
  end
54
67
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Nyaa
3
3
 
4
- BASE_URL = 'http://www.nyaa.se/?page=search'
4
+ BASE_URL = 'http://www.nyaa.se/?page=rss'
5
5
 
6
6
  CATS = {
7
7
  :all_categories => {
@@ -120,4 +120,18 @@ module Nyaa
120
120
  :title => 'A+ only'
121
121
  },
122
122
  }
123
+
124
+ SORT = {
125
+ :date => '1',
126
+ :seed => '2',
127
+ :leech => '3',
128
+ :download => '4',
129
+ :size => '5',
130
+ :name => '6'
131
+ }
132
+
133
+ ORDER = {
134
+ :desc => '1',
135
+ :asc => '2'
136
+ }
123
137
  end
@@ -16,10 +16,13 @@ module Nyaa
16
16
 
17
17
  def save
18
18
  unless @fail
19
+ path = self.destination + '/' + filename;
19
20
  File.open("#{self.destination}/#{filename}", 'w') do |f|
20
21
  f.write(self.response.read)
21
22
  end
23
+ return path;
22
24
  end
25
+ return nil;
23
26
  end
24
27
 
25
28
  def failed?
@@ -1,14 +1,18 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Nyaa
3
3
  class Search
4
- attr_accessor :query, :category, :filter
4
+ attr_accessor :query, :category, :filter, :sort, :order
5
5
  attr_accessor :offset, :count, :results
6
6
  attr_accessor :runid, :cachedir
7
7
 
8
- def initialize(query, cat = nil, fil = nil)
8
+ def initialize(query, cat = nil, fil = nil, sort = nil, order = nil)
9
9
  self.query = URI.escape(query)
10
+
10
11
  self.category = cat ? CATS[cat.to_sym][:id] : '0_0'
11
12
  self.filter = fil ? FILS[fil.to_sym][:id] : '0'
13
+ self.sort = sort ? SORT[sort.to_sym] : nil
14
+ self.order = order ? ORDER[order.to_sym] : '2'
15
+
12
16
  self.offset = 0
13
17
  self.results = []
14
18
  self.count = 1.0/0.0
@@ -32,10 +36,8 @@ module Nyaa
32
36
 
33
37
  def more
34
38
  self.offset += 1
35
- if self.results.length < self.count
36
- extract(self.offset)
37
- end
38
- self
39
+ extract(self.offset)
40
+ return self
39
41
  end
40
42
 
41
43
  # TODO: Deprecated function
@@ -94,17 +96,17 @@ module Nyaa
94
96
 
95
97
  def extract(page)
96
98
  raw = fetch(page)
97
- doc = Nokogiri::HTML(raw)
98
- self.count = doc.css('span.notice').text.match(/\d+/).to_s.to_i
99
- rows = doc.css('div#main div.content table.tlist tr.tlistrow')
99
+ doc = Nokogiri::XML(raw)
100
+ rows = doc.xpath("//item");
100
101
  rows.each { |row| self.results << Torrent.new(row) }
102
+ self.count = self.results.count;
101
103
  #dump(page, self.results)
102
104
  #dump_json(page, self.results)
103
105
  end
104
106
 
105
107
  def fetch(page)
106
108
  url = "#{BASE_URL}&offset=#{page}"
107
- url << "&cats=#{self.category}&filter=#{self.filter}"
109
+ url << "&cats=#{self.category}&filter=#{self.filter}" + ( self.sort != nil ? "&sort=#{self.sort}&order=#{self.order}" : "");
108
110
  url << "&term=#{self.query}" unless self.query.empty?
109
111
  open(url).read
110
112
  end
@@ -1,25 +1,30 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require 'time'
2
3
  module Nyaa
3
4
 
4
5
  class Torrent
5
6
  attr_accessor :tid, :name, :info, :link
6
7
  attr_accessor :filesize, :seeders, :leechers
7
- attr_accessor :category, :status, :downloads, :comments
8
+ attr_accessor :category, :status, :downloads, :date
8
9
  attr_accessor :health, :bytes
9
10
 
10
11
  def initialize (row = nil)
11
- self.tid = row.css('td.tlistname').at('a')['href'][/tid=\d+/].gsub(/\D/,'')
12
- self.name = row.css('td.tlistname').at('a').text.strip
13
- self.info = row.css('td.tlistname').at('a')['href']
14
- self.link = row.css('td.tlistdownload').at('a')['href']
15
- self.filesize = row.css('td.tlistsize').text
16
- self.seeders = row.css('td.tlistsn').text.to_i
17
- self.leechers = row.css('td.tlistln').text.to_i
12
+ self.tid = row.at_css("link").text[/tid=\d+/].gsub(/\D/,'')
13
+ self.name = row.at_css("title").text;
14
+ self.info = row.at_css("guid").text;
15
+ self.link = row.at_css("link").text;
18
16
 
19
- self.status = state(row.values[0])
20
- self.category = row.css('td.tlisticon').at('a')['title']
21
- self.downloads = row.css('td.tlistdn').text
22
- self.comments = row.css('td.tlistmn').text
17
+ row.at_css("description").text.match(/(\d+)[^\d]+(\d+)[^\d]+(\d+)[^\d]+([^-]+)-?([^-]+)?/){
18
+ self.seeders = $1.to_i;
19
+ self.leechers = $2.to_i;
20
+ self.downloads = $3.to_i;
21
+ self.filesize = $4.strip;
22
+ filter = $5.nil? ? '' : $5.strip.downcase
23
+ self.status = state(filter)
24
+ }
25
+
26
+ self.category = row.at_css("category").text;
27
+ self.date = Time.parse(row.at_css("pubDate")).localtime;
23
28
  end
24
29
 
25
30
 
@@ -44,10 +49,10 @@ module Nyaa
44
49
 
45
50
  def state(value)
46
51
  case value
47
- when 'trusted tlistrow' then status = 'Trusted'
48
- when 'remake tlistrow' then status = 'Remake'
49
- when 'aplus tlistrow' then status = 'A+'
50
- when 'tlistrow' then status = 'Normal'
52
+ when 'trusted' then status = 'Trusted'
53
+ when 'remake' then status = 'Remake'
54
+ when 'a+' then status = 'A+'
55
+ when '' then status = 'Normal'
51
56
  else status = 'Normal'
52
57
  end
53
58
  status
@@ -21,6 +21,7 @@ module Nyaa
21
21
  @commands = {
22
22
  '?' => 'help',
23
23
  'g' => 'get',
24
+ 's' => 'start',
24
25
  'i' => 'info',
25
26
  'n' => 'next',
26
27
  'p' => 'prev',
@@ -30,6 +31,7 @@ module Nyaa
30
31
  @search = search
31
32
  @torrents = @search.more.results
32
33
  @num_torrents = @torrents.size
34
+ @loading = @torrents.size % 100 == 0 ? true : false;
33
35
  harvester # start bg harvester
34
36
 
35
37
  @menusize = lines - 4 # lines - header + footer + status
@@ -63,8 +65,8 @@ module Nyaa
63
65
 
64
66
  search_summary = sprintf " %-14s %-14s %-14s",
65
67
  "view: [#{@offset+1}-#{@offset+@menusize}]/#{@search.count}",
66
- "recv: #{@num_torrents}/#{@search.count}",
67
- "page: #{@page}/#{@num_pages}"
68
+ "recv: #{@num_torrents}/#{@loading ? "unk" : @search.count}",
69
+ "page: #{@page}/#{@loading ? "unk" : @num_pages}"
68
70
  attrset(color_pair(2))
69
71
  setpos(lines - 2, 0)
70
72
  addstr(sprintf "%-#{cols}s", search_summary)
@@ -93,10 +95,8 @@ module Nyaa
93
95
  setpos(xpos, 0)
94
96
 
95
97
  (0..@menusize-1).each do |i|
98
+
96
99
  if i < @search.count - @offset
97
- if @torrents[@offset + i].nil?
98
- status("Fetching more results, try again.", :failure)
99
- else
100
100
  line_text = sprintf("% -#{@name_column_width}s %9s %9s %9s",
101
101
  truncate("#{@torrents[@offset + i].name}", @name_column_width),
102
102
  @torrents[@offset + i].filesize,
@@ -114,7 +114,6 @@ module Nyaa
114
114
  addstr(line_text)
115
115
  end
116
116
  xpos += 1
117
- end
118
117
  else
119
118
  # blank lines if there's < @menusize of results
120
119
  line_text = " "*cols
@@ -122,6 +121,8 @@ module Nyaa
122
121
  xpos += 1
123
122
  end
124
123
  end
124
+
125
+ status("Fetching more results, try again.", :failure) if @loading && @torrents[@offset + 1].nil?;
125
126
  end
126
127
 
127
128
  def help
@@ -154,17 +155,25 @@ module Nyaa
154
155
  def get(choice)
155
156
  torrent = @torrents[@offset + choice - 1]
156
157
  download = Downloader.new(torrent.link, @config[:output])
157
- download.save
158
+ path = download.save
159
+
158
160
  unless download.failed?
159
161
  status("Downloaded successful: #{torrent.tid}", :success)
160
162
  else
161
163
  status("Download failed (3 attempts): #{torrent.tid}", :failure)
164
+ return nil;
162
165
  end
166
+
167
+ return path;
168
+ end
169
+
170
+ def start(choice)
171
+ path = self.get(choice);
172
+ self.open(path) if path != nil;
163
173
  end
164
174
 
165
175
  def open(choice)
166
- torrent = @torrents[@offset + choice - 1]
167
- link = "#{torrent.info}"
176
+ link = choice.class == Fixnum ? @torrents[@offset + choice - 1].info.to_s : choice;
168
177
  if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ then
169
178
  system("start #{link}")
170
179
  elsif RbConfig::CONFIG['host_os'] =~ /darwin/ then
@@ -177,23 +186,17 @@ module Nyaa
177
186
 
178
187
  def next_page
179
188
  status("Ready.")
180
- unless @page + 1 > @num_pages
189
+ unless @page + 1 > @num_pages && @loading == false
181
190
  @page += 1
182
191
  end
183
-
184
- unless @offset + @menusize > @num_torrents
185
- @offset += @menusize
186
- end
192
+ @offset = (page - 1) * @menusize;
187
193
  end
188
194
 
189
195
  def prev_page
190
196
  unless @page - 1 < 1
191
197
  @page += -1
192
198
  end
193
-
194
- unless @offset == 0
195
- @offset -= @menusize
196
- end
199
+ @offset = (@page - 1) * @menusize;
197
200
  end
198
201
 
199
202
  def resize_handler(cursor)
@@ -204,10 +207,21 @@ module Nyaa
204
207
 
205
208
  def harvester
206
209
  Thread.new do
207
- until @num_torrents == @search.count
210
+ last = @torrents.size;
211
+ loop do
208
212
  @torrents = @search.more.results
209
213
  @num_torrents = @torrents.size
210
- sleep 2
214
+
215
+ if last == @torrents.size then
216
+ @loading = false;
217
+ @num_pages = (@torrents.size / @menusize.to_f).ceil;
218
+ @page = @page > @num_pages ? @num_pages : @page;
219
+ @offset = (@page - 1) * @menusize;
220
+ break;
221
+ end
222
+
223
+ last = @torrents.size;
224
+ sleep(2);
211
225
  end
212
226
  Thread.kill
213
227
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Nyaa
3
3
  NAME = 'nyaa'
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyaa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Palma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.5.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.5
27
27
  description: Browse and download from NyaaTorrents from the command-line. Supports
@@ -32,7 +32,7 @@ executables:
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".gitignore"
35
+ - .gitignore
36
36
  - Gemfile
37
37
  - LICENSE
38
38
  - README.md
@@ -58,12 +58,12 @@ require_paths:
58
58
  - - lib
59
59
  required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []