class Shout

Constants

HTTP
ICY
INT_ACCESSORS
MP3
OGG
STRING_ACCESSORS
VORBIS
XAUDIOCAST

Attributes

charset[W]

Public Class Methods

new(*args) click to toggle source

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;
}
new(opts={}) click to toggle source
# 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
Also aliased as: ext_initialize
version() click to toggle source

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

agent() click to toggle source
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);
}
agent=(p1) click to toggle source

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;
}
bitrate() click to toggle source
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);
}
bitrate=(p1) click to toggle source

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;
}
charset() click to toggle source
# File lib/shout.rb, line 38
def charset
  @charset || ((format && format==Shout::MP3) ? 'ISO-8859-1' : 'UTF-8')
end
close() click to toggle source

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() click to toggle source

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;
}
connect_non_blocking() click to toggle source

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);
}
connected?() click to toggle source

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;
        }
}
delay() click to toggle source

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);
}
description() click to toggle source
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);
}
description=(p1) click to toggle source

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() click to toggle source

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;
}
dumpfile() click to toggle source
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);
}
dumpfile=(p1) click to toggle source

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;
}
ext_initialize(opts={})
Alias for: new
format() click to toggle source
VALUE _sh_format(VALUE self) {
        int value;
        shout_connection *s; GET_SC(self, s);

        value = shout_get_format(s->conn);
        return INT2FIX(value);
}
format=(p1) click to toggle source

Set the format of the audio. Possible values are:

Shout::VORBIS

Ogg Vorbis

Shout::MP3

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;
}
genre() click to toggle source
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);
}
genre=(p1) click to toggle source

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;
}
host() click to toggle source
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);
}
host=(p1) click to toggle source

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;
}
metadata=(p1) click to toggle source

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;
}
mount() click to toggle source
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);
}
mount=(p1) click to toggle source

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;
}
name() click to toggle source
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);
}
name=(p1) click to toggle source

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;
}
open() click to toggle source

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;
}
pass() click to toggle source
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);
}
pass=(p1) click to toggle source

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;
}
password() click to toggle source
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);
}
password=(p1) click to toggle source

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;
}
port() click to toggle source
VALUE _sh_port(VALUE self) {
        int value;
        shout_connection *s; GET_SC(self, s);

        value = shout_get_port(s->conn);
        return INT2FIX(value);
}
port=(p1) click to toggle source

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;
}
protocol() click to toggle source
VALUE _sh_proto(VALUE self) {
        int value;
        shout_connection *s; GET_SC(self, s);

        value = shout_get_protocol(s->conn);
        return INT2FIX(value);
}
protocol=(p1) click to toggle source

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;
}
public() click to toggle source
VALUE _sh_public(VALUE self) {
        int value;
        shout_connection *s; GET_SC(self, s);

        value = shout_get_public(s->conn);
        return INT2FIX(value);
}
public=(p1) click to toggle source

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(p1) click to toggle source

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;
}
send_non_blocking(p1) click to toggle source

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);
}
sync() click to toggle source

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;
}
url() click to toggle source
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);
}
url=(p1) click to toggle source

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;
}
user() click to toggle source
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);
}
user=(p1) click to toggle source

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;
}
user_agent() click to toggle source
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);
}
user_agent=(p1) click to toggle source

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;
}
username() click to toggle source
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);
}
username=(p1) click to toggle source

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

decode(s, orig_string) click to toggle source
# 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
encode(s) click to toggle source
# 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