Skip to content

Instantly share code, notes, and snippets.

@sharifulin
Created June 23, 2010 16:18
Show Gist options
  • Select an option

  • Save sharifulin/450150 to your computer and use it in GitHub Desktop.

Select an option

Save sharifulin/450150 to your computer and use it in GitHub Desktop.
Mojo::IOLoop for stream URL frod.io
#!/usr/bin/perl
use common::sense;
use lib qw(../../lib /tk/lib /tk/mojo/lib);
use Mojo::IOLoop;
use Mojo::Message::Request;
use Data::Dumper;
my $url = Mojo::URL->new('http://frod.io:8000/station-aac');
my $loop = Mojo::IOLoop->new;
my $id = $loop->connect(
address => $url->host,
port => $url->port,
args => { LocalPort => 9876 },
write_cb => sub {
my ($self, $id) = @_;
$self->not_writing($id);
my $r = Mojo::Message::Request->new;
$r->headers->header( 'Icy-MetaData' => 1 );
$r->url( $url );
return $r->to_string;
},
read_cb => sub {
my ($self, $id, $chunk) = @_;
return unless my %tag = $chunk =~ /Stream(\w+)=([^;]+)/g;
say Dumper \%tag;
},
error_cb => sub {
my ($self, $id, $msg) = @_;
say "ERROR: $msg";
},
hup_cb => sub {
my ($self, $id) = @_;
say 'HUP';
},
);
$loop->writing($id);
$loop->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment