vti (owner)

Revisions

gist: 231883 Download_button fork
public
Public Clone URL: git://gist.github.com/231883.git
Embed All Files: show embed
mojo-mp3-stream-client.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl
 
use Mojo::Client;
use Mojo::Transaction::Single;
 
my $url = shift @ARGV;
my $handler = 'mpg123 -';
 
open(HANDLER, "|$handler") or die "Cannot pipe input to $handler: $!\n";
 
my $tx = Mojo::Transaction::Single->new;
$tx->req->method('GET');
$tx->req->url->parse($url);
$tx->res->body(
    sub {
        my ($res, $chunk) = @_;
        print HANDLER $chunk;
    }
);
 
Mojo::Client->new->process($tx);
 
close HANDLER;