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