sleeproom 0.2.0 → 0.9.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/Gemfile.lock +57 -23
- data/Rakefile +3 -1
- data/bin/sleeproom +2 -2
- data/lib/sleeproom/async/websocket.rb +8 -6
- data/lib/sleeproom/cli.rb +26 -19
- data/lib/sleeproom/record.rb +8 -5
- data/lib/sleeproom/record/api/api.rb +6 -7
- data/lib/sleeproom/record/api/room.rb +2 -1
- data/lib/sleeproom/record/api/room_api.rb +2 -1
- data/lib/sleeproom/record/api/streaming_api.rb +7 -2
- data/lib/sleeproom/record/record.rb +138 -171
- data/lib/sleeproom/record/tasks.rb +64 -55
- data/lib/sleeproom/record/web/app.rb +53 -0
- data/lib/sleeproom/record/websocket.rb +81 -66
- data/lib/sleeproom/record/write_status.rb +29 -2
- data/lib/sleeproom/utils.rb +73 -16
- data/lib/sleeproom/version.rb +1 -1
- data/sleeproom.gemspec +11 -7
- metadata +88 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1164a0ff4adcb7d05b1a089972e1d895a10a334eb0d42be870a13198efbeec65
|
4
|
+
data.tar.gz: a22e22bc58e4db57da69b233d81026f6449645a4755a93c2353cb40430ab3ad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2999e46c33eaf5eed3fe5687e7815f74fcf0b0b702a9fc25113f10234c4d8e2d54d4023d460e7fb54a1f84a02b266c3d3f27dfb823ec0e16a0db2292ae6e8dad
|
7
|
+
data.tar.gz: 284d500d464e090b83dc7d72a4e1ed1e6db3322095e60f93e079359a0c25a8cef12804b3c9eb3f3a0a7a6fd45aaf32dbd684b03284eacd3317cbb33df367e968
|
data/Gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in sleeproom.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem "rake", "~>
|
8
|
+
gem "rake", "~> 13.0"
|
7
9
|
gem "rspec", "~> 3.0"
|
8
|
-
gem "rubocop", "~> 0.79.0"
|
9
10
|
gem "rubocop-github"
|
10
11
|
gem "rubocop-performance", require: false
|
data/Gemfile.lock
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sleeproom (0.
|
5
|
-
async
|
6
|
-
async-http-faraday
|
7
|
-
async-websocket
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
sleeproom (0.9.0.pre1)
|
5
|
+
async (~> 1.26.0)
|
6
|
+
async-http-faraday (~> 0.9.0)
|
7
|
+
async-websocket (~> 0.15.0)
|
8
|
+
backports (~> 3.0)
|
9
|
+
colorize (~> 0.8.0)
|
10
|
+
configatron (~> 4.5.0)
|
11
|
+
falcon (~> 0.36.0)
|
12
|
+
roda (~> 3.33.0)
|
13
|
+
ruby-next-core (~> 0.9.0)
|
14
|
+
terminal-table (~> 1.8.0)
|
11
15
|
|
12
16
|
GEM
|
13
17
|
remote: https://rubygems.org/
|
14
18
|
specs:
|
15
|
-
activesupport (6.0.3.
|
19
|
+
activesupport (6.0.3.2)
|
16
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
21
|
i18n (>= 0.7, < 2)
|
18
22
|
minitest (~> 5.1)
|
19
23
|
tzinfo (~> 1.1)
|
20
24
|
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
-
ast (2.4.
|
22
|
-
async (1.26.
|
25
|
+
ast (2.4.1)
|
26
|
+
async (1.26.2)
|
23
27
|
console (~> 1.0)
|
24
28
|
nio4r (~> 2.3)
|
25
29
|
timers (~> 4.1)
|
30
|
+
async-container (0.16.6)
|
31
|
+
async (~> 1.0)
|
32
|
+
async-io (~> 1.26)
|
26
33
|
async-http (0.52.4)
|
27
34
|
async (~> 1.25)
|
28
35
|
async-io (~> 1.28)
|
@@ -30,6 +37,8 @@ GEM
|
|
30
37
|
protocol-http (~> 0.20.0)
|
31
38
|
protocol-http1 (~> 0.13.0)
|
32
39
|
protocol-http2 (~> 0.14.0)
|
40
|
+
async-http-cache (0.2.0)
|
41
|
+
async-http (~> 0.51)
|
33
42
|
async-http-faraday (0.9.0)
|
34
43
|
async-http (~> 0.42)
|
35
44
|
faraday
|
@@ -41,22 +50,40 @@ GEM
|
|
41
50
|
async-http (~> 0.51)
|
42
51
|
async-io (~> 1.23)
|
43
52
|
protocol-websocket (~> 0.7.0)
|
53
|
+
backports (3.18.1)
|
54
|
+
build-environment (1.13.0)
|
44
55
|
colorize (0.8.1)
|
45
56
|
concurrent-ruby (1.1.6)
|
46
57
|
configatron (4.5.1)
|
47
58
|
console (1.8.2)
|
48
59
|
diff-lcs (1.3)
|
60
|
+
falcon (0.36.4)
|
61
|
+
async (~> 1.13)
|
62
|
+
async-container (~> 0.16.0)
|
63
|
+
async-http (~> 0.52.0)
|
64
|
+
async-http-cache (~> 0.2.0)
|
65
|
+
async-io (~> 1.22)
|
66
|
+
build-environment (~> 1.13)
|
67
|
+
localhost (~> 1.1)
|
68
|
+
process-metrics (~> 0.2.0)
|
69
|
+
rack (>= 1.0)
|
70
|
+
samovar (~> 2.1)
|
49
71
|
faraday (1.0.1)
|
50
72
|
multipart-post (>= 1.2, < 3)
|
51
73
|
i18n (1.8.3)
|
52
74
|
concurrent-ruby (~> 1.0)
|
53
75
|
jaro_winkler (1.5.4)
|
76
|
+
localhost (1.1.6)
|
77
|
+
mapping (1.1.1)
|
54
78
|
minitest (5.14.1)
|
55
79
|
multipart-post (2.1.1)
|
56
80
|
nio4r (2.5.2)
|
57
|
-
parallel (1.19.
|
58
|
-
parser (2.7.1.
|
59
|
-
ast (~> 2.4.
|
81
|
+
parallel (1.19.2)
|
82
|
+
parser (2.7.1.4)
|
83
|
+
ast (~> 2.4.1)
|
84
|
+
process-metrics (0.2.1)
|
85
|
+
console (~> 1.8)
|
86
|
+
samovar (~> 2.1)
|
60
87
|
protocol-hpack (1.4.2)
|
61
88
|
protocol-http (0.20.0)
|
62
89
|
protocol-http1 (0.13.0)
|
@@ -67,9 +94,12 @@ GEM
|
|
67
94
|
protocol-websocket (0.7.4)
|
68
95
|
protocol-http (~> 0.2)
|
69
96
|
protocol-http1 (~> 0.2)
|
70
|
-
rack (2.2.
|
97
|
+
rack (2.2.3)
|
71
98
|
rainbow (3.0.0)
|
72
|
-
rake (
|
99
|
+
rake (13.0.1)
|
100
|
+
rexml (3.2.4)
|
101
|
+
roda (3.33.0)
|
102
|
+
rack
|
73
103
|
rspec (3.9.0)
|
74
104
|
rspec-core (~> 3.9.0)
|
75
105
|
rspec-expectations (~> 3.9.0)
|
@@ -83,31 +113,36 @@ GEM
|
|
83
113
|
diff-lcs (>= 1.2.0, < 2.0)
|
84
114
|
rspec-support (~> 3.9.0)
|
85
115
|
rspec-support (3.9.3)
|
86
|
-
rubocop (0.
|
116
|
+
rubocop (0.82.0)
|
87
117
|
jaro_winkler (~> 1.5.1)
|
88
118
|
parallel (~> 1.10)
|
89
119
|
parser (>= 2.7.0.1)
|
90
120
|
rainbow (>= 2.2.2, < 4.0)
|
121
|
+
rexml
|
91
122
|
ruby-progressbar (~> 1.7)
|
92
|
-
unicode-display_width (>= 1.4.0, <
|
123
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
93
124
|
rubocop-github (0.16.0)
|
94
125
|
rubocop (<= 0.82.0)
|
95
126
|
rubocop-performance (~> 1.0)
|
96
127
|
rubocop-rails (~> 2.0)
|
97
128
|
rubocop-performance (1.6.1)
|
98
129
|
rubocop (>= 0.71.0)
|
99
|
-
rubocop-rails (2.
|
100
|
-
activesupport
|
130
|
+
rubocop-rails (2.6.0)
|
131
|
+
activesupport (>= 4.2.0)
|
101
132
|
rack (>= 1.1)
|
102
|
-
rubocop (>= 0.
|
133
|
+
rubocop (>= 0.82.0)
|
134
|
+
ruby-next-core (0.9.2)
|
103
135
|
ruby-progressbar (1.10.1)
|
136
|
+
samovar (2.1.4)
|
137
|
+
console (~> 1.0)
|
138
|
+
mapping (~> 1.0)
|
104
139
|
terminal-table (1.8.0)
|
105
140
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
106
141
|
thread_safe (0.3.6)
|
107
142
|
timers (4.3.0)
|
108
143
|
tzinfo (1.2.7)
|
109
144
|
thread_safe (~> 0.1)
|
110
|
-
unicode-display_width (1.
|
145
|
+
unicode-display_width (1.7.0)
|
111
146
|
zeitwerk (2.3.0)
|
112
147
|
|
113
148
|
PLATFORMS
|
@@ -115,9 +150,8 @@ PLATFORMS
|
|
115
150
|
x64-mingw32
|
116
151
|
|
117
152
|
DEPENDENCIES
|
118
|
-
rake (~>
|
153
|
+
rake (~> 13.0)
|
119
154
|
rspec (~> 3.0)
|
120
|
-
rubocop (~> 0.79.0)
|
121
155
|
rubocop-github
|
122
156
|
rubocop-performance
|
123
157
|
sleeproom!
|
data/Rakefile
CHANGED
data/bin/sleeproom
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "async/websocket/connection"
|
2
4
|
class WebSocketConnection < Async::WebSocket::Connection
|
3
5
|
def read
|
@@ -5,16 +7,16 @@ class WebSocketConnection < Async::WebSocket::Connection
|
|
5
7
|
parse(buffer)
|
6
8
|
end
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
def write(object)
|
10
12
|
super(dump(object))
|
11
13
|
end
|
12
|
-
|
14
|
+
|
13
15
|
def parse(buffer)
|
14
|
-
|
16
|
+
buffer
|
15
17
|
end
|
16
|
-
|
18
|
+
|
17
19
|
def dump(object)
|
18
|
-
|
20
|
+
object
|
19
21
|
end
|
20
|
-
end
|
22
|
+
end
|
data/lib/sleeproom/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "backports/2.5" if RUBY_VERSION < "2.5.0"
|
4
|
+
require "ruby-next"
|
3
5
|
require "optparse"
|
4
6
|
require "yaml"
|
5
7
|
require "sleeproom/record"
|
@@ -8,19 +10,19 @@ module SleepRoom
|
|
8
10
|
class CLI
|
9
11
|
# @param argv [Array]
|
10
12
|
def initialize(argv)
|
13
|
+
SleepRoom.reload_config
|
11
14
|
@options = {}
|
12
15
|
build
|
13
|
-
|
16
|
+
if argv.empty? == false
|
14
17
|
@parser.parse!(argv)
|
15
18
|
action = argv.shift
|
16
|
-
|
19
|
+
case action
|
20
|
+
when "status"
|
17
21
|
SleepRoom::Record::Tasks.status
|
18
|
-
|
19
|
-
SleepRoom::Record::Tasks.start
|
20
|
-
|
21
|
-
|
22
|
-
elsif action == "exit"
|
23
|
-
SleepRoom::Record::Tasks.stop
|
22
|
+
when "start"
|
23
|
+
SleepRoom::Record::Tasks.start(**@options)
|
24
|
+
when "lists"
|
25
|
+
SleepRoom::Record::Tasks.lists
|
24
26
|
end
|
25
27
|
exit(0)
|
26
28
|
else
|
@@ -29,22 +31,20 @@ module SleepRoom
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
# @return [void]
|
33
|
-
def run
|
34
|
-
SleepRoom::Record::Tasks.start
|
35
|
-
end
|
36
|
-
|
37
34
|
# @return [void]
|
38
35
|
def build
|
39
36
|
@parser = OptionParser.new do |opt|
|
40
37
|
opt.version = "SleepRoom / #{SleepRoom::VERSION}"
|
41
|
-
opt.banner =
|
38
|
+
opt.banner = opt.version.to_s
|
42
39
|
opt.banner += "\nUsage: sleeproom [Options]\n\n"
|
43
40
|
|
44
41
|
opt.banner += "Action:\n"
|
45
42
|
opt.banner += "status".rjust(10)
|
46
43
|
opt.banner += "显示任务状态".rjust(33)
|
47
44
|
opt.banner += "\n"
|
45
|
+
opt.banner += "list".rjust(8)
|
46
|
+
opt.banner += "显示录制列表".rjust(35)
|
47
|
+
opt.banner += "\n"
|
48
48
|
opt.banner += "exit".rjust(8)
|
49
49
|
opt.banner += "关闭任务队列".rjust(35)
|
50
50
|
opt.banner += "\n\nCommands:\n"
|
@@ -53,16 +53,23 @@ module SleepRoom
|
|
53
53
|
SleepRoom::Record::Tasks.add(room[0].to_s, room[1].to_s)
|
54
54
|
end
|
55
55
|
|
56
|
-
opt.on("-r", "--remove [
|
56
|
+
opt.on("-r", "--remove [ROOM]", "从监视列表移除") do |room|
|
57
57
|
SleepRoom::Record::Tasks.remove(room)
|
58
58
|
end
|
59
59
|
|
60
|
-
opt.on("-
|
61
|
-
|
60
|
+
opt.on("-d", "--download [ROOM]", "录制指定房间") do |room|
|
61
|
+
raise Error, "房间名不能为空" if room.nil?
|
62
|
+
|
63
|
+
room = room.match(%r{https://www.showroom-live.com/(.*)})[1] if room.match?("https://www.showroom-live.com/")
|
64
|
+
write_status = SleepRoom::Record::WriteStatus.new
|
65
|
+
Async do
|
66
|
+
record = SleepRoom::Record::Showroom.new(room: room, group: "download", queue: write_status)
|
67
|
+
record.record
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
|
-
opt.on("-
|
65
|
-
@options[:
|
71
|
+
opt.on("-v", "--verbose", "Print log") do
|
72
|
+
@options[:verbose] = true
|
66
73
|
end
|
67
74
|
|
68
75
|
opt.on_tail("--version", "Print version") do
|
data/lib/sleeproom/record.rb
CHANGED
@@ -8,13 +8,16 @@ require "sleeproom/record/record"
|
|
8
8
|
require "sleeproom/record/tasks"
|
9
9
|
require "sleeproom/record/websocket"
|
10
10
|
require "sleeproom/record/api/api"
|
11
|
+
require "sleeproom/record/web/app"
|
11
12
|
require "async"
|
13
|
+
require "roda"
|
14
|
+
require "rack/handler/falcon"
|
12
15
|
require "shellwords"
|
13
16
|
module SleepRoom
|
14
17
|
module Record
|
15
18
|
# Okite!!!
|
16
19
|
# @param url [String]
|
17
|
-
# @return [
|
20
|
+
# @return [Integer]
|
18
21
|
def self.call_minyami(url:, is_live: true, threads: configatron.minyami.threads, output:, retries: configatron.minyami.retries)
|
19
22
|
command = "minyami -d #{Shellwords.escape(url)}"
|
20
23
|
command += " --retries #{retries.to_i}" if retries
|
@@ -24,23 +27,23 @@ module SleepRoom
|
|
24
27
|
command += " --output #{Shellwords.escape(output)}" if output
|
25
28
|
download_dir_check(output)
|
26
29
|
pid = exec_command(command, output)
|
27
|
-
|
30
|
+
pid
|
28
31
|
end
|
29
32
|
|
30
33
|
# @param command [String]
|
31
|
-
# @return [
|
34
|
+
# @return [Integer]
|
32
35
|
def self.exec_command(command, output)
|
33
36
|
SleepRoom.info("Call command: #{command}")
|
34
37
|
SleepRoom.info("STDOUT: #{output}.out , STDERR: #{output}.err")
|
35
38
|
pid = spawn(command, out: "#{output}.out", err: "#{output}.err")
|
36
39
|
SleepRoom.info("PID: #{pid}")
|
37
40
|
Process.detach(pid)
|
38
|
-
|
41
|
+
pid
|
39
42
|
end
|
40
43
|
|
41
44
|
def self.download_dir_check(output)
|
42
45
|
dir = File.dirname(output)
|
43
|
-
|
46
|
+
unless Dir.exist?(dir)
|
44
47
|
SleepRoom.info("#{dir} does not exist, creating...")
|
45
48
|
SleepRoom.mkdir(dir)
|
46
49
|
end
|
@@ -10,17 +10,16 @@ module SleepRoom
|
|
10
10
|
module Record
|
11
11
|
module API
|
12
12
|
class Error < StandardError; end
|
13
|
-
|
14
|
-
ROOM_API = "https://www.showroom-live.com/api/room/status"
|
15
|
-
STREAMING_API = "https://www.showroom-live.com/api/live/streaming_url"
|
16
|
-
|
13
|
+
class NotFoundError < Error; end
|
17
14
|
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
|
18
15
|
|
19
|
-
def self.get(url)
|
20
|
-
|
21
|
-
http = Faraday.get(url, nil, {"User-Agent": USER_AGENT})
|
16
|
+
def self.get(url, task: Async::Task.current)
|
17
|
+
task.async do
|
18
|
+
http = Faraday.get(url, nil, { "User-Agent": USER_AGENT })
|
22
19
|
if http.status == 200
|
23
20
|
@json = JSON.parse(http.body)
|
21
|
+
elsif http.status == 404
|
22
|
+
raise NotFoundError
|
24
23
|
else
|
25
24
|
raise Error, "HTTP Error: #{http.status}"
|
26
25
|
end
|
@@ -4,11 +4,12 @@ module SleepRoom
|
|
4
4
|
module Record
|
5
5
|
module API
|
6
6
|
class Room
|
7
|
+
ROOM_URL = "https://www.showroom-live.com"
|
7
8
|
def initialize(room_name)
|
8
9
|
@url = ROOM_URL + "/" + room_name
|
9
10
|
end
|
10
11
|
|
11
|
-
def get
|
12
|
+
def get
|
12
13
|
@json = API.get(@url).wait
|
13
14
|
end
|
14
15
|
end
|
@@ -4,13 +4,14 @@ module SleepRoom
|
|
4
4
|
module Record
|
5
5
|
module API
|
6
6
|
class RoomAPI
|
7
|
+
ROOM_API = "https://www.showroom-live.com/api/room/status"
|
7
8
|
def initialize(room_url_key)
|
8
9
|
@url = ROOM_API + "?room_url_key=" + room_url_key
|
9
10
|
@json = nil
|
10
11
|
get
|
11
12
|
end
|
12
13
|
|
13
|
-
def get
|
14
|
+
def get
|
14
15
|
@json = API.get(@url).wait
|
15
16
|
end
|
16
17
|
|
@@ -4,18 +4,23 @@ module SleepRoom
|
|
4
4
|
module Record
|
5
5
|
module API
|
6
6
|
class StreamingAPI
|
7
|
+
STREAMING_API = "https://www.showroom-live.com/api/live/streaming_url"
|
7
8
|
def initialize(room_id)
|
8
9
|
@url = STREAMING_API + "?room_id=" + room_id.to_s + "&ignore_low_stream=1"
|
9
10
|
@json = nil
|
10
11
|
get
|
11
12
|
end
|
12
13
|
|
13
|
-
def get
|
14
|
+
def get
|
14
15
|
@json = API.get(@url).wait
|
15
16
|
end
|
16
17
|
|
17
18
|
def streaming_url
|
18
|
-
@json["streaming_url_list"].
|
19
|
+
if @json["streaming_url_list"].nil?
|
20
|
+
raise Error, "streaming url is null."
|
21
|
+
else
|
22
|
+
@json["streaming_url_list"].min_by { |hash| -hash["quality"] }["url"]
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|