nyaa 1.0.2 → 1.0.3

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.
data/README.md CHANGED
@@ -37,12 +37,6 @@ For a list of categories and filters, see `nyaa -h`.
37
37
 
38
38
  ![](https://github.com/mistofvongola/nyaa/raw/master/screenshots/v1.0.0_help.png)
39
39
 
40
- ## The old interface
41
-
42
- The old nyaa interface is deprecated, but is still included. You can use the old interface using the `--classic` option.
43
-
44
- ![](https://github.com/mistofvongola/nyaa/raw/master/screenshots/screenshot_1.png)
45
-
46
40
  ## Contributing
47
41
  1. Fork it
48
42
  2. Create your feature branch (`git checkout -b my-new-feature`)
data/bin/nyaa CHANGED
@@ -19,15 +19,6 @@ def batch_mode
19
19
  exit
20
20
  end
21
21
 
22
- def browser_mode
23
- begin
24
- nyaa = Nyaa::Browser.new(@opts, @search)
25
- rescue Interrupt
26
- puts "\nInterrupt received. Exiting."
27
- exit
28
- end
29
- end
30
-
31
22
  def curses_mode
32
23
  begin
33
24
  yield
@@ -42,35 +33,31 @@ if @opts[:batch]
42
33
  batch_mode
43
34
  end
44
35
 
45
- if @opts[:classic] # use old interface
46
- browser_mode
47
- else
48
- nyaa = Nyaa::UI.new(@opts, @search)
49
- cursor = 1
36
+ nyaa = Nyaa::UI.new(@opts, @search)
37
+ cursor = 1
50
38
 
51
- curses_mode do
52
- #TODO: Gracefully handle window resizing
53
- #Signal.trap('SIGWINCH', nyaa.status("Window size changed!", :failure))
54
- loop do
55
- nyaa.header
56
- nyaa.status
57
- nyaa.footer
58
- nyaa.menu(cursor)
59
- refresh
39
+ curses_mode do
40
+ #TODO: Gracefully handle window resizing
41
+ #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
60
48
 
61
- case getch
62
- when Key::UP then cursor = nyaa.move(cursor, -1)
63
- when Key::DOWN then cursor = nyaa.move(cursor, 1)
64
- when 'k' then cursor = nyaa.move(cursor, -1)
65
- when 'j' then cursor = nyaa.move(cursor, 1)
66
- when '?' then nyaa.status('help not implemented!', :failure)
67
- when 'g' then nyaa.get(cursor)
68
- when 'i' then nyaa.open(cursor)
69
- when 'n' then nyaa.next_page
70
- when 'p' then nyaa.prev_page
71
- when 'q' then @search.purge && break
72
- #when Key::RESIZE then nyaa.status("Window size changed!", :failure)
73
- end
49
+ case getch
50
+ when Key::UP then cursor = nyaa.move(cursor, -1)
51
+ when Key::DOWN then cursor = nyaa.move(cursor, 1)
52
+ when 'k' then cursor = nyaa.move(cursor, -1)
53
+ when 'j' then cursor = nyaa.move(cursor, 1)
54
+ when '?' then nyaa.status('help not implemented!', :failure)
55
+ when 'g' then nyaa.get(cursor)
56
+ when 'i' then nyaa.open(cursor)
57
+ when 'n' then nyaa.next_page
58
+ when 'p' then nyaa.prev_page
59
+ when 'q' then @search.purge && break
60
+ #when Key::RESIZE then nyaa.status("Window size changed!", :failure)
74
61
  end
75
62
  end
76
63
  end
@@ -9,8 +9,6 @@ require 'curses'
9
9
  begin
10
10
  require 'rubygems' # for ruby 1.8 compat
11
11
  require 'nokogiri'
12
- require 'rest_client'
13
- require 'formatador'
14
12
  rescue LoadError => e
15
13
  puts "LoadError: #{e.message}"
16
14
  end
@@ -23,6 +21,5 @@ require 'nyaa/torrent'
23
21
  require 'nyaa/search'
24
22
 
25
23
  # internal tools
26
- require 'nyaa/browser' # old ui
27
- require 'nyaa/ui' # new ui
24
+ require 'nyaa/ui'
28
25
  require 'nyaa/downloader'
@@ -28,10 +28,6 @@ module Nyaa
28
28
  @config[:batch] = batch
29
29
  end
30
30
 
31
- opt.on('-t', '--classic', 'Use the old interface (deprecated)') do |classic|
32
- @config[:classic] = classic
33
- end
34
-
35
31
  opt.on('-v', '--version', 'Print version info') do
36
32
  puts "nyaa #{Nyaa::VERSION}"
37
33
  puts "Copyright (c) 2013 David Palma"
@@ -2,7 +2,6 @@
2
2
  module Nyaa
3
3
 
4
4
  BASE_URL = 'http://www.nyaa.eu/?page=search'
5
- PSIZE = 100
6
5
 
7
6
  CATS = {
8
7
  :all_categories => {
@@ -17,7 +17,7 @@ module Nyaa
17
17
  def save
18
18
  unless @fail
19
19
  File.open("#{self.destination}/#{filename}", 'w') do |f|
20
- f.write(self.response.body)
20
+ f.write(self.response.read)
21
21
  end
22
22
  end
23
23
  end
@@ -30,7 +30,7 @@ module Nyaa
30
30
 
31
31
  def request
32
32
  begin
33
- response = RestClient.get(self.target)
33
+ response = open(self.target)
34
34
  rescue StandardError => e
35
35
  if retries > 0
36
36
  retries -= 1
@@ -46,7 +46,7 @@ module Nyaa
46
46
  # Filename from Content Disposition Header Field
47
47
  # http://www.ietf.org/rfc/rfc2183.txt
48
48
  def name_from_disposition
49
- disp = self.response.headers[:content_disposition]
49
+ disp = self.response.meta['content-disposition']
50
50
  disp_filename = disp.split(/;\s+/).select { |v| v =~ /filename\s*=/ }[0]
51
51
  re = /([""'])(?:(?=(\\?))\2.)*?\1/
52
52
  if re.match(disp_filename)
@@ -34,13 +34,11 @@ module Nyaa
34
34
  self.offset += 1
35
35
  if self.results.length < self.count
36
36
  extract(self.offset)
37
- else
38
- self.results = []
39
- puts "No more results"
40
37
  end
41
38
  self
42
39
  end
43
40
 
41
+ # TODO: Deprecated function
44
42
  def cached(page)
45
43
  cachefile = "#{self.cachedir}/cache_#{self.runid}_p#{page}"
46
44
  p cachefile
@@ -63,6 +61,7 @@ module Nyaa
63
61
 
64
62
  private
65
63
 
64
+ # TODO: Deprecated function
66
65
  def dump(page, results)
67
66
  cachefile = "cache_#{self.runid}_p#{page}"
68
67
  File.open("#{self.cachedir}/#{cachefile}", 'wb') do |file|
@@ -99,7 +98,7 @@ module Nyaa
99
98
  self.count = doc.css('span.notice').text.match(/\d+/).to_s.to_i
100
99
  rows = doc.css('div#main div.content table.tlist tr.tlistrow')
101
100
  rows.each { |row| self.results << Torrent.new(row) }
102
- dump(page, self.results)
101
+ #dump(page, self.results)
103
102
  #dump_json(page, self.results)
104
103
  end
105
104
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Nyaa
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
@@ -15,7 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  s.require_path = ['lib']
17
17
 
18
- s.add_runtime_dependency 'formatador', '~> 0.2.3'
19
18
  s.add_runtime_dependency 'nokogiri', '~> 1.5.5'
20
- s.add_runtime_dependency 'rest-client', '~> 1.6.7'
21
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyaa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-17 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: formatador
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 0.2.3
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.2.3
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: nokogiri
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -43,22 +27,6 @@ dependencies:
43
27
  - - ~>
44
28
  - !ruby/object:Gem::Version
45
29
  version: 1.5.5
46
- - !ruby/object:Gem::Dependency
47
- name: rest-client
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 1.6.7
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.6.7
62
30
  description: Browse and download from NyaaTorrents from the command-line. Supports
63
31
  categories and filters.
64
32
  email: david@davidpalma.me
@@ -74,7 +42,6 @@ files:
74
42
  - Rakefile
75
43
  - bin/nyaa
76
44
  - lib/nyaa.rb
77
- - lib/nyaa/browser.rb
78
45
  - lib/nyaa/cli.rb
79
46
  - lib/nyaa/constants.rb
80
47
  - lib/nyaa/downloader.rb
@@ -83,9 +50,6 @@ files:
83
50
  - lib/nyaa/ui.rb
84
51
  - lib/nyaa/version.rb
85
52
  - nyaa.gemspec
86
- - screenshots/screenshot_1.png
87
- - screenshots/screenshot_2.png
88
- - screenshots/screenshot_3.png
89
53
  - screenshots/v1.0.0_browse.png
90
54
  - screenshots/v1.0.0_help.png
91
55
  - screenshots/v1.0.0_search.png
@@ -1,171 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module Nyaa
3
- class Browser
4
- def initialize(opts, search)
5
- @opts = opts
6
- @opts[:size] = 4 if opts[:size].nil?
7
- @opts[:size] = PSIZE if opts[:size] > PSIZE
8
- @opts[:size] = 1 if opts[:size] <= 1
9
- @marker = 0
10
- @format = Formatador.new
11
- @page = 0 # Current browser page
12
- @search = search
13
- start
14
- end
15
-
16
- def start
17
- #@search = Search.new(@opts[:query], @opts[:category], @opts[:filter])
18
- page_results = @search.more.get_results
19
- @page += 1
20
- part = partition(page_results, 0, @opts[:size])
21
- screen(page_results, part)
22
- end
23
-
24
- def partition(ary, start, size)
25
- start = 0 if start < 0
26
- @marker = start
27
- size = PSIZE if size > PSIZE
28
- part = ary[start, size]
29
- part = [] if part.nil?
30
- part
31
- end
32
-
33
- def torrent_info(page_results, torrent)
34
- case torrent.status
35
- when 'A+' then flag = 'blue'
36
- when 'Trusted' then flag = 'green'
37
- when 'Remake' then flag = 'red'
38
- else flag = 'yellow'
39
- end
40
-
41
- @format.display_line("#{page_results.index(torrent)+1}. "\
42
- "#{torrent.name[0..70]}[/]")
43
- @format.indent {
44
- @format.display_line(
45
- "[bold]Size: [purple]#{torrent.filesize}[/] "\
46
- "[bold]SE: [green]#{torrent.seeders}[/] "\
47
- "[bold]LE: [red]#{torrent.leechers}[/] "\
48
- "[bold]DLs: [yellow]#{torrent.downloads}[/] "\
49
- "[bold]Msg: [blue]#{torrent.comments}[/]")
50
- @format.display_line("[bold]DL:[/] [#{flag}]#{torrent.link}[/]")
51
- }
52
- end
53
-
54
- def header_info
55
- @format.display_line( "\t[yellow]NyaaTorrents >> "\
56
- "Browse | Anime, manga, and music[/]\n" )
57
- @format.display_line(
58
- "[bold]#{CATS[@opts[:category].to_sym][:title]}\n[/]" )
59
- end
60
-
61
- def footer_info
62
- start_count = @marker + 1
63
- start_count = PSIZE if start_count > PSIZE
64
- end_count = @marker + @opts[:size]
65
- end_count = PSIZE if end_count > PSIZE
66
-
67
- @format.display_line("\n\t[yellow]Displaying results "\
68
- "#{start_count} through #{end_count} of #{PSIZE} "\
69
- "(Page ##{@page})\n")
70
- end
71
-
72
- def screen(page_results, screen_items)
73
- header_info
74
-
75
- if screen_items.empty?
76
- @format.display_line( "[normal]End of results.")
77
- @format.display_line("For more search options, see --help.[/]\n")
78
- exit
79
- end
80
-
81
- screen_items.each do |torrent|
82
- torrent_info(page_results, torrent)
83
- end
84
-
85
- footer_info
86
- prompt(page_results, screen_items)
87
- end
88
-
89
- def prompt(page_results, screen_items)
90
- @format.display_line("[yellow]Help: q to quit, "\
91
- "h for display help, "\
92
- "n/p for pagination, "\
93
- "or a number to download that choice.")
94
- @format.display("[bold]>[/] ")
95
-
96
- choice = STDIN.gets
97
- if choice.nil?
98
- choice = ' '
99
- else
100
- choice.strip
101
- end
102
-
103
- case
104
- when choice[0] == 'q' then @search.purge && exit
105
- when choice[0] == 'n' then paginate(page_results)
106
- when choice[0] == 'p' then reverse_paginate(page_results, screen_items)
107
- when choice[0].match(/\d/) then retrieve(choice, page_results, screen_items)
108
- when choice[0] == 'h'
109
- @format.display_line("[normal]The color of an entry's DL link "\
110
- "represents its status:[/]")
111
- @format.display_line("[blue]A+[/], [green]Trusted[/], "\
112
- "[yellow]Normal[/], or [red]Remake[/]")
113
- prompt(page_results, screen_items)
114
- else
115
- @format.display_line("[red]Unrecognized option.[/]")
116
- prompt(page_results, screen_items)
117
- end
118
- end
119
-
120
- def paginate(page_results)
121
- if @marker + @opts[:size] == 100
122
- @format.display_line("[yellow]Loading more results...[/]")
123
- if @page == @search.offset
124
- page_results = @search.more.get_results
125
- else # @page < @search.offset
126
- page_results = @search.cached(@page + 1)
127
- end
128
- @page += 1
129
- part = partition(page_results, 0, @opts[:size])
130
- else
131
- part = partition(page_results, @marker + @opts[:size], @opts[:size])
132
- end
133
- screen(page_results, part)
134
- end
135
-
136
- def reverse_paginate(page_results, screen_items)
137
- if @marker < 1
138
- if @page == 1
139
- @format.display_line("[red]Already at page one.[/]")
140
- prompt(page_results, screen_items)
141
- else # @page > 1
142
- @format.display_line("[yellow]Loading results...[/]")
143
- # TODO Bug: This fails with --size 100
144
- # TODO Bug: reverse paginate sometimes only returns p1 cache
145
- page_results = @search.cached(@page - 1)
146
- @page -= 1
147
- part = partition(page_results, PSIZE - @opts[:size], @opts[:size])
148
- screen(page_results, part)
149
- end
150
- else
151
- part = partition(page_results, @marker - @opts[:size], @opts[:size])
152
- screen(page_results, part)
153
- end
154
- end
155
-
156
- def retrieve(choice, page_results, screen_items)
157
- /(\d+)(\s*\|(.*))*/.match(choice) do |str|
158
- num = str[1].to_i - 1
159
- download = Downloader.new(page_results[num].link, @opts[:outdir])
160
- download.save
161
- unless download.failed?
162
- @format.display_line(
163
- "[green]Downloaded '#{download.filename}' successfully.[/]")
164
- else
165
- @format.display_line("[red]Download failed (3 attempts).[/]")
166
- end
167
- prompt(page_results, screen_items)
168
- end
169
- end
170
- end
171
- end
Binary file
Binary file
Binary file