yamazaki 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/yam +43 -0
- data/lib/yamazaki.rb +25 -0
- data/lib/yamazaki/core.rb +40 -0
- data/lib/yamazaki/database.rb +58 -0
- data/lib/yamazaki/torrent.rb +41 -0
- data/lib/yamazaki/version.rb +17 -0
- data/lib/yamazaki/yamazaki.rb +86 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc22be5bbc6105df490c4d7de42f2611fedb272f1d4dea8edaabd242eb2ffa4a
|
4
|
+
data.tar.gz: 8801122b786c96f1d93242e5d230ed22bb3fed9f714db3bb231b938aea41c9d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0fc54c64f0ad417a56be182832a3852e87ac1f9bd965cde1ae3484bffa6be2e80c14c633575bcfa1adbcdf1300657a34f5ff5862a12744c00bba1f4e493d34e
|
7
|
+
data.tar.gz: e06cabfa91ca2b6ccb0aa7fa9eb27a4b9fd1ea411c88bc4659bc21b6a9313fd8cc4a4ccc604e16b05a5b6090a8cdb8d663f9424d2704fdc57f2a9c7653426cce
|
data/bin/yam
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##
|
3
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
4
|
+
## Version 2, December 2004
|
5
|
+
##
|
6
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
7
|
+
## copies of this license document, and changing it is allowed as long
|
8
|
+
## as the name is changed.
|
9
|
+
##
|
10
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
11
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
##
|
13
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
14
|
+
###
|
15
|
+
|
16
|
+
require 'yamazaki'
|
17
|
+
require 'optparse'
|
18
|
+
require 'colorb'
|
19
|
+
|
20
|
+
WATCH_DIR = File.join ENV['HOME'], '.watch'
|
21
|
+
|
22
|
+
opts = OptionParser.new { |opts|
|
23
|
+
opts.banner = "#{"Yamazaki - Moe doesn't exist in the 3D form!".cyan.bold}\n#{'Usage: yam <command> <arg>'.bold}\nCheck more: `yam -h`"
|
24
|
+
|
25
|
+
opts.on( '-s', '--search KEYWORDS', 'Search with given keywords.' ) do |key|
|
26
|
+
Yamazaki.search(key)
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on( '-h', '--help', 'Display this.' ) do
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on( '-l', '--list [n=5]', 'Show last n episodes.' ) do |n|
|
35
|
+
Yamazaki.list(n.to_i)
|
36
|
+
end
|
37
|
+
}
|
38
|
+
|
39
|
+
if ARGV.any?
|
40
|
+
opts.parse!
|
41
|
+
else
|
42
|
+
puts opts.banner
|
43
|
+
end
|
data/lib/yamazaki.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
##
|
2
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
## Version 2, December 2004
|
4
|
+
##
|
5
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
6
|
+
## copies of this license document, and changing it is allowed as long
|
7
|
+
## as the name is changed.
|
8
|
+
##
|
9
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
10
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
11
|
+
##
|
12
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
|
+
##
|
14
|
+
|
15
|
+
require 'open-uri'
|
16
|
+
require 'rss'
|
17
|
+
require 'colorb'
|
18
|
+
require 'optparse'
|
19
|
+
require 'oj'
|
20
|
+
|
21
|
+
require 'yamazaki/database'
|
22
|
+
require 'yamazaki/torrent'
|
23
|
+
require 'yamazaki/core'
|
24
|
+
require 'yamazaki/yamazaki'
|
25
|
+
require 'yamazaki/version'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
##
|
2
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
## Version 2, December 2004
|
4
|
+
##
|
5
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
6
|
+
## copies of this license document, and changing it is allowed as long
|
7
|
+
## as the name is changed.
|
8
|
+
##
|
9
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
10
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
11
|
+
##
|
12
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
|
+
##
|
14
|
+
|
15
|
+
module Yamazaki
|
16
|
+
module Core
|
17
|
+
LIST = 'http://www.nyaa.si/?page=rss&cats=1_0'.freeze
|
18
|
+
SEARCH = 'http://www.nyaa.si/?page=rss&term='.freeze
|
19
|
+
|
20
|
+
def list(n = nil)
|
21
|
+
[].tap do |items|
|
22
|
+
lrss = RSS::Parser.parse(open(LIST))
|
23
|
+
|
24
|
+
n ||= items.size
|
25
|
+
0.upto(n-1) { |no| items << Torrent.from_rss(lrss.items[no], no) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def search(key)
|
30
|
+
raise ArgumentError, 'Valid keywords were expected.'.freeze if key.to_s.strip.empty?
|
31
|
+
|
32
|
+
[].tap do |items|
|
33
|
+
url = "#{SEARCH}#{key.gsub(' '.freeze, ?+)}"
|
34
|
+
rss = RSS::Parser.parse(open(url))
|
35
|
+
|
36
|
+
0.upto(rss.items.size-1) { |n| items << Torrent.from_rss(rss.items[n], n) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
##
|
2
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
## Version 2, December 2004
|
4
|
+
##
|
5
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
6
|
+
## copies of this license document, and changing it is allowed as long
|
7
|
+
## as the name is changed.
|
8
|
+
##
|
9
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
10
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
11
|
+
##
|
12
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
|
+
##
|
14
|
+
|
15
|
+
module Yamazaki
|
16
|
+
class Database
|
17
|
+
def initialize(track_file, save_on_push = true)
|
18
|
+
@track_file = track_file
|
19
|
+
@save_on_push = save_on_push
|
20
|
+
|
21
|
+
@db = Oj.load(File.read(track_file)) if File.exists?(track_file)
|
22
|
+
@db ||= []
|
23
|
+
@db.sort_by! { |t| t[:filename] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(filename)
|
27
|
+
unless self.include? filename
|
28
|
+
@db << { filename: filename, added_at: Time.now }
|
29
|
+
@db.sort_by! { |t| t[:filename] }
|
30
|
+
save if @save_on_push
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def include?(filename)
|
35
|
+
begin
|
36
|
+
@db.bsearch { |t| t[:filename] >= filename }[:filename] == filename
|
37
|
+
rescue
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def size
|
43
|
+
@db.size
|
44
|
+
end
|
45
|
+
|
46
|
+
def empty?
|
47
|
+
@db.size == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def save
|
53
|
+
File.open(@track_file, ?w) do |f|
|
54
|
+
f.write(Oj.dump(@db))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
##
|
2
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
## Version 2, December 2004
|
4
|
+
##
|
5
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
6
|
+
## copies of this license document, and changing it is allowed as long
|
7
|
+
## as the name is changed.
|
8
|
+
##
|
9
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
10
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
11
|
+
##
|
12
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
|
+
##
|
14
|
+
|
15
|
+
module Yamazaki
|
16
|
+
class Torrent
|
17
|
+
attr_reader :title, :description, :pub_date, :link, :index
|
18
|
+
attr_accessor :filename
|
19
|
+
|
20
|
+
def initialize(title, description, pub_date, link, index = 0, filename="")
|
21
|
+
raise ArgumentError.new("you cannot have a negative index!") if index < 0
|
22
|
+
|
23
|
+
@title = title
|
24
|
+
@description = description
|
25
|
+
@pub_date = pub_date
|
26
|
+
@link = link
|
27
|
+
@index = index
|
28
|
+
@filename = filename
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
"#{(@index + 1).to_s.black.cyan} #{@title.bold} #{@pub_date.strftime('%m/%d/%Y %H:%M'.freeze).color(50)}\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def from_rss(hash, index)
|
37
|
+
Torrent.new(hash.title, hash.description, hash.pubDate, hash.link, index)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
##
|
2
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
## Version 2, December 2004
|
4
|
+
##
|
5
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
6
|
+
## copies of this license document, and changing it is allowed as long
|
7
|
+
## as the name is changed.
|
8
|
+
##
|
9
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
10
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
11
|
+
##
|
12
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
|
+
##
|
14
|
+
|
15
|
+
module Yamazaki
|
16
|
+
VERSION = '0.3.8'
|
17
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
##
|
2
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
## Version 2, December 2004
|
4
|
+
##
|
5
|
+
## Everyone is permitted to copy and distribute verbatim or modified
|
6
|
+
## copies of this license document, and changing it is allowed as long
|
7
|
+
## as the name is changed.
|
8
|
+
##
|
9
|
+
## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
10
|
+
## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
11
|
+
##
|
12
|
+
## 0. You just DO WHAT THE FUCK YOU WANT TO.
|
13
|
+
##
|
14
|
+
|
15
|
+
module Yamazaki
|
16
|
+
class << self
|
17
|
+
include Core
|
18
|
+
|
19
|
+
DEFAULT_WATCH_DIR = File.join ENV['HOME'], '.watch'
|
20
|
+
DEFAULT_TRACK_FILE = File.join ENV['HOME'], '.yam.db'
|
21
|
+
|
22
|
+
def list(n)
|
23
|
+
n = 5 if n.to_i == 0
|
24
|
+
|
25
|
+
items = super(n)
|
26
|
+
|
27
|
+
puts "Last #{n} torrents on Nyaa (#{Time.now.hour}:#{Time.now.min})\n\n".cyan.bold
|
28
|
+
return if items.empty?
|
29
|
+
|
30
|
+
items.each { |item| puts item.to_s }
|
31
|
+
prompt_download items
|
32
|
+
end
|
33
|
+
|
34
|
+
def search(key)
|
35
|
+
items = super(key)
|
36
|
+
return if items.empty?
|
37
|
+
|
38
|
+
items.each { |item| puts "#{item.to_s}\t#{item.description}" }
|
39
|
+
prompt_download items
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_database
|
43
|
+
track_file = defined?(TRACK_FILE) == 'constant'.freeze ? TRACK_FILE : DEFAULT_TRACK_FILE
|
44
|
+
@db = Database.new(track_file)
|
45
|
+
end
|
46
|
+
|
47
|
+
def download_torrent(name, link, force = false)
|
48
|
+
name.gsub! '/'.freeze, '-'.freeze
|
49
|
+
|
50
|
+
watch_dir = defined?(WATCH_DIR) == 'constant'.freeze ? WATCH_DIR : DEFAULT_WATCH_DIR
|
51
|
+
filename = "#{watch_dir}/#{name}.torrent"
|
52
|
+
|
53
|
+
if force != true && torrent_downloaded?(filename)
|
54
|
+
false
|
55
|
+
else
|
56
|
+
download(filename, link)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def torrent_downloaded?(filename)
|
63
|
+
(@db ||= load_database).include?(filename)
|
64
|
+
end
|
65
|
+
|
66
|
+
def download(filename, link)
|
67
|
+
File.open(filename, 'wb'.freeze) do |torrent_file|
|
68
|
+
torrent_file.write(open(link).read)
|
69
|
+
end
|
70
|
+
|
71
|
+
(@db ||= load_database) << filename
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def prompt_download(ary)
|
77
|
+
num = prompt
|
78
|
+
download_torrent(ary[num].title, ary[num].link) if num >= 0 && num <= ary.length
|
79
|
+
end
|
80
|
+
|
81
|
+
def prompt
|
82
|
+
print '>> '.freeze
|
83
|
+
STDIN.gets.to_i - 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yamazaki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hydride0
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
description: Your favourite anime manager
|
56
|
+
email: mail@example.com
|
57
|
+
executables:
|
58
|
+
- yam
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/yam
|
63
|
+
- lib/yamazaki.rb
|
64
|
+
- lib/yamazaki/core.rb
|
65
|
+
- lib/yamazaki/database.rb
|
66
|
+
- lib/yamazaki/torrent.rb
|
67
|
+
- lib/yamazaki/version.rb
|
68
|
+
- lib/yamazaki/yamazaki.rb
|
69
|
+
homepage: https://github.com/hydride0/yamazaki
|
70
|
+
licenses:
|
71
|
+
- WTFPL
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.1.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Moe doesn't exist in the 3D form!
|
92
|
+
test_files: []
|