sleeproom 0.1.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/bin/sleeproom +2 -1
- data/lib/sleeproom/cli.rb +13 -8
- data/lib/sleeproom/record/api/api.rb +3 -0
- data/lib/sleeproom/record/api/streaming_api.rb +5 -1
- data/lib/sleeproom/record/record.rb +43 -8
- data/lib/sleeproom/record/websocket.rb +5 -10
- data/lib/sleeproom/utils.rb +36 -10
- data/lib/sleeproom/version.rb +1 -1
- data/sleeproom.gemspec +6 -6
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16490f0f3a48428466310c0a5ab4c89a7395aeeb9c71aaba2679b43894c145db
|
4
|
+
data.tar.gz: e03f35faf54bd848151501bbb0dd14c56ea935647fe7bc1e8b9f00095d665691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 819b5780ed280aefcc693986715e30c014128da80d110fc8abb35a23992efdda1f3344ec9b343a1ce746b29a8bd89cf2f90d1beb3989abf9c3d333b8b8f03d5c
|
7
|
+
data.tar.gz: 90a9e5e52b573c39b8627521b04ac7811067a8a1c6f379d597f7c35fbdb7b94a345980feaf74ef4bd49df793d35f40d6135b9e3984633937517d045d6b32140c
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sleeproom (0.
|
5
|
-
async
|
6
|
-
async-http-faraday
|
7
|
-
async-websocket
|
8
|
-
colorize
|
9
|
-
configatron
|
10
|
-
terminal-table
|
4
|
+
sleeproom (0.4.3)
|
5
|
+
async (~> 1.26.0)
|
6
|
+
async-http-faraday (~> 0.9.0)
|
7
|
+
async-websocket (~> 0.15.0)
|
8
|
+
colorize (~> 0.8.0)
|
9
|
+
configatron (~> 4.5.0)
|
10
|
+
terminal-table (~> 1.8.0)
|
11
11
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
data/bin/sleeproom
CHANGED
data/lib/sleeproom/cli.rb
CHANGED
@@ -8,6 +8,7 @@ module SleepRoom
|
|
8
8
|
class CLI
|
9
9
|
# @param argv [Array]
|
10
10
|
def initialize(argv)
|
11
|
+
SleepRoom.reload_config
|
11
12
|
@options = {}
|
12
13
|
build
|
13
14
|
unless argv.empty?
|
@@ -17,8 +18,6 @@ module SleepRoom
|
|
17
18
|
SleepRoom::Record::Tasks.status
|
18
19
|
elsif action == "start"
|
19
20
|
SleepRoom::Record::Tasks.start
|
20
|
-
elsif action == "download"
|
21
|
-
raise "未实现"
|
22
21
|
elsif action == "exit"
|
23
22
|
SleepRoom::Record::Tasks.stop
|
24
23
|
end
|
@@ -53,18 +52,24 @@ module SleepRoom
|
|
53
52
|
SleepRoom::Record::Tasks.add(room[0].to_s, room[1].to_s)
|
54
53
|
end
|
55
54
|
|
56
|
-
opt.on("-r", "--remove [
|
55
|
+
opt.on("-r", "--remove [ROOM]", "从监视列表移除") do |room|
|
57
56
|
SleepRoom::Record::Tasks.remove(room)
|
58
57
|
end
|
59
58
|
|
60
|
-
opt.on("-
|
61
|
-
|
59
|
+
opt.on("-d", "--download [ROOM]", "录制指定房间") do |room|
|
60
|
+
raise Error.new("房间名不能为空") if room.nil?
|
61
|
+
if room.match?("https://www.showroom-live.com/")
|
62
|
+
room = room.match(/https:\/\/www.showroom-live.com\/(.*)/)[1]
|
63
|
+
end
|
64
|
+
write_status = SleepRoom::Record::WriteStatus.new
|
65
|
+
record = SleepRoom::Record::Showroom.new(room: room, group: "download", queue: write_status)
|
66
|
+
record.record
|
62
67
|
end
|
63
68
|
|
64
|
-
opt.on("-
|
65
|
-
@options[:
|
69
|
+
opt.on("-v", "--verbose", "Print log") do
|
70
|
+
@options[:verbose] = true
|
66
71
|
end
|
67
|
-
|
72
|
+
|
68
73
|
opt.on_tail("--version", "Print version") do
|
69
74
|
STDOUT.puts(opt.version)
|
70
75
|
end
|
@@ -10,6 +10,7 @@ module SleepRoom
|
|
10
10
|
module Record
|
11
11
|
module API
|
12
12
|
class Error < StandardError; end
|
13
|
+
class NotFoundError < Error; end
|
13
14
|
ROOM_URL = "https://www.showroom-live.com"
|
14
15
|
ROOM_API = "https://www.showroom-live.com/api/room/status"
|
15
16
|
STREAMING_API = "https://www.showroom-live.com/api/live/streaming_url"
|
@@ -21,6 +22,8 @@ module SleepRoom
|
|
21
22
|
http = Faraday.get(url, nil, {"User-Agent": USER_AGENT})
|
22
23
|
if http.status == 200
|
23
24
|
@json = JSON.parse(http.body)
|
25
|
+
elsif http.status == 404
|
26
|
+
raise NotFoundError
|
24
27
|
else
|
25
28
|
raise Error, "HTTP Error: #{http.status}"
|
26
29
|
end
|
@@ -15,7 +15,11 @@ module SleepRoom
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def streaming_url
|
18
|
-
@json["streaming_url_list"].
|
18
|
+
if @json["streaming_url_list"].nil?
|
19
|
+
raise Error.new("streaming url is null.")
|
20
|
+
else
|
21
|
+
@json["streaming_url_list"].sort_by{|hash| -hash["quality"]}.first["url"]
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -112,15 +112,27 @@ module SleepRoom
|
|
112
112
|
end
|
113
113
|
|
114
114
|
Async do |task|
|
115
|
+
last_ack = nil
|
116
|
+
last_ping = nil
|
115
117
|
while @running && @downlaoding == false
|
116
|
-
|
117
|
-
if !
|
118
|
+
queue = ws.queue.items
|
119
|
+
if !queue.empty?
|
120
|
+
queue.each do |event|
|
121
|
+
case event[:event]
|
122
|
+
when :ack
|
123
|
+
last_ack = event[:time]
|
124
|
+
when :ping
|
125
|
+
last_ping = event[:ping]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
if !last_ack.nil? && Time.now.to_i - last_ack.to_i > 65
|
118
130
|
ws.running = false
|
119
131
|
@running = false
|
120
132
|
task.stop
|
121
133
|
end
|
122
|
-
waiting_live(
|
123
|
-
task.sleep
|
134
|
+
waiting_live({last_ack: last_ack})
|
135
|
+
task.sleep 1
|
124
136
|
end
|
125
137
|
end
|
126
138
|
task.children.each(&:wait)
|
@@ -131,17 +143,29 @@ module SleepRoom
|
|
131
143
|
end
|
132
144
|
|
133
145
|
def set_room_info
|
134
|
-
api = API::RoomAPI.new(room)
|
146
|
+
api = API::RoomAPI.new(@room)
|
135
147
|
@room_id = api.room_id
|
136
148
|
@room_name = api.room_name
|
137
149
|
@is_live = api.live?
|
138
150
|
@broadcast_host = api.broadcast_host
|
139
151
|
@broadcast_key = api.broadcast_key
|
152
|
+
rescue API::NotFoundError
|
153
|
+
SleepRoom.error("[#{@room}] The room does not exist.")
|
154
|
+
log("Task stopped.")
|
155
|
+
Async::Task.current.stop
|
156
|
+
rescue => e
|
157
|
+
SleepRoom.error(e.message)
|
158
|
+
log("[setRoomInfo] Retry...")
|
159
|
+
retry
|
140
160
|
end
|
141
161
|
|
142
162
|
def parse_streaming_url(task: Async::Task.current)
|
143
163
|
api = API::StreamingAPI.new(@room_id)
|
144
164
|
streaming_url_list = api.streaming_url
|
165
|
+
rescue => e
|
166
|
+
SleepRoom.error(e.full_message)
|
167
|
+
log("[parseStreamingUrl] Retry...")
|
168
|
+
retry
|
145
169
|
end
|
146
170
|
|
147
171
|
def build_output(task: Async::Task.current)
|
@@ -166,8 +190,9 @@ module SleepRoom
|
|
166
190
|
download_pid: pid
|
167
191
|
})
|
168
192
|
task.async do |t|
|
169
|
-
|
170
|
-
|
193
|
+
loop do
|
194
|
+
live = API::RoomAPI.new(@room).live?
|
195
|
+
if !SleepRoom.running?(pid) && !live
|
171
196
|
log("Download complete.")
|
172
197
|
@downlaoding = false
|
173
198
|
@queue.add({
|
@@ -178,8 +203,18 @@ module SleepRoom
|
|
178
203
|
status: :complete,
|
179
204
|
})
|
180
205
|
break
|
206
|
+
elsif live && !SleepRoom.running?(pid)
|
207
|
+
log("Minyami crash.")
|
208
|
+
streaming_url = parse_streaming_url
|
209
|
+
output = build_output
|
210
|
+
pid = SleepRoom::Record.call_minyami(url: streaming_url, output: output)
|
211
|
+
elsif !live && SleepRoom.running?(pid)
|
212
|
+
log("Live stop.")
|
181
213
|
end
|
182
|
-
t.sleep
|
214
|
+
t.sleep 120
|
215
|
+
rescue Faraday::ConnectionFailed
|
216
|
+
log("Network error.")
|
217
|
+
retry
|
183
218
|
end
|
184
219
|
end.wait
|
185
220
|
end
|
@@ -6,12 +6,13 @@ require "json"
|
|
6
6
|
module SleepRoom
|
7
7
|
module Record
|
8
8
|
class WebSocket
|
9
|
+
attr_accessor :queue
|
9
10
|
def initialize(room:, broadcast_key:, url:)
|
10
11
|
@room = room
|
11
12
|
@url = "wss://" + url
|
12
13
|
@broadcast_key = broadcast_key
|
13
14
|
@running = false
|
14
|
-
@
|
15
|
+
@queue = Async::Queue.new
|
15
16
|
end
|
16
17
|
|
17
18
|
def connect(task: Async::Task.current)
|
@@ -23,12 +24,12 @@ module SleepRoom
|
|
23
24
|
connection.write("SUB\t#{@broadcast_key}")
|
24
25
|
connection.flush
|
25
26
|
log("Connect to websocket server.")
|
26
|
-
@
|
27
|
+
@queue.enqueue({event: :connect, time: Time.now})
|
27
28
|
|
28
29
|
ping_task = task.async do |sub|
|
29
30
|
while @running
|
30
31
|
sub.sleep 60
|
31
|
-
@
|
32
|
+
@queue.enqueue({event: :ping, time: Time.now})
|
32
33
|
connection.write("PING\tshowroom")
|
33
34
|
connection.flush
|
34
35
|
end
|
@@ -44,12 +45,10 @@ module SleepRoom
|
|
44
45
|
end
|
45
46
|
|
46
47
|
while message = connection.read
|
47
|
-
@status[:last_update]
|
48
48
|
if message == "ACK\tshowroom"
|
49
|
-
@
|
49
|
+
@queue.enqueue({event: :ack, time: Time.now}) if message == "ACK\tshowroom"
|
50
50
|
end
|
51
51
|
if message.start_with?("MSG")
|
52
|
-
@status[:last_msg] = Time.now
|
53
52
|
begin
|
54
53
|
yield JSON.parse(message.split("\t")[2])
|
55
54
|
rescue => e
|
@@ -79,10 +78,6 @@ module SleepRoom
|
|
79
78
|
@connection.close
|
80
79
|
end
|
81
80
|
|
82
|
-
def status
|
83
|
-
@status
|
84
|
-
end
|
85
|
-
|
86
81
|
def log(str)
|
87
82
|
SleepRoom.info("[#{@room}] #{str}")
|
88
83
|
end
|
data/lib/sleeproom/utils.rb
CHANGED
@@ -4,6 +4,7 @@ require "configatron"
|
|
4
4
|
require "colorize"
|
5
5
|
require "fileutils"
|
6
6
|
require "yaml"
|
7
|
+
require "logger"
|
7
8
|
|
8
9
|
module SleepRoom
|
9
10
|
class Error < StandardError; end
|
@@ -109,12 +110,8 @@ module SleepRoom
|
|
109
110
|
logger: {
|
110
111
|
console: true,
|
111
112
|
file: {
|
112
|
-
use:
|
113
|
+
use: false,
|
113
114
|
path: "#{sleeproom_dir}/log"
|
114
|
-
},
|
115
|
-
websocket: {
|
116
|
-
log: true,
|
117
|
-
ping_log: false
|
118
115
|
}
|
119
116
|
}
|
120
117
|
}
|
@@ -145,7 +142,8 @@ module SleepRoom
|
|
145
142
|
end
|
146
143
|
true
|
147
144
|
rescue Errno::ENOENT => e
|
148
|
-
|
145
|
+
info("Creating configuration...")
|
146
|
+
init_base
|
149
147
|
false
|
150
148
|
end
|
151
149
|
|
@@ -168,7 +166,7 @@ module SleepRoom
|
|
168
166
|
|
169
167
|
def self.running?(pid=nil)
|
170
168
|
pid = SleepRoom.load_config(:pid) if pid.nil?
|
171
|
-
Process.
|
169
|
+
Process.kill(0, pid)
|
172
170
|
true
|
173
171
|
rescue
|
174
172
|
false
|
@@ -197,18 +195,46 @@ module SleepRoom
|
|
197
195
|
# @param string [String]
|
198
196
|
# @return [nil]
|
199
197
|
def self.info(string)
|
200
|
-
|
198
|
+
log(:info, string)
|
201
199
|
end
|
202
200
|
|
203
201
|
# @param string [String]
|
204
202
|
# @return [nil]
|
205
203
|
def self.warning(string)
|
206
|
-
|
204
|
+
log(:warning, string)
|
207
205
|
end
|
208
206
|
|
209
207
|
# @param string [String]
|
210
208
|
# @return [nil]
|
211
209
|
def self.error(string)
|
212
|
-
|
210
|
+
log(:error, string)
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.log(type, log)
|
214
|
+
if configatron.logger.console == true
|
215
|
+
case type
|
216
|
+
when :info
|
217
|
+
puts("[INFO] #{log}".colorize(:white))
|
218
|
+
when :warning
|
219
|
+
warn("[WARN] #{log}".colorize(:yellow))
|
220
|
+
when :error
|
221
|
+
puts("[ERROR] #{log}".colorize(:red))
|
222
|
+
end
|
223
|
+
end
|
224
|
+
file_logger(type, log) if configatron.logger.file.use == true
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.file_logger(type, log)
|
228
|
+
path = configatron.logger.file.path
|
229
|
+
mkdir(File.dirname(path)) unless Dir.exist?(File.dirname(path))
|
230
|
+
logger = Logger.new(path)
|
231
|
+
case type
|
232
|
+
when :info
|
233
|
+
logger.info(log)
|
234
|
+
when :warning
|
235
|
+
logger.warning(log)
|
236
|
+
when :error
|
237
|
+
logger.error(log)
|
238
|
+
end
|
213
239
|
end
|
214
240
|
end
|
data/lib/sleeproom/version.rb
CHANGED
data/sleeproom.gemspec
CHANGED
@@ -25,12 +25,12 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = ["sleeproom"]
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_runtime_dependency("colorize")
|
29
|
-
spec.add_runtime_dependency("async")
|
30
|
-
spec.add_runtime_dependency("async-websocket")
|
31
|
-
spec.add_runtime_dependency("configatron")
|
32
|
-
spec.add_runtime_dependency("async-http-faraday")
|
33
|
-
spec.add_runtime_dependency("terminal-table")
|
28
|
+
spec.add_runtime_dependency("colorize", "~> 0.8.0")
|
29
|
+
spec.add_runtime_dependency("async", "~> 1.26.0")
|
30
|
+
spec.add_runtime_dependency("async-websocket", "~> 0.15.0")
|
31
|
+
spec.add_runtime_dependency("configatron", "~> 4.5.0")
|
32
|
+
spec.add_runtime_dependency("async-http-faraday", "~> 0.9.0")
|
33
|
+
spec.add_runtime_dependency("terminal-table", "~> 1.8.0")
|
34
34
|
|
35
35
|
spec.post_install_message = <<~STR
|
36
36
|
SleepRoom 需要:
|
metadata
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleeproom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: async
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.26.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.26.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: async-websocket
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.15.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.15.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: configatron
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 4.5.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 4.5.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: async-http-faraday
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.9.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.9.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: terminal-table
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.8.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.8.0
|
97
97
|
description:
|
98
98
|
email:
|
99
99
|
- i@wug.moe
|