nyaa-transmission 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/nyaa +50 -0
- data/lib/magnet.rb +10 -0
- data/lib/nyaa_scraper.rb +37 -0
- data/lib/nyaa_search.rb +40 -0
- data/lib/providers.rb +51 -0
- data/lib/transmission_client.rb +81 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7652cb46a607367dca0fdb54d14eb089ab2a549967108f89f95b8ad01cb00e55
|
4
|
+
data.tar.gz: f05163fae939be272cc9c01b9fb5e576d22e324bcd887a41b82999abd00cc334
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09f28030eaff509845c5279735317b7a36e6e1ac565d99d9f6f742211251c265af0b27dd5f702379491dcefa4e32f5dfa0e4279fc3a4b9f4ba2b85bf80396583'
|
7
|
+
data.tar.gz: fc3d0f3ada3bc3971de9f1bc0bc61e5476082829c2a8bdbf456aff9f2f6e0c2a6ab2350a7e9ac8e0f1a793d615b5aca140b4745056a416e1a04e0e54d49013a8
|
data/bin/nyaa
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "providers"
|
5
|
+
require "transmission_client"
|
6
|
+
require "optparse"
|
7
|
+
|
8
|
+
options = {
|
9
|
+
:logger => Logger.new(STDOUT),
|
10
|
+
:database => File.expand_path("nyaa.db", ENV["XDG_DATA_HOME"] || "~/.local/share"),
|
11
|
+
:provider => "EraiRaws"
|
12
|
+
}
|
13
|
+
|
14
|
+
# Show banner if there are no arguments
|
15
|
+
if ARGV.empty?
|
16
|
+
ARGV << "-h"
|
17
|
+
end
|
18
|
+
|
19
|
+
optparse = OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage: nyaa [OPTIONS] QUERY"
|
21
|
+
|
22
|
+
opts.on("-d DATABASE", "--database=DATABASE", "The SQLite3 database [default: $HOME/.local/share/nyaa.db]") do |db|
|
23
|
+
options[:database] = File.expand_path db
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-p PROVIDER", "--provider=PROVIDER", "One of: #{Provider.list.join ', '} [default: EraiRaws]") do |provider|
|
27
|
+
options[:provider] = provider
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on_tail("-h", "--help", "Shows this help") do
|
31
|
+
puts opts
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
optparse.parse!
|
38
|
+
|
39
|
+
# Show banner if there is no query
|
40
|
+
if ARGV.length == 0
|
41
|
+
puts optparse
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
anime_series = ARGV
|
46
|
+
transmission_bt = TransmissionClient.new options
|
47
|
+
|
48
|
+
anime_series.each do |series|
|
49
|
+
transmission_bt.add_magnets Kernel.const_get(options[:provider]).search_for(series)
|
50
|
+
end
|
data/lib/magnet.rb
ADDED
data/lib/nyaa_scraper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "open-uri"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
class NyaaScraper
|
6
|
+
attr_accessor :base
|
7
|
+
|
8
|
+
def initialize(search)
|
9
|
+
@search = search
|
10
|
+
self.base = "https://nyaa.si"
|
11
|
+
end
|
12
|
+
|
13
|
+
def uri
|
14
|
+
URI.join self.base, "?#{@search.querystring}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def html
|
18
|
+
uri.read
|
19
|
+
end
|
20
|
+
|
21
|
+
def links
|
22
|
+
Nokogiri::HTML(html)\
|
23
|
+
.css(".torrent-list tr a") \
|
24
|
+
.map { |link| link["href"] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def magnets
|
28
|
+
links.select { |href| href =~ /^magnet/ }
|
29
|
+
end
|
30
|
+
|
31
|
+
def torrents
|
32
|
+
links.select { |href| href =~ /\.torrent$/ } \
|
33
|
+
.map { |href| URI.join self.base, "#{href}" } \
|
34
|
+
.map { |uri| uri.to_s }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/lib/nyaa_search.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
module Nyaa; end
|
4
|
+
|
5
|
+
module Nyaa::Filter
|
6
|
+
NoFilter = "0"
|
7
|
+
NoRemakes = "1"
|
8
|
+
TrustedOnly = "2"
|
9
|
+
end
|
10
|
+
|
11
|
+
module Nyaa::Category
|
12
|
+
AllCategories = "0_0"
|
13
|
+
|
14
|
+
module Anime
|
15
|
+
MusicVideo = "1_1"
|
16
|
+
EnglishTranslated = "1_2"
|
17
|
+
NonEnglishTranslated = "1_3"
|
18
|
+
Raw = "1_4"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class NyaaSearch
|
23
|
+
attr_accessor :filter, :category, :query, :page
|
24
|
+
|
25
|
+
def initialize(args={})
|
26
|
+
self.filter = args[:filter] || Nyaa::Filter::NoFilter
|
27
|
+
self.category = args[:category] || Nyaa::Category::AllCategories
|
28
|
+
self.query = args[:query] || ""
|
29
|
+
self.page = args[:page] || 1
|
30
|
+
end
|
31
|
+
|
32
|
+
def querystring
|
33
|
+
URI.encode_www_form(
|
34
|
+
"f" => self.filter,
|
35
|
+
"c" => self.category,
|
36
|
+
"q" => self.query,
|
37
|
+
"p" => self.page
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
data/lib/providers.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "objspace"
|
2
|
+
require "nyaa_search"
|
3
|
+
require "nyaa_scraper"
|
4
|
+
|
5
|
+
class Provider
|
6
|
+
def self.list
|
7
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class HorribleSubs < Provider
|
12
|
+
def self.search_for(series)
|
13
|
+
search_criteria = NyaaSearch.new(
|
14
|
+
:filter => Nyaa::Filter::TrustedOnly,
|
15
|
+
:category => Nyaa::Category::Anime::EnglishTranslated,
|
16
|
+
:query => "HorribleSubs 1080p -batch #{series}",
|
17
|
+
:page => 1
|
18
|
+
)
|
19
|
+
|
20
|
+
scraper = NyaaScraper.new(search_criteria)
|
21
|
+
return scraper.magnets
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class EraiRaws < Provider
|
26
|
+
def self.search_for(series)
|
27
|
+
search_criteria = NyaaSearch.new(
|
28
|
+
:filter => Nyaa::Filter::TrustedOnly,
|
29
|
+
:category => Nyaa::Category::Anime::EnglishTranslated,
|
30
|
+
:query => "Erai-raws 1080p -\"~\" #{series}",
|
31
|
+
:page => 1
|
32
|
+
)
|
33
|
+
|
34
|
+
scraper = NyaaScraper.new(search_criteria)
|
35
|
+
return scraper.magnets
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Blackjaxx < Provider
|
40
|
+
def self.search_for(series)
|
41
|
+
search_criteria = NyaaSearch.new(
|
42
|
+
:filter => Nyaa::Filter::NoFilter,
|
43
|
+
:category => Nyaa::Category::Anime::EnglishTranslated,
|
44
|
+
:query => "Blackjaxx 1080p -batch #{series}",
|
45
|
+
:page => 1
|
46
|
+
)
|
47
|
+
|
48
|
+
scraper = NyaaScraper.new(search_criteria)
|
49
|
+
return scraper.magnets
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "transmission"
|
2
|
+
require "sqlite3"
|
3
|
+
require "magnet"
|
4
|
+
|
5
|
+
class TransmissionClient
|
6
|
+
def initialize(args={})
|
7
|
+
@host = args[:host] || "localhost"
|
8
|
+
@port = args[:port] || 9091
|
9
|
+
@user = args[:user] || "transmission"
|
10
|
+
@pass = args[:pass] || "transmission"
|
11
|
+
@database = args[:database] || ":memory:"
|
12
|
+
@logger = args[:logger] || Logger.new(IO::NULL)
|
13
|
+
|
14
|
+
@sqlite = SQLite3::Database.new @database
|
15
|
+
@sqlite.execute <<~SQL
|
16
|
+
CREATE TABLE IF NOT EXISTS links (
|
17
|
+
id INTEGER PRIMARY KEY,
|
18
|
+
link TEXT UNIQUE,
|
19
|
+
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
20
|
+
)
|
21
|
+
SQL
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_magnets(magnets)
|
25
|
+
magnets.each do |m|
|
26
|
+
record_link m
|
27
|
+
@logger.info Magnet.name(m)
|
28
|
+
transmission.add_magnet m
|
29
|
+
rescue SQLite3::ConstraintException
|
30
|
+
next
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_torrents(torrents)
|
35
|
+
torrents.each do |t|
|
36
|
+
record_link t
|
37
|
+
@logger.info t
|
38
|
+
transmission.add_torrentfile t
|
39
|
+
rescue SQLite3::ConstraintException
|
40
|
+
next
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def count
|
45
|
+
list_all.length
|
46
|
+
end
|
47
|
+
|
48
|
+
def purge_all
|
49
|
+
transmission.list.each do |t|
|
50
|
+
transmission.delete(t["id"], true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def history
|
55
|
+
sqlite.get_first_value "SELECT COUNT(id) FROM links"
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def transmission
|
61
|
+
@transmission ||= Transmission.new(
|
62
|
+
:host => @host,
|
63
|
+
:port => @port,
|
64
|
+
:user => @user,
|
65
|
+
:pass => @pass
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def sqlite
|
70
|
+
@sqlite
|
71
|
+
end
|
72
|
+
|
73
|
+
def record_link(link)
|
74
|
+
sqlite.execute "INSERT INTO links ( link ) VALUES ( ? )", link
|
75
|
+
end
|
76
|
+
|
77
|
+
def list_all
|
78
|
+
transmission.list
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nyaa-transmission
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anthony Poon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: transmission-ng
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.10
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.10
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sqlite3
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.4'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.4'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '12.3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '12.3'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.11'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.11'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: webmock
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.6'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.6'
|
103
|
+
description:
|
104
|
+
email: marquis.andras@gmail.com
|
105
|
+
executables:
|
106
|
+
- nyaa
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- bin/nyaa
|
111
|
+
- lib/magnet.rb
|
112
|
+
- lib/nyaa_scraper.rb
|
113
|
+
- lib/nyaa_search.rb
|
114
|
+
- lib/providers.rb
|
115
|
+
- lib/transmission_client.rb
|
116
|
+
homepage: https://github.com/destiny-index/nyaa-transmission
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubygems_version: 3.1.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Search and submit anime on NyaaTorrents to Transmission
|
139
|
+
test_files: []
|