| 1 | =head1 NAME | ||
| 2 | |||
| 3 | StreamFinder::EpochTV - Fetch actual raw streamable video URLs on www.theepochtimes.com | ||
| 4 | |||
| 5 | =head1 AUTHOR | ||
| 6 | |||
| 7 | This module is Copyright (C) 2022-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::EpochTV; | ||
| 26 | |||
| 27 | die "..usage: $0 ID|URL\n" unless ($ARGV[0]); | ||
| 28 | |||
| 29 | my $video = new StreamFinder::EpochTV($ARGV[0]); | ||
| 30 | |||
| 31 | die "Invalid URL or no streams found!\n" unless ($video); | ||
| 32 | |||
| 33 | my $firstStream = $video->get(); | ||
| 34 | |||
| 35 | print "First Stream URL=$firstStream\n"; | ||
| 36 | |||
| 37 | my $url = $video->getURL(); | ||
| 38 | |||
| 39 | print "Stream URL=$url\n"; | ||
| 40 | |||
| 41 | my $videoTitle = $video->getTitle(); | ||
| 42 | |||
| 43 | print "Title=$videoTitle\n"; | ||
| 44 | |||
| 45 | my $videoDescription = $video->getTitle('desc'); | ||
| 46 | |||
| 47 | print "Description=$videoDescription\n"; | ||
| 48 | |||
| 49 | my $videoID = $video->getID(); | ||
| 50 | |||
| 51 | print "Video ID=$videoID\n"; | ||
| 52 | |||
| 53 | my $artist = $video->{'artist'}; | ||
| 54 | |||
| 55 | print "Artist=$artist\n" if ($artist); | ||
| 56 | |||
| 57 | my $genre = $video->{'genre'}; | ||
| 58 | |||
| 59 | print "Genre=$genre\n" if ($genre); | ||
| 60 | |||
| 61 | my $icon_url = $video->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) = $video->getIconData(); | ||
| 68 | |||
| 69 | if ($icon_image && open IMGOUT, ">/tmp/${videoID}.$image_ext") { | ||
| 70 | |||
| 71 | binmode IMGOUT; | ||
| 72 | |||
| 73 | print IMGOUT $icon_image; | ||
| 74 | |||
| 75 | close IMGOUT; | ||
| 76 | |||
| 77 | print "...Icon image downloaded to (/tmp/${videoID}.$image_ext)\n"; | ||
| 78 | |||
| 79 | } | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | my $stream_count = $video->count(); | ||
| 84 | |||
| 85 | print "--Stream count=$stream_count=\n"; | ||
| 86 | |||
| 87 | my @streams = $video->get(); | ||
| 88 | |||
| 89 | foreach my $s (@streams) { | ||
| 90 | |||
| 91 | print "------ stream URL=$s=\n"; | ||
| 92 | |||
| 93 | } | ||
| 94 | |||
| 95 | =head1 DESCRIPTION | ||
| 96 | |||
| 97 | StreamFinder::EpochTV accepts a valid video/channel ID or URL on | ||
| 98 | www.theepochtimes.com and returns the actual stream URL(s), title, and cover | ||
| 99 | art icon. The purpose is that one needs one of these URLs in order to have | ||
| 100 | the option to stream the video 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 | www.theepochtimes.com streams. | ||
| 107 | |||
| 108 | One stream URL can be returned for each video. | ||
| 109 | |||
| 110 | =head1 SUBROUTINES/METHODS | ||
| 111 | |||
| 112 | =over 4 | ||
| 113 | |||
| 114 | =item B<new>(I<ID>|I<url> [, I<-speakericon> [ => 0|1 ]] | ||
| 115 | [, I<-secure> [ => 0|1 ]] [, I<-debug> [ => 0|1|2 ]]) | ||
| 116 | |||
| 117 | Accepts a www.theepochtimes.com video or channel ID or URL and creates and | ||
| 118 | returns a a new video object, or I<undef> if the URL is not a valid video, or | ||
| 119 | no streams are found. The URL can be the full URL, ie. | ||
| 120 | https://www.theepochtimes.com/epochtv/B<channel_or_video-id>, or just | ||
| 121 | B<channel_or_video-id>. EpochTV can't really distinguish between episode and | ||
| 122 | channel IDs except that channel pages do not contain a specific video stream | ||
| 123 | URL, so if no stream URL is found, it assumes a channel page, in which case, | ||
| 124 | the first (latest) episode is returned (along with the channel's playlist). | ||
| 125 | |||
| 126 | The optional I<-speakericon> argument can be set to use the artist/speaker's | ||
| 127 | icon usually resulting in the artist icon being a photo of the individual | ||
| 128 | artist/speaker's photo, instead of the channel's icon. Regardless of setting, | ||
| 129 | if either icon is missing, the other will be used. | ||
| 130 | |||
| 131 | DEFAULT zero (I<false>): Prefer to use the channel's icon for artist's icon. | ||
| 132 | |||
| 133 | The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>). | ||
| 134 | If 1 then only secure ("https://") streams will be returned. Currently, | ||
| 135 | all EpochTV streaming URLs are believed to be secure (https). | ||
| 136 | |||
| 137 | DEFAULT I<-secure> is 0 (false) - return all streams (http and https). | ||
| 138 | |||
| 139 | Additional options: | ||
| 140 | |||
| 141 | I<-log> => "I<logfile>" | ||
| 142 | |||
| 143 | Specify path to a log file. If a valid and writable file is specified, A line | ||
| 144 | will be appended to this file every time one or more streams is successfully | ||
| 145 | fetched for a url. | ||
| 146 | |||
| 147 | DEFAULT I<-none-> (no logging). | ||
| 148 | |||
| 149 | I<-logfmt> specifies a format string for lines written to the log file. | ||
| 150 | |||
| 151 | DEFAULT "I<[time] [url] - [site]: [title] ([total])>". | ||
| 152 | |||
| 153 | The valid field I<[variables]> are: [stream]: The url of the first/best | ||
| 154 | stream found. | ||
| 155 | [site]: The site name (EpochTV). [url]: The url searched for streams. | ||
| 156 | [time]: Perl timestamp when the line was logged. [title], [artist], [album], | ||
| 157 | [description], [year], [genre], [total], [albumartist]: The corresponding | ||
| 158 | field data returned (or "I<-na->", if no value). | ||
| 159 | |||
| 160 | =item $video->B<get>() | ||
| 161 | |||
| 162 | Returns an array of strings representing all stream URLs found. | ||
| 163 | Note: If an author / channel page url is given, rather than an individual | ||
| 164 | video episode's url, get() returns the first (latest?) video episode found. | ||
| 165 | |||
| 166 | =item $video->B<getURL>([I<options>]) | ||
| 167 | |||
| 168 | Similar to B<get>() except it only returns a single stream representing | ||
| 169 | the first valid stream found. There currently are no valid I<options>. | ||
| 170 | |||
| 171 | =item $video->B<count>() | ||
| 172 | |||
| 173 | Returns the number of streams found for the video (will nearly always be 1). | ||
| 174 | |||
| 175 | =item $video->B<getID>() | ||
| 176 | |||
| 177 | Returns the video's EpochTV ID (default). EpochTV video and channel IDs | ||
| 178 | consist of combinations of lower-case letters, numbers and hyphens, and are | ||
| 179 | indestinguishable from each other, except that channel pages don't return | ||
| 180 | a specific video streaming URL, but rather fetch and return the first | ||
| 181 | (latest) episode video's streaming URL and metadata. | ||
| 182 | |||
| 183 | =item $video->B<getTitle>(['desc']) | ||
| 184 | |||
| 185 | Returns the video's title, or (long description). Videos | ||
| 186 | on EpochTV can have separate descriptions, but for videos, | ||
| 187 | it is always the video's title. | ||
| 188 | |||
| 189 | Note: EpochTV video descriptions are usually incomplete, ending with a "..", | ||
| 190 | since on the page itself there's a "Read More" button to view the rest, and | ||
| 191 | "the rest" can only be obtained with Javascript. | ||
| 192 | |||
| 193 | =item $video->B<getIconURL>(['artist']) | ||
| 194 | |||
| 195 | Returns the URL for the video's "cover art" icon image, if any. | ||
| 196 | If B<'artist'> is specified, the channel artist's icon url is returned, | ||
| 197 | if any. | ||
| 198 | |||
| 199 | Note: EpochTV videos (unlike most other sites) often have both | ||
| 200 | an artist icon (for the channel) AND an artist image for that individual | ||
| 201 | artist/author (photo). See the B<-speakericon> option for preferring the | ||
| 202 | artist/author's photo in lieu of the channel's icon. | ||
| 203 | |||
| 204 | =item $video->B<getIconData>(['artist']) | ||
| 205 | |||
| 206 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 207 | "gif", "jpeg", etc.) and the actual icon image (binary data), if any. | ||
| 208 | If B<'artist'> is specified, the channel artist's icon data is returned, | ||
| 209 | if any. | ||
| 210 | |||
| 211 | =item $video->B<getImageURL>(['artist']) | ||
| 212 | |||
| 213 | Returns the URL for the video's "cover art" (usually larger) | ||
| 214 | banner image. If B<'artist'> is specified, the channel artist's image URL | ||
| 215 | is returned, if any. | ||
| 216 | |||
| 217 | |||
| 218 | =item $video->B<getImageData>(['artist']) | ||
| 219 | |||
| 220 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 221 | "gif", "jpeg", etc.) and the actual video's banner image (binary data). | ||
| 222 | If B<'artist'> is specified, the channel artist's image data is returned, | ||
| 223 | if any. Individual artists on epochtv.com often do have their own | ||
| 224 | separate larger banner image. | ||
| 225 | |||
| 226 | =item $video->B<getType>() | ||
| 227 | |||
| 228 | Returns the video's type ("EpochTV"). | ||
| 229 | |||
| 230 | =back | ||
| 231 | |||
| 232 | =head1 CONFIGURATION FILES | ||
| 233 | |||
| 234 | The default root location directory for StreamFinder configuration files | ||
| 235 | is "~/.config/StreamFinder". To use an alternate location directory, | ||
| 236 | specify it in the "I<STREAMFINDER>" environment variable, ie.: | ||
| 237 | B<$ENV{STREAMFINDER} = "/etc/StreamFinder">. | ||
| 238 | |||
| 239 | =over 4 | ||
| 240 | |||
| 241 | =item ~/.config/StreamFinder/EpochTV/config | ||
| 242 | |||
| 243 | Optional text file for specifying various configuration options | ||
| 244 | for a specific site (submodule). Each option is specified on a | ||
| 245 | separate line in the format below: | ||
| 246 | NOTE: Do not follow the lines with a semicolon, comma, or any other | ||
| 247 | separator. Non-numeric I<values> should be surrounded with quotes, either | ||
| 248 | single or double. Blank lines and lines beginning with a "#" sign as | ||
| 249 | their first non-blank character are ignored as comments. | ||
| 250 | |||
| 251 | 'option' => 'value' [,] | ||
| 252 | |||
| 253 | and the options are loaded into a hash used only by the specific | ||
| 254 | (submodule) specified. Valid options include | ||
| 255 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 256 | |||
| 257 | Options specified here override any specified in I<~/.config/StreamFinder/config>. | ||
| 258 | |||
| 259 | =item ~/.config/StreamFinder/config | ||
| 260 | |||
| 261 | Optional text file for specifying various configuration options. | ||
| 262 | Each option is specified on a separate line in the format below: | ||
| 263 | |||
| 264 | 'option' => 'value' [,] | ||
| 265 | |||
| 266 | and the options are loaded into a hash used by all sites | ||
| 267 | (submodules) that support them. Valid options include | ||
| 268 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 269 | |||
| 270 | =back | ||
| 271 | |||
| 272 | NOTE: Options specified in the options parameter list of the I<new()> | ||
| 273 | function will override those corresponding options specified in these files. | ||
| 274 | |||
| 275 | =head1 KEYWORDS | ||
| 276 | |||
| 277 | epochtv | ||
| 278 | |||
| 279 | =head1 DEPENDENCIES | ||
| 280 | |||
| 281 | L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent> | ||
| 282 | |||
| 283 | =head1 RECCOMENDS | ||
| 284 | |||
| 285 | wget | ||
| 286 | |||
| 287 | =head1 BUGS | ||
| 288 | |||
| 289 | Please report any bugs or feature requests to C<bug-streamFinder-iheartradio at rt.cpan.org>, or through | ||
| 290 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-EpochTV>. I will be notified, and then you'll | ||
| 291 | automatically be notified of progress on your bug as I make changes. | ||
| 292 | |||
| 293 | =head1 SUPPORT | ||
| 294 | |||
| 295 | You can find documentation for this module with the perldoc command. | ||
| 296 | |||
| 297 | perldoc StreamFinder::EpochTV | ||
| 298 | |||
| 299 | You can also look for information at: | ||
| 300 | |||
| 301 | =over 4 | ||
| 302 | |||
| 303 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 304 | |||
| 305 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-EpochTV> | ||
| 306 | |||
| 307 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 308 | |||
| 309 | L<http://annocpan.org/dist/StreamFinder-EpochTV> | ||
| 310 | |||
| 311 | =item * Search CPAN | ||
| 312 | |||
| 313 | L<http://search.cpan.org/dist/StreamFinder-EpochTV/> | ||
| 314 | |||
| 315 | =back | ||
| 316 | |||
| 317 | =head1 LICENSE AND COPYRIGHT | ||
| 318 | |||
| 319 | Copyright 2022-2026 Jim Turner. | ||
| 320 | |||
| 321 | This program is free software; you can redistribute it and/or modify it | ||
| 322 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 323 | copy of the full license at: | ||
| 324 | |||
| 325 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 326 | |||
| 327 | Any use, modification, and distribution of the Standard or Modified | ||
| 328 | Versions is governed by this Artistic License. By using, modifying or | ||
| 329 | distributing the Package, you accept this license. Do not use, modify, | ||
| 330 | or distribute the Package, if you do not accept this license. | ||
| 331 | |||
| 332 | If your Modified Version has been derived from a Modified Version made | ||
| 333 | by someone other than you, you are nevertheless required to ensure that | ||
| 334 | your Modified Version complies with the requirements of this license. | ||
| 335 | |||
| 336 | This license does not grant you the right to use any trademark, service | ||
| 337 | mark, tradename, or logo of the Copyright Holder. | ||
| 338 | |||
| 339 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 340 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 341 | otherwise transfer the Package with respect to any patent claims | ||
| 342 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 343 | Package. If you institute patent litigation (including a cross-claim or | ||
| 344 | counterclaim) against any party alleging that the Package constitutes | ||
| 345 | direct or contributory patent infringement, then this Artistic License | ||
| 346 | to you shall terminate on the date that such litigation is filed. | ||
| 347 | |||
| 348 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 349 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 350 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 351 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 352 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 353 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 354 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 355 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 356 | |||
| 357 | =cut | ||
| 358 | |||
| 359 | package StreamFinder::EpochTV; | ||
| 360 | |||
| 361 | use strict; | ||
| 362 | use warnings; | ||
| 363 | use URI::Escape; | ||
| 364 | use HTML::Entities (); | ||
| 365 | use LWP::UserAgent (); | ||
| 366 | use parent 'StreamFinder::_Class'; | ||
| 367 | |||
| 368 | my $DEBUG = 0; | ||
| 369 | |||
| 370 | sub new | ||
| 371 | { | ||
| 372 | my $class = shift; | ||
| 373 | my $url = shift; | ||
| 374 | |||
| 375 | return undef unless ($url); | ||
| 376 | |||
| 377 | my $self = $class->SUPER::new('EpochTV', @_); | ||
| 378 | |||
| 379 | while (@_) { | ||
| 380 | if ($_[0] =~ /^\-?debug$/o) { | ||
| 381 | shift; | ||
| 382 | $DEBUG = (defined($_[0]) && $_[0] =~/^[0-9]$/) ? shift : 1; | ||
| 383 | } elsif ($_[0] =~ /^\-?secure$/o) { | ||
| 384 | shift; | ||
| 385 | $self->{'secure'} = (defined $_[0]) ? shift : 1; | ||
| 386 | } elsif ($_[0] =~ /^\-?speakericon$/o) { | ||
| 387 | shift; | ||
| 388 | $self->{'speakericon'} = (defined $_[0]) ? shift : 1; | ||
| 389 | } else { | ||
| 390 | shift; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | $self->{'speakericon'} = 0 unless (defined $self->{'speakericon'}); | ||
| 394 | $DEBUG = $self->{'debug'} if (defined $self->{'debug'}); | ||
| 395 | my $baseURL = 'https://www.theepochtimes.com'; | ||
| 396 | $self->{'id'} = ''; | ||
| 397 | (my $url2fetch = $url); | ||
| 398 | my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}}); | ||
| 399 | $ua->timeout($self->{'timeout'}); | ||
| 400 | $ua->cookie_jar({}); | ||
| 401 | $ua->env_proxy; | ||
| 402 | my $html = ''; | ||
| 403 | my $response; | ||
| 404 | my $isEpisode = 1; | ||
| 405 | my $tried = 0; | ||
| 406 | |||
| 407 | TRYIT: | ||
| 408 | $html = ''; #RESET HTML EACH TRY. | ||
| 409 | if ($url2fetch =~ m#^(https?\:\/\/[^\/]+)#) { | ||
| 410 | $baseURL = $1; | ||
| 411 | $self->{'id'} = $1 if ($url =~ m#\/([a-z\-\d]+)\/?$#); | ||
| 412 | } else { | ||
| 413 | $self->{'id'} = $url; | ||
| 414 | $url2fetch = $baseURL . '/epochtv/' . $url; | ||
| 415 | } | ||
| 416 | |||
| 417 | print STDERR "-0(EpochTV): FETCHING URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG); | ||
| 418 | $response = $ua->get($url2fetch); | ||
| 419 | if ($response->is_success) { | ||
| 420 | $html = $response->decoded_content; | ||
| 421 | } else { | ||
| 422 | print STDERR $response->status_line if ($DEBUG); | ||
| 423 | } | ||
| 424 | print STDERR "-1: html=$html=\n" if ($DEBUG > 1); | ||
| 425 | return undef unless ($html); #STEP 1 FAILED, INVALID EpochTV URL, PUNT! | ||
| 426 | |||
| 427 | my $protocol = $self->{'secure'} ? '' : '?'; | ||
| 428 | $self->{'genre'} = 'Video'; #www.theepochtimes.com DOES NOT CURRENTLY INCLUDE A GENRE/CATEGORY. | ||
| 429 | if ($html =~ m#\,\"contentUrl\"\:\"(https${protocol}\:[^\"]+)#s) { | ||
| 430 | my $stream = $1; | ||
| 431 | $stream =~ s/\.(mp3|m3u8|mp4|m4a|pls)\?.*$/\.$1/ unless ($self->{'notrim'}); #STRIP OFF EXTRA GARBAGE PARMS, COMMENT OUT IF STARTS FAILING! | ||
| 432 | push (@{$self->{'streams'}}, $stream); #WE'RE AN EPISODE PAGE, CONTINUE: | ||
| 433 | } elsif ($html =~ m#\<video\s+src\=\"(https${protocol}\:[^\"]+)#si) { #LEGACY VIDEO STREAM: | ||
| 434 | my $stream = $1; | ||
| 435 | $stream =~ s/\.(mp3|m3u8|mp4|m4a|pls)\?.*$/\.$1/ unless ($self->{'notrim'}); #STRIP OFF EXTRA GARBAGE PARMS, COMMENT OUT IF STARTS FAILING! | ||
| 436 | push (@{$self->{'streams'}}, $stream); #WE'RE AN EPISODE PAGE, CONTINUE: | ||
| 437 | } elsif ($html =~ m#\<audio\s+src\=\"(https${protocol}\:[^\"]+)#si) { #LEGACY AUDIO STREAM: | ||
| 438 | my $stream = $1; | ||
| 439 | $stream =~ s/\.(mp3|m3u8|mp4|m4a|pls)\?.*$/\.$1/ unless ($self->{'notrim'}); #STRIP OFF EXTRA GARBAGE PARMS, COMMENT OUT IF STARTS FAILING! | ||
| 440 | push (@{$self->{'streams'}}, $stream); #WE'RE AN EPISODE PAGE, CONTINUE: | ||
| 441 | $self->{'genre'} = 'Podcast'; | ||
| 442 | } elsif ($tried < 1) { #NO STREAM URL FOUND, ASSUME WE'RE A CHANNEL PAGE & TRY AGAIN W/IT'S 1ST EPISODE!: | ||
| 443 | ++$tried; | ||
| 444 | $isEpisode = 0; | ||
| 445 | if ($html =~ m#\<div\s+class\=\"basis\-1\/6\s+pt\-2\s+sm\:pt\-4\"\>\s*\<a\s+href\=\"([^\"]+)#s) { | ||
| 446 | $url2fetch = $1; | ||
| 447 | $url2fetch = $baseURL . $url2fetch unless ($url2fetch =~ m#^https?\:#); | ||
| 448 | print STDERR "i:No stream, perhaps channel page1, so fetch marquee episode URL=$url2fetch=\n" if ($DEBUG); | ||
| 449 | goto TRYIT; | ||
| 450 | } elsif ($html =~ m#\<div\s+class\="relative\s+lg\:order\-first\"\>\s*\<a\s+href\=\"([^\"]+)#s) { | ||
| 451 | $url2fetch = $1; | ||
| 452 | $url2fetch = $baseURL . $url2fetch unless ($url2fetch =~ m#^https?\:#); | ||
| 453 | print STDERR "i:No stream, perhaps channel page2, so fetch marquee episode URL=$url2fetch=\n" if ($DEBUG); | ||
| 454 | goto TRYIT; | ||
| 455 | } | ||
| 456 | } | ||
| 457 | |||
| 458 | print STDERR "---ID=".$self->{'id'}."=\n" if ($DEBUG); | ||
| 459 | $self->{'title'} = $1 if ($html =~ m#\<meta\s+(?:name|property)\=\"(?:og|twitter)\:title\"\s+content\=\"([^\"]+)\"\s*\/\>#s); | ||
| 460 | $self->{'title'} ||= $1 if ($html =~ m#\"VideoObject\"\,\"name\"\:\"([^\"]+)#s); | ||
| 461 | $self->{'title'} ||= $1 if ($html =~ m#\<title\>(.+?)\<\/title\>#si); | ||
| 462 | $self->{'iconurl'} = $1 if ($html =~ m#\<meta\s+(?:name|property)\=\"(?:og|twitter)\:image\"\s+content\=\"([^\"]+)#s); | ||
| 463 | $self->{'iconurl'} ||= $1 if ($html =~ m#data\-thumbnail\=\"([^\"]+)#s); | ||
| 464 | $self->{'imageurl'} = $1 if ($html =~ m#\,\"thumbnailUrl\"\:\"([^\"]+)#s); | ||
| 465 | $self->{'album'} = ($html =~ m#\bmd\:text\-lg\"\>([^\<]+)#s) ? $1 : ''; | ||
| 466 | $self->{'_artisturl'} = ''; | ||
| 467 | unless ($self->{'album'}) { | ||
| 468 | my $albumdata = $1 if ($html =~ m#\,\"author\"\:\[([^\]]+)#s); | ||
| 469 | $self->{'album'} = $1 if ($albumdata =~ m#\"url\"\:\"([^\"]+)#s); | ||
| 470 | } | ||
| 471 | #FETCH CHANNEL'S DATA: | ||
| 472 | if ($html =~ m#\<a\s+href\=\"([^\"]+)\"><div class="(?:h-\d+\s+w-\d+|size\-\d+)">(.+?)\<\/div\>#s) { | ||
| 473 | $self->{'albumartist'} = $1; | ||
| 474 | my $channeldata = $2; | ||
| 475 | $self->{'articonurl'} = $1 if ($channeldata =~ m#\burl\=([^\"]+)#s); | ||
| 476 | $self->{'articonurl'} =~ s/\s+\dx.+$//s if ($self->{'articonurl'}); | ||
| 477 | print STDERR "i:channel avatar found($$self{'articonurl'}).\n" if ($DEBUG); | ||
| 478 | } | ||
| 479 | #FETCH ARTIST'S DATA (ARTIST/AUTHOR MAY NOT BE SAME AS CHANNEL)!: | ||
| 480 | if ($html =~ m#\\\"authors\\\"\:\[\{([^}]+)#s) { | ||
| 481 | my $artistdata = $1; | ||
| 482 | $self->{'artist'} = $1 if ($artistdata =~ m#\\\"name\\\"\:\\\"([^\\]+)#s); | ||
| 483 | if ($artistdata =~ m#\\\"avatar\\\"\:\\\"([^\\]+)#s) { | ||
| 484 | my $artisticon = $1; | ||
| 485 | if ($self->{'speakericon'}) { | ||
| 486 | $self->{'articonurl'} = $artisticon; | ||
| 487 | print STDERR "i:Individual artist avatar found($$self{'articonurl'}).\n" if ($DEBUG); | ||
| 488 | } else { | ||
| 489 | $self->{'articonurl'} ||= $artisticon; | ||
| 490 | } | ||
| 491 | } | ||
| 492 | if ($artistdata =~ m#\\\"uri\\\"\:\\\"([^\\]+)#s) { | ||
| 493 | $self->{'_artisturl'} = $1; | ||
| 494 | $self->{'_artisturl'} = '/author/' . $self->{'_artisturl'} | ||
| 495 | unless ($self->{'_artisturl'} =~ m#^(?:\/|https?\:)#); | ||
| 496 | $self->{'_artisturl'} = $baseURL . $self->{'_artisturl'} | ||
| 497 | unless ($self->{'_artisturl'} =~ m#^https?\:#); | ||
| 498 | } | ||
| 499 | } | ||
| 500 | $self->{'articonurl'} ||= $1 if ($html =~ m#\\\"termIcon\\\"\:\\\"([^\\]+)#s); | ||
| 501 | $self->{'articonurl'} = HTML::Entities::decode_entities($self->{'articonurl'}); | ||
| 502 | $self->{'articonurl'} = uri_unescape($self->{'articonurl'}); | ||
| 503 | $self->{'articonurl'} =~ s/(?:\%|\\?u?00)([0-9A-Fa-f]{2})/chr(hex($1))/egso; | ||
| 504 | $self->{'articonurl'} =~ s#\&.*$##; | ||
| 505 | $self->{'artimageurl'} = $1 if ($html =~ m#\\\"termPoster\\\"\:\\\"([^\\]+)#s); | ||
| 506 | if ($self->{'albumartist'}) { | ||
| 507 | $self->{'albumartist'} = $baseURL . $self->{'albumartist'} | ||
| 508 | unless ($self->{'albumartist'} =~ m#^https?\:#); | ||
| 509 | } | ||
| 510 | if ($self->{'_artisturl'}) { | ||
| 511 | $self->{'artist'} .= ' - ' if ($self->{'artist'}); | ||
| 512 | $self->{'artist'} .= $self->{'_artisturl'}; | ||
| 513 | } | ||
| 514 | $self->{'articonurl'} ||= $self->{'artimageurl'}; | ||
| 515 | ($self->{'description'} = $1) =~ s#\\$## if ($html =~ m#\\\"content\\\"\:\[\{\\\"type\\\"\:\\\"p\\\",\\\"text\\\"\:\\\"([^\"]+)#s); | ||
| 516 | $self->{'description'} ||= $1 if ($html =~ m#\bwhitespace\-break\-spaces\"\>([^\<]+)#s); | ||
| 517 | $self->{'description'} ||= $1 if ($html =~ m#\<meta\s+name\=\"description\"\s+content\=\"([^\"]+)#s); | ||
| 518 | $self->{'description'} ||= $1 if ($html =~ m#\<meta\s+property\=\"og\:description\"\s+content\=\"([^\"]+)#s); | ||
| 519 | $self->{'created'} = $1 if ($html =~ m#\"uploadDate\"\:\"([^\"]+)#s); | ||
| 520 | $self->{'created'} ||= $1 if ($html =~ m#\<div\s+class\=\"whitespace\-nowrap]s+text\-sm\s+text\-\[\#707070\]\"\>([^\<]+)#s); | ||
| 521 | $self->{'created'} ||= $1 if ($html =~ m#\,\"datePublished\"\:\"([^\"]+)#s); | ||
| 522 | $self->{'year'} = ($self->{'created'} =~ /(\d\d\d\d)/) ? $1 : ''; | ||
| 523 | foreach my $i (qw(description title artist)) { | ||
| 524 | $self->{$i} = HTML::Entities::decode_entities($self->{$i}); | ||
| 525 | $self->{$i} = uri_unescape($self->{$i}); | ||
| 526 | $self->{$i} =~ s/(?:\%|\\?u?00)([0-9A-Fa-f]{2})/chr(hex($1))/egso; | ||
| 527 | } | ||
| 528 | $self->{'imageurl'} ||= $self->{'iconurl'}; | ||
| 529 | |||
| 530 | $self->{'cnt'} = scalar @{$self->{'streams'}}; | ||
| 531 | |||
| 532 | #MUST NOW "FIX" SOME OF THEIR "STREAMS"!: | ||
| 533 | for (my $i=0;$i<$self->{'cnt'};$i++) { | ||
| 534 | if ($self->{'streams'}->[$i] | ||
| 535 | =~ s#\/vod\.brightchat\.com\/embed\/#\/vod\.brightchat\.com\/assets\/#o) { | ||
| 536 | $self->{'streams'}->[$i] .= '/playlist.m3u8' | ||
| 537 | unless ($self->{'streams'}->[$i] =~ /\.(?:mp3|m3u8|mp4|m4a|pls)$/); | ||
| 538 | } | ||
| 539 | } | ||
| 540 | $self->{'Url'} = ($self->{'cnt'} > 0) ? $self->{'streams'}->[0] : ''; | ||
| 541 | |||
| 542 | #NOW GET PLAYLIST DATA: | ||
| 543 | |||
| 544 | my (%epiHash, %epiTitlesSorted); | ||
| 545 | my $epiCnt = $self->{'cnt'}; | ||
| 546 | if ($self->{'cnt'} > 0) { | ||
| 547 | $epiHash{$self->{'title'}} = $self->{'Url'}; | ||
| 548 | print STDERR "--0:EPISODE($epiCnt): T=$$self{'title'}= S=$epiHash{$$self{'title'}}=\n" if ($DEBUG); | ||
| 549 | $epiTitlesSorted{sprintf('%3.3d', $epiCnt++)} = $self->{'title'}; | ||
| 550 | } | ||
| 551 | #DEPRECIATED (DATA NO LONGER SEEMS TO BE PROVIDED!): | ||
| 552 | #DEPRECIATED: unless ($isEpisode) { | ||
| 553 | #DEPRECIATED: while ($html =~ s#^.+?\\\"(?:video|audio)\\\"\:\{\\\"id\\\"\:\\\"##sio) { | ||
| 554 | #DEPRECIATED: if ($html =~ m#\\\"url\\\"\:\\\"(https${protocol}\:[^\\]+)#s) { | ||
| 555 | #DEPRECIATED: my $epiStream = $1; | ||
| 556 | #DEPRECIATED: if ($epiStream =~ /\.(?:mp3|m3u8|mp4|m4a|pls)/o && $html =~ m#\d\d\,\\\"(?:title|caption)\\\"\:\\\"([^\\]+)#so) { | ||
| 557 | #DEPRECIATED: my $epiTitle = $1; | ||
| 558 | #DEPRECIATED: unless (defined $epiHash{$epiTitle}) { | ||
| 559 | #DEPRECIATED: $epiHash{$epiTitle} = $epiStream; | ||
| 560 | #DEPRECIATED: $epiTitlesSorted{sprintf('%3.3d', $epiCnt++)} = $epiTitle; | ||
| 561 | #DEPRECIATED: } | ||
| 562 | #DEPRECIATED: } | ||
| 563 | #DEPRECIATED: } | ||
| 564 | #DEPRECIATED: } | ||
| 565 | #DEPRECIATED: } | ||
| 566 | |||
| 567 | $self->{'playlist'} = "#EXTM3U\n"; | ||
| 568 | $self->{'playlist_cnt'} = 0; | ||
| 569 | foreach my $x (sort keys %epiTitlesSorted) { | ||
| 570 | $self->{'playlist'} .= "#EXTINF:-1, " . $epiTitlesSorted{$x} . "\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'} .= $epiHash{$epiTitlesSorted{$x}} . "\n"; | ||
| 578 | ++$self->{'playlist_cnt'}; | ||
| 579 | } | ||
| 580 | $self->{'total'} = $self->{'cnt'} = scalar @{$self->{'streams'}}; | ||
| 581 | |||
| 582 | |||
| 583 | if ($DEBUG) { | ||
| 584 | foreach my $f (sort keys %{$self}) { | ||
| 585 | print STDERR "--KEY=$f= VAL=$$self{$f}=\n"; | ||
| 586 | } | ||
| 587 | print STDERR "-SUCCESS: 1st stream=".$self->{'Url'}."=\n"; | ||
| 588 | } | ||
| 589 | |||
| 590 | |||
| 591 | return undef unless ($self->{'cnt'} > 0); | ||
| 592 | |||
| 593 | $self->_log($url); #LOG IT. | ||
| 594 | |||
| 595 | bless $self, $class; #BLESS IT! | ||
| 596 | |||
| 597 | return $self; | ||
| 598 | } | ||
| 599 | |||
| 600 | 1 |