jam-cloud/ruby/lib/jam_ruby/models/icecast_mount.rb

65 lines
3.6 KiB
Ruby

module JamRuby
class IcecastMount < ActiveRecord::Base
belongs_to :authentication, class_name: "JamRuby::IcecastUserAuthentication", inverse_of: :mount
has_and_belongs_to_many :servers, :class_name => "JamRuby::IcecastServer", :join_table => "icecast_server_mounts"
validates :mount_name, presence: true
validates :username, length: {minimum: 5}, if: lambda {|m| m.username.present?}
validates :password, length: {minimum: 5}, if: lambda {|m| m.password.present?}
validates :max_listeners, length: {in: 1..15000}, if: lambda {|m| m.max_listeners.present?}
validates :max_listener_duration, length: {in: 1..3600 * 48}, if: lambda {|m| m.max_listener_duration.present?}
validates :fallback_override, :inclusion => {:in => [true, false]} , if: lambda {|m| m.fallback_mount.present?}
validates :fallback_when_full, :inclusion => {:in => [true, false]} , if: lambda {|m| m.fallback_mount.present?}
validates :is_public, presence: true, :inclusion => {:in => [-1, 0, 1]}
validates :stream_name, presence: true
validates :stream_description, presence: true
validates :stream_url, presence: true
validates :genre, presence: true
validates :bitrate, numericality: {only_integer: true}, if: lambda {|m| m.bitrate.present?}
validates :mime_type, presence: true
validates :subtype, presence: true
validates :burst_size, numericality: {only_integer: true}, if: lambda {|m| m.burst_size.present?}
validates :mp3_metadata_interval, numericality: {only_integer: true}, if: lambda {|m| m.mp3_metadata_interval.present?}
validates :hidden, presence: true, :inclusion => {:in => [true, false]}
def dumpXml(builder)
builder.tag! 'mount' do |mount|
mount.tag! 'mount-name', mount_name
mount.tag! 'username', username if username
mount.tag! 'password', password if password
mount.tag! 'max-listeners', max_listeners if max_listeners
mount.tag! 'max-listener-duration', max_listener_duration if max_listener_duration
mount.tag! 'dump-file', dump_file if dump_file
mount.tag! 'intro', intro if intro
mount.tag! 'fallback-mount', fallback_mount if fallback_mount
mount.tag! 'fallback-override', fallback_override ? '1' : '0' unless fallback_override.nil?
mount.tag! 'fallback-when-full', fallback_when_full ? '1' : '0' unless fallback_when_full.nil?
mount.tag! 'charset', charset if charset
mount.tag! 'public', is_public
mount.tag! 'stream-name', stream_name if stream_name
mount.tag! 'stream-description', stream_description if stream_description
mount.tag! 'stream-url', stream_url if stream_url
mount.tag! 'genre', genre if genre
mount.tag! 'bitrate', bitrate if bitrate
mount.tag! 'type', mime_type
mount.tag! 'subtype', subtype
mount.tag! 'burst-size', burst_size if burst_size
mount.tag! 'mp3-metadata-interval', mp3_metadata_interval if mp3_metadata_interval
mount.tag! 'hidden', hidden ? '1' : '0'
mount.tag! 'on-connect', on_connect if on_connect
mount.tag! 'on-disconnect', on_disconnect if on_disconnect
authentication.dumpXml(builder) if authentication
end
end
def get_media_url
raise "Unassociated server to mount" if self.server_mount.nil?
"http://" + server_mount.server.hostname + self.mount_name
end
end
end