Rechercher une page de manuel
MP3::Icecast.3pm
Langue: en
Version: 2004-02-02 (mandriva - 01/05/08)
Section: 3 (Bibliothèques de fonctions)
NAME
MP3::Icecast - Generate Icecast streams, as well as M3U and PLSv2 playlists.SYNOPSIS
use MP3::Icecast; use MP3::Info; use IO::Socket; my $listen_socket = IO::Socket::INET->new( LocalPort => 8000, #standard Icecast port Listen => 20, Proto => 'tcp', Reuse => 1, Timeout => 3600); #create an instance to find all files below /usr/local/mp3 my $finder = MP3::Icecast->new(); $finder->recursive(1); $finder->add_directory('/usr/local/mp3'); my @files = $finder->files; #accept TCP 8000 connections while(1){ next unless my $connection = $listen_socket->accept; defined(my $child = fork()) or die "Can't fork: $!"; if($child == 0){ $listen_socket->close; my $icy = MP3::Icecast->new; #stream files that have an ID3 genre tag of "jazz" while(@files){ my $file = shift @files; my $info = new MP3::Info $file; next unless $info; next unless $info->genre =~ /jazz/i; $icy->stream($file,0,$connection); } exit 0; } #a contrived example to demonstrate that MP3::Icecast #can generate M3U and PLSv2 media playlists. print STDERR $icy->m3u, "\n"; print STDERR $icy->pls, "\n"; $connection->close; }
ABSTRACT
MP3::Icecast supports streaming Icecast protocol over socket or other filehandle (including STDIN). This is useful for writing a streaming media server.MP3::Icecast also includes support for generating M3U and PLSv2 playlist files. These are common formats supported by most modern media players, including XMMS, Windows Media Player 9, and Winamp.
SEE ALSO
The Icecast project http://www.icecast.org Namp! (Apache::MP3) http://namp.sourceforge.net Unofficial M3U and PLS specifications http://forums.winamp.com/showthread.php?threadid=65772
AUTHOR
Allen Day, E<lt>allenday@ucla.eduE<gt>
COPYRIGHT AND LICENSE
Copyright 2003, Allen DayThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
new
Title : new Usage : $icy = MP3::Icecast->new(%arg); Function: create a new MP3::Icecast instance Returns : an MP3::Icecast object Args : none
add_directory
Title : add_directory Usage : $icy->add_directory('/usr/local/mp3'); Function: add a directory of files to be added to the playlist Returns : true on success, false on failure Args : a system path
_process_directory
Title : _process_directory Usage : $icy->_process_directory('/usr/local/mp3'); Function: searches a directory for files to add to the playlist Returns : true on success Args : a system path to search for files
add_file
Title : add_file Usage : $icy->add_file('/usr/local/mp3/meow.mp3') Function: add a file to be added to the playlist Returns : true on success, false on failure Args : a system path
files
Title : files Usage : @files = $icy->files Function: returns a list of all files that have been added from calls to add_file() and add_directory() Returns : a list of files Args : none
clear_files
Title : clear_files Usage : Function: Example : Returns : Args :
m3u
Title : m3u Usage : $m3u_text = $icy->m3u Function: generates an Extended M3U string from the contents of the list returned by files(). files not recognized by MP3::Info are silently ignored Returns : a Extended M3U string Args : none
pls
Title : pls Usage : $pls_text = $icy->pls Function: generates a PLSv2 string from the contents of the list returned by files(). files not recognized by MP3::Info are silently ignored. Returns : a PLSv2 string Args : none
stream
Title : streamll: 1 at /raid5a/allenday/projects/MP3/Icecast.pm line 459. Usage : $icy->stream('/usr/local/mp3/meow.mp3',0); $icy->stream('/usr/local/mp3/meow.mp3',0,$io_handle); Function: stream an audio file. prints to STDOUT unless a third argument is given, in which case ->print() is called on the second argument. An IO::Handle or Apache instance will work here. Returns : true on success, false on failure Args : 1) system path to the file to stream 2) offset in file to start streaming 3) (optional) object to call ->print() on, rather than printing to STDOUT
_open_file
Title : _open_file Usage : $fh = $icy->open_file('/usr/local/mp3/meow.mp3'); Function: Example : Returns : Args :
_mangle_path
Title : _mangle_path Usage : $path = $icy->_mangle_path('/usr/local/mp3/meow.mp3'); Function: applies alias substitutions and prefixes to a system path. this is intended to be used to create resolvable URLs. Returns : a string Args : a system path
_path_escape
Title : _path_escape Usage : Function: Example : Returns : Args :
_get_info
Title : _get_info Usage : $mp3_info = $icy->_get_info($file) Function: constucts and returns an MP3::Info object. the intended use here is to access MP3 metadata (from ID3 tags, filesize, etc). Returns : a new MP3::Info object on success, false on failure Args : a system path to a file
alias
Title : alias Usage : #returns 1 $icy->alias('/home/allenday/mp3' => '/mp3'); #returns '/mp3' $icy->alias('/home/allenday/mp3'); #returns 1 $icy->alias('/usr/local/share/mp3' => '/share/mp3'); #returns 1 #returns qw(/mp3 /share/mp3) $icy->alias(); Function: this method provides similar behavior to Apache's Alias directive. it allows mapping of system paths to virtual paths for usage by, for instance, a webserver. the mapping is simple: when examining a file, MP3::Icecast tries to match the beginning of the file's full path to a sorted list of aliases. the first alias to match is accepted. this may cause unexpected behavior in the event that a file's path matches multiple alias entries. patches welcome. Returns : see Usage Args : see Usage
prefix
Title : prefix Usage : $icy->prefix('http://'); Function: prefix all entries in the playlist with this value. this string is *not* uri or system path escaped. Returns : value of prefix (a scalar) Args : on set, new value (a scalar or undef, optional)
postfix
Title : postfix Usage : $obj->postfix($newval) Function: postfix all entries in the playlist with this value. this string is *not* uri or system path escaped. uri escaped. Returns : value of postfix (a scalar) Args : on set, new value (a scalar or undef, optional)
recursive
Title : recursive Usage : $obj->recursive($newval) Function: flag determining whether a directory is recursively searched for files when passed to ::add_directory(). default is false (no recursion). Example : Returns : value of recursive (a scalar) Args : on set, new value (a scalar or undef, optional)
shuffle
Title : shuffle Usage : $obj->shuffle($newval) Function: Example : Returns : value of shuffle (a scalar) Args : on set, new value (a scalar or undef, optional)
description
Title : description Usage : $description = $icy->description('/usr/local/mp3/meow.mp3'); Function: returns a description string of an MP3. this is extracted from the ID3 tags by MP3::Info. the description format can be customized, see the description_format() method. Returns : a description string Args : a valid system path
description_format
Title : description_format Usage : $icy->description_format($format_string) Function: Returns : value of description_format (a scalar) Args : on set, new value (a scalar or undef, optional)
Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre