StreamFinder/Brighteon.pm untested

filter: Statementstmt 0.0% 0 / 222 Branchbran 0.0% 0 / 162 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 480 CC 82 SCAR 87.3
CC
82
Cov
0%
new
6806.0
getImageData
2.0
BEGIN
2.0
CRAP 6201.2
1 =head1 NAME
2  
3 StreamFinder::Brighteon - Fetch actual raw streamable URLs from Brighteon.com.
4  
5 =head1 AUTHOR
6  
7 This module is Copyright (C) 2017-2026 by
8  
9 Jim Turner, C<< <turnerjw784 at yahoo.com> >>
10
11 Email: turnerjw784@yahoo.com
12  
13 All rights reserved.
14  
15 You may distribute this module under the terms of either the GNU General
16 Public License or the Artistic License, as specified in the Perl README
17 file.
18  
19 =head1 SYNOPSIS
20  
21 #!/usr/bin/perl
22  
23 use strict;
24  
25 use StreamFinder::Brighteon;
26  
27 die "..usage: $0 ID|URL\n" unless ($ARGV[0]);
28  
29 my $video = new StreamFinder::Brighteon($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 $albumartist = $video->{'albumartist'};
58  
59 print "Album Artist=$albumartist\n" if ($albumartist);
60
61 my $icon_url = $video->getIconURL();
62  
63 if ($icon_url) { #SAVE THE ICON TO A TEMP. FILE:
64  
65 my ($image_ext, $icon_image) = $video->getIconData();
66  
67 if ($icon_image && open IMGOUT, ">/tmp/${videoID}.$image_ext") {
68  
69 binmode IMGOUT;
70  
71 print IMGOUT $icon_image;
72  
73 close IMGOUT;
74  
75 }
76  
77 }
78  
79 my $stream_count = $video->count();
80  
81 print "--Stream count=$stream_count=\n";
82  
83 my @streams = $video->get();
84  
85 foreach my $s (@streams) {
86  
87 print "------ stream URL=$s=\n";
88  
89 }
90  
91 =head1 DESCRIPTION
92  
93 StreamFinder::Brighteon accepts a valid full Brighteon video ID or URL on
94 brighteon.com and returns the actual stream URL, title, and cover art icon
95 for that video. The purpose is that one needs this URL in order to have
96 the option to stream the video in one's own choice of media player
97 software rather than using their web browser and accepting any / all flash,
98 ads, javascript, cookies, trackers, web-bugs, and other crapware that can
99 come with that method of play. The author uses his own custom all-purpose
100 media player called "fauxdacious" (his custom hacked version of the
101 open-source "audacious" audio player). "fauxdacious" incorporates this
102 module to decode and play brighteon.com videos. This is a submodule of the
103 general StreamFinder module.
104  
105 Depends:
106  
107 L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent>
108  
109 The separate application program: youtube-dl, or a compatable program
110 such as yt-dlp (only if wishing to use the I<-youtube> option).
111  
112 =head1 SUBROUTINES/METHODS
113  
114 =over 4
115  
116 =item B<new>(I<ID>|I<url> [, I<-youtube> => yes|no|first|last|only ]
117 [, I<-keep> => "type1,type2?..." | [type1,type2?...] ]
118 [, I<-secure> [ => 0|1 ]] [, I<-debug> [ => 0|1|2 ]])
119  
120 Accepts a brighteon.com video ID or URL and creates and returns a new video
121 object, or I<undef> if the URL is not a valid Brighteon video or no streams
122 are found. The URL can be the full URL, ie.
123 https://www.brighteon.com/B<video-id>,
124 or just I<video-id>.
125  
126 NOTE: Brighteon channel pages are no longer accepted as Brighteon.com has
127 recently made them non-scrapable (without Javascript).
128  
129 The optional I<-keep> argument can be either a comma-separated string or an
130 array reference ([...]) of stream types to keep (include) and returned in
131 order specified (type1, type2...). Each "type" can be one of: extension
132 (ie. m4a, mp4, etc.), "playlist", "stream", or ("any" or "all").
133  
134 DEFAULT I<-keep> list is: 'm4a,mpd,stream,all', meaning that all m4a streams
135 followed by all "mpd" streams, followed by non-playlists, followed by all
136 remaining (playlists: (pls) streams. More than one value can be specified to
137 control order of search.
138  
139 NOTE: I<-keep> is ignored if I<-youtube> is set to "I<only>".
140  
141 The optional I<-youtube> argument can be set to "I<yes>" or "I<last>" - also
142 include streams youtube-dl finds (last); "I<no>" - only include streams
143 embedded in the video's brighteon.com page, unless none are found;
144 "I<only>" - only include streams youtube-dl finds; or "I<first>" - include
145 streams youtube-dl finds first. Default is B<"yes">. This is needed because
146 currently the streams on the page: (mpd plays best but is unseekable, and the
147 m3u8 (HLS) stream doesn't seem to work well). youtube-dl also returns a
148 "chunky" m3u8 (HLS) stream that is seekable and seems to work ok.
149  
150 The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>).
151 If 1 then only secure ("https://") streams will be returned.
152  
153 DEFAULT I<-secure> is 0 (false) - return all streams (http and https).
154  
155 Additional options:
156  
157 Certain youtube-dl (L<StreamFinder::Youtube>) configuration options,
158 namely I<format>, I<formatonly>, I<youtube-dl-args>, and I<youtube-dl-add-args>
159 can be overridden here by specifying I<youtube-format>, I<youtube-formatonly>,
160 I<youtube-dl-args>, and I<youtube-dl-add-args> arguments respectively. It is
161 however, recommended to specify these in the Brighteon-specific
162 configuration file (see B<CONFIGURATION FILES> below. NOTE: These are only
163 applicable when using the option: I<-youtube> => I<yes|only|top>, etc.
164  
165 I<-log> => "I<logfile>"
166  
167 Specify path to a log file. If a valid and writable file is specified, A line
168 will be appended to this file every time one or more streams is successfully
169 fetched for a url.
170  
171 DEFAULT I<-none-> (no logging).
172  
173 I<-logfmt> specifies a format string for lines written to the log file.
174  
175 DEFAULT "I<[time] [url] - [site]: [title] ([total])>".
176  
177 The valid field I<[variables]> are: [stream]: The url of the first/best
178 stream found. [site]: The site name (Brighteon). [url]: The url searched
179 for streams. [time]: Perl timestamp when the line was logged. [title],
180 [artist], [album], [description], [year], [genre], [total], [albumartist]:
181 The corresponding field data returned (or "I<-na->", if no value).
182  
183 =item $video->B<get>()
184  
185 Returns an array of strings representing all stream URLs found.
186  
187 =item $video->B<getURL>([I<options>])
188  
189 Similar to B<get>() except it only returns a single stream representing
190 the first valid stream found.
191  
192 Current options are: I<"random">, I<"nopls">, and I<"noplaylists">.
193 By default, the first ("best"?) stream is returned. If I<"random"> is
194 specified, then a random one is selected from the list of streams found.
195 If I<"nopls"> is specified, and the stream to be returned is a ".pls" playlist,
196 it is first fetched and the first entry (or a random entry if I<"random"> is
197 specified) is returned. This is needed by Fauxdacious Mediaplayer.
198 If I<"noplaylists"> is specified, and the stream to be returned is a
199 "playlist" (either .pls or .m3u? extension), it is first fetched and the first
200 entry (or a random entry if I<"random"> is specified) in the playlist
201 is returned.
202  
203 =item $video->B<count>()
204  
205 Returns the number of streams found for the video.
206  
207 =item $video->B<getID>()
208  
209 Returns the video's Brighteon ID (alphanumeric).
210  
211 =item $video->B<getTitle>(['desc'])
212  
213 Returns the video's title, or (long description).
214  
215 =item $video->B<getIconURL>(['artist'])
216  
217 Returns the URL for the video's "cover art" icon image, if any.
218 If B<'artist'> is specified, the channel artist's icon url is returned,
219 if any.
220  
221 =item $video->B<getIconData>(['artist'])
222  
223 Returns a two-element array consisting of the extension (ie. "png",
224 "gif", "jpeg", etc.) and the actual icon image (binary data), if any.
225 If B<'artist'> is specified, the channel artist's icon data is returned,
226 if any.
227  
228 =item $video->B<getImageURL>()
229  
230 Returns the URL for the video's "cover art" banner image, which for
231 Brighteon videos is always the icon image, as Brighteon does not
232 support a separate banner image at this time.
233  
234 =item $video->B<getImageData>()
235  
236 Returns a two-element array consisting of the extension (ie. "png",
237 "gif", "jpeg", etc.) and the actual video's banner image (binary data).
238  
239 =item $video->B<getType>()
240  
241 Returns the video's type ("Brighteon").
242  
243 =back
244  
245 =head1 CONFIGURATION FILES
246  
247 The default root location directory for StreamFinder configuration files
248 is "~/.config/StreamFinder". To use an alternate location directory,
249 specify it in the "I<STREAMFINDER>" environment variable, ie.:
250 B<$ENV{STREAMFINDER} = "/etc/StreamFinder">.
251  
252 =over 4
253  
254 =item ~/.config/StreamFinder/Brighteon/config
255  
256 Optional text file for specifying various configuration options
257 for a specific site (submodule). Each option is specified on a
258 separate line in the format below:
259 NOTE: Do not follow the lines with a semicolon, comma, or any other
260 separator. Non-numeric I<values> should be surrounded with quotes, either
261 single or double. Blank lines and lines beginning with a "#" sign as
262 their first non-blank character are ignored as comments.
263  
264 'option' => 'value' [,]
265  
266 and the options are loaded into a hash used only by the specific
267 (submodule) specified. Valid options include
268 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
269  
270 Options specified here override any specified in
271 I<~/.config/StreamFinder/config>.
272  
273 Among options valid for Brighteon streams is the I<-keep> and
274 I<-youtube> options described in the B<new()> function. Also,
275 various youtube-dl (L<StreamFinder::Youtube>) configuration options,
276 namely I<format>, I<formatonly>, I<youtube-dl-args>, and I<youtube-dl-add-args>
277 can be overridden here by specifying I<youtube-format>, I<youtube-formatonly>,
278 I<youtube-dl-args>, and I<youtube-dl-add-args> arguments respectively.
279 NOTE: These are only applicable when using the option:
280 I<-youtube> => I<yes|only|top>, etc.
281  
282 =item ~/.config/StreamFinder/config
283  
284 Optional text file for specifying various configuration options.
285 Each option is specified on a separate line in the format below:
286  
287 'option' => 'value' [,]
288  
289 and the options are loaded into a hash used by all sites
290 (submodules) that support them. Valid options include
291 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
292  
293 =back
294  
295 NOTE: Options specified in the options parameter list of the I<new()>
296 function will override those corresponding options specified in these files.
297  
298 =head1 KEYWORDS
299  
300 brighteon
301  
302 =head1 DEPENDENCIES
303  
304 L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent>
305  
306 =head1 RECCOMENDS
307  
308 youtube-dl (or yt-dlp, or other compatable program)
309  
310 wget
311  
312 =head1 BUGS
313  
314 Please report any bugs or feature requests to C<bug-streamFinder-brighteon at rt.cpan.org>, or through
315 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-Brighteon>. I will be notified, and then you'll
316 automatically be notified of progress on your bug as I make changes.
317  
318 =head1 SUPPORT
319  
320 You can find documentation for this module with the perldoc command.
321  
322 perldoc StreamFinder::Brighteon
323  
324 You can also look for information at:
325  
326 =over 4
327  
328 =item * RT: CPAN's request tracker (report bugs here)
329  
330 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-Brighteon>
331  
332 =item * AnnoCPAN: Annotated CPAN documentation
333  
334 L<http://annocpan.org/dist/StreamFinder-Brighteon>
335  
336 =item * Search CPAN
337  
338 L<http://search.cpan.org/dist/StreamFinder-Brighteon/>
339  
340 =back
341  
342 =head1 LICENSE AND COPYRIGHT
343  
344 Copyright 2017-2026 Jim Turner.
345  
346 This program is free software; you can redistribute it and/or modify it
347 under the terms of the the Artistic License (2.0). You may obtain a
348 copy of the full license at:
349  
350 L<http://www.perlfoundation.org/artistic_license_2_0>
351  
352 Any use, modification, and distribution of the Standard or Modified
353 Versions is governed by this Artistic License. By using, modifying or
354 distributing the Package, you accept this license. Do not use, modify,
355 or distribute the Package, if you do not accept this license.
356  
357 If your Modified Version has been derived from a Modified Version made
358 by someone other than you, you are nevertheless required to ensure that
359 your Modified Version complies with the requirements of this license.
360  
361 This license does not grant you the right to use any trademark, service
362 mark, tradename, or logo of the Copyright Holder.
363  
364 This license includes the non-exclusive, worldwide, free-of-charge
365 patent license to make, have made, use, offer to sell, sell, import and
366 otherwise transfer the Package with respect to any patent claims
367 licensable by the Copyright Holder that are necessarily infringed by the
368 Package. If you institute patent litigation (including a cross-claim or
369 counterclaim) against any party alleging that the Package constitutes
370 direct or contributory patent infringement, then this Artistic License
371 to you shall terminate on the date that such litigation is filed.
372  
373 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
374 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
375 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
376 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
377 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
378 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
379 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
380 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
381  
382 =cut
383  
384 package StreamFinder::Brighteon;
385  
386 use strict;
387 use warnings;
388 use URI::Escape;
389 use HTML::Entities ();
390 use LWP::UserAgent ();
391 use parent 'StreamFinder::_Class';
392  
393 my $DEBUG = 0;
394  
395 sub new
396 {
397 my $class = shift;
398 my $url = shift;
399  
400 return undef unless ($url);
401  
402 my $self = $class->SUPER::new('Brighteon', @_);
403 $DEBUG = $self->{'debug'} if (defined $self->{'debug'});
404  
405 my @okStreams;
406 $self->{'youtube'} = 'no' unless (defined $self->{'youtube'});
407 while (@_) {
408 if ($_[0] =~ /^\-?youtube$/o) {
409 shift;
410 $self->{'youtube'} = (defined $_[0]) ? shift : 'yes';
411 } elsif ($_[0] =~ /^\-?keep$/o) {
412 shift;
413 if (defined $_[0]) {
414 my $keeporder = shift;
415 @okStreams = (ref($keeporder) =~ /ARRAY/) ? @{$keeporder} : split(/\,\s*/, $keeporder);
416 }
417 } else {
418 shift;
419 }
420 }
421 if (!defined($okStreams[0]) && defined($self->{'keep'})) {
422 @okStreams = (ref($self->{'keep'}) =~ /ARRAY/) ? @{$self->{'keep'}} : split(/\,\s*/, $self->{'keep'});
423 }
424 @okStreams = (qw(m4a mpd mp3 stream all)) unless (defined $okStreams[0]); # one of: {m4a, <ext>, direct, stream, any, all}
425  
426 print STDERR "-0(Brighteon): URL=$url=\n" if ($DEBUG);
427 $url =~ s/\?autoplay\=true$//; #STRIP THIS OFF SO WE DON'T HAVE TO.
428 (my $url2fetch = $url);
429 #DEPRECIATED (VIDEO-IDS NOW INCLUDE STUFF BEFORE THE DASH: ($self->{'id'} = $url) =~ s#^.*\-([a-z]\d+)\/?$#$1#;
430 if ($url2fetch =~ m#^https?\:#) {
431 $url2fetch =~ s#\/embed\/#\/#; #CONVERT "embed" URLS TO STANDARD ONES.
432 $self->{'id'} = $1 if ($url2fetch =~ m#\/([^\/]+)\/?$#);
433 $self->{'id'} =~ s/[\?\&].*$//;
434 } else {
435 $self->{'id'} = $url;
436 $url2fetch = ($url =~ /\-\w\w\w\w\-/) ? 'https://www.brighteon.com/'
437 : 'https://www.brighteon.com/channels/';
438 $url2fetch .= $url;
439 }
440 print STDERR "-1 FETCHING URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
441 $self->{'genre'} = 'Video';
442  
443 my $html = '';
444 my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}});
445 $ua->timeout($self->{'timeout'});
446 $ua->cookie_jar({});
447 $ua->env_proxy;
448 my $response = $ua->get($url2fetch);
449 if ($response->is_success) {
450 $html = $response->decoded_content;
451 } else {
452 print STDERR $response->status_line if ($DEBUG);
453 my $no_wget = system('wget','-V');
454 unless ($no_wget) {
455 print STDERR "\n..trying wget...\n" if ($DEBUG);
456 $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `;
457 }
458 }
459 return undef unless ($html);
460  
461 if ($url2fetch =~ m#\/channels\/#) { #WE'RE A CHANNEL PAGE, GRAB 1ST VIDEO! (DEPRECIATED!):
462 print "--WE'RE A BRIGHTEON CHANNEL URL!\n" if ($DEBUG);
463 if ($html =~ m#\bhref\=\"([^\"]+)\"\>\s*\<img\s+src\=\"https\:\/\/photos\.brighteon\.com\/thumbnail#) {
464 ($url2fetch = $1) =~ s#^\/#https://www.brighteon.com/#;
465 $self->{'id'} = $1 if ($url2fetch =~ m#\/([^\/]+)\/?$#);
466 $self->{'id'} =~ s/[\?\&].*$//;
467 print "---FOUND 1ST EPISODE! FETCHING=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
468 $response = $ua->get($url2fetch);
469 if ($response->is_success) {
470 $html = $response->decoded_content;
471 } else {
472 print STDERR $response->status_line if ($DEBUG);
473 my $no_wget = system('wget','-V');
474 unless ($no_wget) {
475 print STDERR "\n..trying wget...\n" if ($DEBUG);
476 $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `;
477 }
478 }
479 return undef unless ($html);
480 } else {
481 print STDERR "\ne:Brighteon podcast/channel pages no longer supported (unscrapable)!\n";
482 return undef;
483 }
484 }
485  
486 $html =~ s/\\\"/\&quot\;/gs;
487 if ($html =~ s#\<a\s+href\=\"([^\"]*)\"\s+title\=\"[^\"]*\"\s+class\=\"author\_\_name\"\>([^\<]+)\<##s) {
488 my $one = $1;
489 ($self->{'artist'} = $2) =~ s/\s+$//;
490 $self->{'albumartist'} = 'https://www.brighteon.com' . $one if ($one);
491 } elsif ($html =~ m#\"shortUrl\"\:\"([^\"]+)\"\,\"name\"\:\"([^\"]+)\"#) {
492 $self->{'artist'} = $2;
493 $self->{'albumartist'} = "http://www.brighteon.com/channels/$1" if ($1);
494 }
495  
496 #FETCH ALL STREAMS:
497  
498 unless ($self->{'youtube'} =~ /only/i) { #FETCH STREAMS HERE UNLESS USER WANT'S youtube-dl STREAMS ONLY:
499 my $streams = '';
500 if ($html =~ m#\"source\"\:\[([^\]]+)#s) {
501 my $sourcedata = $1;
502 my ($one, $ext);
503 while ($sourcedata =~ s#\{\"src\"\:\"([^\"]+)\"##so) {
504 $one = $1;
505 $ext = ($one =~ /\.(\w+)$/) ? $1 : '';
506 $streams .= "$ext=$one|";
507 }
508 }
509 if ($html =~ m#\"audioSource\"\:\[([^\]]+)#s) {
510 my $sourcedata = $1;
511 my ($one, $ext);
512 while ($sourcedata =~ s#\{\"src\"\:\"([^\"]+)\"##so) {
513 $one = $1;
514 $ext = ($one =~ /\.(\w+)$/) ? $1 : '';
515 $streams .= "$ext=$one|";
516 }
517 }
518 if ($streams) {
519 my $stindex = 0;
520 my $savestreams = $streams;
521 my %havestreams = ();
522  
523 if (defined $self->{'formats_by_channel'} && $self->{'albumartist'}) {
524 my %formats_by_url = %{$self->{'formats_by_channel'}};
525 foreach my $i (keys %formats_by_url) {
526 if ($self->{'albumartist'} =~ m#$i#i) {
527 @okStreams = split(/\,\s*/, $formats_by_url{$i});
528 }
529 }
530 }
531 print STDERR "--Brighteon: ok Stream types=".join('|',@okStreams)."= channel=".$self->{'albumartist'}."=\n" if ($DEBUG);
532 foreach my $streamtype (@okStreams) {
533 $streams = $savestreams;
534 if ($streamtype =~ /^stream$/i) {
535 while ($streams =~ /^([^\=]*)\=([^\|]+)/o) {
536 my $ext = $1;
537 my $one = $2;
538 $one = 'https://video.brighteon.com/file/BTBucket-Prod/' . $one
539 unless ($one =~ m#^https?\:\/\/#);
540 if ($ext !~ /^pls$/i && !defined($havestreams{"$ext|$one"})) {
541 unless ($self->{'secure'} && $one !~ /^https/o) {
542 $self->{'streams'}->[$stindex++] = $one;
543 $havestreams{"$ext|$one"}++;
544 }
545 }
546 $streams =~ s/^[^\|]*\|//o;
547 }
548 } elsif ($streamtype =~ /^playlist$/i) {
549 while ($streams =~ /^([^\=]*)\=([^\|]+)/o) {
550 my $ext = $1;
551 my $one = $2;
552 if ($ext =~ /^pls$/i && !defined($havestreams{"$ext|$one"})) {
553 unless ($self->{'secure'} && $one !~ /^https/o) {
554 $self->{'streams'}->[$stindex++] = $one;
555 $havestreams{"$ext|$one"}++;
556 }
557 }
558 $streams =~ s/^[^\|]*\|//o;
559 }
560 } elsif ($streamtype =~ /^a(?:ny|ll)$/i) {
561 while ($streams =~ /^([^\=]*)\=([^\|]+)/o) {
562 my $ext = $1;
563 my $one = $2;
564 unless (defined($havestreams{"$ext|$one"})) {
565 unless ($self->{'secure'} && $one !~ /^https/o) {
566 $self->{'streams'}->[$stindex++] = $one;
567 $havestreams{"$ext|$one"}++;
568 }
569 }
570 $streams =~ s/^[^\|]*\|//o;
571 }
572 } else {
573 while ($streams =~ /^([^\=]*)\=([^\|]+)/o) {
574 my $ext = $1;
575 my $one = $2;
576 if ($ext =~ /^${streamtype}$/i && !defined($havestreams{"$ext|$one"})) {
577 unless ($self->{'secure'} && $one !~ /^https/o) {
578 $self->{'streams'}->[$stindex++] = $one;
579 $havestreams{"$ext|$one"}++;
580 }
581 }
582 $streams =~ s/^[^\|]*\|//o;
583 }
584 }
585 }
586 $self->{'cnt'} = scalar @{$self->{'streams'}};
587 } elsif ($html =~ m#\"audio\"\:\"([^\"]+)#s) { #TRY FALLBACK AUDIO STREAM IF NO STREAMS FOUND:
588 my $one = $1;
589 $one = 'https://video.brighteon.com/file/BTBucket-Prod/' . $one
590 unless ($one =~ m#^https?\:\/\/#);
591 unless ($self->{'secure'} && $one !~ /^https/o) {
592 $self->{'streams'}->[0] = $one;
593 $self->{'cnt'} = scalar @{$self->{'streams'}};
594 }
595 }
596 }
597  
598 #FETCH OTHER METADATA FROM PAGE:
599  
600 $self->{'title'} = $1 if ($html =~ m#\"name\"\:\"([^\"]+)#s);
601 $self->{'description'} = $1 if ($html =~ m#\"description\"\:\"([^\"]+)#s);
602 $self->{'iconurl'} = $1 if ($html =~ m#\"thumbnail\"\:\"([^\"]+)#s);
603 $self->{'imageurl'} = ($html =~ m#\"poster\"\:\"(https?\:\/\/[^\"]+)#s)
604 ? $1 : $self->{'iconurl'};
605 $self->{'articonurl'} = $1 if ($html =~ m#\"thumbnailUrl\"\:\"([^\"]+)#s);
606 $self->{'articonurl'} ||= $1 if ($html =~ m#\"channelAvatar\"\:\"([^\"]+)#s);
607 if ($html =~ m#\"createdAt\"\:\"([^\"]+)#s) {
608 $self->{'created'} = $1;
609 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
610 }
611  
612 #IF WE DIDN'T FIND ANY STREAMS IN THE PAGE, TRY youtube-dl (DEPRECIATED!):
613  
614 if ($self->{'cnt'} <= 0 || $self->{'youtube'} =~ /(?:yes|top|first|last|only)/i) { #(ANYTHING BUT "no"):
615 my $haveYoutube = 0;
616 eval { require 'StreamFinder/Youtube.pm'; $haveYoutube = 1; };
617 print STDERR "\n-2 NO STREAMS FOUND IN PAGE (haveYoutube=$haveYoutube)\n" if ($DEBUG && $self->{'cnt'} <= 0);
618 if ($haveYoutube) {
619 print STDERR "\n-2 TRYING youtube-dl($self->{'youtube'})...\n" if ($DEBUG && $self->{'youtube'} =~ /(?:yes|top|first)/i);
620 my %globalArgs = (
621 '-noiframes' => 1, '-fast' => 1, '-debug' => $DEBUG
622 );
623 foreach my $arg (qw(secure log logfmt youtube-format youtube-format-fallback
624 youtube-formatonly youtube-dl-args youtube-dl-add-args)) {
625 (my $arg0 = $arg) =~ s/^youtube\-(?!dl)//o;
626 $globalArgs{$arg0} = $self->{$arg} if (defined $self->{$arg});
627 }
628 my $yt = new StreamFinder::Youtube($url2fetch, %globalArgs);
629 if ($yt && $yt->count() > 0) {
630 my @ytStreams = $yt->get();
631 if ($self->{'youtube'} =~ /(?:top|first)/i) { #PUT youtube-dl STREAMS ON TOP:
632 unshift @{$self->{'streams'}}, @ytStreams;
633 } else {
634 push @{$self->{'streams'}}, @ytStreams;
635 }
636 foreach my $field (qw(title iconurl)) {
637 $self->{$field} ||= $yt->{$field} if (defined($yt->{$field}) && $yt->{$field});
638 }
639 $self->{'description'} = $yt->{'description'} if (length($yt->{'description'}) > length($self->{'description'}));
640 $self->{'cnt'} = scalar @{$self->{'streams'}};
641 print STDERR "i:Found stream(s) (".join('|',@ytStreams).") via youtube-dl.\n" if ($DEBUG);
642 }
643 }
644 }
645 if ($self->{'description'} =~ /\w/) {
646 $self->{'description'} =~ s/\s+$//;
647 } else {
648 $self->{'description'} = $self->{'title'};
649 }
650 foreach my $i (qw(title artist description)) {
651 $self->{$i} = HTML::Entities::decode_entities($self->{$i});
652 $self->{$i} = uri_unescape($self->{$i});
653 $self->{$i} =~ s/(?:\%|\\[ux\%]?00|\bu00)([0-9A-Fa-f]{2})/chr(hex($1))/egs;
654  
655 }
656 $self->{'total'} = $self->{'cnt'};
657 $self->{'Url'} = ($self->{'cnt'} > 0) ? $self->{'streams'}->[0] : '';
658 if ($DEBUG) {
659 foreach my $i (sort keys %{$self}) {
660 print STDERR "--KEY=$i= VAL=".$self->{$i}."=\n";
661 }
662 print STDERR "--SUCCESS: 1st stream=".$self->{'Url'}."= total=".$self->{'total'}."=\n"
663 if ($self->{'cnt'} > 0);
664 }
665 $self->_log($url);
666  
667 bless $self, $class; #BLESS IT!
668  
669 return $self;
670 }
671  
672 sub getImageData
673 {
674 my $self = shift;
675 return $self->getIconData();
676 }
677  
678 1