Created
June 23, 2010 16:18
-
-
Save sharifulin/450150 to your computer and use it in GitHub Desktop.
Mojo::IOLoop for stream URL frod.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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