StreamFinder/Subsplash.pm untested

filter: Statementstmt 0.0% 0 / 198 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 395 CC 70 SCAR 84.2
CC
70
Cov
0%
new
4970.0
BEGIN
2.0
BEGIN
2.0
CRAP 4518.4
1 =head1 NAME
2  
3 StreamFinder::Subsplash - Fetch actual raw streamable URLs on subsplash.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::Subsplash;
26  
27 die "..usage: $0 ID|URL\n" unless ($ARGV[0]);
28  
29 my $podcast = new StreamFinder::Subsplash($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::Subsplash accepts a valid podcast (sermon) page URL on
90 Subsplash.com and returns the actual stream URL(s), title, and cover art icon.
91 The purpose is that one needs one of these URLs in order to have the option to
92 stream the podcast in one's own choice of media player software rather than
93 using their web browser and accepting any / all flash, ads, javascript,
94 cookies, trackers, web-bugs, and other crapware that can come with that method
95 of play. The author uses his own custom all-purpose media player called
96 "fauxdacious" (his custom hacked version of the open-source "audacious"
97 audio player). "fauxdacious" can incorporate this module to decode and play
98 Subsplash.com streams.
99  
100 One or more stream URLs can be returned for each podcast.
101  
102 =head1 SUBROUTINES/METHODS
103  
104 =over 4
105  
106 =item B<new>(I<url> [, I<-secure> [ => 0|1 ]
107 [, I<-nohls> [ => 0|1 ]] [, I<-debug> [ => 0|1|2 ]
108 [, I<-youtube> => yes|no|first|last|only|ifneeded ]])
109  
110 Accepts a subsplash.com podcast (sermon) URL and creates and returns a
111 a new podcast object, or I<undef> if the URL is not a valid podcast, or no
112 streams are found. The URL must be the full URL, ie.
113 https://subsplash.com/...B<channel>/.../B<episode><id>.
114  
115 The optional I<-youtube> argument can be set to "I<yes>" or "I<last>" -
116 Subsplash will also look for streams via the external program yt-dlp ,if
117 available, (last - after Subsplash streams, if any, found on the page);
118 "I<no>" - only include streams found from the video's subsplash.com page;
119 "I<only>" - return only streams returned by yt-dlp; or "I<first>" - include the
120 yt-dlp streams (if any) first.
121 NOTE: Unlike most other modules, yt-dlp will NOT be used if I<-youtube> is set
122 to I<no> regardless of whether any Subsplash streams were found.
123 If I<-youtube> is set to I<ifneeded>, then yt-dlp
124 will only be called if no other streams found. Default is set to "first"
125 because now generally only audio streams are found on Subsplash pages.
126  
127 DEFAULT I<-youtube> is 'first'.
128  
129 The optional (<-nohls> argument can be set to either 0 or 1
130 (I<false> or I<true>). If 1 (I<true>), then only non-HLS (.m3u8?) streams
131 will be accepted from Subsplash or yt-dlp (Youtube).
132  
133 DEFAULT I<-nohls> is 0 (false) - return all streams yt-dlp finds in Subsplash.
134  
135 The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>). If 1
136 then only secure ("https://") streams will be returned.
137  
138 DEFAULT I<-secure> is 0 (false) - return all streams (http and https).
139  
140 Additional options:
141  
142 Certain yt-dlp (L<StreamFinder::Youtube>) configuration options,
143 namely I<-format>, I<-formatonly>, I<-youtube-dl-args>,
144 and I<-youtube-dl-add-args> can be overridden here by specifying
145 I<-youtube-format>, I<-youtube-formatonly>, I<-youtube-dl-args>,
146 and I<-youtube-dl-add-args> arguments respectively. It is however,
147 recommended to specify these in the Subsplash-specific configuration file
148 (see B<CONFIGURATION FILES> below).
149  
150 I<-log> => "I<logfile>"
151  
152 Specify path to a log file. If a valid and writable file is specified,
153 A line will be appended to this file every time one or more streams is
154 successfully fetched for a url.
155  
156 DEFAULT I<-none-> (no logging).
157  
158 I<-logfmt> specifies a format string for lines written to the log file.
159  
160 DEFAULT "I<[time] [url] - [site]: [title] ([total])>".
161  
162 The valid field I<[variables]> are: [stream]: The url of the first/best
163 stream found. [site]: The site name (Subsplash). [url]: The url searched
164 for streams. [time]: Perl timestamp when the line was logged. [title],
165 [artist], [album], [description], [year], [genre], [total], [albumartist]:
166 The corresponding field data returned (or "I<-na->", if no value).
167  
168 =item $podcast->B<get>()
169  
170 Returns an array of strings representing all stream URLs found.
171  
172 =item $podcast->B<getURL>([I<options>])
173  
174 Similar to B<get>() except it only returns a single stream representing
175 the first valid stream found. There currently are no valid I<options>.
176  
177 =item $podcast->B<count>()
178  
179 Returns the number of streams found for the podcast.
180  
181 =item $podcast->B<getID>()
182  
183 Returns the podcast's Subsplash ID (default). For podcasts, the Subsplash ID
184 is a single value. For individual podcast episodes it's two values
185 separated by a slash ("/").
186  
187 =item $podcast->B<getTitle>(['desc'])
188  
189 Returns the podcast's title, or (long description). Podcasts
190 on Subsplash can have separate descriptions, but for podcasts,
191 it is always the podcast's title.
192  
193 =item $podcast->B<getIconURL>(['artist'])
194  
195 Returns the URL for the podcast'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 =item $podcast->B<getIconData>(['artist'])
200  
201 Returns a two-element array consisting of the extension (ie. "png",
202 "gif", "jpeg", etc.) and the actual icon image (binary data), if any.
203 If B<'artist'> is specified, the channel artist's icon data is returned,
204 if any.
205  
206 =item $podcast->B<getImageURL>(['artist'])
207  
208 Returns the URL for the podcast's "cover art" (usually larger)
209 banner image. Note: Subsplash returns the same image url as the icon url.
210 If B<'artist'> is specified, the channel artist's image URL
211 is returned, if any, which may be larger than the artist's icon image.
212  
213 =item $podcast->B<getImageData>(['artist'])
214  
215 Returns a two-element array consisting of the extension (ie. "png",
216 "gif", "jpeg", etc.) and the actual podcast's banner image (binary data).
217 If B<'artist'> is specified, the channel artist's image data is returned,
218 if any.
219  
220 =item $podcast->B<getType>()
221  
222 Returns the podcast's type ("Subsplash").
223  
224 =back
225  
226 =head1 CONFIGURATION FILES
227  
228 The default root location directory for StreamFinder configuration files
229 is "~/.config/StreamFinder". To use an alternate location directory,
230 specify it in the "I<STREAMFINDER>" environment variable, ie.:
231 B<$ENV{STREAMFINDER} = "/etc/StreamFinder">.
232  
233 =over 4
234  
235 =item ~/.config/StreamFinder/Subsplash/config
236  
237 Optional text file for specifying various configuration options
238 for a specific site (submodule). Each option is specified on a
239 separate line in the format below:
240 NOTE: Do not follow the lines with a semicolon, comma, or any other
241 separator. Non-numeric I<values> should be surrounded with quotes, either
242 single or double. Blank lines and lines beginning with a "#" sign as
243 their first non-blank character are ignored as comments.
244  
245 'option' => 'value' [,]
246  
247 and the options are loaded into a hash used only by the specific
248 (submodule) specified. Valid options include
249 I<-debug> => [0|1|2]> and most of the L<LWP::UserAgent> options.
250  
251 Among options valid for Subsplash streams are the various youtube-dl
252 (L<StreamFinder::Youtube>) configuration options,
253 namely I<format>, I<formatonly>, I<youtube-dl-args>, and I<youtube-dl-add-args>
254 can be overridden here by specifying I<youtube-format>, I<youtube-formatonly>,
255 I<youtube-dl-args>, and I<youtube-dl-add-args> arguments respectively.
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 will override
273 those corresponding options specified in these files.
274  
275 =head1 KEYWORDS
276  
277 subsplash
278  
279 =head1 DEPENDENCIES
280  
281 L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent>
282  
283 =head1 RECCOMENDS
284  
285 yt-dlp, or other compatable program
286  
287 wget
288  
289 =head1 BUGS
290  
291 Please report any bugs or feature requests to C<bug-streamFinder-subsplash at rt.cpan.org>, or through
292 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-Subsplash>. I will be notified, and then you'll
293 automatically be notified of progress on your bug as I make changes.
294  
295 =head1 SUPPORT
296  
297 You can find documentation for this module with the perldoc command.
298  
299 perldoc StreamFinder::Subsplash
300  
301 You can also look for information at:
302  
303 =over 4
304  
305 =item * RT: CPAN's request tracker (report bugs here)
306  
307 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-Subsplash>
308  
309 =item * AnnoCPAN: Annotated CPAN documentation
310  
311 L<http://annocpan.org/dist/StreamFinder-Subsplash>
312  
313 =item * Search CPAN
314  
315 L<http://search.cpan.org/dist/StreamFinder-Subsplash/>
316  
317 =back
318  
319 =head1 LICENSE AND COPYRIGHT
320  
321 Copyright 2021-2026 Jim Turner.
322  
323 This program is free software; you can redistribute it and/or modify it
324 under the terms of the the Artistic License (2.0). You may obtain a
325 copy of the full license at:
326  
327 L<http://www.perlfoundation.org/artistic_license_2_0>
328  
329 Any use, modification, and distribution of the Standard or Modified
330 Versions is governed by this Artistic License. By using, modifying or
331 distributing the Package, you accept this license. Do not use, modify,
332 or distribute the Package, if you do not accept this license.
333  
334 If your Modified Version has been derived from a Modified Version made
335 by someone other than you, you are nevertheless required to ensure that
336 your Modified Version complies with the requirements of this license.
337  
338 This license does not grant you the right to use any trademark, service
339 mark, tradename, or logo of the Copyright Holder.
340  
341 This license includes the non-exclusive, worldwide, free-of-charge
342 patent license to make, have made, use, offer to sell, sell, import and
343 otherwise transfer the Package with respect to any patent claims
344 licensable by the Copyright Holder that are necessarily infringed by the
345 Package. If you institute patent litigation (including a cross-claim or
346 counterclaim) against any party alleging that the Package constitutes
347 direct or contributory patent infringement, then this Artistic License
348 to you shall terminate on the date that such litigation is filed.
349  
350 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
351 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
352 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
353 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
354 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
355 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
356 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
357 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
358  
359 =cut
360  
361 package StreamFinder::Subsplash;
362  
363 use strict;
364 use warnings;
365 use URI::Escape;
366 use HTML::Entities ();
367 use LWP::UserAgent ();
368 use parent 'StreamFinder::_Class';
369  
370 my $DEBUG = 0;
371  
372 sub new
373 {
374 my $class = shift;
375 my $url = shift;
376  
377 return undef unless ($url);
378  
379 my $self = $class->SUPER::new('Subsplash', @_);
380 $DEBUG = $self->{'debug'} if (defined $self->{'debug'});
381 $self->{'youtube'} = 'first' unless (defined $self->{'youtube'});
382 $self->{'nohls'} = 0 unless (defined $self->{'nohls'});
383 while (@_) {
384 if ($_[0] =~ /^\-?youtube$/o) {
385 shift;
386 $self->{'youtube'} = (defined $_[0]) ? shift : 'first';
387 } elsif ($_[0] =~ /^\-?nohls$/o) {
388 shift;
389 $self->{'nohls'} = (defined $_[0]) ? shift : 1;
390 } else {
391 shift;
392 }
393 }
394  
395 $url =~ s#\\##g;
396 my $url2fetch = HTML::Entities::decode_entities($url);
397 my ($protocol, undef, $server, @urlparts) = split(m#\/#, $url2fetch);
398 my $channel = '';
399 foreach my $j (@urlparts) {
400 $j =~ s/[\?\&].*$//o;
401 next if ($j =~ /\b(?:embed|media)\b/o);
402 if (length($j) < 4) {
403 $self->{'albumartist'} .= '/' . $j unless ($channel);
404 next;
405 } elsif ($channel) {
406 $self->{'id'} = $j;
407 } else {
408 $self->{'albumartist'} .= '/' . $j;
409 $channel = $j;
410 }
411 }
412 $self->{'id'} ||= $channel;
413 my $baseURL = $protocol . '//' . $server;
414 $self->{'albumartist'} = $baseURL . $self->{'albumartist'} . '/media';
415 my $html = '';
416 print STDERR "-0(Subsplash): FETCHING URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
417 my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}});
418 $ua->timeout($self->{'timeout'});
419 $ua->cookie_jar({});
420 $ua->env_proxy;
421 my $response = $ua->get($url2fetch);
422 if ($response->is_success) {
423 $html = $response->decoded_content;
424 } else {
425 print STDERR $response->status_line if ($DEBUG);
426 }
427 print STDERR "-1: html=$html=\n" if ($DEBUG > 1);
428 return undef unless ($html); #STEP 1 FAILED, INVALID PODCAST URL, PUNT!
429 $self->{'cnt'} = 0;
430 $self->{'title'} = '';
431 $self->{'artist'} = '';
432 $self->{'album'} = $url2fetch;
433 $self->{'description'} = '';
434 $self->{'created'} = '';
435 $self->{'year'} = '';
436 $self->{'genre'} = 'Podcast';
437 $self->{'iconurl'} = '';
438 $self->{'streams'} = [];
439 $self->{'Url'} = '';
440 $self->{'playlist'} = '';
441 my %dups = ();
442 my $stream = '';
443 my @nonYtStreams = ();
444 my $nonYtCnt = 0;
445 my @YTDLstreams = ();
446 my $YTDLcnt = 0;
447 my $embedPage = 0;
448 unless ($self->{'youtube'} =~ /only/i) {
449 #TRY TO FETCH ANY STREAM IN THE SUBSPLASH PAGE ITSELF:
450 foreach my $tag ('video', 'audio') {
451 if ($html =~ s#\<$tag\s+preload(.+?)\<\/$tag\>##si) {
452 my $stuff = $1;
453 if ($stuff =~ m#\<source\s+src\=\"([^\"]+)#) {
454 $stream = $1;
455 next if ($self->{'nohls'} && $stream =~ /\.m3u8?/o);
456 print STDERR "+++++FOUND $tag stream in page=$stream=\n" if ($DEBUG);
457 push (@nonYtStreams, $stream)
458 unless ($self->{'secure'} && $stream !~ /^https/o);
459 }
460 }
461 }
462 $nonYtCnt = scalar (@nonYtStreams);
463  
464 return undef unless ($nonYtCnt > 0 || $self->{'youtube'} !~ /no/i);
465 }
466  
467 foreach my $tag ('og:title', 'twitter:title') {
468 if ($html =~ s#\"$tag\"\s+content\=\"([^\"]+)\"##gso) {
469 $self->{'title'} = $1;
470 last if ($self->{'title'});
471 }
472 }
473 foreach my $tag ('og:description', 'twitter:description') {
474 if ($html =~ s#\"$tag\"\s+content\=\"([^\"]+)\"##gso) {
475 $self->{'description'} = $1;
476 last if ($self->{'description'});
477 }
478 }
479 foreach my $tag ('og:image', 'twitter:image') {
480 if ($html =~ s#\"$tag\"\s+content\=\"([^\"]+)\"##gso) {
481 $self->{'iconurl'} = $1;
482 ($self->{'imageurl'} = $self->{'iconurl'}) =~ s/\&.+$//;
483 last if ($self->{'iconurl'});
484 }
485 }
486 unless ($self->{'iconurl'}) {
487 if ($html =~ m#\<img\s+class\=\"kit\-image\_\_image\"\s+src\=\"([^\"]+)\"#g) {
488 ($self->{'iconurl'} = $1) =~ s/\&amp\;.*$//;
489 $self->{'imageurl'} = $self->{'iconurl'};
490 }
491 }
492 if ($html =~ s#kit\-player\_\_info\-text\-\-date\"\>(.+?)\<\/div\>##s) {
493 $self->{'created'} = $1;
494 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
495 } elsif ($html =~ s#app\_\_footer\-copyright\"\>(.+?)\<\/div\>##s) {
496 $self->{'created'} = $1;
497 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
498 } elsif ($html =~ m#\\\"date\\\"\:\\\"(.+?)\\\"#s) {
499 $self->{'created'} = $1;
500 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
501 } elsif ($html =~ m#\<\!\-\-\s+\-\-\>(\d\d\d\d)\<\!\-\-\s+\-\-\>#) {
502 $self->{'created'} = $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
503 }
504 if ($html =~ m#\<div\s+class\=\"route\-media\-item\_\_basic\-info\"\>(.+?)\<\/div\>#s) {
505 my $addtl = $1;
506 if ($addtl =~ m#\<p\>\s*(.+?)\<\/p\>#s) {
507 my $stuff = $1;
508 if ($stuff =~ s#^\s*(.+?\d\d\d\d)##s) {
509 $self->{'created'} = $1;
510 $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
511 ($self->{'artist'} = $stuff) =~ s#^[^\w]+##s;
512 $self->{'artist'} =~ s/\s+$//;
513 $self->{'artist'} =~ s/[\\\"].*$//s;
514 }
515 }
516 } elsif ($html =~ s#kit\-player\_\_info\-text\-\-additional\"\>(.+?)\<\/div\>##s) { ## DEPRECIATED? ##:
517 $self->{'artist'} = $1;
518 $self->{'artist'} =~ s/^\s+//s;
519 $self->{'artist'} =~ s/\s+$//s;
520 } elsif ($html =~ m#\\\"speaker\\\"\:\\\"(.+?)\\\"#s) {
521 $self->{'artist'} = $1;
522 } elsif ($html =~ m#\<meta\s+property\="(?:og|twitter)\:site\_name\"\s+content\=\"([^\"]+)#s) {
523 $self->{'artist'} = $1;
524 }
525 $self->{'genre'} = $1 if ($html =~ m#\\\"topic\:(.+?)\\\"#s);
526 if ($html =~ m#\<div\s+class\=\"route\-media\-item\_\_more\-items\-title\"(.+?)\<\/div\>#s) {
527 my $addtl = $1;
528 if ($addtl =~ m#\<a[^\>]+\>\s*(.+?)\<\/a\>#s) {
529 ($self->{'album'} = $1) =~ s/\s+$//;
530 }
531 }
532 if ($html =~ m#\<img\s+alt\=\"logo\" ([^\>]+)#s) {
533 my $data = $1;
534 $self->{'articonurl'} = $1 if ($data =~ m#src\=\"(.+?)(?:\"| \dx)#);
535 $self->{'articonurl'} = $baseURL . $self->{'articonurl'}
536 if ($self->{'articonurl'} =~ m#^\/#);
537 $self->{'articonurl'} =~ s/\"$//;
538 $self->{'articonurl'} = uri_unescape($self->{'articonurl'});
539 $self->{'articonurl'} = HTML::Entities::decode_entities($self->{'articonurl'});
540 $self->{'articonurl'} =~ s/^.*\?url\=//;
541 }
542  
543 my $haveYoutube = 0;
544 unless ($self->{'youtube'} =~ /no/i || ($nonYtCnt > 0 && $self->{'youtube'} =~ /ifneeded/i)) {
545 eval { require 'StreamFinder/Youtube.pm'; $haveYoutube = 1; };
546 }
547 print STDERR "\n-2 NO STREAMS FOUND IN PAGE (haveYoutube=$haveYoutube)\n" if ($DEBUG && $nonYtCnt <= 0);
548 if ($haveYoutube) {
549 print STDERR "\n-2 TRYING yt-dlp...\n" if ($DEBUG);
550 my %globalArgs = (
551 '-noiframes' => 1, '-fast' => 1, '-debug' => $DEBUG
552 );
553 foreach my $arg (qw(secure log logfmt youtube-format youtube-format-fallback
554 youtube-formatonly youtube-dl-args youtube-dl-add-args)) {
555 (my $arg0 = $arg) =~ s/^youtube\-(?!dl)//o;
556 $globalArgs{$arg0} = $self->{$arg} if (defined $self->{$arg});
557 }
558 my $yt = new StreamFinder::Youtube($url2fetch, %globalArgs);
559 if ($yt) {
560 if ($yt->count() > 0) {
561 my @ytStreams = $yt->get();
562 foreach my $s (@ytStreams) {
563 print STDERR "+++++FOUND stream via yt-dlp=$s=\n" if ($DEBUG);
564 push (@YTDLstreams, $s) unless ($self->{'nohls'} && $s =~ /\.m3u8?/o);
565 }
566 $YTDLcnt = scalar (@YTDLstreams);
567 $self->{'description'} = $yt->{'description'}
568 if (length($yt->{'description'}) > length($self->{'description'}));
569 }
570 }
571 }
572 push (@{$self->{'streams'}}, @YTDLstreams)
573 if ($YTDLcnt > 0 && $self->{'youtube'} =~ /(?:yes|top|first|last|only|ifneeded)/i);
574 if ($nonYtCnt > 0 && $self->{'youtube'} !~ /only/i) {
575 if ($self->{'youtube'} =~ /(?:top|first)/i) { #PUT yt-dlp STREAMS ON TOP:
576 push @{$self->{'streams'}}, @nonYtStreams;
577 } else { #PUT STREAMS FROM PAGE ON TOP:
578 unshift @{$self->{'streams'}}, @nonYtStreams;
579 }
580 }
581 $self->{'cnt'} = scalar @{$self->{'streams'}};
582  
583 foreach my $field (qw(title description artist)) {
584 $self->{$field} = HTML::Entities::decode_entities($self->{$field});
585 $self->{$field} = uri_unescape($self->{$field});
586 $self->{$field} =~ s/(?:\%|\\?u?00)([0-9A-Fa-f]{2})/chr(hex($1))/eg;
587 }
588 $self->{'total'} = $self->{'cnt'};
589 $self->{'id'} =~ s/[\+]//g; #DON'T LEAVE THESE IN POTENTIAL FILE-NAMES!:
590 $self->{'id'} =~ s/^[\-]//;
591 $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : '';
592 print STDERR "-SUCCESS: 1st stream=".$self->{'Url'}."=\n" if ($DEBUG);
593 $self->_log($url);
594 if ($DEBUG) {
595 foreach my $i (sort keys %{$self}) {
596 print STDERR "--KEY=$i= VAL=".$self->{$i}."=\n";
597 }
598 print STDERR "--FIRST STREAM=".${$self->{'streams'}}[0]."=\n";
599 }
600  
601 bless $self, $class; #BLESS IT!
602  
603 return $self;
604 }
605  
606 1