nyaa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/LICENSE +7 -0
- data/README.md +4 -0
- data/bin/nyaa +48 -0
- data/lib/nyaa.rb +185 -0
- data/lib/nyaa/version.rb +3 -0
- data/nyaa.gemspec +21 -0
- metadata +117 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2012 David Palma
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/bin/nyaa
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'nyaa'
|
4
|
+
|
5
|
+
opts = Trollop::options do
|
6
|
+
version "nyaa v0.1.0 (c) 2012 David Palma http://github.com/mistofvongola"
|
7
|
+
banner <<-EOM
|
8
|
+
The nyaa gem is a simple CLI browser for NyaaTorrents.
|
9
|
+
Usage:
|
10
|
+
nyaa [options] "my search"
|
11
|
+
|
12
|
+
Categories:
|
13
|
+
anime_all, anime_raw, anime_english, anime_nonenglish, anime_music_video
|
14
|
+
books_all, books_raw, books_english, books_nonenglish
|
15
|
+
audio_all, audio_lossless, audio_lossy
|
16
|
+
pictures_all, pictures_photos, pictures_graphics,
|
17
|
+
live_all, live_raw, live_english, live_nonenglish, live_promo
|
18
|
+
software_all, software_apps, software_games
|
19
|
+
|
20
|
+
Filters:
|
21
|
+
show_all, filter_remakes, trusted_only, aplus_only
|
22
|
+
|
23
|
+
Options:
|
24
|
+
EOM
|
25
|
+
opt :category, "Select a category to search in. See below for valid options.", :default => 'anime_english'
|
26
|
+
opt :filter, "Select a filter for your search. See below for valid options.", :default => 'show_all'
|
27
|
+
opt :outdir, "Select the download directory.", :default => File.expand_path('~/Downloads')
|
28
|
+
opt :size, "Show <i> results at a time. Must be between 1 and 100.", :type => :int, :default => 4
|
29
|
+
opt :page, "Start by showing the <i>th result page.", :type => :int, :default => 1
|
30
|
+
opt :version, "Print the version and exit."
|
31
|
+
opt :help, "Show this information and exit."
|
32
|
+
end
|
33
|
+
|
34
|
+
unless Nyaa::CATS.has_key?(opts[:category])
|
35
|
+
Trollop::die :category, "is not a valid category"
|
36
|
+
end
|
37
|
+
unless Nyaa::FILS.has_key?(opts[:filter])
|
38
|
+
Trollop::die :filter, "is not a valid filter"
|
39
|
+
end
|
40
|
+
query = ARGV.join(' ')
|
41
|
+
|
42
|
+
begin
|
43
|
+
n = Nyaa.new query, opts
|
44
|
+
n.search
|
45
|
+
rescue Interrupt
|
46
|
+
puts "\nInterrupt received. Exiting."
|
47
|
+
exit
|
48
|
+
end
|
data/lib/nyaa.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'trollop'
|
6
|
+
require 'formatador'
|
7
|
+
|
8
|
+
class Nyaa
|
9
|
+
BASE_URL = 'http://www.nyaa.eu/?page=torrents'
|
10
|
+
PSIZE = 100
|
11
|
+
CATS = {
|
12
|
+
'anime_all' => '1_0',
|
13
|
+
'anime_raw' => '1_11',
|
14
|
+
'anime_english' => '1_37',
|
15
|
+
'anime_nonenglish' => '1_38',
|
16
|
+
'anime_music_video' => '1_32',
|
17
|
+
'books_all' => '2_0',
|
18
|
+
'books_raw' => '2_13',
|
19
|
+
'books_english' => '2_12',
|
20
|
+
'books_nonenglish' => '2_39',
|
21
|
+
'audio_all' => '3_0',
|
22
|
+
'audio_lossless' => '3_14',
|
23
|
+
'audio_lossy' => '3_15',
|
24
|
+
'pictures_all' => '4_0',
|
25
|
+
'pictures_photos' => '4_17',
|
26
|
+
'pictures_graphics' => '4_18',
|
27
|
+
'live_all' => '5_0',
|
28
|
+
'live_raw' => '5_20',
|
29
|
+
'live_english' => '5_19',
|
30
|
+
'live_nonenglish' => '5_21',
|
31
|
+
'live_promo' => '5_22',
|
32
|
+
'software_all' => '6_0',
|
33
|
+
'software_apps' => '6_23',
|
34
|
+
'software_games' => '6_24',
|
35
|
+
}
|
36
|
+
FILS = {
|
37
|
+
'show_all' => '0',
|
38
|
+
'filter_remakes' => '1',
|
39
|
+
'trusted_only' => '2',
|
40
|
+
'aplus_only' => '3',
|
41
|
+
}
|
42
|
+
|
43
|
+
def initialize(query, opts)
|
44
|
+
@query = query
|
45
|
+
@opts = opts
|
46
|
+
@opts[:size] = PSIZE if opts[:size] > PSIZE
|
47
|
+
@opts[:size] = 1 if opts[:size] <= 1
|
48
|
+
@marker = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
def search
|
52
|
+
data = harvest(@query, @opts[:page])
|
53
|
+
part = partition(data, 0, @opts[:size])
|
54
|
+
display(data, part)
|
55
|
+
end
|
56
|
+
|
57
|
+
def harvest(query, page)
|
58
|
+
url = "#{BASE_URL}"
|
59
|
+
url << "&cats=#{CATS[@opts[:category]]}" if @opts[:category]
|
60
|
+
url << "&filter=#{FILS[@opts[:filter]]}" if @opts[:filter]
|
61
|
+
url << "&offset=#{page}" if @opts[:page]
|
62
|
+
url << "&term=#{query}" unless @query.empty?
|
63
|
+
doc = Nokogiri::HTML(RestClient.get(url))
|
64
|
+
items = []
|
65
|
+
rows = doc.css('div#main div.content table.tlist tr.tlistrow')
|
66
|
+
#puts "DEBUG: Row: #{rows[0].to_s}"
|
67
|
+
rows.each do |row|
|
68
|
+
items << {
|
69
|
+
:cat => row.css('td.tlisticon').at('a')['title'],
|
70
|
+
:name => row.css('td.tlistname').at('a').text.strip,
|
71
|
+
:dl => row.css('td.tlistdownload').at('a')['href'],
|
72
|
+
:size => row.css('td.tlistsize').text,
|
73
|
+
:se => row.css('td.tlistsn').text,
|
74
|
+
:le => row.css('td.tlistln').text,
|
75
|
+
:dls => row.css('td.tlistdn').text,
|
76
|
+
:msg => row.css('td.tlistmn').text,
|
77
|
+
# TODO: The status hashkey is broken
|
78
|
+
:status =>
|
79
|
+
if row.at('tr.trusted')
|
80
|
+
'trusted'
|
81
|
+
elsif row.at('tr.remake')
|
82
|
+
'remake'
|
83
|
+
elsif row.at('tr.aplus')
|
84
|
+
'aplus'
|
85
|
+
else
|
86
|
+
'normal'
|
87
|
+
end
|
88
|
+
}
|
89
|
+
end
|
90
|
+
items
|
91
|
+
end
|
92
|
+
|
93
|
+
def partition(ary, start, size)
|
94
|
+
start = 0 if start < 0
|
95
|
+
# update marker
|
96
|
+
@marker = start
|
97
|
+
size = PSIZE if size > PSIZE
|
98
|
+
|
99
|
+
part = ary[start, size]
|
100
|
+
part
|
101
|
+
end
|
102
|
+
|
103
|
+
def display(data, results)
|
104
|
+
f = Formatador.new
|
105
|
+
f.display_line( "\t[yellow]NyaaTorrents >> Browse | Anime, manga, and music[/]\n" )
|
106
|
+
f.display_line( "[bold]#{data[0][:cat]}\n[/]" )
|
107
|
+
|
108
|
+
results.each do |item|
|
109
|
+
case item[:status]
|
110
|
+
when 'aplus'
|
111
|
+
flag = 'blue'
|
112
|
+
when 'trusted'
|
113
|
+
flag = 'green'
|
114
|
+
when 'remake'
|
115
|
+
flag = 'red'
|
116
|
+
else
|
117
|
+
flag = 'normal'
|
118
|
+
end
|
119
|
+
f.display_line( "[#{flag}]#{data.index(item)+1}. #{item[:name]}[/]")
|
120
|
+
|
121
|
+
f.indent {
|
122
|
+
f.display_line( "[bold]SE: [green]#{item[:se]}[/] [bold]LE: [red]#{item[:le]}[/] [bold]DLs: [yellow]#{item[:dls]}[/] [bold]Msg: [blue]#{item[:msg]}[/]" )
|
123
|
+
f.display_line( "[green]#{item[:dl]}[/]" )
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
start_count = @marker + 1
|
128
|
+
start_count = PSIZE if start_count > PSIZE
|
129
|
+
end_count = @marker + @opts[:size]
|
130
|
+
end_count = PSIZE if end_count > PSIZE
|
131
|
+
|
132
|
+
f.display_line("\n\t[yellow]Displaying results #{start_count} through #{end_count} of #{PSIZE} (Page #{@opts[:page]})\n")
|
133
|
+
|
134
|
+
prompt(data, results)
|
135
|
+
end
|
136
|
+
|
137
|
+
def prompt(data, results)
|
138
|
+
f = Formatador.new
|
139
|
+
f.display_line("[yellow]Help: q to quit, n/p for pagination, or a number to download that choice.")
|
140
|
+
# prompt
|
141
|
+
f.display("[bold]>[/] ")
|
142
|
+
|
143
|
+
# handle input
|
144
|
+
choice = STDIN.gets
|
145
|
+
if choice.nil?
|
146
|
+
choice = ' '
|
147
|
+
else
|
148
|
+
choice.strip
|
149
|
+
end
|
150
|
+
|
151
|
+
case
|
152
|
+
when choice[0] == 'q'
|
153
|
+
exit
|
154
|
+
when choice[0] == 'n'
|
155
|
+
if @marker + @opts[:size] == 100
|
156
|
+
@opts[:page] += 1
|
157
|
+
f.indent { f.display_line("[purple][blink_fast]! Loading more results...[/]") }
|
158
|
+
data = harvest(@query, @opts[:page])
|
159
|
+
@marker = 0
|
160
|
+
part = partition(data, 0, @opts[:size])
|
161
|
+
else
|
162
|
+
part = partition(data, @marker + @opts[:size], @opts[:size])
|
163
|
+
end
|
164
|
+
display(data, part)
|
165
|
+
when choice[0] == 'p'
|
166
|
+
if @marker < 1
|
167
|
+
f.indent { f.display_line("[purple]! Already at page one.[/]") }
|
168
|
+
input(data, results)
|
169
|
+
else
|
170
|
+
part = partition(data, @marker - @opts[:size], @opts[:size])
|
171
|
+
display(data, part)
|
172
|
+
end
|
173
|
+
when choice[0].match(/\d/)
|
174
|
+
/(\d+)(\s*\|(.*))*/.match(choice) do |str|
|
175
|
+
num = str[1].to_i - 1
|
176
|
+
download(data[num][:dl], @opts[:outdir])
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def download(url, output_path)
|
182
|
+
get_cmd = "curl -J -O '#{url}'"
|
183
|
+
`cd #{output_path} && #{get_cmd}`
|
184
|
+
end
|
185
|
+
end
|
data/lib/nyaa/version.rb
ADDED
data/nyaa.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path("../lib/nyaa/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'nyaa'
|
5
|
+
s.version = Nyaa::VERSION
|
6
|
+
s.homepage = 'https://github.com/mistofvongola/nyaa'
|
7
|
+
s.summary = 'The nyaa gem is a CLI to NyaaTorrents.'
|
8
|
+
s.description = 'Browse and download from NyaaTorrents from the command-line. Supports categories and filters.'
|
9
|
+
|
10
|
+
s.authors = ['David Palma']
|
11
|
+
s.email = 'requiem.der.seele@gmail.com'
|
12
|
+
|
13
|
+
s.executables = ['nyaa']
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_path = 'lib'
|
16
|
+
|
17
|
+
s.add_runtime_dependency 'trollop', '>= 1.16.2'
|
18
|
+
s.add_runtime_dependency 'formatador', '>= 0.2.3'
|
19
|
+
s.add_runtime_dependency 'nokogiri', '>= 1.5.5'
|
20
|
+
s.add_runtime_dependency 'rest-client', '>= 1.6.7'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nyaa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Palma
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: trollop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.16.2
|
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: 1.16.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: formatador
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.2.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.2.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.5
|
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.5.5
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rest-client
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.6.7
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.7
|
78
|
+
description: Browse and download from NyaaTorrents from the command-line. Supports
|
79
|
+
categories and filters.
|
80
|
+
email: requiem.der.seele@gmail.com
|
81
|
+
executables:
|
82
|
+
- nyaa
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- bin/nyaa
|
90
|
+
- lib/nyaa.rb
|
91
|
+
- lib/nyaa/version.rb
|
92
|
+
- nyaa.gemspec
|
93
|
+
homepage: https://github.com/mistofvongola/nyaa
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.23
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: The nyaa gem is a CLI to NyaaTorrents.
|
117
|
+
test_files: []
|