sleeproom 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 176b96c36ba23668dfa2b208022214cf61fa3a3d25d206466ebc8f01ceb1e4e2
4
- data.tar.gz: 3bc135a5913ccc38dd81e4f49a8e3c33e8db9986eb282c5a61014725fca3bb0b
3
+ metadata.gz: a8b882f789e21adccfa42fdb69e4c103b6397421b7ba688f2f2465d3ba874be1
4
+ data.tar.gz: 51436fb96ee7f78de6e8e38541a260a5361bd4add38f0896f216728fa6ed3b03
5
5
  SHA512:
6
- metadata.gz: 1a907be22130df26ce7dd9a66c4753e06b31570724d4aaf4e90a62b0c147f6d86d010ce3dae31a7db32ab07600d99dbf302f1efb82473ef94dc6affe84cb3b0d
7
- data.tar.gz: 06d08117b5c8c9c392619ba57c85f658e4fdf1a75902d163ed53e51b77234ef949fa8dd17ebedcc021ee5edfdd334f1193792fc5219ed27cbdb3fdae362f8150
6
+ metadata.gz: c697893e07f46d16341ed3a6008c9b4fe304f7b76c3c8c3c6105a3c3c136d46daeade8530696eed0fe806989bca7e60acac10edb4eeb0e2fcf6e5ad312c60c6f
7
+ data.tar.gz: 0f5f7ae15517f8281ce44e3d8c0536b235436cf44fcfd9833c3f61b60a0cf82dd128788812a7185f4de82c8e3592fb5d11ca65edef58dc8b33b0fe4474e72ee6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sleeproom (0.3.0)
4
+ sleeproom (0.4.0)
5
5
  async (~> 1.26.0)
6
6
  async-http-faraday (~> 0.9.0)
7
7
  async-websocket (~> 0.15.0)
@@ -17,8 +17,6 @@ module SleepRoom
17
17
  SleepRoom::Record::Tasks.status
18
18
  elsif action == "start"
19
19
  SleepRoom::Record::Tasks.start
20
- elsif action == "download"
21
- raise "未实现"
22
20
  elsif action == "exit"
23
21
  SleepRoom::Record::Tasks.stop
24
22
  end
@@ -53,18 +51,21 @@ module SleepRoom
53
51
  SleepRoom::Record::Tasks.add(room[0].to_s, room[1].to_s)
54
52
  end
55
53
 
56
- opt.on("-r", "--remove [URL]", "从监视列表移除") do |room|
54
+ opt.on("-r", "--remove [ROOM]", "从监视列表移除") do |room|
57
55
  SleepRoom::Record::Tasks.remove(room)
58
56
  end
59
57
 
60
- opt.on("-v", "--verbose", "Print log") do
61
- @options[:verbose] = true
58
+ opt.on("-d", "--download [ROOM]", "录制指定房间") do |room|
59
+ raise Error.new("房间名不能为空") if room.nil?
60
+ write_status = SleepRoom::Record::WriteStatus.new
61
+ record = SleepRoom::Record::Showroom.new(room: room, group: "download", queue: write_status)
62
+ record.record
62
63
  end
63
64
 
64
- opt.on("-d", "daemon", "Daemonize the script into the background") do
65
- @options[:daemon] = true
65
+ opt.on("-v", "--verbose", "Print log") do
66
+ @options[:verbose] = true
66
67
  end
67
-
68
+
68
69
  opt.on_tail("--version", "Print version") do
69
70
  STDOUT.puts(opt.version)
70
71
  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
@@ -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...")
@@ -186,7 +190,7 @@ module SleepRoom
186
190
  download_pid: pid
187
191
  })
188
192
  task.async do |t|
189
- while true
193
+ loop do
190
194
  live = API::RoomAPI.new(@room).live?
191
195
  if !SleepRoom.running?(pid) && !live
192
196
  log("Download complete.")
@@ -208,10 +212,10 @@ module SleepRoom
208
212
  log("Live stop.")
209
213
  end
210
214
  t.sleep 120
215
+ rescue Faraday::ConnectionFailed
216
+ log("Network error.")
217
+ retry
211
218
  end
212
- rescue Faraday::ConnectionFailed
213
- log("Network error.")
214
- retry
215
219
  end.wait
216
220
  end
217
221
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SleepRoom
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeproom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
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-14 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize