class Shout
Constants
- HTTP
- ICY
- INT_ACCESSORS
- MP3
- OGG
- STRING_ACCESSORS
- VORBIS
- XAUDIOCAST
Attributes
Public Class Methods
Make a new shout object. This method does not connect to any server. See connect.
static VALUE _Sh_new(int argc, VALUE *argv, VALUE klass) { VALUE self = Data_Wrap_Struct(klass, 0, free_sh, 0); rb_obj_call_init(self, argc, argv); return self; }
# File lib/shout.rb, line 12 def initialize(opts={}) ext_initialize (STRING_ACCESSORS + INT_ACCESSORS + [:charset]).each do |a| self.__send__ :"#{a}=", opts[a] if opts[a] end end
Returns the libshout version, as a string.
static VALUE _Sh_version(VALUE klass) { const char *version; VALUE version_String; version = shout_version(NULL, NULL, NULL); version_String = rb_str_new2(version); return version_String; }
Public Instance Methods
VALUE _sh_agent(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_agent(s->conn); return rb_str_new2(value); }
Set the User-Agent reported. The default is “libshout/<libshout version>”, e.g. “libshout/2.0.0”.
VALUE _sh_agent_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_agent(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_bitrate(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_audio_info(s->conn, SHOUT_AI_BITRATE); return rb_str_new2(value); }
Set the 'bitrate' in the audio_info of the stream.
VALUE _sh_bitrate_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_audio_info(s->conn, SHOUT_AI_BITRATE, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
# File lib/shout.rb, line 38 def charset @charset || ((format && format==Shout::MP3) ? 'ISO-8859-1' : 'UTF-8') end
Disconnect from the server.
static VALUE _sh_disconnect(VALUE self) { int err; shout_connection *s; GET_SC(self, s); err = shout_close(s->conn); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return Qtrue; }
Connect to the server. You must set all the parameters you're going to set before connecting.
static VALUE _sh_connect(VALUE self) { int err; shout_connection *s; GET_SC(self, s); err = shout_open(s->conn); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return Qtrue; }
The new _sh_connect_non_blocking function (aka connect_non_blocking method) wrapping _sh_connect in a rb_thread_blocking_region call.
static VALUE _sh_connect_non_blocking(VALUE self) { return rb_thread_blocking_region(_sh_connect, self, RUBY_UBF_IO, NULL); }
Returns true if connected, false otherwise, nil if something really crazy happened.
static VALUE _sh_connectedp(VALUE self) { int err; shout_connection *s; GET_SC(self, s); err = shout_get_connected(s->conn); if(err == SHOUTERR_CONNECTED) { return Qtrue; } else if(err == SHOUTERR_UNCONNECTED) { return Qfalse; } else { return Qnil; } }
Return the proper amount of time, in milliseconds, before more data needs to be sent. This is for use when you would like to do something else in the intervening time period besides sleep.
static VALUE _sh_delay(VALUE self) { int ms; shout_connection *s; GET_SC(self, s); ms = shout_delay(s->conn); return INT2NUM(ms); }
VALUE _sh_description(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_description(s->conn); return rb_str_new2(value); }
Set a longer description of the stream. Probably several lines of text.
VALUE _sh_description_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_description(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
Disconnect from the server.
static VALUE _sh_disconnect(VALUE self) { int err; shout_connection *s; GET_SC(self, s); err = shout_close(s->conn); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return Qtrue; }
VALUE _sh_dumpfile(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_dumpfile(s->conn); return rb_str_new2(value); }
Set a filename where the server should dump the data from this stream. Only do this if you know what you are doing.
VALUE _sh_dumpfile_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_dumpfile(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_format(VALUE self) { int value; shout_connection *s; GET_SC(self, s); value = shout_get_format(s->conn); return INT2FIX(value); }
Set the format of the audio. Possible values are:
- Shout::VORBIS
-
Ogg Vorbis
- Shout::MP3
VALUE _sh_format_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_FIXNUM); err = shout_set_format(s->conn, FIX2INT(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_genre(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_genre(s->conn); return rb_str_new2(value); }
Set the 'genre' of the stream.
VALUE _sh_genre_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_genre(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_host(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_host(s->conn); return rb_str_new2(value); }
Set the hostname to connect to. The default is localhost.
VALUE _sh_host_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_host(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
Set MP3 metadata. Create a ShoutMetadata object, add some stuff to it and pass it to this method. If the format of the stream isn't MP3, and you try to set its metadata, an exception will most likely be raised.
VALUE _sh_metadata_eq(VALUE self, VALUE meta) { int err; shout_connection *s; GET_SC(self, s); shout_metadata_t *m; Data_Get_Struct(meta, shout_metadata_t, m); err = shout_set_metadata(s->conn, m); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return meta; }
VALUE _sh_mount(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_mount(s->conn); return rb_str_new2(value); }
Set the mountpoint on the server.
VALUE _sh_mount_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_mount(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_name(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_name(s->conn); return rb_str_new2(value); }
Set the name of the stream, e.g. “monkey's radio tunes.”
VALUE _sh_name_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_name(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
Connect to the server. You must set all the parameters you're going to set before connecting.
static VALUE _sh_connect(VALUE self) { int err; shout_connection *s; GET_SC(self, s); err = shout_open(s->conn); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return Qtrue; }
VALUE _sh_pass(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_password(s->conn); return rb_str_new2(value); }
Set the password to authenticate with. The default is no password.
VALUE _sh_pass_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_password(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_pass(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_password(s->conn); return rb_str_new2(value); }
Set the password to authenticate with. The default is no password.
VALUE _sh_pass_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_password(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_port(VALUE self) { int value; shout_connection *s; GET_SC(self, s); value = shout_get_port(s->conn); return INT2FIX(value); }
Set the destination port. The default is 8000.
VALUE _sh_port_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_FIXNUM); err = shout_set_port(s->conn, FIX2INT(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_proto(VALUE self) { int value; shout_connection *s; GET_SC(self, s); value = shout_get_protocol(s->conn); return INT2FIX(value); }
Set the protocol to use when connecting. Default is Shout::HTTP. Possible values are:
- Shout::HTTP
-
HTTP; the protocol used by Icecast.
- Shout::XAUDIOCAST
-
XAudioCast. Obsolete.
- Shout::ICY
-
Icy. Obsolete. Used by Shoutcast.
VALUE _sh_proto_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_FIXNUM); err = shout_set_protocol(s->conn, FIX2INT(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_public(VALUE self) { int value; shout_connection *s; GET_SC(self, s); value = shout_get_public(s->conn); return INT2FIX(value); }
Set whether or not this stream should be “public”, i.e. advertised to a yp server such as yp.icecast.org. True or false. Nil counts as false.
VALUE _sh_public_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); if(value == Qfalse || value == Qnil || (FIXNUM_P(value) && FIX2INT(value) == 0) ) { err = shout_set_public(s->conn, 0); } else { err = shout_set_public(s->conn, 1); } if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
Send some data. to_send is a String containing the data to send.
static VALUE _sh_send(VALUE self, VALUE to_send) { int err; shout_connection *s; GET_SC(self, s); SafeStringValue(to_send); err = shout_send(s->conn, (unsigned char *) (RSTRING_PTR(to_send)), RSTRING_LEN(to_send)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return Qtrue; }
The new _sh_send_non_blocking function (aka send_non_blocking method) packing the arguments of _sh_send in a struct and wrapping the _sh_send call into a rb_thread_blocking_region call.
static VALUE _sh_send_non_blocking(VALUE self, VALUE to_send) { SHOUT_SEND_ARGS send_args; send_args.self = self; send_args.to_send = (unsigned char *) to_send; return rb_thread_blocking_region(_sh_send_non_block_unpack, &send_args, RUBY_UBF_IO, NULL); }
Sleep the necessary amount of time to play back the audio data sent since the last call to sync. After calling this, it's time to send more data.
static VALUE _sh_sync(VALUE self) { shout_connection *s; GET_SC(self, s); shout_sync(s->conn); return Qtrue; }
VALUE _sh_url(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_url(s->conn); return rb_str_new2(value); }
Set the URL to send the data to. Takes a string.
VALUE _sh_url_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_url(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_user(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_user(s->conn); return rb_str_new2(value); }
Set the user to authenticate as. The default is “source”.
VALUE _sh_user_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_user(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_agent(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_agent(s->conn); return rb_str_new2(value); }
Set the User-Agent reported. The default is “libshout/<libshout version>”, e.g. “libshout/2.0.0”.
VALUE _sh_agent_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_agent(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
VALUE _sh_user(VALUE self) { const char *value; shout_connection *s; GET_SC(self, s); value = shout_get_user(s->conn); return rb_str_new2(value); }
Set the user to authenticate as. The default is “source”.
VALUE _sh_user_eq(VALUE self, VALUE value) { int err; shout_connection *s; GET_SC(self, s); Check_Type(value, T_STRING); err = shout_set_user(s->conn, RSTRING_PTR(value)); if(err != SHOUTERR_SUCCESS) { raise_shout_error(s->conn); } return value; }
Private Instance Methods
# File lib/shout.rb, line 48 def decode(s, orig_string) return s unless s.is_a? String orig_charset = orig_string.encoding.name s.encode(orig_charset, charset, :invalid => :replace, :undef => :replace, :replace => '') end
# File lib/shout.rb, line 43 def encode(s) return s unless s.is_a? String s.encode(charset, :invalid => :replace, :undef => :replace, :replace => '') end