Thread Perl script als Router zwischen icecast und VLC client
(14 answers)
Opened by cbxk1xg at 2023-01-16 00:20
Der folgende Code, aufgerufen via
Code: (dl
)
plackup --listen :8000 testStreamingServer.pl --debug Code: (dl
)
print "Starting server\n"; Hat jemand eine Idee? Code (perl): (dl
)
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 #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use LWP::UserAgent; use Plack::Runner; use File::Temp qw(tempfile); my $source_url = 'http://server1.example.com/stream.mp3'; my $redirect_url = 'http://server2.example.com/stream.mp3'; my $ua = LWP::UserAgent->new(); print "Starting server\n"; my $app = sub { print "Request received\n"; my $response = $ua->get($source_url); if ($response->is_success) { print "Source server is online, stream is playable\n"; my ($fh, $filename) = tempfile(); my $content_response = $ua->get($source_url, ':content_file' => $filename); my $headers = $content_response->headers(); print Dumper $headers; my $size = -s $filename; open(my $file, "<", $filename); my $file_content = do { local $/; <$file> }; close $file; return [ 200, [ 'Content-Type' => 'audio/mpeg', 'Content-Length' => $size, 'icy-metaint' => 8192, 'icy-name' => 'My Stream', 'icy-description' => 'My stream description', 'icy-genre' => 'variety', 'icy-pub' => 1, 'icy-br' => 128, 'Connection' => 'close' ], [ $file_content ], ]; } else { print "Source server is offline, redirecting to backup stream\n"; return [ 302, [ 'Location' => $redirect_url, 'Connection' => 'close' ], [], ]; } }; my $runner = Plack::Runner->new; $runner->parse_options(qw(--listen :8000 --server HTTP::Server::PSGI)); $runner->run($app); print "Server started\n"; |