Net-Icecast-Source
view release on metacpan or search on metacpan
lib/Net/Icecast/Source.pm view on Meta::CPAN
package Net::Icecast::Source;
use strict;
use warnings;
use Carp qw/croak/;
use IO::Socket::INET;
use IO::Handle;
use MIME::Base64;
######################
our $VERSION = '1.1';
our $BUF_SIZE = 1460; # how many bytes to read/transmit at a time
######################
=head1 NAME
Net::Icecast::Source - Icecast streaming source
=head1 SYNOPSIS
use Net::Icecast::Source;
my $source = new Net::Icecast::Source(
username => 'revmischa',
password => 'hackthegibson',
server => '128.128.64.64',
port => '8000',
mount_point => '/source',
mime_type => 'audio/mpeg',
meta => {
name => 'lol dongs radio fun land',
description => 'party time all day',
aim => 'lindenstacker',
url => 'http://icecast.org',
},
);
# attempt to connect to the streaming server
$source->connect
or die "Unable to connect to server: $!\n";
# attempt to log in to the specified mountpoint
$source->login
or die "Incorrect username/password\n";
# stream mp3
my $sample;
open $sample, "sample.mp3" or die $!;
$source->stream_fh($sample);
close $sample;
# done, clean up
$source->disconnect
=head1 DESCRIPTION
C<Net::Icecast::Source> is a simple module designed to make it easy to
build programs which stream audio data to an Icecast2 server to be relayed.
=head1 CONSTRUCTOR
=over 4
=item new (%opts)
Create a new source instance. Options are: username, password, server,
port, mount_point, meta, mime_type
=cut
sub new {
my ($class, %opts) = @_;
my $self = \%opts;
return bless $self, $class;
}
=item connect
Connect to the server, use this before logging in. Returns success/failure
=cut
sub connect {
my ($self) = @_;
my $server = $self->{server} or croak "no server specified";
my $port = $self->{port} || 8000;
my $sock = IO::Socket::INET->new(
PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp',
Timeout => 10,
);
$self->{sock} = $sock;
( run in 1.584 second using v1.01-cache-2.11-cpan-39bf76dae61 )