sleeproom 0.2.0 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +16 -16
- 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 +19 -4
- 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: 6cceff5806149367580bf38a490ac4301887c28390941d68dcbcba58b1e359e3
|
4
|
+
data.tar.gz: add480c7ae186cdf5cc9b8e7c857d1edd127fd25d6f15ace7ed12e60bf5b0c3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ec44e1d44f7637a047b1793bb8df34aed091a6610cc00a4a41bcbed8af55ae28bc54d8462724dbaeab48710264e4cd38b746affaa50a97c304db9e5c6173ffa
|
7
|
+
data.tar.gz: c4d2dfa38c44c479e7a0fd074470e8bf59ea193e719df7f9a4a6cb91678c3efa40ae4965fdc673a0d75fd16dd58ee72c11e412f2e9276e4d79b92bcf909d5812
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
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.4)
|
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/
|
14
14
|
specs:
|
15
|
-
activesupport (6.0.3.
|
15
|
+
activesupport (6.0.3.2)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 0.7, < 2)
|
18
18
|
minitest (~> 5.1)
|
19
19
|
tzinfo (~> 1.1)
|
20
20
|
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
-
ast (2.4.
|
22
|
-
async (1.26.
|
21
|
+
ast (2.4.1)
|
22
|
+
async (1.26.2)
|
23
23
|
console (~> 1.0)
|
24
24
|
nio4r (~> 2.3)
|
25
25
|
timers (~> 4.1)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
concurrent-ruby (1.1.6)
|
46
46
|
configatron (4.5.1)
|
47
47
|
console (1.8.2)
|
48
|
-
diff-lcs (1.
|
48
|
+
diff-lcs (1.4.4)
|
49
49
|
faraday (1.0.1)
|
50
50
|
multipart-post (>= 1.2, < 3)
|
51
51
|
i18n (1.8.3)
|
@@ -54,9 +54,9 @@ GEM
|
|
54
54
|
minitest (5.14.1)
|
55
55
|
multipart-post (2.1.1)
|
56
56
|
nio4r (2.5.2)
|
57
|
-
parallel (1.19.
|
58
|
-
parser (2.7.1.
|
59
|
-
ast (~> 2.4.
|
57
|
+
parallel (1.19.2)
|
58
|
+
parser (2.7.1.4)
|
59
|
+
ast (~> 2.4.1)
|
60
60
|
protocol-hpack (1.4.2)
|
61
61
|
protocol-http (0.20.0)
|
62
62
|
protocol-http1 (0.13.0)
|
@@ -67,7 +67,7 @@ GEM
|
|
67
67
|
protocol-websocket (0.7.4)
|
68
68
|
protocol-http (~> 0.2)
|
69
69
|
protocol-http1 (~> 0.2)
|
70
|
-
rack (2.2.
|
70
|
+
rack (2.2.3)
|
71
71
|
rainbow (3.0.0)
|
72
72
|
rake (12.3.3)
|
73
73
|
rspec (3.9.0)
|
@@ -108,7 +108,7 @@ GEM
|
|
108
108
|
tzinfo (1.2.7)
|
109
109
|
thread_safe (~> 0.1)
|
110
110
|
unicode-display_width (1.6.1)
|
111
|
-
zeitwerk (2.3.
|
111
|
+
zeitwerk (2.3.1)
|
112
112
|
|
113
113
|
PLATFORMS
|
114
114
|
ruby
|
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
|
@@ -149,6 +149,10 @@ module SleepRoom
|
|
149
149
|
@is_live = api.live?
|
150
150
|
@broadcast_host = api.broadcast_host
|
151
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
|
152
156
|
rescue => e
|
153
157
|
SleepRoom.error(e.message)
|
154
158
|
log("[setRoomInfo] Retry...")
|
@@ -159,7 +163,7 @@ module SleepRoom
|
|
159
163
|
api = API::StreamingAPI.new(@room_id)
|
160
164
|
streaming_url_list = api.streaming_url
|
161
165
|
rescue => e
|
162
|
-
SleepRoom.error(e.
|
166
|
+
SleepRoom.error(e.full_message)
|
163
167
|
log("[parseStreamingUrl] Retry...")
|
164
168
|
retry
|
165
169
|
end
|
@@ -186,8 +190,9 @@ module SleepRoom
|
|
186
190
|
download_pid: pid
|
187
191
|
})
|
188
192
|
task.async do |t|
|
189
|
-
|
190
|
-
|
193
|
+
loop do
|
194
|
+
live = API::RoomAPI.new(@room).live?
|
195
|
+
if !SleepRoom.running?(pid) && !live
|
191
196
|
log("Download complete.")
|
192
197
|
@downlaoding = false
|
193
198
|
@queue.add({
|
@@ -198,8 +203,18 @@ module SleepRoom
|
|
198
203
|
status: :complete,
|
199
204
|
})
|
200
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.")
|
201
213
|
end
|
202
|
-
t.sleep
|
214
|
+
t.sleep 120
|
215
|
+
rescue Faraday::ConnectionFailed
|
216
|
+
log("Network error.")
|
217
|
+
retry
|
203
218
|
end
|
204
219
|
end.wait
|
205
220
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-02 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
|