Thread Perl als icecast stream proxy (9 answers)
Opened by cbxk1xg at 2019-05-02 23:08

cbxk1xg
 2019-05-02 23:08
#189993 #189993
User since
2003-10-20
496 Artikel
BenutzerIn
[default_avatar]
Hallo!

Ich versuche gerade einen MP3-Stream via LWP::UserAgent durchzureichen. Mit einem Bild klappt es, da das ein definiertes Ende hat. Aber wie bekomme ich das mit einem Stream hin?

Hier mein erster Versuch.

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
#!/usr/bin/perl

use strict;
use warnings;
use utf8;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Daemon;
use threads;

my $d = HTTP::Daemon->new(LocalAddr => $ARGV[0],
                          LocalPort => 80,
                          Reuse  => 1,
                          Listen => 20) || die;
print "Web Server started.\n"."address: ", $d->sockhost(), "\n"."port: ", $d->sockport(), "\n";

while (my $conn = $d->accept) {
  threads->create(\&process_one_req, $conn)->detach();
}

sub process_one_req {
  my $conn = shift;
  my $request = $conn->get_request;
  #print Dumper($request);

  my $url = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Kitten_in_Rizal_Park%2C_Manila.jpg/800px-Kitten_in_Rizal_Park%2C_Manila.jpg";
  #my $url = "https://example.com/stream.mp3";
  my $ua = LWP::UserAgent->new;
     $ua->ssl_opts(verify_hostname => 0);
     $ua->ssl_opts(SSL_verify_mode => 0x00);
     $ua->show_progress( "TRUE" );
  $conn->send_response($ua->get($url));
  
  #print Dumper($response);
  $conn->close;
  undef($conn);
  undef($ua);
}

View full thread Perl als icecast stream proxy