1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/usr/bin/perl
#!/usr/bin/perl -w
# (the Shout library causes warnings if we use -w)
#
# yashout
# 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 POSIX qw(:sys_wait_h setsid);
use Shout;
my $encoder_password = 'haze420';
#read options from commandline
my($filename, $mountpoint, $port) = @ARGV;
my $conn = new Shout (
ip => 'localhost',
port => $port || 8000,
mount => $mountpoint,
password => $encoder_password,
icy_compat => 0,
dumpfile => undef,
name => 'Fonestream audio',
url => 'http://www.fonestream.com/',
genre => 'talk',
description => 'The easiest way to webcast.',
bitrate => 16,
ispublic => 0,
);
$conn->connect or die "Failed to connect: ". $conn->error;
open(SFILE,"</home/ivan/plexmp3/silence.mp3") or die "Can't open silence.mp3: $!";
open(FILE,"<$filename") or die "Can't open $filename: $!";
daemonize(); #fork/disconnect so plex.pls will return to client
if ( 0 ) {
#send silence header to server
my( $sbuffer, $sbytes ) = ( '', 0 );
while ( ( $sbytes = read( SFILE, $sbuffer, 4096 ) ) > 0 ) {
$conn->sendData( $sbuffer ) && next;
# error handling???
print STDERR "Error while sending: ", $conn->error, "\n";
last;
} continue {
$conn->sleep;
}
}
sleep 10;
#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;
}
|