StreamFinder/PodcastAddict.pm untested

filter: Statementstmt 0.0% 0 / 211 Branchbran 0.0% 0 / 150 Conditioncond 0.0% 0 / 47 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 447 CC 76 SCAR 86.0
CC
76
Cov
0%
new
5852.0
BEGIN
2.0
BEGIN
2.0
CRAP 5424.0
1 =head1 NAME
2  
3 StreamFinder::PodcastAddict - Fetch actual raw streamable URLs on podcastaddict.com
4  
5 =head1 AUTHOR
6  
7 This module is Copyright (C) 2023-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::PodcastAddict;
26  
27 die "..usage: $0 ID|URL\n" unless ($ARGV[0]);
28  
29 my $podcast = new StreamFinder::PodcastAddict($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 $artist = $podcast->{'artist'};
54  
55 print "Artist=$artist\n" if ($artist);
56
57 my $genre = $podcast->{'genre'};
58  
59 print "Genre=$genre\n" if ($genre);
60
61 my $icon_url = $podcast->getIconURL();
62  
63 if ($icon_url) { #SAVE THE ICON TO A TEMP. FILE:
64  
65 print "Icon URL=$icon_url=\n";
66  
67 my ($image_ext, $icon_image) = $podcast->getIconData();
68  
69 if ($icon_image && open IMGOUT, ">/tmp/${podcastID}.$image_ext") {
70  
71 binmode IMGOUT;
72  
73 print IMGOUT $icon_image;
74  
75 close IMGOUT;
76  
77 print "...Icon image downloaded to (/tmp/${podcastID}.$image_ext)\n";
78  
79 }
80  
81 }
82  
83 my $stream_count = $podcast->count();
84  
85 print "--Stream count=$stream_count=\n";
86  
87 my @streams = $podcast->get();
88  
89 foreach my $s (@streams) {
90  
91 print "------ stream URL=$s=\n";
92  
93 }
94  
95 =head1 DESCRIPTION
96  
97 StreamFinder::PodcastAddict accepts a valid podcast ID or URL on
98 PodcastAddict.com and returns the actual stream URL(s), title, and cover art
99 icon. The purpose is that one needs one of these URLs in order to have the
100 option to stream the podcast in one's own choice of media player software
101 rather than using their web browser and accepting any / all flash, ads,
102 javascript, cookies, trackers, web-bugs, and other crapware that can come with
103 that method of play. The author uses his own custom all-purpose media player
104 called "fauxdacious" (his custom hacked version of the open-source "audacious"
105 audio player). "fauxdacious" can incorporate this module to decode and play
106 PodcastAddict.com streams.
107  
108 One or more stream URLs can be returned for each podcast.
109  
110 =head1 SUBROUTINES/METHODS
111  
112 =over 4
113  
114 =item B<new>(I<ID> | I<url> [, I<-secure> [ => 0|1 ]] [, I<-debug> [ => 0|1|2 ]])
115  
116 Accepts a podcastaddict.com podcast ID or URL and creates and returns a
117 a new podcast object, or I<undef> if the URL is not a valid podcast, or no streams
118 are found. The URL can be the full URL, ie.
119 I<https://podcastaddict.com/episode/>B<episode-id#>,
120 I<https://podcastaddict.com/podcast/>B<podcast-id#>, or just
121 I<podcast-id#> or I<podcast-id/episode-id>.
122  
123 The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>). If 1
124 then only secure ("https://") streams will be returned.
125  
126 DEFAULT I<-secure> is 0 (false) - return all streams (http and https).
127  
128 Additional options:
129  
130 I<-log> => "I<logfile>"
131  
132 Specify path to a log file. If a valid and writable file is specified, A line will be
133 appended to this file every time one or more streams is successfully 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 stream found.
142 [site]: The site name (PodcastAddict). [url]: The url searched for streams.
143 [time]: Perl timestamp when the line was logged. [title], [artist], [album],
144 [description], [year], [genre], [total], [albumartist]: The corresponding field data
145 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. 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 I<"playlist"> is specified, the number of episodes returned in the
166 playlist is returned (the playlist can have more than one item if a
167 podcast page URL is specified).
168  
169 =item $podcast->B<getID>()
170  
171 Returns the podcast's PodcastAddict ID (default). For podcasts, the PodcastAddict ID
172 is a single value. For individual podcast episodes it's two values
173 separated by a slash ("/").
174  
175 =item $podcast->B<getTitle>(['desc'])
176  
177 Returns the podcast's title, or (long description). Podcasts
178 on PodcastAddict can have separate descriptions, but for podcasts,
179 it is always the podcast's title.
180  
181 =item $podcast->B<getIconURL>(['artist'])
182  
183 Returns the URL for the podcast's "cover art" icon image, if any.
184 If B<'artist'> is specified, the channel artist's icon url is returned,
185 if any.
186  
187 =item $podcast->B<getIconData>(['artist'])
188  
189 Returns a two-element array consisting of the extension (ie. "png",
190 "gif", "jpeg", etc.) and the actual icon image (binary data), if any.
191 If B<'artist'> is specified, the channel artist's icon data is returned,
192 if any.
193  
194 =item $podcast->B<getImageURL>()
195  
196 Returns the URL for the podcast's "cover art" (usually larger)
197 banner image.
198  
199 =item $podcast->B<getImageData>()
200  
201 Returns a two-element array consisting of the extension (ie. "png",
202 "gif", "jpeg", etc.) and the actual podcast's banner image (binary data).
203  
204 =item $podcast->B<getType>()
205  
206 Returns the podcast's type ("PodcastAddict").
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/PodcastAddict/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 I<~/.config/StreamFinder/config>.
236  
237 =item ~/.config/StreamFinder/config
238  
239 Optional text file for specifying various configuration options.
240 Each option is specified on a separate line in the format below:
241  
242 'option' => 'value' [,]
243  
244 and the options are loaded into a hash used by all sites
245 (submodules) that support them. Valid options include
246 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
247  
248 =back
249  
250 NOTE: Options specified in the options parameter list of the I<new()>
251 function will override those corresponding options specified in these files.
252  
253 =head1 KEYWORDS
254  
255 podcastaddict
256  
257 =head1 DEPENDENCIES
258  
259 L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent>
260  
261 =head1 RECCOMENDS
262  
263 wget
264  
265 =head1 BUGS
266  
267 Please report any bugs or feature requests to C<bug-streamFinder-iheartradio at rt.cpan.org>, or through
268 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-PodcastAddict>. I will be notified, and then you'll
269 automatically be notified of progress on your bug as I make changes.
270  
271 =head1 SUPPORT
272  
273 You can find documentation for this module with the perldoc command.
274  
275 perldoc StreamFinder::PodcastAddict
276  
277 You can also look for information at:
278  
279 =over 4
280  
281 =item * RT: CPAN's request tracker (report bugs here)
282  
283 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-PodcastAddict>
284  
285 =item * AnnoCPAN: Annotated CPAN documentation
286  
287 L<http://annocpan.org/dist/StreamFinder-PodcastAddict>
288  
289 =item * Search CPAN
290  
291 L<http://search.cpan.org/dist/StreamFinder-PodcastAddict/>
292  
293 =back
294  
295 =head1 LICENSE AND COPYRIGHT
296  
297 Copyright 2023-2026 Jim Turner.
298  
299 This program is free software; you can redistribute it and/or modify it
300 under the terms of the the Artistic License (2.0). You may obtain a
301 copy of the full license at:
302  
303 L<http://www.perlfoundation.org/artistic_license_2_0>
304  
305 Any use, modification, and distribution of the Standard or Modified
306 Versions is governed by this Artistic License. By using, modifying or
307 distributing the Package, you accept this license. Do not use, modify,
308 or distribute the Package, if you do not accept this license.
309  
310 If your Modified Version has been derived from a Modified Version made
311 by someone other than you, you are nevertheless required to ensure that
312 your Modified Version complies with the requirements of this license.
313  
314 This license does not grant you the right to use any trademark, service
315 mark, tradename, or logo of the Copyright Holder.
316  
317 This license includes the non-exclusive, worldwide, free-of-charge
318 patent license to make, have made, use, offer to sell, sell, import and
319 otherwise transfer the Package with respect to any patent claims
320 licensable by the Copyright Holder that are necessarily infringed by the
321 Package. If you institute patent litigation (including a cross-claim or
322 counterclaim) against any party alleging that the Package constitutes
323 direct or contributory patent infringement, then this Artistic License
324 to you shall terminate on the date that such litigation is filed.
325  
326 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
327 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
328 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
329 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
330 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
331 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
332 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
333 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
334  
335 =cut
336  
337 package StreamFinder::PodcastAddict;
338  
339 use strict;
340 use warnings;
341 use URI::Escape;
342 use HTML::Entities ();
343 use LWP::UserAgent ();
344 use parent 'StreamFinder::_Class';
345  
346 my $DEBUG = 0;
347  
348 sub new
349 {
350 my $class = shift;
351 my $url = shift;
352  
353 return undef unless ($url);
354  
355 my $self = $class->SUPER::new('PodcastAddict', @_);
356 $DEBUG = $self->{'debug'} if (defined $self->{'debug'});
357 my $baseURL = 'https://podcastaddict.com';
358 $self->{'id'} = '';
359 $self->{'_podcast_id'} = '';
360 my $url2fetch = $url;
361 my $tried = 0;
362 my @epiTitles = ();
363 my @epiStreams = ();
364 my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}});
365 $ua->timeout($self->{'timeout'});
366 $ua->cookie_jar({});
367 $ua->env_proxy;
368 my $html = '';
369 my $response;
370 my $isEpisode;
371  
372 #NOTE: THE ONLY "EPISODE" URLS NOW USED BY PODCASTADDICT ARE THE URI-ESCAPED ONES CONTAINING
373 #THE STREAM URL EMBEDDED IN THEIR PODCAST PAGES (WITH NO EPISODE-ID#) AND HAVE THE FORMAT (EXAMPLE):
374 #"https://podcastaddict.com/episode/https%3A%2F%2Fpscrb.fm%2Frss%2Fp%2Fpdst.fm%2Fe%2Farttrk.com%2Fp%2FABMA5%2Faudioboom.com%2Fposts%2F8280770.mp3%3Fmodified%3D1681401989%26sid%3D2399216%26source%3Drss&podcastId=1719501"
375 #TO PREVENT USING THE FULL STREAM-URL FOR THE UNIQUE EPISODE-ID#, WE JUST USE THE PODCAST-ID#.
376 #NO KNOWN WAY EXISTS FOR FETCHING EPISODES VIA JUST A PODCAST AND EPISODE-ID, THEREFORE WE CAN'T
377 #DETERMINE WHAT THE REAL EPISODE-ID IS, EXCEPT ON PODCAST PAGES STILL USING THE CLASSIC, UNESCAPED
378 #EPISODE-URLS (format: "https://podcastaddict.com/episode/<episode-ID-number>")!
379 #(NOTE ALSO THAT THE "&podcastId=#####" PART OF THE URL IS *NOT* THE SEARCHABLE PODCAST-ID EITHER,
380 #BUT RATHER THE PODCAST ARTIST'S/CHANNEL ID#)!
381  
382 TRYIT:
383 if ($url2fetch =~ m#^([0-9]+)$#) { #ASSUME PODCAST-ID, AS EPISODES NO LONGER HAVE DESCERNABLE IDs:
384 $self->{'id'} = $1;
385 $url2fetch = "$baseURL/podcast/".$self->{'id'};
386 $isEpisode = 0;
387 print STDERR "-1- PODCAST ID, ID=".$self->{'id'}."= found ($url2fetch)\n" if ($DEBUG);
388 } elsif ($url2fetch =~ m#\/episode\/https?#) { #(LONG) EPISODE URL (ON PODCAST PAGES, ESCAPED):
389 $url2fetch = uri_escape($url2fetch) unless($url2fetch =~ m#\%3A#); #PODCASTADDICT EPISODE URLS NOW MUST BE URI-ESCAPED!
390 #$self->{'id'} IS NOT EMBEDDED OR DETERMINABLE, WILL SET TO PODCAST-ID LATER!
391 $isEpisode = 1;
392 print STDERR "-2- EPISODE URL, ID=UNKNOWN= found ($url2fetch)\n" if ($DEBUG);
393 } elsif ($url2fetch =~ m#\/episode\/(\d+)\/?$#) { #CLASSIC (SHORT) EPISODE URL WITH ID. (DEPRECIATED)
394 $self->{'id'} = $2; #CLASSIC EPISODE URLS HAVE A PROPER EPISODE-ID EMBEDDED!
395 $isEpisode = 1;
396 print STDERR "-3- CLASSIC EPISODE URL, ID=".$self->{'id'}."= found ($url2fetch)\n" if ($DEBUG);
397 } elsif ($url2fetch =~ m#\/podcast\/([^\/]+)#) { #PODCAST URL
398 $self->{'id'} = $1; #USE UNIQUE NUMBER AS A MADE-UP "EPISODE-ID"
399 $self->{'id'} = $1 if ($url2fetch =~ m#\/(\d\d\d\d+)$#);
400 $isEpisode = 0;
401 print STDERR "-4- PODCAST URL, ID=".$self->{'id'}."= found ($url2fetch)\n" if ($DEBUG);
402 } elsif ($url2fetch =~ m#^([^\/]+)\/(\d+)#) { #EPISODE-ID:
403 my $podcastID = $1;
404 my $episodeID = $2;
405 $url2fetch = "$baseURL/$podcastID/episode/$episodeID";
406 $self->{'id'} = "$podcastID/$episodeID"; #USE UNIQUE NUMBER AS A MADE-UP "EPISODE-ID"
407 $isEpisode = 1;
408 print STDERR "-5- EPISODE ID=".$self->{'id'}."= found ($url2fetch)\n" if ($DEBUG);
409 } else {
410 return undef; #INVALID ID/URL!
411 }
412  
413 $html = '';
414 print STDERR "-0(PodcastAddict): ($tried) FETCHING URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
415 $response = $ua->get($url2fetch);
416 if ($response->is_success) {
417 $html = $response->decoded_content;
418 } else {
419 print STDERR $response->status_line if ($DEBUG);
420 }
421 print STDERR "-1: html=$html=\n" if ($DEBUG > 1);
422 return undef unless ($html); #STEP 1 FAILED, INVALID PODCAST URL, PUNT!
423  
424 $self->{'genre'} = 'Podcast';
425 print STDERR "---ID=".$self->{'id'}."= tried=$tried=\n" if ($DEBUG);
426 unless ($isEpisode) { #PODCAST PAGE ID (FETCH XML PAGE):
427 print STDERR "-----WE'RE A PODCAST PAGE: ID=".$self->{'id'}."!\n" if ($DEBUG);
428  
429 #FETCH PODCAST-WIDE METADATA HERE!:
430 $self->{'albumartist'} = $url2fetch;
431 $self->{'albumartist'} = $1 if ($html =~ m#\<meta\s+property\=\"(?:og|twitter)\:url\"\s+content\=\"([^\"]+)\"\>#s);
432 $self->{'id'} = $1 if ($self->{'albumartist'} =~ m#(\d+)\/?$#);
433 if ($html =~ m#\<div\s+class\=\"headerThumbnail\"\>(.+?)\<\/div\>#s) {
434 my $thumbnaildata = $1;
435 $self->{'articonurl'} = $1 if ($thumbnaildata =~ m#\<img\s+src\=\"([^\"]+)#s);
436 $self->{'iconurl'} = $self->{'articonurl'};
437 $self->{'imageurl'} = $self->{'articonurl'};
438 }
439 $self->{'artist'} = $1 if ($html =~ m#name\=\"author\"\s+class\=\"[\w\-]+\"\s+value\=\"([^\"]+)#);
440 $self->{'album'} = $1 if ($html =~ m#\<meta\s+itemprop\=\"name\"\s+content\=\"([^\"]+)#s);
441  
442 #WE NEED TO EXTRACT 1ST EPISODE ID, BUT WHILST AT IT, GO AHEAD AND FETCH PLAYLIST DATA HERE TOO!:
443 my $ep1id = '';
444 while ($html =~ s#^.+?\<div\s+class\=\"cellcontent\"\s+itemscope\>##s) {
445 if ($html =~ m#\<a\s+class\=\"clickeableItem\"\s+href\=\"([^\"]+)#) {
446 my $streamURL = $1;
447 (my $stream = uri_unescape($streamURL)) =~ s#^https?\:\/\/podcastaddict\.\w+\/episode\/##o;
448 next if ($self->{'secure'} && $stream !~ /^https/o);
449  
450 if ($ep1id) {
451 $stream =~ s#\?utm_source=Podcast.*$##o;
452 $stream =~ s#[\?\&]from\=PodcastAddict$##o;
453 $stream =~ s#\.mp3\?.*$#\.mp3#o;
454 if ($html =~ m#\<h3[^\>]*\>(.+?)\<\/h3>#o) {
455 (my $title = $1) =~ s#\<[^\>]*\>##go;
456 push @epiStreams, $stream;
457 push @epiTitles, $title;
458 }
459 } else {
460 $ep1id = $streamURL;
461 }
462 }
463 }
464 if ($ep1id) { #WE FOUND AN EPISODE, SO RETRY (TO FETCH THE EPISODE PAGE):
465 ++$tried;
466 $url2fetch = $ep1id;
467 print STDERR "-!!!!- RETRY w/1ST EPISODE URL=$url2fetch=\n" if ($DEBUG);
468 goto TRYIT;
469 } else {
470 print STDERR "e:Podcast ($url2fetch) has no episodes!\n";
471 }
472 } else { #EPISODE PAGE ID (NOW GET THE DETAILED EPISODE METADATA & WE'RE DONE):
473 my $epid = $1 if ($html =~ m#\<meta\s+name="(?:og|twitter)\:url\"\s+content\=\"([^\"]+)#);
474 $self->{'id'} = "$1/$2" if ($epid && $epid =~ m#^$baseURL\/([^\/]+)\/episode\/([^\/]+)#);
475 print STDERR "-----WE'RE AN EPISODE PAGE: ID=".$self->{'id'}."!\n" if ($DEBUG);
476 if ($html =~ m#\<h1[^\>]*\>(.+?)\<\/h1\>#s) {
477 my $h1data = $1;
478 if ($h1data =~ m#\<a\s+href\=\"([^\"]+)#s) {
479 $self->{'albumartist'} = $1;
480 my $channelID = $1 if ($self->{'albumartist'} =~ m#\/(\d+)$#); #USE PODCAST'S ID FOR ARTIST ICON.
481 $self->{'id'} ||= $channelID; #USE PODCAST'S ID SINCE NEWER (LONG) EPISODES DON'T HAVE ONE.
482 $self->{'articonurl'} ||= "$baseURL/cache/artwork/thumb/$channelID";
483 }
484 #NOTE: podcastaddict DOES NOT INCLUDE THE PODCAST ALBUM'S NAME IN EPISODE PAGES.
485 #IF WE ALREADY HAVE (THE CORRECT) ALBUM FIELD, IT MEANS WE FETCHED A PODCAST
486 #PAGE FIRST AND HERE WE'RE FETCHING THE 1ST EPISODE, SO LEAVE 'EM ALONE (THEY'RE CORRECT)!:
487 #(FOR REFERENCE, NORMALLY THE "ARTIST" IS THE PODCAST'S ARTIST'S NAME, AND ALBUM IS THE
488 #PODCAST'S NAME (AN ARTIST CAN HAVE MULTIPLE PODCASTS & A PODCAST CAN HAVE MULT. EPISODES)!)
489 $self->{'album'} = $1 if ($h1data =~ m#\>(.+?)\<\/a\>#s);
490 }
491 $self->{'artist'} = $1 if ($html =~ m# by ([^\"]+?) on Podcast Addict\"#s);
492 $self->{'title'} = $1 if ($html =~ m#\<h2[^\>]*\>(.+?)\<\/h2>#s);
493 $self->{'title'} ||= $1 if ($html =~ m#\<meta\s+property\=\"(?:og|twitter)\:title\"\s+content\=\"([^\"]+)#s);
494 $self->{'imageurl'} = $1 if ($html =~ m#Artwork\"\s+src\=\"([^\"]+)#s);
495 $self->{'imageurl'} ||= $1 if ($html =~ m#\<meta\s+property\=\"og\:image\"\s+content\=\"([^\"]+)#);
496 $self->{'iconurl'} = $self->{'imageurl'};
497 $self->{'articonurl'} ||= $self->{'imageurl'};
498 if ($html =~ m#\<i class\=\"fa fa\-calendar\"\>\<\/i\>(.*?)(\d\d\d\d)\<\/span\>#) {
499 $self->{'year'} = $2;
500 ($self->{'created'} = $1 . $2) =~ s/^\s+//;
501 }
502 $self->{'description'} = $1 if ($html =~ m#\<meta\s+property\=\"(?:og|twitter)\:description\"\s+content\=\"(.+?)\"\s*\>#);
503 while ($html =~ s#\<video(.+?)</video>##sio) { #GRAB ANY VIDEO STREAMS (PODCASTADDICT SUPPORTS VIDEO PODCASTS!):
504 my $videodata = $1;
505 my $stream = $1 if ($videodata =~ m#src\=\"([^\"]+)#s);
506 if ($stream) {
507 next if ($self->{'secure'} && $stream !~ /^https/o);
508  
509 $stream =~ s#\?utm\_source\=.*$##o;
510 $stream =~ s#\&from\=PodcastAddict##o;
511 $stream =~ s#[\?\&]from\=PodcastAddict$##o;
512 $stream =~ s#\.mp3\?.*$#\.mp3#o;
513 push @{$self->{'streams'}}, $stream;
514 $self->{'cnt'}++;
515 }
516 }
517 while ($html =~ s#\<audio(.+?)</audio>##sio) { #GRAB ANY AUDIO STREAMS:
518 my $audiodata = $1;
519 my $stream = $1 if ($audiodata =~ m#src\=\"([^\"]+)#s);
520 if ($stream) {
521 next if ($self->{'secure'} && $stream !~ /^https/o);
522  
523 $stream =~ s#\?utm\_source\=.*$##o;
524 $stream =~ s#[\?\&]from\=PodcastAddict$##o;
525 $stream =~ s#\.mp3\?.*$#\.mp3#o;
526 push @{$self->{'streams'}}, $stream;
527 $self->{'cnt'}++;
528 }
529 }
530 #FALLBACK TO JSON, (IN CASE ANYTHING'S MISSING):
531 if ($html =~ s#\<script\s+type\=\"application\/ld\+json\"\s*\>##s) {
532 if ($html =~ s#\"name\"\:\s+\"([^\"]+)\"\,##s) {
533 $self->{'title'} ||= $1;
534 }
535 if ((!$self->{'created'} || !$self->{'year'})
536 && $html =~ s#\"datePublished\"\:\s*\"([^\"]+)\"\,##s) {
537 $self->{'created'} = $1;
538 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
539 }
540 $self->{'description'} ||= $1
541 if ($html =~ s#\"description\"\:\s*\"([^\"]+)\"\,##s);
542 if ($self->{'cnt'} <= 0
543 && $html =~ s#\"contentUrl\"\:\s*\"(https?\:\/\/[^\"]+)\"##s) {
544 my $stream = $1;
545 if ($stream) {
546 unless ($self->{'secure'} && $stream !~ /^https/o) {
547 $stream =~ s#\?utm\_source\=.*$##o;
548 $stream =~ s#[\?\&]from\=PodcastAddict$##o;
549 $stream =~ s#\.mp3\?.*$#\.mp3#o;
550 print STDERR "-----FOUND LAST-DITCH STREAM=$stream=!\n"
551 if ($DEBUG);
552 push @{$self->{'streams'}}, $stream;
553 $self->{'cnt'}++;
554 }
555 }
556 }
557 $self->{'album'} ||= $1 if ($html =~ s#\"name\"\:\s*\"([^\"]+)\"\,##s);
558 }
559 }
560  
561 $self->{'total'} = $self->{'cnt'};
562 $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : '';
563 foreach my $i (qw(title artist album description genre)) {
564 $self->{$i} = HTML::Entities::decode_entities($self->{$i});
565 $self->{$i} = uri_unescape($self->{$i});
566 $self->{$i} =~ s/(?:\%|\\[ux\%]?00|\bu00)([0-9A-Fa-f]{2})/chr(hex($1))/egs;
567 }
568  
569 #GENERATE EXTENDED-M3U PLAYLIST (NOTE: MAY NOT BE ABLE TO UNTIL USER CALLS $podcast->get('playlist')!):
570 if ($self->{'cnt'} > 0) {
571 $self->{'playlist'} = "#EXTM3U\n";
572 $self->{'playlist'} = "#EXTM3U\n";
573 $self->{'playlist'} .= "#EXTINF:-1, " . $self->{'title'} . "\n";
574 $self->{'playlist'} .= "#EXTART:" . $self->{'artist'} . "\n"
575 if ($self->{'artist'});
576 $self->{'playlist'} .= "#EXTALB:" . $self->{'album'} . "\n"
577 if ($self->{'album'});
578 $self->{'playlist'} .= "#EXTGENRE:" . $self->{'genre'} . "\n";
579 $self->{'playlist'} .= ${$self->{'streams'}}[0] . "\n";
580 $self->{'playlist_cnt'} = 1;
581 if ($#epiStreams >= 0) {
582 $self->{'playlist_cnt'} += scalar @epiStreams;
583 for (my $i=0;$i<=$#epiStreams;$i++) {
584 last if ($i > $#epiTitles);
585 $self->{'playlist'} .= "#EXTINF:-1, " . $epiTitles[$i] . "\n";
586 $self->{'playlist'} .= "#EXTART:" . $self->{'artist'} . "\n"
587 if ($self->{'artist'});
588 $self->{'playlist'} .= "#EXTALB:" . $self->{'album'} . "\n"
589 if ($self->{'album'});
590 $self->{'playlist'} .= "#EXTGENRE:" . $self->{'genre'} . "\n";
591 $self->{'playlist'} .= $epiStreams[$i] . "\n";
592 }
593 }
594 }
595  
596 $self->{'total'} = $self->{'cnt'};
597 $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : '';
598 if ($DEBUG) {
599 foreach my $f (sort keys %{$self}) {
600 print STDERR "--KEY=$f= VAL=$$self{$f}=\n";
601 }
602 print STDERR "-SUCCESS: 1st stream=".$self->{'Url'}."=\n" if ($self->{'cnt'} > 0);;
603 }
604  
605 $self->_log($url);
606  
607 bless $self, $class; #BLESS IT!
608  
609 return $self;
610 }
611  
612 1