Tunein-Streams

 view release on metacpan or  search on metacpan

lib/Tunein/Streams.pm  view on Meta::CPAN


	my (@streams, @streamHash, $s, $html2);
	$self->{'cnt'} = 0;
	$self->{'total'} = '0';
	$self->{'id'} = ($url =~ m#([\w\d]+)\/?$#) ? $1 : $url;
	$self->{'title'} = ($html =~ m#\<title\>(.+?)\<\/title\>#) ? $1 : '';
	$self->{'iconurl'} = ($html =~ m#\<meta\s+property\s*\=\s*\"og\:image\"\s+content\s*\=\"([^\"]+)#) ? $1 : '';
	$self->{'imageurl'} = ($html =~ m#\"hero\"\s+id=\s*\"imgSrc\"\s+style\=\"background\-image\:\s+url\(([^\)]+)\)#) ? $1 : '';
	while ($html =~ s/StreamUrl\"\:\s*\"([^\"]+)\"(\,\s*\"DirectStreams\"\:\s*\[([^\]]+)\])?//o) {  #FIND ONE (OR MORE) STREAM URLS:
		$s = $1;
		if ($2) {   #WE HAVE A DIRECT STREAM (EMBEDDED TREE), USE THAT:
			$html2 = $2;
			$html2 =~ s/^\,\s*\"Direct//io;
			$html2 = '{ "' . $html2 . ' }';
		} else {    #WE HAVE A STREAM URL, FETCH TREE FROM THERE:
			$s = 'http:' . $s  if ($s && $s !~ m#^\w+\:\/\/#o);
			$wait = 1;
			for (my $i=0; $i<=2; $i++) {  #WE TRY THIS FETCH 3 TIMES SINCE FOR SOME REASON, DOESN'T ALWAYS RETURN RESULTS 1ST TIME?!:
				$html2 = LWP::Simple::get($s);
				last  if ($html);
				sleep $wait;



( run in 0.639 second using v1.01-cache-2.11-cpan-71847e10f99 )