StreamFinder/SermonAudio.pm untested

filter: Statementstmt 0.0% 0 / 224 Branchbran 0.0% 0 / 218 Conditioncond 0.0% 0 / 75 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 575 CC 110 SCAR 93.6
CC
110
Cov
0%
new
12210.0
BEGIN
2.0
BEGIN
2.0
CRAP 11578.6
1 =head1 NAME
2  
3 StreamFinder::SermonAudio - Fetch actual raw streamable URLs on sermonaudio.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::SermonAudio;
26  
27 die "..usage: $0 ID|URL\n" unless ($ARGV[0]);
28  
29 my $podcast = new StreamFinder::SermonAudio($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::SermonAudio accepts a valid podcast (sermon) ID or URL on
90 SermonAudio.com and returns the actual stream URL(s), title, and cover art
91 icon. The purpose is that one needs one of these URLs in order to have the
92 option to stream the podcast in one's own choice of media player software
93 rather than using their web browser and accepting any / all flash, ads,
94 javascript, cookies, trackers, web-bugs, and other crapware that can come with
95 that method of play. The author uses his own custom all-purpose media player
96 called "fauxdacious" (his custom hacked version of the open-source "audacious"
97 audio player). "fauxdacious" can incorporate this module to decode and play
98 SermonAudio.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<ID>|I<url> [, I<-quality> => audio|any ]
107 [, I<-speakericon> [ => 0|1 ]] [, I<-secure> [ => 0|1 ]]
108 [, I<-notrim> [ => 0|1 ]] [, I<-nowebp> [ => 0|1 ]]
109 [, I<-debug> [ => 0|1|2 ]])
110  
111 Accepts a www.sermonaudio.com podcast (sermon) ID or URL and creates and
112 returns a a new podcast object, or I<undef> if the URL is not a valid podcast,
113 or no streams are found. The URL can be the full URL, ie.
114 https://www.sermonaudio.com/sermons/B<sermon-id>,
115 https://www.sermonaudio.com/speakers/B<speaker-id>,
116 https://www.sermonaudio.com/broadcasters/B<church-id>,
117 https://www.sermonaudio.com/series/B<series-id>,
118 https://www.sermonaudio.com/sermoninfo.asp?SID=B<id>,
119 https://www.sermonaudio.com/source_detail.asp?sourceid=B<source-id>,
120 or just I<sermon-id> (>8 digits), I<speaker-id> (5 digits),
121 I<series-id> (6 digits), or I<church-id> (alphanumeric).
122  
123 The optional I<-quality> argument, can be set to either "audio",
124 or "any". "audio" means only accept audio streams, "any" or "all"
125 (any other value) means accept both video and audio streams found
126 (subject to the I<-secure> argument, if specified). Unless "audio" is
127 specified, and any video stream is accepted (subject to the above limitations),
128 then the "best" stream returned will be video (video streams are by default
129 favored over audio). Note: "high" and "low" are no longer used in v2.41+,
130 as now only a single video stream is returned in HLS format (users should
131 use "hls_bitrate" config file option to limit video stream bandwidth.
132  
133 DEFAULT I<-quality> is "I<any>": (accept both video and audio streams).
134  
135 The optional I<-speakericon> argument can be set to reverse the artist
136 (channel) icon and artist image, usually resulting in the artist icon being a
137 photo of the preacher, instead of his church's thumbnail icon.
138  
139 DEFAULT I<-speakericon> is 0 (I<false>): Don't reverse the artist icon and image.
140  
141 The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>).
142 If 1 then only secure ("https://") streams will be returned.
143  
144 DEFAULT I<-secure> is 0 (false) - return all streams (http and https).
145  
146 The optional I<-notrim> argument can be either 0 or 1 (I<false> or I<true>).
147 If 0 (I<false>) then stream URLs are trimmed of excess "ad" parameters
148 (everything after the first "?" character, ie. "?ads.cust_params=premium" is
149 removed, including the "?". Otherwise, the stream URLs are returned as-is.
150  
151 DEFAULT I<-notrim> is 0 (I<false>) and URLs are trimmed. If
152 I<-notrim> is specified without argument, the default is 1 (I<true>). Try
153 using I<-notrim> if stream will not play without the extra arguments.
154  
155 Note: -notrim = 0 will not trim the "webp=true" portion of icon / image URLs
156 unless -nowebp is set to 1.
157  
158 The optional I<-nowebp> argument can be either 0 or 1 (I<false> or I<true>).
159 If 1 then image files specified as "img.{png|jpg|jpeg|gif}?webp=true" are
160 stripped of the "?webp=true" part which causes them to be downloaded in
161 their native format instead of webp. This is needed by the GTK versions
162 of Fauxdacious.
163  
164 DEFAULT I<-nowebp> is 0 (I<false>): Download webp images as webp.
165  
166 Additional options:
167  
168 I<-log> => "I<logfile>"
169  
170 Specify path to a log file. If a valid and writable file is specified, A line
171 will be appended to this file every time one or more streams is successfully
172 fetched for a url.
173  
174 DEFAULT I<-none-> (no logging).
175  
176 I<-logfmt> specifies a format string for lines written to the log file.
177  
178 DEFAULT "I<[time] [url] - [site]: [title] ([total])>".
179  
180 The valid field I<[variables]> are: [stream]: The url of the first/best stream
181 found. [site]: The site name (SermonAudio). [url]: The url searched for
182 streams. [time]: Perl timestamp when the line was logged. [title], [artist],
183 [album], [description], [year], [genre], [total], [albumartist]:
184 The corresponding field data returned (or "I<-na->", if no value).
185  
186 =item $podcast->B<get>()
187  
188 Returns an array of strings representing all stream URLs found.
189  
190 =item $podcast->B<getURL>([I<options>])
191  
192 Similar to B<get>() except it only returns a single stream representing
193 the first valid stream found. There currently are no valid I<options>.
194  
195 =item $podcast->B<count>()
196  
197 Returns the number of streams found for the podcast.
198  
199 =item $podcast->B<getID>()
200  
201 Returns the podcast's SermonAudio ID (default). For podcasts, the SermonAudio
202 ID is a single value. For individual podcast episodes it's two values
203 separated by a slash ("/").
204  
205 =item $podcast->B<getTitle>(['desc'])
206  
207 Returns the podcast's title, or (long description). Podcasts
208 on SermonAudio can have separate descriptions, but for podcasts,
209 it is always the podcast's title.
210  
211 =item $podcast->B<getIconURL>(['artist'])
212  
213 Returns the URL for the podcast's "cover art" icon image, if any.
214  
215 If B<'artist'> is specified, the channel artist's icon url is returned,
216 if any.
217  
218 =item $podcast->B<getIconData>(['artist'])
219  
220 Returns a two-element array consisting of the extension (ie. "png",
221 "gif", "jpeg", etc.) and the actual icon image (binary data), if any.
222  
223 If B<'artist'> is specified, the channel artist's icon data is returned,
224 if any.
225  
226 =item $podcast->B<getImageURL>(['artist'])
227  
228 Returns the URL for the podcast's "cover art" (usually larger)
229 banner image.
230  
231 If B<'artist'> is specified, the channel artist's image url is returned,
232 if any.
233  
234 Note: SermonAudio sermons (unlike most other podcast sites) often have both
235 an artist icon (for the church) AND an artist image for that artist/channel
236 (preacher), and the artist's image is usually slightly larger and is a photo
237 of the specific preacher. See also the B<-speakericon> option.
238  
239 =item $podcast->B<getImageData>(['artist'])
240  
241 Returns a two-element array consisting of the extension (ie. "png",
242 "gif", "jpeg", etc.) and the actual podcast's banner image (binary data).
243  
244 If B<'artist'> is specified, the channel artist's icon data is returned,
245 if any.
246  
247 =item $podcast->B<getType>()
248  
249 Returns the podcast's type ("SermonAudio").
250  
251 =back
252  
253 =head1 CONFIGURATION FILES
254  
255 The default root location directory for StreamFinder configuration files
256 is "~/.config/StreamFinder". To use an alternate location directory,
257 specify it in the "I<STREAMFINDER>" environment variable, ie.:
258 B<$ENV{STREAMFINDER} = "/etc/StreamFinder">.
259  
260 =over 4
261  
262 =item ~/.config/StreamFinder/SermonAudio/config
263  
264 Optional text file for specifying various configuration options
265 for a specific site (submodule). Each option is specified on a
266 separate line in the format below:
267 NOTE: Do not follow the lines with a semicolon, comma, or any other
268 separator. Non-numeric I<values> should be surrounded with quotes, either
269 single or double. Blank lines and lines beginning with a "#" sign as
270 their first non-blank character are ignored as comments.
271  
272 'option' => 'value' [,]
273  
274 and the options are loaded into a hash used only by the specific
275 (submodule) specified. Valid options include
276 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
277  
278 Options specified here override any specified in
279 I<~/.config/StreamFinder/config>.
280  
281 =item ~/.config/StreamFinder/config
282  
283 Optional text file for specifying various configuration options.
284 Each option is specified on a separate line in the format below:
285  
286 'option' => 'value' [,]
287  
288 and the options are loaded into a hash used by all sites
289 (submodules) that support them. Valid options include
290 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
291  
292 =back
293  
294 NOTE: Options specified in the options parameter list of the I<new()>
295 function will override those corresponding options specified in these files.
296  
297 =head1 KEYWORDS
298  
299 sermonaudio
300  
301 =head1 DEPENDENCIES
302  
303 L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent>
304  
305 =head1 RECCOMENDS
306  
307 wget
308  
309 =head1 BUGS
310  
311 Please report any bugs or feature requests to C<bug-streamFinder-iheartradio at rt.cpan.org>, or through
312 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-SermonAudio>. I will be notified, and then you'll
313 automatically be notified of progress on your bug as I make changes.
314  
315 =head1 SUPPORT
316  
317 You can find documentation for this module with the perldoc command.
318  
319 perldoc StreamFinder::SermonAudio
320  
321 You can also look for information at:
322  
323 =over 4
324  
325 =item * RT: CPAN's request tracker (report bugs here)
326  
327 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-SermonAudio>
328  
329 =item * AnnoCPAN: Annotated CPAN documentation
330  
331 L<http://annocpan.org/dist/StreamFinder-SermonAudio>
332  
333 =item * Search CPAN
334  
335 L<http://search.cpan.org/dist/StreamFinder-SermonAudio/>
336  
337 =back
338  
339 =head1 LICENSE AND COPYRIGHT
340  
341 Copyright 2021-2026 Jim Turner.
342  
343 This program is free software; you can redistribute it and/or modify it
344 under the terms of the the Artistic License (2.0). You may obtain a
345 copy of the full license at:
346  
347 L<http://www.perlfoundation.org/artistic_license_2_0>
348  
349 Any use, modification, and distribution of the Standard or Modified
350 Versions is governed by this Artistic License. By using, modifying or
351 distributing the Package, you accept this license. Do not use, modify,
352 or distribute the Package, if you do not accept this license.
353  
354 If your Modified Version has been derived from a Modified Version made
355 by someone other than you, you are nevertheless required to ensure that
356 your Modified Version complies with the requirements of this license.
357  
358 This license does not grant you the right to use any trademark, service
359 mark, tradename, or logo of the Copyright Holder.
360  
361 This license includes the non-exclusive, worldwide, free-of-charge
362 patent license to make, have made, use, offer to sell, sell, import and
363 otherwise transfer the Package with respect to any patent claims
364 licensable by the Copyright Holder that are necessarily infringed by the
365 Package. If you institute patent litigation (including a cross-claim or
366 counterclaim) against any party alleging that the Package constitutes
367 direct or contributory patent infringement, then this Artistic License
368 to you shall terminate on the date that such litigation is filed.
369  
370 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
371 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
372 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
373 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
374 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
375 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
376 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
377 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
378  
379 =cut
380  
381 package StreamFinder::SermonAudio;
382  
383 use strict;
384 use warnings;
385 use URI::Escape;
386 use HTML::Entities ();
387 use LWP::UserAgent ();
388 use parent 'StreamFinder::_Class';
389  
390 my $DEBUG = 0;
391  
392 sub new
393 {
394 my $class = shift;
395 my $url = shift;
396  
397 return undef unless ($url);
398  
399 my $self = $class->SUPER::new('SermonAudio', @_);
400 $DEBUG = $self->{'debug'} if (defined $self->{'debug'});
401  
402 while (@_) {
403 if ($_[0] =~ /^\-?debug$/o) {
404 shift;
405 $DEBUG = (defined($_[0]) && $_[0] =~/^[0-9]$/) ? shift : 1;
406 } elsif ($_[0] =~ /^\-?secure$/o) {
407 shift;
408 $self->{'secure'} = (defined $_[0]) ? shift : 1;
409 } elsif ($_[0] =~ /^\-?quality$/o) {
410 shift;
411 $self->{'quality'} = (defined $_[0]) ? shift : 'any';
412 } elsif ($_[0] =~ /^\-?speakericon$/o) {
413 shift;
414 $self->{'speakericon'} = (defined $_[0]) ? shift : 1;
415 } elsif ($_[0] =~ /^\-?notrim$/o) {
416 shift;
417 $self->{'notrim'} = (defined $_[0]) ? shift : 1;
418 } elsif ($_[0] =~ /^\-?nowebp$/o) {
419 shift;
420 $self->{'nowebp'} = (defined $_[0]) ? shift : 1;
421 } else {
422 shift;
423 }
424 }
425 $self->{'quality'} = 'any' unless (defined $self->{'quality'});
426 $self->{'speakericon'} = 0 unless (defined $self->{'speakericon'});
427 $self->{'notrim'} = 0 unless (defined $self->{'notrim'});
428 $self->{'nowebp'} = 0 unless (defined $self->{'nowebp'});
429  
430 my $isEpisode = 1;
431 $url =~ s#\\##g;
432 (my $url2fetch = $url);
433 $url2fetch =~ s#\?.*$## unless ($self->{'notrim'});
434 if ($url =~ /^https?\:/) { #FULL URL:
435 $self->{'id'} = $1 if ($url2fetch =~ m#\?SID\=([\d]+)#);
436 unless ($self->{'id'}) { #WE'RE ONE OF SERMONAUDIO'S ALTERNATE URLS:
437 $self->{'id'} = $1 if ($url2fetch =~ /sermonaudio/i && $url2fetch =~ m#([\d]+)\/?$#);
438 if ($url2fetch =~ m#\/speakers?\/#) {
439 $isEpisode = 0; #ASSUME WE'RE AN AUTHOR/PREACHER PAGE.
440 } elsif ($url2fetch =~ m#\/series\/#) {
441 $isEpisode = 0; #ASSUME WE'RE A SERIES (SERMON GROUP) PAGE.
442 } elsif ($url2fetch =~ m#\/broadcasters?\/([a-zA-Z0-9]+)#) {
443 $self->{'id'} = $1;
444 $isEpisode = 0; #ASSUME WE'RE A CHURCH PAGE.
445 } elsif ($self->{'id'}) {
446 $url2fetch = 'https://www.sermonaudio.com/sermoninfo.asp?SID='.$self->{'id'};
447 } elsif ($url2fetch =~ m#\bsourceid\=([^\?\&]+)$#) {
448 $self->{'id'} = $1;
449 $isEpisode = 0; #ASSUME WE'RE NOT AN EPISODE PAGE.
450 } elsif ($url2fetch =~ m#https://www.sermonaudio.com\/[a-z]+\/([^\?\&]+)$#) {
451 $self->{'id'} = $1;
452 $isEpisode = 0; #ASSUME WE'RE AN AUTHOR/PREACHER PAGE.
453 } else {
454 $self->{'id'} = 'sermonaudio';
455 $isEpisode = 0; #ASSUME WE'RE A SEARCH/FOUND PAGE.
456 }
457 }
458 } elsif ($url =~ /^\d\d\d\d\d\d\d\d+$/) { #(URL=###########)
459 $self->{'id'} = $url;
460 $url2fetch = "https://www.sermonaudio.com/sermoninfo.asp?SID=$url";
461 } elsif ($url =~ /^\d\d\d\d\d$/) { #5-DIGIT ID (AUTHOR/PREACHER PAGE)
462 $self->{'id'} = $url;
463 $isEpisode = 0; #WE'RE AN AUTHOR/PREACHER PAGE.
464 $url2fetch = "https://www.sermonaudio.com/speakers/$url";
465 } elsif ($url =~ /^\d\d\d\d\d\d$/) { #6-DIGIT ID (SERIES PAGE)
466 $self->{'id'} = $url;
467 $url2fetch = "https://www.sermonaudio.com/series/$url";
468 } elsif ($url =~ /^[a-z]+$/i) { #ALPHANUMERIC ID (CHURCH PAGE)
469 $self->{'id'} = $url;
470 $url2fetch = "https://www.sermonaudio.com/broadcasters/$url";
471 $isEpisode = 0;
472 } elsif ($url =~ m#\/#) { #KEYWORD/ID
473 $self->{'id'} = $url;
474 $url2fetch = "https://www.sermonaudio.com/$url";
475 $isEpisode = 0;
476 }
477 return undef unless ($self->{'id'});
478  
479 my $html = '';
480 my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}});
481 $ua->timeout($self->{'timeout'});
482 $ua->cookie_jar({});
483 $ua->env_proxy;
484 my $response;
485 my $tried = 0;
486  
487 TRYIT:
488 print STDERR "-${tried}(SermonAudio): FETCHING URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
489  
490 $response = $ua->get($url2fetch);
491 if ($response->is_success) {
492 $html = $response->decoded_content;
493 } else {
494 print STDERR $response->status_line if ($DEBUG);
495 }
496 print STDERR "-1: html=$html=\n" if ($DEBUG > 1);
497 print STDERR "---ID=".$self->{'id'}."= isEpisode=$isEpisode=\n" if ($DEBUG);
498 return undef unless ($self->{'id'} && $html);
499  
500 my $baseURL = ($html =~ m#\bhostname\:\"([^\"]+)#) ? $1 : 'https://www.sermonaudio.com';
501 $baseURL =~ s#^\/##;
502 $baseURL = 'https://' . $baseURL unless ($baseURL =~ m#^http#);
503 if ($isEpisode) {
504 print STDERR "-1: html=$html=\n" if ($DEBUG > 1);
505 return undef unless ($html && $self->{'id'}); #STEP 1 FAILED, INVALID PODCAST URL, PUNT!
506  
507 $self->{'genre'} = 'Sermon';
508 $self->{'albumartist'} = $url2fetch;
509 if ($self->{'quality'} !~ /audio/i && $html =~ s#\<video.+?src\=\"([^\"]+)##s) {
510 my $mediaurl = $1;
511 unless ($self->{'secure'} && $mediaurl !~ /^https/o) {
512 $mediaurl =~ s#\?.*$## unless ($self->{'notrim'}); #STRIP OFF ANY EXTRA ARGS
513 push @{$self->{'streams'}}, $mediaurl;
514 print STDERR "--stream found=$mediaurl=\n" if ($DEBUG);
515 $self->{'cnt'}++;
516 }
517 }
518 if ($html =~ s#\<audio.+?src\=\"([^\"]+)##s) {
519 my $audiourl = $1;
520 unless ($self->{'secure'} && $audiourl !~ /^https/o) {
521 $audiourl =~ s#\?.*$## unless ($self->{'notrim'}); #STRIP OFF ANY EXTRA ARGS
522 push @{$self->{'streams'}}, $audiourl;
523 print STDERR "--stream found=$audiourl=\n" if ($DEBUG);
524 $self->{'cnt'}++;
525 }
526 }
527 $self->{'total'} = $self->{'cnt'};
528 # return undef unless ($self->{'cnt'} > 0);
529  
530 $html =~ s/\\\"/\&quot\;/gs;
531 $self->{'title'} = $1 if ($html =~ m#\<title\>\s*([^\|\<]+)#si);
532 $self->{'title'} ||= $1 if ($html =~ m#\"(?:og|twitter)\:title\"\s+content\=\"([^\"]+)#s);
533 $self->{'description'} = $1 if ($html =~ m#subtitle\:\w\,moreInfoText\:\"([^\"]+)#s);
534 $self->{'description'} ||= $1 if ($html =~ m#\-\-md\-spacing\:1em\;\"\>\<p\>(.+?)\<\/p\>#is);
535 $self->{'description'} ||= $self->{'title'};
536 $self->{'genre'} = $1 if ($html =~ m#\>\s*Category\s*\<\/td\>\s*\<td[^\>]*\>(.+?)\<\/td\>#s);
537 $self->{'genre'} =~ s/\<[^\>]+\>//gs;
538 $self->{'genre'} =~ s/^\s+//s;
539 $self->{'genre'} =~ s/\s+$//s;
540 if ($html =~ m#(?:\"uploadDate\"\:|\<time\s+datetime\=)\"([^\"]+)#
541 || $html =~ m#\>Date\<\/td\>\s*\<td[^\>]*\>(.+?)\<\/td\>#s) {
542 $self->{'created'} = $1;
543 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
544 }
545 foreach my $field (qw(title description)) {
546 $self->{$field} = HTML::Entities::decode_entities($self->{$field});
547 $self->{$field} = uri_unescape($self->{$field});
548 $self->{$field} =~ s/(?:\%|\\?u?00)([0-9A-Fa-f]{2})/chr(hex($1))/eg;
549 }
550 $self->{'iconurl'} = $1 if ($html =~ m#\"(?:og|twitter)\:image\:secure_url\"\s+content\=\"([^\"]+)#s);
551 $self->{'iconurl'} ||= $1 if ($html =~ m#\"(?:og|twitter)\:image(?:\:url)?\"\s+content\=\"([^\"]+)#s);
552 if ($html =~ s#\<div\s+class\=\"absolute-fill\s+bg\-black(.+?)\<\/div\>##s) {
553 my $data = $1;
554 $self->{'imageurl'} = $1 if ($data =~ m#\"background\-image\:url\((http[^\)]+)#s);
555 }
556  
557 #BEGIN LIKELY-DEPRECIATED:
558 if ($html =~ m#\<span\s+class\=\"bg\-cover.+?style\=\"background\-image\:url\((http[^\)]+)#s) {
559 $self->{'articonurl'} = $1;
560 } elsif ($html =~ s#<div class="bg-cover[^\"]+\"\s+style\=\"background\-image\:url\((http[^\)]+)\)##s) {
561 $self->{'articonurl'} = $1;
562 }
563 $self->{'iconurl'} ||= $1 if ($html =~ s#\<img\s+src\=\"(http[^\"]+)##s);
564 $self->{'artimageurl'} = $1 if ($html =~ s#\<img\s+src\=\"(http[^\"]+)##s);
565 $self->{'imageurl'} ||= $self->{'iconurl'};
566 $self->{'artimageurl'} = 'https:' . $self->{'artimageurl'} if ($self->{'artimageurl'} =~ m#^\/\/#);
567 $self->{'articonurl'} ||= $self->{'artimageurl'};
568
569 if ($html =~ s#\<a\s+href\=\"([^\"]*?\/broadcasters?\/[^\/]+\/)\"\s+class\=\"link\"[^\>]*\>([^\<]+)##s) {
570 my ($one, $two) = ($1, $2);
571 $one = $baseURL . $one if ($one =~ m#^\/broadcaster#);
572 $self->{'albumartist'} = "$two - $one";
573 }
574 if ($html =~ s#\<a\s+href\=\"([^\"]*?\/speakers?\/\d+\/)\"\s+class\=\"link\"[^\>]*\>([^\<]+)##s) {
575 my ($one, $two) = ($1, $2);
576 $one = $baseURL . $one if ($one =~ m#^\/speaker#);
577 $self->{'artist'} = $two;
578 unless ($self->{'albumartist'} && $self->{'albumartist'} !~ m#$one#) {
579 $self->{'albumartist'} ||= $one;
580 }
581 }
582 if (!$self->{'artist'} && $html =~ m#\<meta\s+name\=\"description\"\s+content\=\"([^\"]+)"#s) {
583 ($self->{'artist'} = $1) =~ s/\s+\|.*$//;
584 }
585 #END LIKELY-DEPRECIATED
586  
587 #NEWER? JASON TAKES PRECEDENCE FOR ARTIST & ALBUMARTIST DATA:
588 if ($html =~ s#\{"\@type":"Person",([^\}]+)\}##s) {
589 my $artistStuff = $1;
590 my $artistURL = ($artistStuff =~ m#\"\@id\"\:\"([^\"]+)#) ? $1 : '';
591 $artistURL ||= $1 if ($artistStuff =~ m#\"url\"\:\"([^\"]+)#);
592 $self->{'artist'} = $1 if ($artistStuff =~ m#\"name\"\:\"([^\"]+)#);
593 if ($artistURL) {
594 $self->{'artist'} .= ' - ' if ($self->{'artist'});
595 $self->{'artist'} .= $artistURL;
596 }
597 $self->{'artimageurl'} ||= $1 if ($artistStuff =~ m#\"image\"\:\"([^\"]+)#);
598 }
599 if ($html =~ s#\{"\@type":"Organization",([^\}]+)\}##s) {
600 my $channelStuff = $1;
601 $self->{'albumartist'} = ($channelStuff =~ m#\"\@id\"\:\"([^\"]+)#) ? $1 : '';
602 $self->{'album'} = $1 if ($channelStuff =~ m#\"name\"\:\"([^\"]+)#);
603 $self->{'articonurl'} = $1 if ($channelStuff =~ m#\"image\"\:\"([^\"]+)#);
604 }
605  
606 if ($self->{'speakericon'} && $self->{'artimageurl'}) { #USE PREACHER'S THUMBNAIL (REVERSE articon AND artimage):
607 my $x = $self->{'artimageurl'};
608 $self->{'artimageurl'} = $self->{'articonurl'};
609 $self->{'articonurl'} = ($html =~ s#\<\/i\>\s+\<img\s+src\=\"(http[^\"]+)##s)
610 ? $1 : $x;
611 }
612 $self->{'album'} = $1 if ($html =~ m#\<meta\s+name\=\"description\"\s+content\=\"([^\"]+)#s);
613 $self->{'album'} ||= $1 if ($html =~ m#\<meta\s+property\=\"og\:description\"\s+content\=\"([^\"]+)#s);
614 $self->{'album'} =~ s#$self->{'artist'}\s*\|\s*## if ($self->{'artist'});
615 $self->{'albumartist'} ||= $1 if ($html =~ m#href\=\"([^\"]+)\"\>Web\<\/a\>#s);
616 $self->{'articonurl'} ||= $self->{'artimageurl'};
617 $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : '';
618  
619 if ($self->{'notrim'}) {
620 if ($self->{'nowebp'}) {
621 foreach my $field (qw(iconurl imageurl articonurl artimageurl)) {
622 $self->{$field} =~ s#[\&\?]webp\=[a-z]+##;
623 $self->{$field} =~ s#\.(png|jpe?g|gif)\&#\.$1\?#;
624 }
625 }
626 } else {
627 foreach my $field (qw(iconurl imageurl articonurl artimageurl)) {
628 my $webp = ($self->{$field} =~ /[\&\?](webp\=[a-z]+)/) ? $1 : 0;
629 $self->{$field} =~ s#\.(png|jpe?g|gif)[\&\?].*$#\.$1#;
630 $self->{$field} .= "?$webp" if ($webp && !$self->{'nowebp'});
631 }
632 }
633 } else {
634 print STDERR "--NOT EPISODE, tried=$tried=\n" if ($DEBUG);
635 if ($tried < 2) { #WE'RE A PODCAST PAGE!:
636 #NOTE: SERMONAUDIO PODCAST PAGES DO NOT HAVE STREAMS, ONLY EPISODE-IDS+TITLES, SO
637 #WE CAN'T CONSTRUCT A PLAYLIST, BUT ONLY GRAB THE 1ST EPISODE AND TRY AND FETCH THAT: :(
638 ++$tried;
639 $html =~ s#^.+?\<div\s+class\=\"wrapper\-element\s##s;
640 if ($html =~ s#\<a\s+href\=\"([^\"]*?\/sermons?\/)(\d+)\/?\"##s) {
641 my $one = $1;
642 $self->{'id'} = $2;
643 $one = $baseURL . $one if ($one =~ m#^\/sermon#);
644 $isEpisode = 1;
645 $url2fetch = $one . $self->{'id'};
646 print STDERR "-!!!!- RETRY w/1ST EPISODE ID=$url2fetch= TITLE=".$self->{'title'}."=\n" if ($DEBUG);
647 goto TRYIT;
648 } elsif ($html =~ s#\<a\s+href\=\"([^\"]*?\/series\/)(\d+)\/?\"##s) {
649 my $one = $1;
650 $self->{'id'} = $2;
651 $one = $baseURL . $one if ($one =~ m#^\/series#);
652 $isEpisode = 0;
653 $url2fetch = $one . $self->{'id'};
654 print STDERR "-!!!!- RETRY w/1ST SERIES ID=$url2fetch= TITLE=".$self->{'title'}."=\n" if ($DEBUG);
655 goto TRYIT;
656 }
657 }
658 return undef unless ($self->{'total'} > 0); #NO VALID PAGE FOUND!
659 }
660  
661 if ($DEBUG) {
662 foreach my $i (sort keys %{$self}) {
663 print STDERR "--KEY=$i= VAL=".$self->{$i}."=\n";
664 }
665 print STDERR "--SUCCESS: 1st stream=".$self->{'Url'}."= total=".$self->{'total'}."=\n"
666 if ($self->{'cnt'} > 0);
667 }
668  
669 $self->_log($url);
670  
671 bless $self, $class; #BLESS IT!
672  
673 return $self;
674 }
675  
676 1