sleeproom 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0154be3d205feeac7e626a12dce7c76e54253c9731d926e35aab1478e046f5f5
4
+ data.tar.gz: 93ed191055cbe4af6c73890bb50daadef4296857ba1f90f2b924547aefbfa92d
5
+ SHA512:
6
+ metadata.gz: d9d8f2c0ddb0cad2c30c8bb9c3f9719eb9585c1895b0e114f97f11d534c52372925225a9b61dfbb89be05605e6e6637e801ba547417626dfde035b1b7ea94620
7
+ data.tar.gz: 5d1b0e70df00ae7e069f9af9a41c751445d8a9ab24f0223f573ab7e8e61064eb2ab82a91193ebf65c0e94face9e906254928b85335bd72ca6b37621fd2281a76
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.vscode/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # config
15
+ /config/base.yml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ inherit_gem:
3
+ rubocop-github:
4
+ - config/default_edge.yml
@@ -0,0 +1,2 @@
1
+ StringLiterals:
2
+ Enable: False
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sleeproom.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rubocop", "~> 0.79.0"
9
+ gem "rubocop-github"
10
+ gem "rubocop-performance", require: false
@@ -0,0 +1,126 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sleeproom (0.1.1)
5
+ async
6
+ async-http-faraday
7
+ async-websocket
8
+ colorize
9
+ configatron
10
+ terminal-table
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (6.0.3.1)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
+ ast (2.4.0)
22
+ async (1.26.1)
23
+ console (~> 1.0)
24
+ nio4r (~> 2.3)
25
+ timers (~> 4.1)
26
+ async-http (0.52.4)
27
+ async (~> 1.25)
28
+ async-io (~> 1.28)
29
+ async-pool (~> 0.2)
30
+ protocol-http (~> 0.20.0)
31
+ protocol-http1 (~> 0.13.0)
32
+ protocol-http2 (~> 0.14.0)
33
+ async-http-faraday (0.9.0)
34
+ async-http (~> 0.42)
35
+ faraday
36
+ async-io (1.30.0)
37
+ async (~> 1.14)
38
+ async-pool (0.3.2)
39
+ async (~> 1.25)
40
+ async-websocket (0.15.0)
41
+ async-http (~> 0.51)
42
+ async-io (~> 1.23)
43
+ protocol-websocket (~> 0.7.0)
44
+ colorize (0.8.1)
45
+ concurrent-ruby (1.1.6)
46
+ configatron (4.5.1)
47
+ console (1.8.2)
48
+ diff-lcs (1.3)
49
+ faraday (1.0.1)
50
+ multipart-post (>= 1.2, < 3)
51
+ i18n (1.8.3)
52
+ concurrent-ruby (~> 1.0)
53
+ jaro_winkler (1.5.4)
54
+ minitest (5.14.1)
55
+ multipart-post (2.1.1)
56
+ nio4r (2.5.2)
57
+ parallel (1.19.1)
58
+ parser (2.7.1.3)
59
+ ast (~> 2.4.0)
60
+ protocol-hpack (1.4.2)
61
+ protocol-http (0.20.0)
62
+ protocol-http1 (0.13.0)
63
+ protocol-http (~> 0.19)
64
+ protocol-http2 (0.14.0)
65
+ protocol-hpack (~> 1.4)
66
+ protocol-http (~> 0.18)
67
+ protocol-websocket (0.7.4)
68
+ protocol-http (~> 0.2)
69
+ protocol-http1 (~> 0.2)
70
+ rack (2.2.2)
71
+ rainbow (3.0.0)
72
+ rake (12.3.3)
73
+ rspec (3.9.0)
74
+ rspec-core (~> 3.9.0)
75
+ rspec-expectations (~> 3.9.0)
76
+ rspec-mocks (~> 3.9.0)
77
+ rspec-core (3.9.2)
78
+ rspec-support (~> 3.9.3)
79
+ rspec-expectations (3.9.2)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.9.0)
82
+ rspec-mocks (3.9.1)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.9.0)
85
+ rspec-support (3.9.3)
86
+ rubocop (0.79.0)
87
+ jaro_winkler (~> 1.5.1)
88
+ parallel (~> 1.10)
89
+ parser (>= 2.7.0.1)
90
+ rainbow (>= 2.2.2, < 4.0)
91
+ ruby-progressbar (~> 1.7)
92
+ unicode-display_width (>= 1.4.0, < 1.7)
93
+ rubocop-github (0.16.0)
94
+ rubocop (<= 0.82.0)
95
+ rubocop-performance (~> 1.0)
96
+ rubocop-rails (~> 2.0)
97
+ rubocop-performance (1.6.1)
98
+ rubocop (>= 0.71.0)
99
+ rubocop-rails (2.5.2)
100
+ activesupport
101
+ rack (>= 1.1)
102
+ rubocop (>= 0.72.0)
103
+ ruby-progressbar (1.10.1)
104
+ terminal-table (1.8.0)
105
+ unicode-display_width (~> 1.1, >= 1.1.1)
106
+ thread_safe (0.3.6)
107
+ timers (4.3.0)
108
+ tzinfo (1.2.7)
109
+ thread_safe (~> 0.1)
110
+ unicode-display_width (1.6.1)
111
+ zeitwerk (2.3.0)
112
+
113
+ PLATFORMS
114
+ ruby
115
+ x64-mingw32
116
+
117
+ DEPENDENCIES
118
+ rake (~> 12.0)
119
+ rspec (~> 3.0)
120
+ rubocop (~> 0.79.0)
121
+ rubocop-github
122
+ rubocop-performance
123
+ sleeproom!
124
+
125
+ BUNDLED WITH
126
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Koell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # SLEEPROOM
2
+
3
+ ## Installation
4
+ $ gem install sleeproom
5
+
6
+ ## Dependency
7
+ * [Minyami](https://github.com/Last-Order/Minyami)
8
+
9
+ ## Usage
10
+ $ ln -s sleeproom.service /etc/systemd/system/
11
+ $ sudo service sleeproom start
12
+ $ sleeproom status
13
+
14
+ 默认配置文件保存在 ~/.config/sleeproom/base.yml
15
+
16
+ ## TODO
17
+ * [ ] 代理支持
18
+ * [ ] Web GUI
19
+ * [ ] 日志保存
20
+
21
+ ## Service example
22
+ ```
23
+ [Unit]
24
+ Description=SLEEPROOM
25
+ After=network.target
26
+
27
+ [Service]
28
+ Type=simple
29
+ User=root
30
+ WorkingDirectory=[WorkingDirectory]
31
+ ExecStart=[ExecStart]
32
+ TimeoutSec=300
33
+ Restart=always
34
+
35
+ [Install]
36
+ WantedBy=multi-user.target
37
+ ```
38
+
39
+ ## License
40
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sleeproom/cli"
4
+
5
+ cli = SleepRoom::CLI.new(ARGV)
6
+ cli.run
@@ -0,0 +1,20 @@
1
+ require "async/websocket/connection"
2
+ class WebSocketConnection < Async::WebSocket::Connection
3
+ def read
4
+ if buffer = super
5
+ parse(buffer)
6
+ end
7
+ end
8
+
9
+ def write(object)
10
+ super(dump(object))
11
+ end
12
+
13
+ def parse(buffer)
14
+ return buffer
15
+ end
16
+
17
+ def dump(object)
18
+ return object
19
+ end
20
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "yaml"
5
+ require "sleeproom/record"
6
+
7
+ module SleepRoom
8
+ class CLI
9
+ # @param argv [Array]
10
+ def initialize(argv)
11
+ @options = {}
12
+ build
13
+ unless argv.empty?
14
+ @parser.parse!(argv)
15
+ action = argv.shift
16
+ if action == "status"
17
+ SleepRoom::Record::Tasks.status
18
+ elsif action == "start"
19
+ SleepRoom::Record::Tasks.start
20
+ elsif action == "download"
21
+ raise "未实现"
22
+ elsif action == "exit"
23
+ SleepRoom::Record::Tasks.stop
24
+ end
25
+ exit(0)
26
+ else
27
+ puts @parser
28
+ exit(0)
29
+ end
30
+ end
31
+
32
+ # @return [void]
33
+ def run
34
+ SleepRoom::Record::Tasks.start
35
+ end
36
+
37
+ # @return [void]
38
+ def build
39
+ @parser = OptionParser.new do |opt|
40
+ opt.version = "SleepRoom / #{SleepRoom::VERSION}"
41
+ opt.banner = "#{opt.version}"
42
+ opt.banner += "\nUsage: sleeproom [Options]\n\n"
43
+
44
+ opt.banner += "Action:\n"
45
+ opt.banner += "status".rjust(10)
46
+ opt.banner += "显示任务状态".rjust(33)
47
+ opt.banner += "\n"
48
+ opt.banner += "exit".rjust(8)
49
+ opt.banner += "关闭任务队列".rjust(35)
50
+ opt.banner += "\n\nCommands:\n"
51
+
52
+ opt.on("-a ROOM, NAME", "--add ROOM, GROUP", Array, "添加到监视列表") do |room|
53
+ SleepRoom::Record::Tasks.add(room[0].to_s, room[1].to_s)
54
+ end
55
+
56
+ opt.on("-r", "--remove [URL]", "从监视列表移除") do |room|
57
+ SleepRoom::Record::Tasks.remove(room)
58
+ end
59
+
60
+ opt.on("-v", "--verbose", "Print log") do
61
+ @options[:verbose] = true
62
+ end
63
+
64
+ opt.on("-d", "daemon", "Daemonize the script into the background") do
65
+ @options[:daemon] = true
66
+ end
67
+
68
+ opt.on_tail("--version", "Print version") do
69
+ STDOUT.puts(opt.version)
70
+ end
71
+
72
+ opt.on_tail("-h", "--help", "Print help") do
73
+ STDOUT.puts(opt)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "configatron"
5
+ require "sleeproom/utils"
6
+ require "sleeproom/version"
7
+ require "sleeproom/record/record"
8
+ require "sleeproom/record/tasks"
9
+ require "sleeproom/record/websocket"
10
+ require "sleeproom/record/api/api"
11
+ require "async"
12
+ require "shellwords"
13
+ module SleepRoom
14
+ module Record
15
+ # Okite!!!
16
+ # @param url [String]
17
+ # @return [Boolean]
18
+ def self.call_minyami(url:, is_live: true, threads: configatron.minyami.threads, output:, retries: configatron.minyami.retries)
19
+ command = "minyami -d #{Shellwords.escape(url)}"
20
+ command += " --retries #{retries.to_i}" if retries
21
+ command += " --threads #{threads.to_i}" if threads
22
+ command += " --live" if is_live
23
+ output = File.join(configatron.save_path, output)
24
+ command += " --output #{Shellwords.escape(output)}" if output
25
+ download_dir_check(output)
26
+ pid = exec_command(command, output)
27
+ return pid
28
+ end
29
+
30
+ # @param command [String]
31
+ # @return [Boolean]
32
+ def self.exec_command(command, output)
33
+ SleepRoom.info("Call command: #{command}")
34
+ SleepRoom.info("STDOUT: #{output}.out , STDERR: #{output}.err")
35
+ pid = spawn(command, out: "#{output}.out", err: "#{output}.err")
36
+ SleepRoom.info("PID: #{pid}")
37
+ Process.detach(pid)
38
+ return pid
39
+ end
40
+
41
+ def self.download_dir_check(output)
42
+ dir = File.dirname(output)
43
+ if !Dir.exist?(dir)
44
+ SleepRoom.info("#{dir} does not exist, creating...")
45
+ SleepRoom.mkdir(dir)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "async/http/faraday"
4
+ require "async/http/faraday/default"
5
+ require_relative "room"
6
+ require_relative "room_api"
7
+ require_relative "streaming_api"
8
+
9
+ module SleepRoom
10
+ module Record
11
+ module API
12
+ class Error < StandardError; end
13
+ ROOM_URL = "https://www.showroom-live.com"
14
+ ROOM_API = "https://www.showroom-live.com/api/room/status"
15
+ STREAMING_API = "https://www.showroom-live.com/api/live/streaming_url"
16
+
17
+ 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
+
19
+ def self.get(url)
20
+ Async do
21
+ http = Faraday.get(url, nil, {"User-Agent": USER_AGENT})
22
+ if http.status == 200
23
+ @json = JSON.parse(http.body)
24
+ else
25
+ raise Error, "HTTP Error: #{http.status}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleepRoom
4
+ module Record
5
+ module API
6
+ class Room
7
+ def initialize(room_name)
8
+ @url = ROOM_URL + "/" + room_name
9
+ end
10
+
11
+ def get(task: Async::Task.current)
12
+ @json = API.get(@url).wait
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end