Permalink
Browse files

Add setting/getting bitrate to audio_info.

  • Loading branch information...
1 parent a612cfa commit 15bce8fad36752b01551095f94acc0ed78838148 @rdvdijk rdvdijk committed Nov 15, 2011
Showing with 56 additions and 37 deletions.
  1. +23 −0 ext/shout_ext.c
  2. +14 −14 lib/shout.rb
  3. +12 −20 ruby-shout.gemspec
  4. +4 −0 spec/accessors_spec.rb
  5. +3 −3 spec/build_spec.rb
View
@@ -437,6 +437,15 @@ VALUE _sh_description(VALUE self) {
return rb_str_new2(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);
+}
+
/* Unimplemented: audio_info */
/* audio_info and metadata should both be objects that always exist, and have
@@ -662,6 +671,18 @@ VALUE _sh_metadata_eq(VALUE self, VALUE meta) {
return meta;
}
+/* 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;
+}
/*
@@ -716,6 +737,7 @@ void Init_shout_ext()
rb_define_method(cShout, "url", _sh_url, 0);
rb_define_method(cShout, "genre", _sh_genre, 0);
rb_define_method(cShout, "description",_sh_description,0);
+ rb_define_method(cShout, "bitrate", _sh_bitrate, 0);
/* metadata getting is still unsupported. */
/* audio info thingy. */
/* leave for version 2.2 */
@@ -739,6 +761,7 @@ void Init_shout_ext()
rb_define_method(cShout, "genre=", _sh_genre_eq, 1);
rb_define_method(cShout, "description=", _sh_description_eq,1);
rb_define_method(cShout, "metadata=", _sh_metadata_eq, 1);
+ rb_define_method(cShout, "bitrate=", _sh_bitrate_eq, 1);
rb_define_const(cShout, "HTTP", INT2FIX(SHOUT_PROTOCOL_HTTP));
rb_define_const(cShout, "XAUDIOCAST", INT2FIX(SHOUT_PROTOCOL_XAUDIOCAST));
View
@@ -3,53 +3,53 @@
class Shout
attr_writer :charset
-
+
INT_ACCESSORS = :port, :format
STRING_ACCESSORS = :host, :user, :username, :pass, :password, :protocol, :mount, :dumpfile,
- :agent, :user_agent, :public, :name, :url, :genre, :description
-
+ :agent, :user_agent, :public, :name, :url, :genre, :description, :bitrate
+
alias :ext_initialize :initialize
def initialize(opts={})
ext_initialize
-
+
(STRING_ACCESSORS + INT_ACCESSORS + [:charset]).each do |a|
self.__send__ :"#{a}=", opts[a] if opts[a]
end
end
-
+
STRING_ACCESSORS.each do |accessor|
attr_accessor :"original_#{accessor}"
-
+
alias :"raw_#{accessor}" :"#{accessor}"
define_method accessor do
return nil unless orig_acc = self.__send__("original_#{accessor}")
-
+
decode self.__send__(:"raw_#{accessor}"), orig_acc
end
-
+
alias :"raw_#{accessor}=" :"#{accessor}="
define_method :"#{accessor}=" do |value|
self.__send__ "original_#{accessor}=", value
-
+
self.__send__ :"raw_#{accessor}=", encode(value)
end
end
-
+
def charset
@charset || ((format && format==Shout::MP3) ? 'ISO-8859-1' : 'UTF-8')
end
-
+
private
def encode(s)
return s unless s.is_a? String
-
+
s.encode(charset, :invalid => :replace, :undef => :replace, :replace => '')
end
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
-
+
end
View
@@ -1,44 +1,36 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{ruby-shout}
- s.version = "2.2.0"
+ s.version = "2.2.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Jared Jennings", "Niko Dittmann"]
- s.date = %q{2011-01-05}
+ s.authors = [%q{Jared Jennings}, %q{Niko Dittmann}]
+ s.date = %q{2011-11-15}
s.description = %q{Ruby bindings for libshout 2, a "Library which can be used to write a source client like ices" for Icecast (http://www.icecast.org/download.php).}
s.email = %q{mail@niko-dittmann.com}
- s.extensions = ["ext/extconf.rb"]
+ s.extensions = [%q{ext/extconf.rb}]
s.extra_rdoc_files = [
"README.textile"
]
s.files = [
"README.textile",
- "Rakefile",
- "VERSION",
- "ext/extconf.rb",
- "ext/shout_ext.c",
- "lib/shout.rb"
+ "Rakefile",
+ "VERSION",
+ "ext/extconf.rb",
+ "ext/shout_ext.c",
+ "lib/shout.rb"
]
s.homepage = %q{http://github.com/niko/ruby-shout}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
+ s.require_paths = [%q{lib}]
s.rubyforge_project = %q{ruby-shout}
- s.rubygems_version = %q{1.3.7}
+ s.rubygems_version = %q{1.8.6}
s.summary = %q{Send audio over the network to an Icecast server}
- s.test_files = [
- "spec/accessors_spec.rb",
- "spec/build_spec.rb",
- "spec/integration_spec.rb",
- "spec/spec_helper.rb"
- ]
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
View
@@ -21,6 +21,10 @@
@shout.original_genre.should == @genre
end
end
+ it "should get and set the bitrate in audio_info" do
+ @shout.bitrate = "128"
+ @shout.bitrate.should == "128"
+ end
describe "#initialize" do
it "should set the properies from the opts" do
s = Shout.new :user => 'heinz'
View
@@ -30,17 +30,17 @@ def install_gem
command = %Q{
cd #{BASE_DIR}
rake build
- gem install --no-test --no-rdoc --no-ri --install-dir spec/test_gem_installation --bindir spec/test_gem_installation pkg/ruby-shout-#{VERSION}.gem
+ gem install --no-rdoc --no-ri --install-dir spec/test_gem_installation --bindir spec/test_gem_installation pkg/ruby-shout-#{VERSION}.gem
}
c = `#{command}`
puts c
return c
end
-
+
it "should build" do
clean_test_gem.should be_true
install_gem.should be_true
remove_pkg.should be_true
end
-
+
end

0 comments on commit 15bce8f

Please sign in to comment.