#!/usr/bin/perl
+#!/usr/bin/perl -w
+# (the Shout library causes warnings if we use -w)
#
# yashout
-# Usage: yashout filename mountpoint
+# Usage: yashout filename mountpoint [ port ]
#
# Copyright (c) 2003 Ivan Kohler
# All rights reserved.
# This program is free software; you can redistribute it and/or modify it under
# the same terms as Perl itself.
+use strict;
+use subs qw(daemonize);
use Shout;
+
+#read options from commandline
+my($filename, $mountpoint, $port) = @ARGV;
+
+my $conn = new Shout (
+ ip => 'localhost',
+ port => $port || 8000,
+ mount => $mountpoint,
+ icy_compat => 0,
+ dumpfile => undef,
+ name => 'Fonestream audio',
+ url => 'http://www.fonestream.com/',
+ genre => 'talk',
+ description => 'The easiest way to webcast.',
+ bitrate => 64,
+ ispublic => 0,
+);
+$conn->connect or die "Failed to connect: ". $conn->error;
+
+open(FILE,"<$filename") or die "Can't open $filename: $!";
+
+daemonize(); #fork/disconnect so plex.pls will return to client
+
+#spool file to server
+my( $buffer, $bytes ) = ( '', 0 );
+while ( ( $bytes = read( FILE, $buffer, 4096 ) ) > 0 ) {
+ $conn->sendData( $buffer ) && next;
+ # error handling???
+ print STDERR "Error while sending: ", $conn->error, "\n";
+ last;
+} continue {
+ $conn->sleep;
+}
+
+$conn->disconnect;
+
+sub daemonize {
+ chdir "/" or die "Can't chdir to /: $!";
+ open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
+ defined(my $pid = fork) or die "Can't fork: $!";
+ if ( $pid ) {
+ #print "yashout started with pid $pid\n"; #logging to $log_file\n";
+ exit unless $pid_file;
+ #my $pidfh = new IO::File ">$pid_file" or exit;
+ #print $pidfh "$pid\n";
+ exit;
+ }
+ open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
+ setsid or die "Can't start a new session: $!";
+ open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
+
+ #$SIG{__DIE__} = \&_die;
+ #$SIG{__WARN__} = \&_logmsg;
+
+}
+
+