Class: CastCaster::ChannelCLI
- Inherits:
-
Thor
- Object
- Thor
- CastCaster::ChannelCLI
- Defined in:
- lib/castcaster/channel_cli.rb
Instance Method Summary collapse
- #add ⇒ Object
- #list ⇒ Object
- #rm(name) ⇒ Object
- #start(name) ⇒ Object
- #stop(name) ⇒ Object
- #update(name) ⇒ Object
Instance Method Details
#add ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/castcaster/channel_cli.rb', line 26 def add attrs = { 'engine' => [:engine], 'source' => { 'type' => [:source_type], 'url' => [:source] }.compact, 'status' => 'stopped' } attrs['transcode'] = { 'profiles' => [:transcode], 'bitrate' => [:bitrate] }.compact if [:transcode] || [:bitrate] attrs['snapshot'] = [:snapshot] if [:snapshot] Channel.create([:name], attrs) say_status :ok, "channel '#{[:name]}' created" say_status :info, "Run `docker compose restart nginx` to apply" rescue Error => e say_status :error, e. exit 1 end |
#list ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/castcaster/channel_cli.rb', line 4 def list channels = Channel.all if channels.empty? say 'No channels. Use `castcaster channel add --name NAME` to create one.' return end shell = Thor::Shell::Basic.new rows = channels.map do |ch| [ch.name, ch.engine, ch.live? ? 'live' : 'stopped', ch.source.fetch('url', '-')] end shell.print_table(rows, headings: %w[Name Engine Status Source]) end |
#rm(name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/castcaster/channel_cli.rb', line 43 def rm(name) ch = Channel.find(name) unless ch say_status :error, "channel '#{name}' not found" exit 1 end ch.destroy say_status :ok, "channel '#{name}' removed" say_status :info, "Run `docker compose restart nginx` to apply" end |
#start(name) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/castcaster/channel_cli.rb', line 82 def start(name) ch = Channel.find(name) unless ch say_status :error, "channel '#{name}' not found" exit 1 end ch.status = 'live' ch.save say_status :ok, "channel '#{name}' marked live" end |
#stop(name) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/castcaster/channel_cli.rb', line 94 def stop(name) ch = Channel.find(name) unless ch say_status :error, "channel '#{name}' not found" exit 1 end ch.status = 'stopped' ch.save say_status :ok, "channel '#{name}' marked stopped" end |
#update(name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/castcaster/channel_cli.rb', line 60 def update(name) ch = Channel.find(name) unless ch say_status :error, "channel '#{name}' not found" exit 1 end re_read = YAML.safe_load(File.read(ch.path)) || {} re_read['source'] ||= {} re_read['source']['type'] = [:source_type] if [:source_type] re_read['source']['url'] = [:source] if [:source] if [:transcode] || [:bitrate] re_read['transcode'] = { 'profiles' => [:transcode], 'bitrate' => [:bitrate] }.compact end if .key?(:snapshot) re_read['snapshot'] = [:snapshot] > 0 ? [:snapshot] : nil end File.write(ch.path, YAML.dump(re_read)) say_status :ok, "channel '#{name}' updated" say_status :info, "Run `docker compose restart nginx` to apply" end |