shoutpy
mail feedback: Daniel Holth <dholth@fastmail.fm>
shoutpy uses Boost.Python to expose libshout 2.1 or higher to Python. It includes a separately usable C++ wrapper that makes libshout considerably nicer to program from C++.
See also oggpy. oggpy is a C++ and Boost.Python wrapper for Ogg, Vorbis AND most of Theora. With oggpy and shoutpy you could write a reencoding icecast source in Python.
See the doxygen generated documentation here. It explains some things about stock libshout2 that were unclear from the official documentation.
In Python:
#!/usr/bin/python
#
# Simple streaming to icecast.
#
# Daniel Holth
import sys
import shoutpy
s = shoutpy.Shout()
s.user = "source"
s.password = "hackme"
s.mount = "/shoutpy.ogg"
s.port = 8001
s.format = shoutpy.FORMAT_VORBIS
s.open()
for arg in sys.argv[1:]:
f = open(arg, "rb")
buf = f.read(4096)
while buf:
s.send(buf)
buf = f.read(512)
s.sync()
f.close()
s.close()
In C++:
/* Simple multi-file streaming to a server.
*
* Daniel Holth <dholth@fastmail.fm>
*/
#include "shoutcc.h"
#include <stdio.h>
#define BUFSIZE 4096
void usage(char *name)
{
printf("Usage:\n"
"\t%s file1.ogg [file2.ogg]...\n", name);
}
int main(int argc, char **argv)
{
static unsigned char buffer[BUFSIZE];
Shout s;
try {
try {
s.set_user("source");
s.set_password("hackme");
s.set_mount("/");
s.set_port(8001);
s.set_format(SHOUT_FORMAT_VORBIS);
s.open();
}
catch(ShoutErr error) {
printf("Error connecting to server %s:%d with username %s, password %s.\n",
s.get_host(), s.get_port(), s.get_user(), s.get_password());
throw error;
}
if(argc > 1) {
int delay;
for(int i=1; i<argc; i++) {
size_t bytes = 0;
FILE *f = fopen(*(argv+i), "rb");
while(!feof(f)) {
bytes = fread(buffer, sizeof(char), BUFSIZE, f);
s.send(buffer, bytes);
delay = s.delay();
if(delay > 1000) {
printf("delay: %d\n", s.delay());
}
s.sync();
}
}
s.close();
}
else {
usage(*argv);
}
}
catch(ShoutErr error) {
printf("Shout Error: %s (code %d)\n", error.err.c_str(), error.ern);
exit(1);
}
return 0;
}
Download
News
26 Nov. 2006: shoutpy goes 1.0.0! Thanks to all who helped it to mature over these years. Adds support for nonblocking I/O introduced in libshout 2.1. Deprecated building with boost.build; just use setup.py.
10 April 2004: Version 0.5.2. Added C++ example to distribution. Added a Jamfile so you can optionally build shoutpy with boost.build.
7 April 2004: Cleaned up setup.py; now it should build out of the box on gentoo (if boost.python and libshout are already installed).
27 Jan. 2004: New example.
18 Jan. 2004: Version 0.5. Now including Python module docstrings and doxygen C++ documentation.
15 Jan. 2004, evening (EST): Version 0.4 released. New feature: it can stream audio to an icecast server. ;-)
