| 1 | =head1 NAME | ||
| 2 | |||
| 3 | StreamFinder::Zeno - Fetch actual raw streamable URLs from radio-stations and podcasts on zeno.fm | ||
| 4 | |||
| 5 | =head1 AUTHOR | ||
| 6 | |||
| 7 | This module is Copyright (C) 2017-2026 by | ||
| 8 | |||
| 9 | Jim Turner, C<< <turnerjw784 at yahoo.com> >> | ||
| 10 | |||
| 11 | Email: turnerjw784@yahoo.com | ||
| 12 | |||
| 13 | All rights reserved. | ||
| 14 | |||
| 15 | You may distribute this module under the terms of either the GNU General | ||
| 16 | Public License or the Artistic License, as specified in the Perl README | ||
| 17 | file. | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | #!/usr/bin/perl | ||
| 22 | |||
| 23 | use strict; | ||
| 24 | |||
| 25 | use StreamFinder::Zeno; | ||
| 26 | |||
| 27 | die "..usage: $0 ID|URL\n" unless ($ARGV[0]); | ||
| 28 | |||
| 29 | my $station = new StreamFinder::Zeno($ARGV[0]); | ||
| 30 | |||
| 31 | die "Invalid URL or no streams found!\n" unless ($station); | ||
| 32 | |||
| 33 | my $firstStream = $station->get(); | ||
| 34 | |||
| 35 | print "First Stream URL=$firstStream\n"; | ||
| 36 | |||
| 37 | my $url = $station->getURL(); | ||
| 38 | |||
| 39 | print "Stream URL=$url\n"; | ||
| 40 | |||
| 41 | my $stationTitle = $station->getTitle(); | ||
| 42 | |||
| 43 | print "Title=$stationTitle\n"; | ||
| 44 | |||
| 45 | my $stationDescription = $station->getTitle('desc'); | ||
| 46 | |||
| 47 | print "Title=$stationDescription\n"; | ||
| 48 | |||
| 49 | my $stationID = $station->getID(); | ||
| 50 | |||
| 51 | print "Station ID=$stationID\n"; | ||
| 52 | |||
| 53 | my $genre = $station->{'genre'}; | ||
| 54 | |||
| 55 | print "Genre=$genre\n" if ($genre); | ||
| 56 | |||
| 57 | my $icon_url = $station->getIconURL(); | ||
| 58 | |||
| 59 | if ($icon_url) { #SAVE THE ICON TO A TEMP. FILE: | ||
| 60 | |||
| 61 | my ($image_ext, $icon_image) = $station->getIconData(); | ||
| 62 | |||
| 63 | if ($icon_image && open IMGOUT, ">/tmp/${stationID}.$image_ext") { | ||
| 64 | |||
| 65 | binmode IMGOUT; | ||
| 66 | |||
| 67 | print IMGOUT $icon_image; | ||
| 68 | |||
| 69 | close IMGOUT; | ||
| 70 | |||
| 71 | } | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | my $stream_count = $station->count(); | ||
| 76 | |||
| 77 | print "--Stream count=$stream_count=\n"; | ||
| 78 | |||
| 79 | my @streams = $station->get(); | ||
| 80 | |||
| 81 | foreach my $s (@streams) { | ||
| 82 | |||
| 83 | print "------ stream URL=$s=\n"; | ||
| 84 | |||
| 85 | } | ||
| 86 | |||
| 87 | =head1 DESCRIPTION | ||
| 88 | |||
| 89 | StreamFinder::Zeno accepts a valid radio station or podcast ID or URL on | ||
| 90 | Zeno.fm and returns the actual stream URL(s), title, and cover art icon for | ||
| 91 | that station. The purpose is that one needs one of these URLs in order to | ||
| 92 | have the option to stream the station in one's own choice of media player | ||
| 93 | software rather than using their web browser and accepting any / all flash, | ||
| 94 | ads, javascript, cookies, trackers, web-bugs, and other crapware that can come | ||
| 95 | with that method of play. The author uses his own custom all-purpose media | ||
| 96 | player called "fauxdacious" (his custom hacked version of the open-source | ||
| 97 | "audacious" audio player). "fauxdacious" can incorporate this module to | ||
| 98 | decode and play Zeno.fm streams. | ||
| 99 | |||
| 100 | Generally, only one stream will be returned for each station. | ||
| 101 | |||
| 102 | =head1 SUBROUTINES/METHODS | ||
| 103 | |||
| 104 | =over 4 | ||
| 105 | |||
| 106 | =item B<new>(I<ID>|I<url> [, I<-secure> [ => 0|1 ]] | ||
| 107 | [, I<-debug> [ => 0|1|2 ]]) | ||
| 108 | |||
| 109 | Accepts a Zeno.fm station or podcast ID or URL and creates and returns a new | ||
| 110 | station object, or I<undef> if the URL is not a valid Zeno.fm station or no | ||
| 111 | streams are found. The URL can be the full URL, | ||
| 112 | ie. I<https://www.zeno.fm/radio/>B<station-id>, or just I<station-id>, | ||
| 113 | I<https://www.zeno.fm/podcast/>B<podcast-id>/episodes/B<episode-id> or just | ||
| 114 | I<podcast-id>/I<episode-id>, or I<https://www.zeno.fm/podcast/>B<podcast-id> or | ||
| 115 | just I<p/podcast-id>. If a podcast page URL is specified without the | ||
| 116 | episode-id part, then the first (latest?) episode will be returned. | ||
| 117 | |||
| 118 | The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>). | ||
| 119 | If 1 then only secure ("https://") streams will be returned. Currently, all | ||
| 120 | known Zeno streams seem to be secure ("https://"). | ||
| 121 | |||
| 122 | DEFAULT I<-secure> is 0 (false) - return all streams (http and https). | ||
| 123 | |||
| 124 | Additional options: | ||
| 125 | |||
| 126 | I<-log> => "I<logfile>" | ||
| 127 | |||
| 128 | Specify path to a log file. If a valid and writable file is specified, A line | ||
| 129 | will be appended to this file every time one or more streams is successfully | ||
| 130 | fetched for a url. | ||
| 131 | |||
| 132 | DEFAULT I<-none-> (no logging). | ||
| 133 | |||
| 134 | I<-logfmt> specifies a format string for lines written to the log file. | ||
| 135 | |||
| 136 | DEFAULT "I<[time] [url] - [site]: [title] ([total])>". | ||
| 137 | |||
| 138 | The valid field I<[variables]> are: [stream]: The url of the first/best | ||
| 139 | stream found. [site]: The site name (Zeno). [url]: The url searched | ||
| 140 | for streams. | ||
| 141 | [time]: Perl timestamp when the line was logged. [title], [artist], [album], | ||
| 142 | [description], [year], [genre], [total], [albumartist]: The corresponding | ||
| 143 | field data returned (or "I<-na->", if no value). | ||
| 144 | |||
| 145 | =item $station->B<get>(I<['playlist']>) | ||
| 146 | |||
| 147 | Returns an array of strings representing all stream URLs found. | ||
| 148 | If I<"playlist"> is specified, and the URL is a podcast page, then an extended | ||
| 149 | m3u playlist is returned instead of stream url(s), Otherwise, the array will | ||
| 150 | likely contain a stream for each episode found in order of latest to oldest, | ||
| 151 | as displayed on the podcast's web-page. | ||
| 152 | =item $station->B<getURL>([I<options>]) | ||
| 153 | |||
| 154 | Similar to B<get>() except it only returns a single stream representing | ||
| 155 | the first valid stream found. | ||
| 156 | |||
| 157 | Current options are: I<"random">, I<"nopls">, and I<"noplaylists">. | ||
| 158 | By default, the first ("best"?) stream is returned. If I<"random"> is | ||
| 159 | specified, then a random one is selected from the list of streams found. | ||
| 160 | If I<"nopls"> is specified, and the stream to be returned is a ".pls" playlist, | ||
| 161 | it is first fetched and the first entry (or a random entry if I<"random"> is | ||
| 162 | specified) is returned. This is needed by Fauxdacious Mediaplayer. | ||
| 163 | If I<"noplaylists"> is specified, and the stream to be returned is a | ||
| 164 | "playlist" (either .pls or .m3u? extension), it is first fetched and the first | ||
| 165 | entry (or a random entry if I<"random"> is specified) in the playlist | ||
| 166 | is returned. | ||
| 167 | |||
| 168 | =item $station->B<count>(I<['playlist']>) | ||
| 169 | |||
| 170 | Returns the number of streams found for the station or podcasts | ||
| 171 | (almost always 1 for Zeno.fm). If I<"playlist"> is specified, the number of | ||
| 172 | episodes returned in the playlist is returned (the playlist can have more than | ||
| 173 | one item if a podcast page URL is specified). | ||
| 174 | |||
| 175 | |||
| 176 | =item $station->B<getID>() | ||
| 177 | |||
| 178 | Returns the station's or podcast's Zeno.fm ID (alphanumeric). | ||
| 179 | |||
| 180 | =item $station->B<getTitle>(['desc']) | ||
| 181 | |||
| 182 | Returns the station's or podcast's title, or (long description). | ||
| 183 | |||
| 184 | =item $station->B<getIconURL>() | ||
| 185 | |||
| 186 | Returns the URL for the station's or podcast's "cover art" icon image, if any. | ||
| 187 | |||
| 188 | =item $station->B<getIconData>() | ||
| 189 | |||
| 190 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 191 | "gif", "jpeg", etc.) and the actual icon image (binary data), if any. | ||
| 192 | |||
| 193 | =item $station->B<getImageURL>() | ||
| 194 | |||
| 195 | Returns the URL for the station's "cover art" (usually larger) | ||
| 196 | banner image. Zeno.fm Podcasts do not have a separate banner image. | ||
| 197 | |||
| 198 | =item $station->B<getImageData>() | ||
| 199 | |||
| 200 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 201 | "gif", "jpeg", etc.) and the actual station's banner image (binary data). | ||
| 202 | Zeno.fm Podcasts do not have a separate banner image. | ||
| 203 | |||
| 204 | =item $station->B<getType>() | ||
| 205 | |||
| 206 | Returns the station's / podcast's type ("Zeno"). | ||
| 207 | |||
| 208 | =back | ||
| 209 | |||
| 210 | =head1 CONFIGURATION FILES | ||
| 211 | |||
| 212 | The default root location directory for StreamFinder configuration files | ||
| 213 | is "~/.config/StreamFinder". To use an alternate location directory, | ||
| 214 | specify it in the "I<STREAMFINDER>" environment variable, ie.: | ||
| 215 | B<$ENV{STREAMFINDER} = "/etc/StreamFinder">. | ||
| 216 | |||
| 217 | =over 4 | ||
| 218 | |||
| 219 | =item ~/.config/StreamFinder/Zeno/config | ||
| 220 | |||
| 221 | Optional text file for specifying various configuration options | ||
| 222 | for a specific site (submodule). Each option is specified on a | ||
| 223 | separate line in the format below: | ||
| 224 | NOTE: Do not follow the lines with a semicolon, comma, or any other | ||
| 225 | separator. Non-numeric I<values> should be surrounded with quotes, either | ||
| 226 | single or double. Blank lines and lines beginning with a "#" sign as | ||
| 227 | their first non-blank character are ignored as comments. | ||
| 228 | |||
| 229 | 'option' => 'value' [,] | ||
| 230 | |||
| 231 | and the options are loaded into a hash used only by the specific | ||
| 232 | (submodule) specified. Valid options include | ||
| 233 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 234 | |||
| 235 | Options specified here override any specified in | ||
| 236 | I<~/.config/StreamFinder/config>. | ||
| 237 | |||
| 238 | Among options valid for Zeno streams is the I<-notrim> described in the | ||
| 239 | B<new()> function. | ||
| 240 | |||
| 241 | =item ~/.config/StreamFinder/config | ||
| 242 | |||
| 243 | Optional text file for specifying various configuration options. | ||
| 244 | Each option is specified on a separate line in the format below: | ||
| 245 | |||
| 246 | 'option' => 'value' [,] | ||
| 247 | |||
| 248 | and the options are loaded into a hash used by all sites | ||
| 249 | (submodules) that support them. Valid options include | ||
| 250 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 251 | |||
| 252 | =back | ||
| 253 | |||
| 254 | NOTE: Options specified in the options parameter list of the I<new()> | ||
| 255 | function will override those corresponding options specified in these files. | ||
| 256 | |||
| 257 | =head1 KEYWORDS | ||
| 258 | |||
| 259 | Zeno | ||
| 260 | |||
| 261 | =head1 DEPENDENCIES | ||
| 262 | |||
| 263 | L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent> | ||
| 264 | |||
| 265 | =head1 RECCOMENDS | ||
| 266 | |||
| 267 | wget | ||
| 268 | |||
| 269 | =head1 BUGS | ||
| 270 | |||
| 271 | Please report any bugs or feature requests to C<bug-streamFinder-Zeno at rt.cpan.org>, or through | ||
| 272 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-Zeno>. I will be notified, and then you'll | ||
| 273 | automatically be notified of progress on your bug as I make changes. | ||
| 274 | |||
| 275 | =head1 SUPPORT | ||
| 276 | |||
| 277 | You can find documentation for this module with the perldoc command. | ||
| 278 | |||
| 279 | perldoc StreamFinder::Zeno | ||
| 280 | |||
| 281 | You can also look for information at: | ||
| 282 | |||
| 283 | =over 4 | ||
| 284 | |||
| 285 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 286 | |||
| 287 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-Zeno> | ||
| 288 | |||
| 289 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 290 | |||
| 291 | L<http://annocpan.org/dist/StreamFinder-Zeno> | ||
| 292 | |||
| 293 | =item * Search CPAN | ||
| 294 | |||
| 295 | L<http://search.cpan.org/dist/StreamFinder-Zeno/> | ||
| 296 | |||
| 297 | =back | ||
| 298 | |||
| 299 | =head1 LICENSE AND COPYRIGHT | ||
| 300 | |||
| 301 | Copyright 2017-2026 Jim Turner. | ||
| 302 | |||
| 303 | This program is free software; you can redistribute it and/or modify it | ||
| 304 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 305 | copy of the full license at: | ||
| 306 | |||
| 307 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 308 | |||
| 309 | Any use, modification, and distribution of the Standard or Modified | ||
| 310 | Versions is governed by this Artistic License. By using, modifying or | ||
| 311 | distributing the Package, you accept this license. Do not use, modify, | ||
| 312 | or distribute the Package, if you do not accept this license. | ||
| 313 | |||
| 314 | If your Modified Version has been derived from a Modified Version made | ||
| 315 | by someone other than you, you are nevertheless required to ensure that | ||
| 316 | your Modified Version complies with the requirements of this license. | ||
| 317 | |||
| 318 | This license does not grant you the right to use any trademark, service | ||
| 319 | mark, tradename, or logo of the Copyright Holder. | ||
| 320 | |||
| 321 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 322 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 323 | otherwise transfer the Package with respect to any patent claims | ||
| 324 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 325 | Package. If you institute patent litigation (including a cross-claim or | ||
| 326 | counterclaim) against any party alleging that the Package constitutes | ||
| 327 | direct or contributory patent infringement, then this Artistic License | ||
| 328 | to you shall terminate on the date that such litigation is filed. | ||
| 329 | |||
| 330 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 331 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 332 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 333 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 334 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 335 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 336 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 337 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 338 | |||
| 339 | =cut | ||
| 340 | |||
| 341 | package StreamFinder::Zeno; | ||
| 342 | |||
| 343 | use strict; | ||
| 344 | use warnings; | ||
| 345 | use URI::Escape; | ||
| 346 | use HTML::Entities (); | ||
| 347 | use LWP::UserAgent (); | ||
| 348 | use parent 'StreamFinder::_Class'; | ||
| 349 | |||
| 350 | my $DEBUG = 0; | ||
| 351 | |||
| 352 | sub new | ||
| 353 | { | ||
| 354 | my $class = shift; | ||
| 355 | my $url = shift; | ||
| 356 | |||
| 357 | return undef unless ($url); | ||
| 358 | |||
| 359 | my $self = $class->SUPER::new('Zeno', @_); | ||
| 360 | $DEBUG = $self->{'debug'} if (defined $self->{'debug'}); | ||
| 361 | $self->{'notrim'} = 0; | ||
| 362 | while (@_) { | ||
| 363 | if ($_[0] =~ /^\-?notrim$/o) { | ||
| 364 | shift; | ||
| 365 | $self->{'notrim'} = (defined $_[0]) ? shift : 1; | ||
| 366 | } else { | ||
| 367 | shift; | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | my $baseURL = 'https://zeno.fm'; | ||
| 372 | my $isStation; | ||
| 373 | my $isPodcastPage; | ||
| 374 | my @epiStreams = (); | ||
| 375 | my @epiTitles = (); | ||
| 376 | my $tryit = 0; | ||
| 377 | |||
| 378 | TRYIT: | ||
| 379 | (my $url2fetch = $url) =~ s#\/$##; | ||
| 380 | print STDERR "-0(Zeno): URL=$url= try=$tryit=\n" if ($DEBUG); | ||
| 381 | if ($url =~ /^https?\:/) { | ||
| 382 | if ($url =~ m#\/podcast\/([^\/]+)\/episodes?\/([^\/\?\&]+)#) { | ||
| 383 | $self->{'id'} = "$1/$2"; | ||
| 384 | $url2fetch =~ s#\/episode\/#\/episodes\/#; #CATCH SOME FAT-FINGERS! | ||
| 385 | } elsif ($url =~ m#\/(podcast|radio)\/([^\/\?\&]+)#) { | ||
| 386 | $self->{'id'} = $2; | ||
| 387 | } else { | ||
| 388 | print STDERR "--Invalid Zeno URL (not station, podcast or episode), PUNT!\n"; | ||
| 389 | return undef; | ||
| 390 | } | ||
| 391 | $isStation = ($url =~ m#\/radio\/#) ? 1 : 0; | ||
| 392 | my $pctype = ($self->{'id'} =~ m#\/# ? 'EPISODE' : 'PODCAST'); | ||
| 393 | print STDERR "-We're a full " . ($isStation ? 'STATION' : $pctype) | ||
| 394 | . " url($url2fetch).\n" if ($DEBUG); | ||
| 395 | } elsif ($url =~ m#\/#) { | ||
| 396 | my ($pcid, $epid) = split(m#\/#, $url); | ||
| 397 | $self->{'id'} = $url; | ||
| 398 | $url2fetch = "${baseURL}/podcast/" . (($self->{'id'} =~ s#^p(?:odcast)?\/##) | ||
| 399 | ? $epid : "$pcid/episodes/$epid"); | ||
| 400 | $isStation = 0; | ||
| 401 | print STDERR "-We're a podcast or episode-ID(".$self->{'id'}.") (url:=$url2fetch).\n" | ||
| 402 | if ($DEBUG); | ||
| 403 | } else { | ||
| 404 | $self->{'id'} = $url; | ||
| 405 | $url2fetch = 'https://www.zeno.fm/radio/' . $url; | ||
| 406 | $isStation = 1; | ||
| 407 | print STDERR "-We're a radio-station ID(".$self->{'id'}.") (url:=$url2fetch).\n" | ||
| 408 | if ($DEBUG); | ||
| 409 | } | ||
| 410 | $isPodcastPage = ($isStation || $self->{'id'} =~ m#\/#) ? 0 : 1; | ||
| 411 | $self->{'cnt'} = 0; | ||
| 412 | my $html = ''; | ||
| 413 | my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}}); | ||
| 414 | $ua->timeout($self->{'timeout'}); | ||
| 415 | $ua->cookie_jar({}); | ||
| 416 | $ua->env_proxy; | ||
| 417 | my $response = $ua->get($url2fetch); | ||
| 418 | if ($response->is_success) { | ||
| 419 | $html = $response->decoded_content; | ||
| 420 | } else { | ||
| 421 | print STDERR $response->status_line if ($DEBUG); | ||
| 422 | } | ||
| 423 | print STDERR "-1: html=$html=\n" if ($DEBUG > 1); | ||
| 424 | return undef unless ($html); #STEP 1 FAILED, INVALID STATION URL, PUNT! | ||
| 425 | |||
| 426 | my $have1stepisode = 0; | ||
| 427 | if ($isPodcastPage) { #WE'RE A PODCAST PAGE (NOT SPECIFIC EPISODE), GATHER PLAYLIST DATA: | ||
| 428 | print STDERR "..Podcast PAGE, extract episodes for playlist, then return 1st episode:\n" if ($DEBUG); | ||
| 429 | $html =~ s#^.+?\,\{\"podcastId\"\:\d+\}\,#AGGIES#s; | ||
| 430 | while ($html =~ s#(^.+?)\,\{"podcastId\"\:\d+\,\"episodeId\"\:\d+\}\,##so) { | ||
| 431 | my $epistuff = $1; | ||
| 432 | if ($epistuff =~ m#\d\}\,\"[a-zA-Z0-9\-\_]+\"\,\"([^\"]+)\"\,\"([^\"]+)\"#s) { | ||
| 433 | my $epiID = $1; | ||
| 434 | my $epititle = $2; | ||
| 435 | if ($epistuff =~ s#\,\"(https?\:\/\/anchor\.fm\/[^\"]*)\"##s | ||
| 436 | || $epistuff =~ s#\,\"(https?\:\/\/[^\"]+(?:mp3|ogg|flac|webm|acc|m3u8))\"##s) { | ||
| 437 | my $epistream = $1; | ||
| 438 | unless ($self->{'secure'} && $epistream !~ /^https/o) { | ||
| 439 | push @{$self->{'streams'}}, $epistream; | ||
| 440 | $self->{'cnt'}++; | ||
| 441 | push @epiStreams, $epistream; | ||
| 442 | push @epiTitles, $epititle; | ||
| 443 | $have1stepisode ||= $epiID; | ||
| 444 | } | ||
| 445 | } | ||
| 446 | } | ||
| 447 | } | ||
| 448 | } | ||
| 449 | if ($isStation) { #WE'RE A RADIO-STATION: PROGRMMER NOTE: DO *NOT* USE elsif HERE! | ||
| 450 | print STDERR "-We're a radio-station page!\n" if ($DEBUG); | ||
| 451 | $self->{'title'} = $1 if ($html =~ m#\,\"$$self{'id'}\"\,\"([^\"]+)#s); | ||
| 452 | $self->{'title'} ||= $1 if ($html =~ m#\<meta\s+property="(?:og|twitter)\:title\"\s+content\=\"([^\"]+)\"#s); | ||
| 453 | $self->{'title'} ||= $1 if ($html =~ m#\<title\>([^\<]+)\"#si); | ||
| 454 | $self->{'description'} = $1 if ($html =~ s#\<div\s+class\=\"description[^\>]+\>(.+?)\<\/div\>##s); | ||
| 455 | $self->{'description'} ||= $self->{'title'}; | ||
| 456 | if ($html =~ s#\<h2\>(.+?\<\/h2\>)##si) { | ||
| 457 | my $channeldata = $1; | ||
| 458 | $self->{'albumartist'} = $1 if ($channeldata =~ s#\<a(?:.+?)href\=\"([^\"]+)\"[^\>]*\>##s); | ||
| 459 | $self->{'albumartist'} = $baseURL . $self->{'albumartist'} if ($self->{'albumartist'} =~ m#^\/#); | ||
| 460 | $self->{'artist'} = $1 if ($channeldata =~ m#\s*([^\<]+)#s); | ||
| 461 | } else { | ||
| 462 | ($self->{'albumartist'} = $url2fetch) =~ s#\/podcast\/.+$#\/#; | ||
| 463 | } | ||
| 464 | $self->{'created'} = ($html =~ m#\>([^\<]+)\<\/span\>\<\/div\>\<h1#) ? $1 : ''; | ||
| 465 | $self->{'total'} = $self->{'cnt'}; | ||
| 466 | $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : ''; | ||
| 467 | while ($html =~ s#\,\"(https?\:\/\/anchor\.fm\/[^\"]*)\"##s | ||
| 468 | || $html =~ s#\,\"(https?\:\/\/[^\"]+(?:mp3|ogg|flac|webm|acc|m3u8))\"##s) { | ||
| 469 | my $stream = $1; | ||
| 470 | print STDERR "----RADIO STREAM FOUND1 ($stream)!\n" if ($DEBUG); | ||
| 471 | unless ($self->{'secure'} && $stream !~ /^https/o) { | ||
| 472 | push @{$self->{'streams'}}, $stream; | ||
| 473 | $self->{'cnt'}++; | ||
| 474 | } | ||
| 475 | } | ||
| 476 | |||
| 477 | #NOW REMOVE A BUNCH OF HTML TO MAKE REST EASIER: | ||
| 478 | |||
| 479 | $html =~ s#^.+?(\<script\s+type\=\"application\/json\")#$1#s; | ||
| 480 | |||
| 481 | if ($html =~ s#\,\"(https?\:\/\/stream[^\"]+)\"##) { | ||
| 482 | my $stream = $1; | ||
| 483 | print STDERR "----RADIO STREAM FOUND2 ($stream)!\n" if ($DEBUG); | ||
| 484 | unless ($self->{'secure'} && $stream !~ /^https/o) { | ||
| 485 | push @{$self->{'streams'}}, $stream; | ||
| 486 | $self->{'cnt'}++; | ||
| 487 | } | ||
| 488 | } | ||
| 489 | if ($html =~ s#\,\"(http[^\"]+)\"\,\"[^\"]+\"\,(?:true|false)\,\"https\:\/\/audioad\.zenomedia\.com\/##s) { | ||
| 490 | my $stream = $1; | ||
| 491 | print STDERR "----RADIO STREAM FOUND3 ($stream)!\n" if ($DEBUG); | ||
| 492 | unless ($self->{'secure'} && $stream !~ /^https/o) { | ||
| 493 | push @{$self->{'streams'}}, $stream; | ||
| 494 | $self->{'cnt'}++; | ||
| 495 | } | ||
| 496 | } | ||
| 497 | $self->{'iconurl'} = $1 if ($html =~ s#\,\"(https?\:\/\/[^\"]*)\"##s); | ||
| 498 | $html =~ s#\,\"(https?\:\/\/[^\"]*)\"##s; #THIS ONE'S NO GOOD (SKIP OVER)! | ||
| 499 | $self->{'imageurl'} = ($html =~ s#\,\"(https?\:\/\/[^\"]*)\"##s) ? $1 : $self->{'artimageurl'}; | ||
| 500 | |||
| 501 | $self->{'iconurl'} ||= $1 if ($html =~ s#^.+?\,\"(https?\:\/\/image[^\"]+)\"##s); | ||
| 502 | $self->{'iconurl'} ||= ($html =~ m#\,\"(https?\:\/\/[^\"]+)#s) ? $1 : $self->{'iconurl'}; | ||
| 503 | $self->{'imageurl'} ||= $self->{'iconurl'}; | ||
| 504 | } else { #WE'RE A PODCAST OR PODCAST EPISODE PAGE: | ||
| 505 | print STDERR "---isPodcastPage=$isPodcastPage, have1stEp=$have1stepisode, tryit=$tryit.\n"; | ||
| 506 | if ($isPodcastPage && $have1stepisode && !$tryit) { | ||
| 507 | $url = "$$self{'id'}/$have1stepisode"; | ||
| 508 | ++$tryit; | ||
| 509 | if ($DEBUG) { | ||
| 510 | foreach my $f (sort keys %{$self}) { | ||
| 511 | print STDERR "--PODCAST.KEY=$f= VAL=$$self{$f}=\n"; | ||
| 512 | } | ||
| 513 | } | ||
| 514 | print STDERR "------Podcast PAGE: loopback & FETCH 1ST EPISODE ($url)\n\n" | ||
| 515 | if ($DEBUG); | ||
| 516 | |||
| 517 | goto TRYIT; #PODCAST PAGE: LOOP BACK TO FETCH 1ST EPISODE: | ||
| 518 | } | ||
| 519 | |||
| 520 | #IF HERE, WE HAVE A SPECIFIC PODCAST EPISODE: | ||
| 521 | print STDERR "--We are an EPISODE page!\n" if ($DEBUG); | ||
| 522 | $self->{'genre'} = 'Podcast'; | ||
| 523 | my $epID = ($self->{'id'} =~ m#\/(.+)$#) ? $1 : ''; | ||
| 524 | $self->{'title'} = $1 if ($epID && $html =~ m#\,\"$epID\"\,\"([^\"]+)#s); | ||
| 525 | $self->{'title'} ||= $1 if ($html =~ m#\<meta\s+property="(?:og|twitter)\:title\"\s+content\=\"([^\"]+)\"#s); | ||
| 526 | $self->{'title'} ||= $1 if ($html =~ m#\<title\>([^\<]+)\"#si); | ||
| 527 | $self->{'description'} = $1 if ($html =~ s#\<div\s+class\=\"description[^\>]+\>(.+?)\<\/div\>##s); | ||
| 528 | $self->{'description'} ||= $self->{'title'}; | ||
| 529 | if ($html =~ s#\<h2\>(.+?\<\/h2\>)##si) { | ||
| 530 | my $channeldata = $1; | ||
| 531 | $self->{'albumartist'} = $1 if ($channeldata =~ s#\<a(?:.+?)href\=\"([^\"]+)\"[^\>]*\>##s); | ||
| 532 | $self->{'albumartist'} = $baseURL . $self->{'albumartist'} if ($self->{'albumartist'} =~ m#^\/#); | ||
| 533 | $self->{'artist'} = $1 if ($channeldata =~ m#\s*([^\<]+)#s); | ||
| 534 | } else { | ||
| 535 | ($self->{'albumartist'} = $url2fetch) =~ s#\/podcast\/.+$#\/#; | ||
| 536 | } | ||
| 537 | $self->{'created'} = ($html =~ m#\>([^\<]+)\<\/span\>\<\/div\>\<h1#) ? $1 : ''; | ||
| 538 | |||
| 539 | #NOW REMOVE A BUNCH OF HTML TO MAKE REST EASIER: | ||
| 540 | |||
| 541 | $html =~ s#^.+?(\<script\s+type\=\"application\/json\")#$1#s; | ||
| 542 | |||
| 543 | if ($html =~ s#\,\"(https?\:\/\/[^\"]*)\"##s) { | ||
| 544 | my $artist_website = $1; | ||
| 545 | $self->{'artist'} .= ' - ' if ($self->{'artist'}); | ||
| 546 | $self->{'artist'} .= $artist_website; | ||
| 547 | } | ||
| 548 | $self->{'artimageurl'} = $1 if ($html =~ s#\,\"(https?\:\/\/[^\"]*)\"##s); | ||
| 549 | $self->{'articonurl'} = ($html =~ s#\,\"(https?\:\/\/[^\"]*)\"##s) ? $1 : $self->{'artimageurl'}; | ||
| 550 | |||
| 551 | while ($html =~ s#\,\"(https?\:\/\/anchor\.fm\/[^\"]*)\"##s | ||
| 552 | || $html =~ s#\,\"(https?\:\/\/[^\"]+(?:mp3|ogg|flac|webm|acc|m3u8))\"##s) { | ||
| 553 | my $stream = $1; | ||
| 554 | unless ($self->{'secure'} && $stream !~ /^https/o) { | ||
| 555 | push @{$self->{'streams'}}, $stream; | ||
| 556 | $self->{'cnt'}++; | ||
| 557 | } | ||
| 558 | } | ||
| 559 | $self->{'iconurl'} = $1 if ($html =~ s#^.+?\,\"(https?\:\/\/image[^\"]+)\"##s); | ||
| 560 | $self->{'imageurl'} = ($html =~ m#\,\"(https?\:\/\/[^\"]+)#s) ? $1 : $self->{'iconurl'}; | ||
| 561 | $self->{'iconurl'} ||= $self->{'imageurl'}; | ||
| 562 | $self->{'created'} ||= $1 if ($html =~ m#\}\,\"([^\"]")\,\[#s); | ||
| 563 | $self->{'year'} = ($self->{'created'} && $self->{'created'} =~ /(\d\d\d\d)/s) ? $1 : ''; | ||
| 564 | #IF WAS ORIGINALLY A PODCAST PAGE (NOW 1ST EPISODE), BUILD THE PLAYLIST: | ||
| 565 | $self->{'playlist'} = "#EXTM3U\n"; | ||
| 566 | if ($#epiStreams >= 0) { #PODCAST PAGE (MULTIPLE EPISODES): | ||
| 567 | $self->{'playlist_cnt'} = scalar @epiStreams; | ||
| 568 | for (my $i=0;$i<=$#epiStreams;$i++) { | ||
| 569 | last if ($i > $#epiTitles); | ||
| 570 | $self->{'playlist'} .= "#EXTINF:-1, " . $epiTitles[$i] . "\n"; | ||
| 571 | $self->{'playlist'} .= "#EXTART:" . $self->{'artist'} . "\n" | ||
| 572 | if ($self->{'artist'}); | ||
| 573 | $self->{'playlist'} .= "#EXTALB:" . $self->{'album'} . "\n" | ||
| 574 | if ($self->{'album'}); | ||
| 575 | $self->{'playlist'} .= "#EXTGENRE:" . $self->{'genre'} . "\n" | ||
| 576 | if ($self->{'genre'}); | ||
| 577 | $self->{'playlist'} .= $epiStreams[$i] . "\n"; | ||
| 578 | } | ||
| 579 | } else { #EPISODE PAGE (SINGLE EPISODE): | ||
| 580 | $self->{'playlist_cnt'} = 1; | ||
| 581 | $self->{'playlist'} .= "#EXTINF:-1, " . $self->{'title'} . "\n"; | ||
| 582 | $self->{'playlist'} .= "#EXTART:" . $self->{'artist'} . "\n" | ||
| 583 | if ($self->{'artist'}); | ||
| 584 | $self->{'playlist'} .= "#EXTALB:" . $self->{'album'} . "\n" | ||
| 585 | if ($self->{'album'}); | ||
| 586 | $self->{'playlist'} .= "#EXTGENRE:" . $self->{'genre'} . "\n" | ||
| 587 | if ($self->{'genre'}); | ||
| 588 | $self->{'playlist'} .= ${$self->{'streams'}}[0] . "\n"; | ||
| 589 | } | ||
| 590 | } | ||
| 591 | #CLEAN UP SOME COMMON FIELDS: | ||
| 592 | $self->{'title'} = HTML::Entities::decode_entities($self->{'title'}); | ||
| 593 | $self->{'title'} = uri_unescape($self->{'title'}); | ||
| 594 | $self->{'title'} =~ s/(?:\%|\\[ux\%]?00|\bu00)([0-9A-Fa-f]{2})/chr(hex($1))/egs; | ||
| 595 | $self->{'title'} =~ s/^\s*Listen to\s+//i; #TIDY UP TITLE A BIT. | ||
| 596 | $self->{'title'} =~ s/\s*\|\s*Zeno.FM//; #TIDY UP TITLE A BIT. | ||
| 597 | $self->{'description'} = HTML::Entities::decode_entities($self->{'description'}); | ||
| 598 | $self->{'description'} = uri_unescape($self->{'description'}); | ||
| 599 | $self->{'description'} =~ s/(?:\%|\\[ux\%]?00|\bu00)([0-9A-Fa-f]{2})/chr(hex($1))/egs; #\u003C | ||
| 600 | |||
| 601 | $self->{'total'} = $self->{'cnt'}; | ||
| 602 | $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : ''; | ||
| 603 | if ($DEBUG) { | ||
| 604 | foreach my $f (sort keys %{$self}) { | ||
| 605 | print STDERR "--KEY=$f= VAL=$$self{$f}=\n"; | ||
| 606 | } | ||
| 607 | print STDERR "-SUCCESS: 1st stream=".$self->{'Url'}."=\n" if ($self->{'cnt'} > 0);; | ||
| 608 | } | ||
| 609 | |||
| 610 | $self->_log($url); | ||
| 611 | |||
| 612 | bless $self, $class; #BLESS IT! | ||
| 613 | |||
| 614 | return $self; | ||
| 615 | } | ||
| 616 | |||
| 617 | 1 |