StreamFinder/Rumble.pm untested

filter: Statementstmt 0.0% 0 / 279 Branchbran 0.0% 0 / 222 Conditioncond 0.0% 0 / 105 MC/DCmcdc 0.0% 0 / 70 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 686 CC 112 SCAR 93.9
CC
112
Cov
0%
new
12656.0
getImageData
2.0
BEGIN
2.0
CRAP 11911.6
1 =head1 NAME
2  
3 StreamFinder::Rumble - Fetch actual raw streamable URLs from Rumble.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::Rumble;
26  
27 die "..usage: $0 ID|URL\n" unless ($ARGV[0]);
28  
29 my $video = new StreamFinder::Rumble($ARGV[0], -keep =>
30 ['mp4', 'webm', 'm3u8', 'any']);
31  
32 die "Invalid URL or no streams found!\n" unless ($video);
33  
34 my $firstStream = $video->get();
35  
36 print "First Stream URL=$firstStream\n";
37  
38 my $url = $video->getURL();
39  
40 print "Stream URL=$url\n";
41  
42 my $videoTitle = $video->getTitle();
43
44 print "Title=$videoTitle\n";
45
46 my $videoDescription = $video->getTitle('desc');
47
48 print "Description=$videoDescription\n";
49
50 my $videoID = $video->getID();
51  
52 print "Video ID=$videoID\n";
53
54 my $artist = $video->{'artist'};
55  
56 print "Artist=$artist\n" if ($artist);
57
58 my $albumartist = $video->{'albumartist'};
59  
60 print "Album Artist=$albumartist\n" if ($albumartist);
61
62 my $icon_url = $video->getIconURL();
63  
64 if ($icon_url) { #SAVE THE ICON TO A TEMP. FILE:
65  
66 my ($image_ext, $icon_image) = $video->getIconData();
67  
68 if ($icon_image && open IMGOUT, ">/tmp/${videoID}.$image_ext") {
69  
70 binmode IMGOUT;
71  
72 print IMGOUT $icon_image;
73  
74 close IMGOUT;
75  
76 }
77  
78 }
79  
80 my $stream_count = $video->count();
81  
82 print "--Stream count=$stream_count=\n";
83  
84 my @streams = $video->get();
85  
86 foreach my $s (@streams) {
87  
88 print "------ stream URL=$s=\n";
89  
90 }
91  
92 =head1 DESCRIPTION
93  
94 StreamFinder::Rumble accepts a valid full Rumble video ID or page URL
95 (either one of their ".html" or "embed" URL) on rumble.com and returns
96 the actual stream URL, title, and cover art icon for that video.
97 The purpose is that one needs this URL in order to have the option to
98 stream the video in one's own choice of media player software rather than
99 using their web browser and accepting any / all flash, ads, javascript,
100 cookies, trackers, web-bugs, and other crapware that can come with that
101 method of play. The author uses his own custom all-purpose media player
102 called "fauxdacious" (his custom hacked version of the open-source
103 "audacious" audio player). "fauxdacious" incorporates this module to
104 decode and play rumble.com videos. This is a submodule of the general
105 StreamFinder module.
106  
107 Depends:
108  
109 L<URI::Escape>, L<HTML::Entities>, and L<LWP::UserAgent>.
110  
111 =head1 SUBROUTINES/METHODS
112  
113 =over 4
114  
115 =item B<new>(I<ID>|I<url> [, I<-keep> => I<streamtypes>]
116 [, I<-quality> => I<quality>] [, I<-bitrate> => I<bitrate>]
117 [, I<-secure> [ => 0|1 ]] [, I<-order> => I<"quality"|"ext">]
118 [, I<-debug> [ => 0|1|2 ]])
119  
120 Accepts a rumble.com video ID or URL and creates and returns a new video object,
121 or I<undef> if the URL is not a valid Rumble video or no streams are found.
122 The URL can be the full URL, ie. https://rumble.com/B<video-id>.html,
123 https://rumble.com/c/B<channel-id>, https://rumble.com/embed/B<video-id>
124 or just B<video-id> or B<channel-id>. If a I<channel-id> or channel URL is
125 given, then the first (latest) video of that channel will be returned.
126  
127 The optional I<-keep> argument specifies a list of one or more I<streamtypes>
128 to include. The list can be either a comma-separated string or an array
129 reference ([...]) of stream types, in the order they should be returned.
130 Each stream type in the list can be one of: I<any>, I<mp4>, or I<webm>.
131  
132 DEFAULT I<-keep> list is 'mp4, webm, any', meaning that all mp4 streams
133 followed by all webm streams, then all of any others found.
134  
135 The optional I<-quality> argument, which can be set to a "p number".
136 This limits the video quality.. For example: "720" would mean select
137 a stream "<= 720p".
138  
139 The optional I<-bitrate> argument, which can be set to a number (kbps).
140 This limits the maximum stream bitrate. For example most 720p Rumble
141 streams now exceed bitrate 2000, so limiting bitrate to a lower number
142 will exclude these streams.
143  
144 If both I<-quality> and I<-bitrate> options are specified, video streams
145 will be limited to the most restrictive limit.
146  
147 DEFAULT I<-quality> is accept streams without resolution limit.
148  
149 The optional I<-order> argument specifies what order to return streams.
150 The choices are: I<"quality"> means include all streams of a given quality
151 (resolution) in I<-keep> order before ones of lower quality. I<"ext"> means
152 include all streams of a given extension (ie. mp4 - see I<-keep> option) in
153 descending quality before ones with a different extension.
154  
155 DEFAULT I<"quality">
156  
157 The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>).
158 If 1 then only secure ("https://") streams will be returned.
159  
160 DEFAULT I<-secure> is 0 (false) - return all streams (http and https).
161  
162 Additional options:
163  
164 I<-log> => "I<logfile>"
165  
166 Specify path to a log file. If a valid and writable file is specified, A line
167 will be appended to this file every time one or more streams is successfully
168 fetched for a url.
169  
170 DEFAULT I<-none-> (no logging).
171  
172 I<-logfmt> specifies a format string for lines written to the log file.
173  
174 DEFAULT "I<[time] [url] - [site]: [title] ([total])>".
175  
176 The valid field I<[variables]> are: [stream]: The url of the first/best
177 stream found. [site]: The site name (Rumble). [url]: The url searched for
178 streams. [time]: Perl timestamp when the line was logged. [title], [artist],
179 [album], [description], [year], [genre], [total], [albumartist]:
180 The corresponding field data returned (or "I<-na->", if no value).
181  
182 =item $video->B<get>()
183  
184 Returns an array of strings representing all stream URLs found.
185  
186 =item $video->B<getURL>([I<options>])
187  
188 Similar to B<get>() except it only returns a single stream representing
189 the first valid stream found.
190  
191 Current options are: I<"random">, I<"nopls">, and I<"noplaylists">.
192 By default, the first ("best"?) stream is returned. If I<"random"> is
193 specified, then a random one is selected from the list of streams found.
194 If I<"nopls"> is specified, and the stream to be returned is a ".pls" playlist,
195 it is first fetched and the first entry (or a random entry if I<"random"> is
196 specified) is returned. This is needed by Fauxdacious Mediaplayer.
197 If I<"noplaylists"> is specified, and the stream to be returned is a
198 "playlist" (either .pls or .m3u? extension), it is first fetched and the first
199 entry (or a random entry if I<"random"> is specified) in the playlist
200 is returned.
201  
202 =item $video->B<count>()
203  
204 Returns the number of streams found for the video.
205  
206 =item $video->B<getID>()
207  
208 Returns the video's Rumble ID (alphanumeric).
209  
210 =item $video->B<getTitle>(['desc'])
211  
212 Returns the video's title, or (long description).
213  
214 =item $video->B<getIconURL>(['artist'])
215  
216 Returns the URL for the video's "cover art" icon image, if any.
217 If B<'artist'> is specified, the channel artist's icon url is returned,
218 if any.
219  
220 =item $video->B<getIconData>(['artist'])
221  
222 Returns a two-element array consisting of the extension (ie. "png",
223 "gif", "jpeg", etc.) and the actual icon image (binary data), if any.
224 If B<'artist'> is specified, the channel artist's icon data is returned,
225 if any.
226  
227 =item $video->B<getImageURL>()
228  
229 Returns the URL for the video's "cover art" banner image, which for
230 Rumble videos is always the icon image, as Rumble does not
231 support a separate banner image at this time.
232  
233 =item $video->B<getImageData>()
234  
235 Returns a two-element array consisting of the extension (ie. "png",
236 "gif", "jpeg", etc.) and the actual video's banner image (binary data).
237  
238 =item $video->B<getType>()
239  
240 Returns the video's type ("Rumble").
241  
242 =back
243  
244 =head1 CONFIGURATION FILES
245  
246 The default root location directory for StreamFinder configuration files
247 is "~/.config/StreamFinder". To use an alternate location directory,
248 specify it in the "I<STREAMFINDER>" environment variable, ie.:
249 B<$ENV{STREAMFINDER} = "/etc/StreamFinder">.
250  
251 =over 4
252  
253 =item ~/.config/StreamFinder/Rumble/config
254  
255 Optional text file for specifying various configuration options
256 for a specific site (submodule). Each option is specified on a
257 separate line in the format below:
258 NOTE: Do not follow the lines with a semicolon, comma, or any other
259 separator. Non-numeric I<values> should be surrounded with quotes, either
260 single or double. Blank lines and lines beginning with a "#" sign as
261 their first non-blank character are ignored as comments.
262  
263 'option' => 'value' [,]
264  
265 and the options are loaded into a hash used only by the specific
266 (submodule) specified. Valid options include
267 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
268  
269 Options specified here override any specified in
270 I<~/.config/StreamFinder/config>.
271  
272 Options valid for Rumble streams are described in the B<new()> function.
273  
274 =item ~/.config/StreamFinder/config
275  
276 Optional text file for specifying various configuration options.
277 Each option is specified on a separate line in the format below:
278  
279 'option' => 'value' [,]
280  
281 and the options are loaded into a hash used by all sites
282 (submodules) that support them. Valid options include
283 I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options.
284  
285 =back
286  
287 NOTE: Options specified in the options parameter list of the I<new()>
288 function will override those corresponding options specified in these files.
289  
290 =head1 KEYWORDS
291  
292 rumble
293  
294 =head1 DEPENDENCIES
295  
296 L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent>
297  
298 =head1 RECCOMENDS
299  
300 wget
301  
302 =head1 BUGS
303  
304 Please report any bugs or feature requests to C<bug-streamFinder-rumble at rt.cpan.org>, or through
305 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-Rumble>. I will be notified, and then you'll
306 automatically be notified of progress on your bug as I make changes.
307  
308 =head1 SUPPORT
309  
310 You can find documentation for this module with the perldoc command.
311  
312 perldoc StreamFinder::Rumble
313  
314 You can also look for information at:
315  
316 =over 4
317  
318 =item * RT: CPAN's request tracker (report bugs here)
319  
320 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-Rumble>
321  
322 =item * AnnoCPAN: Annotated CPAN documentation
323  
324 L<http://annocpan.org/dist/StreamFinder-Rumble>
325  
326 =item * Search CPAN
327  
328 L<http://search.cpan.org/dist/StreamFinder-Rumble/>
329  
330 =back
331  
332 =head1 LICENSE AND COPYRIGHT
333  
334 Copyright 2017-2026 Jim Turner.
335  
336 This program is free software; you can redistribute it and/or modify it
337 under the terms of the the Artistic License (2.0). You may obtain a
338 copy of the full license at:
339  
340 L<http://www.perlfoundation.org/artistic_license_2_0>
341  
342 Any use, modification, and distribution of the Standard or Modified
343 Versions is governed by this Artistic License. By using, modifying or
344 distributing the Package, you accept this license. Do not use, modify,
345 or distribute the Package, if you do not accept this license.
346  
347 If your Modified Version has been derived from a Modified Version made
348 by someone other than you, you are nevertheless required to ensure that
349 your Modified Version complies with the requirements of this license.
350  
351 This license does not grant you the right to use any trademark, service
352 mark, tradename, or logo of the Copyright Holder.
353  
354 This license includes the non-exclusive, worldwide, free-of-charge
355 patent license to make, have made, use, offer to sell, sell, import and
356 otherwise transfer the Package with respect to any patent claims
357 licensable by the Copyright Holder that are necessarily infringed by the
358 Package. If you institute patent litigation (including a cross-claim or
359 counterclaim) against any party alleging that the Package constitutes
360 direct or contributory patent infringement, then this Artistic License
361 to you shall terminate on the date that such litigation is filed.
362  
363 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
364 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
365 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
366 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
367 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
368 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
369 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
370 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
371  
372 =cut
373  
374 package StreamFinder::Rumble;
375  
376 use strict;
377 use warnings;
378 use URI::Escape;
379 use HTML::Entities ();
380 use LWP::UserAgent ();
381 use parent 'StreamFinder::_Class';
382  
383 my $DEBUG = 0;
384  
385 sub new
386 {
387 my $class = shift;
388 my $url = shift;
389  
390 return undef unless ($url);
391  
392 my $self = $class->SUPER::new('Rumble', @_);
393 $DEBUG = $self->{'debug'} if (defined $self->{'debug'});
394 my $baseURL = 'https://rumble.com';
395  
396 $self->{'notrim'} = 0;
397 $self->{'order'} = 'quality';
398 my (@okStreams);
399 while (@_) {
400 if ($_[0] =~ /^\-?keep$/o) {
401 shift;
402 if (defined $_[0]) {
403 my $keeporder = shift;
404 @okStreams = (ref($keeporder) =~ /ARRAY/) ? @{$keeporder} : split(/\,\s*/, $keeporder);
405 }
406 } elsif ($_[0] =~ /^\-?quality$/o) {
407 shift;
408 $self->{'quality'} = (defined $_[0]) ? shift : 0;
409 } elsif ($_[0] =~ /^\-?order$/o) {
410 shift;
411 $self->{'order'} = (defined $_[0]) ? shift : 'quality';
412 } elsif ($_[0] =~ /^\-?bitrate$/o) {
413 shift;
414 $self->{'bitrate'} = (defined $_[0]) ? shift : 0;
415 } elsif ($_[0] =~ /^\-?notrim$/o) {
416 shift;
417 $self->{'notrim'} = (defined $_[0]) ? shift : 1;
418 } else {
419 shift;
420 }
421 }
422 if (!defined($okStreams[0]) && defined($self->{'keep'})) {
423 @okStreams = (ref($self->{'keep'}) =~ /ARRAY/) ? @{$self->{'keep'}} : split(/\,\s*/, $self->{'keep'});
424 }
425 @okStreams = (qw(mp4 webm m3u8 any)) unless (defined $okStreams[0]);
426 $self->{'quality'} = 32767 unless (defined($self->{'quality'}) && $self->{'quality'} =~ /^[0-9]+$/);
427 $self->{'bitrate'} = 32767 unless (defined($self->{'bitrate'}) && $self->{'bitrate'} =~ /^[0-9]+$/);
428  
429 my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}});
430 $ua->timeout($self->{'timeout'});
431 $ua->cookie_jar({});
432 $ua->env_proxy;
433 my $response;
434 $self->{'genre'} = 'Video';
435  
436 local *getChannelPage = sub {
437 my $url2fetch = shift;
438 my $url2 = '';
439 my $html = '';
440 print STDERR "-FETCHING CHANNEL URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
441 $response = $ua->get($url2fetch);
442 if ($response->is_success) {
443 $html = $response->decoded_content;
444 } else {
445 print STDERR $response->status_line if ($DEBUG);
446 my $no_wget = system('wget','-V');
447 unless ($no_wget) {
448 print STDERR "\n..trying wget...\n" if ($DEBUG);
449 $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `;
450 }
451 }
452 #x if ($html && $html =~ m#(?:class\=video\-item\-\-a\b|\<\/h3\>\s*\<a)([^\>]+)#s) {
453 if ($html && $html =~ m#\bclass\=\"videostream\_\_link([^\>]+)#s) {
454 my $urldata = $1;
455 ($url2 = $1) =~ s#^\/## if ($urldata =~ m#href\=\"?([^\"\>\s]+)#);
456 print STDERR "---FOUND 1ST EPISODE URL=$url2= IN CHANNEL PAGE, RUN WITH THAT!\n" if ($DEBUG);
457 return "from-channel:$url2" if ($url2);
458 }
459 return $url2;
460 };
461  
462 local *getHtmlPage = sub {
463 my $url = shift;
464 my $url2fetch = $url;
465 my $html = '';
466  
467 #DEPRECIATED (VIDEO-IDS NOW INCLUDE STUFF BEFORE THE DASH: ($self->{'id'} = $url) =~ s#^.*\-([a-z]\d+)\/?$#$1#;
468 if ($url2fetch =~ m#^(https?\:\/\/[^\/]+)#) {
469 $baseURL = $1;
470 $url2fetch =~ s#\?.*$## unless ($self->{'notrim'}); #STRIP OFF ANY EXTRA ARGS, IE. "?e2s=blahblah"
471 # $url2fetch .= '.html' unless ($url2fetch =~ /\.html?$/); #NEEDED FOR Fauxdacious!
472 $self->{'id'} = $1 if ($url2fetch =~ m#\/([^\/]+)\.html?#);
473 unless (defined($self->{'id'}) && $self->{'id'}) { #PERHAPS WE HAVE A CHANNEL PAGE?
474 print STDERR "---HTML PAGE: NO ID, TRY CHANNEL PAGE ($url2fetch)!...\n" if ($DEBUG);
475 return &getChannelPage($url2fetch);
476 }
477 $self->{'id'} =~ s#^\-?([^\-\.]+).*$#$1#;
478 } else {
479 $self->{'id'} = $url;
480 $url2fetch = "$baseURL/${url}.html";
481 }
482  
483 print STDERR "-FETCHING HTML URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG);
484 $response = $ua->get($url2fetch);
485 if ($response->is_success) {
486 $html = $response->decoded_content;
487 } else {
488 print STDERR $response->status_line if ($DEBUG);
489 my $no_wget = system('wget','-V');
490 unless ($no_wget) {
491 print STDERR "\n..trying wget...\n" if ($DEBUG);
492 $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `;
493 }
494 }
495 if ($html && $html =~ m#\"embedUrl\"\:\"([^\"]+)#s) {
496 my $url2 = $1;
497  
498 if ($DEBUG > 1 && open DBG, ">/tmp/rumble_page.htm") {
499 print DBG $html;
500 close DBG;
501 }
502 $self->{'title'} = ($html =~ m#\<title\>([^\<]+)\<\/title\>#s) ? $1 : '';
503 $self->{'title'} ||= $1 if ($html =~ m#\<meta\s+property\=\"?og\:title\"?\s+content\=\"([^\"]+)\"#s);
504  
505 $self->{'artist'} = $1 if ($html =~ m#class\=\"media-heading-name(?:\s+truncate)?\"\>([^\<]+)\<#s);
506 $self->{'artist'} ||= $1 if ($html =~ m#\<button data-title=\"([^\"]+)#s);
507 $self->{'artist'} =~ s/^\s+//s;
508 $self->{'artist'} =~ s/\s+$//s;
509  
510 $self->{'albumartist'} = $baseURL . $1 if ($html =~ m#href\=\"([^\"]+)\" rel=author#s);
511  
512 $self->{'description'} = $1 if ($html =~ m#\<p\s+class\=\"media\-description\s+media\-description[^\>]*\>(.+?)\<\/p\>#s);
513 $self->{'description'} ||= $1 if ($html =~ m#\"description\"\:\"([^\"]+)#s);
514 $self->{'description'} ||= $1 if ($html =~ m#<meta\s+name\=description\"?\s+content\=\"\:\"([^\"]+)#s);
515 $self->{'description'} ||= $1 if ($html =~ m#<meta\s+property\=\"?og\:description\"?\s+content\=\"\:\"([^\"]+)#s);
516 $self->{'description'} ||= $1 if ($html =~ m#\<meta\s+name\=\"?twitter\:description\"?\s+content\=\"([^\"]+)\"#s);
517 $self->{'description'} =~ s/^\s+//s;
518 $self->{'description'} =~ s/\n\n\n+/\n\n/s;
519 $self->{'description'} =~ s/\s+$//s;
520 $self->{'iconurl'} = ($html =~ m#\"thumbnailUrl\"\:\"([^\"]+)#s) ? $1 : '';
521 $self->{'iconurl'} ||= $1 if ($html =~ m#\<meta\s+property\=\"?og\:image\"?\s+content\=\"?([^\<]+)\<#s);
522 $self->{'iconurl'} =~ s/\"$//;
523 $self->{'imageurl'} = $self->{'iconurl'};
524 if ($html =~ m#i\.user\-image\-\-img\-\-id\-[0-9a-f]+\s+\{([^\}]+)#s) {
525 my $stuff = $1;
526 $self->{'articonurl'} = $1 if ($stuff =~ m#url\(([^\)]+)#);
527 }
528  
529 if ($html =~ m#Published(.+?)\<span#s) { #JWT:NOTE: CAN'T USE $self->{'created'} HERE!:
530 my $published = $1;
531 $self->{'year'} = $1 if ($published =~ /(\d\d\d\d)/);
532 }
533  
534 #GRAB VIDEO LENGTH (RECENT ffmpeg DOESN'T SEEM TO RELIABLY ANYMORE)!
535 if (!defined($self->{'length'}) && $html =~ m#\"duration\"\:\"?([^\"\,]+)#s) {
536 my $length = $1;
537 if ($length =~ /^\d+$/) {
538 $self->{'length'} = $length * 1000; #NEED IT IN MILLISECS!
539 } elsif ($length =~ /(\d+)H(\d+)M(\d+)S/) {
540 $self->{'length'} = ($1 * 3600) + ($2 * 60) + $3;
541 $self->{'length'} *= 1000; #NEED IT IN MILLISECS!
542 }
543 }
544  
545 #STEP 2: FETCH THE STREAMS FROM THE "embedUrl":
546 return $url2;
547 }
548 return '';
549 };
550  
551 local *getEmbedPage = sub {
552 my $url2fetch = shift;
553 my $html = '';
554  
555 print STDERR "-FETCHING EMBED URL=$url2fetch=\n" if ($DEBUG);
556 $response = $ua->get($url2fetch);
557 if ($response->is_success) {
558 $html = $response->decoded_content;
559 } else {
560 print STDERR $response->status_line if ($DEBUG);
561 my $no_wget = system('wget','-V');
562 unless ($no_wget) {
563 print STDERR "\n..trying wget...\n" if ($DEBUG);
564 $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `;
565 }
566 }
567 if ($html) {
568 if ($DEBUG > 1 && open DBG, ">/tmp/rumble_embed_page.htm") {
569 print DBG $html;
570 close DBG;
571 }
572 my @streams = ();
573 my %ext = ();
574 my %quality = ();
575 my %qualities = ();
576 my %streamHash = (); #USE THIS HASH TO PREVENT ANY DUPLICATE STREAM URLS:
577 my $ext;
578  
579 $html =~ s#\\\/#\/#gs;
580 $self->{'title'} ||= ($html =~ m#\<title\>([^\<]+)\<\/title\>#s) ? $1 : '';
581 my $url2 = ($html =~ m#\<link\s+rel\=\"canonical\"\s+href\=\"([^\"]+)#s) ? $1 : undef;
582  
583 if ($html =~ m#\"author\"\:\{\"name\"\:\"([^\"]+)\"\,\"url\"\:\"([^\"]+)#s) {
584 $self->{'artist'} ||= $1;
585 $self->{'albumartist'} ||= $2;
586 }
587 if ($html =~ m#\"pubDate\"\:\"([^\"]+)#s) {
588 $self->{'created'} = $1;
589 $self->{'year'} ||= $1 if ($self->{'created'} =~ /(\d\d\d\d)/);
590 }
591 if ($html =~ m#\"i\"\:\"([^\"]+)#s) { #GRAB EMBEDDED IMAGE URL IN CASE MAIN PAGE IS "PRIVATE"(UNFETCHABLE):
592 $self->{'iconurl'} ||= $1;
593 $self->{'imageurl'} ||= $self->{'iconurl'};
594 }
595 #GRAB VIDEO LENGTH (RECENT ffmpeg DOESN'T SEEM TO RELIABLY ANYMORE)!
596 if (!defined($self->{'length'}) && $html =~ m#\"duration\"\:\"?([^\"\,]+)#s) {
597 my $length = $1;
598 if ($length =~ /^\d+$/) {
599 $self->{'length'} = $length * 1000; #NEED IT IN MILLISECS!
600 } elsif ($length =~ /(\d+)H(\d+)M(\d+)S/) {
601 $self->{'length'} = ($1 * 3600) + ($2 * 60) + $3;
602 $self->{'length'} *= 1000; #NEED IT IN MILLISECS!
603 }
604 }
605  
606 $html =~ s#^.+\"u\"\:\{##s;
607 #PARSE OUT ALL STREAMS (CLASS IS EITHER "mp4", "webm", "###" (RESOLUTION) OR OTHER.
608 #SINCE THE STREAMS OF EACH RESOLUTION ARE OFTEN REPEATED UNDER "mp4", "webm", or "<other>"
609 #BASED ON THEIR EXTENSION!:
610 while ($html =~ s#^.+?\"(\w+)\"\:\{\"url\"\:\"([^\"]+)\"##so) {
611 my ($quality, $stream) = ($1, $2);
612 my $bitrate = ($html =~ m#\"bitrate\"\:(\d+)#o) ? $1 : 0;
613 print STDERR "...quality=$quality= bitrate=$bitrate=(max=".$self->{'bitrate'}.") stream=$stream=\n" if ($DEBUG);
614 next if ($bitrate > $self->{'bitrate'});
615 next if ($stream =~ /\.[A-Z]aa(?:\.rec)?\.(?:mp4|webm)$/o); #THESE WON'T PLAY! (VIDEO-ONLY?)
616  
617 $ext = undef;
618 for (my $i=0;$i<=$#okStreams;$i++) {
619 if ($stream =~ /\.$okStreams[$i]\b/) {
620 $ext = $okStreams[$i];
621 last;
622 }
623 }
624 next unless (defined $ext);
625  
626 $quality = 1 if ($ext =~ /aac/o); #MAKE AUDIO-ONLY STREAMS LOWEST QUALITY TO SORT LAST.
627 if ($quality =~ /\D/o) {
628 if ($quality =~ /audio/o) {
629 $quality = 1;
630 } elsif ($quality =~ /(?:hls|auto)/o) {
631 $quality = ($self->{'order'} =~ /ext/io) ? ($self->{'quality'}-1) : 10;
632 } else {
633 next;
634 }
635 }
636 next if ($quality > $self->{'quality'}); #EXCLUDE ANY HIGHER-RES THAN SELECTED QUALITY.
637  
638 $stream =~ s/\&r\_type\=application\%2Fvnd\.apple\.mpegurl.*$//;
639 $quality{$stream} = $quality;
640 $ext{$stream} = $ext;
641 $qualities{$quality} = 1;
642 push @streams, $stream;
643 }
644 print STDERR "--Max res(quality)=".$self->{'quality'}."= bitrate=".$self->{'bitrate'}."=\n" if ($DEBUG);
645  
646 if ($self->{'order'} =~ /ext/i) {
647 print STDERR "--order streams by kept extensions:\n" if ($DEBUG);
648 foreach my $ext (@okStreams) {
649 print STDERR "\n--keep extension=$ext:\n" if ($DEBUG);
650 foreach my $quality (sort { $b <=> $a } keys %qualities) {
651 foreach my $stream (@streams) {
652 next unless ($quality{$stream} == $quality &&
653 ($ext =~ /any/io || $ext{$stream} =~ /$ext/));
654  
655 unless (defined $streamHash{$stream}
656 || ($self->{'secure'} && $stream !~ /^https/o)) {
657 #JWT:NEXT TEST NEEDED BY RECENT libavformat CHANGES:
658 print STDERR "------found($quality) quality="
659 .$quality{$stream}."= stream=$stream=\n" if ($DEBUG);
660 push @{$self->{'streams'}}, $stream;
661 $streamHash{$stream} = $stream;
662 }
663 }
664 }
665 }
666 } else {
667 print STDERR "--order streams by qualities:\n" if ($DEBUG);
668 foreach my $quality (sort { $b <=> $a } keys %qualities) {
669 print STDERR "\n--keep quality=$quality:\n" if ($DEBUG);
670 foreach my $ext (@okStreams) {
671 foreach my $stream (@streams) {
672 next unless ($quality{$stream} == $quality &&
673 ($ext =~ /any/io || $ext{$stream} =~ /$ext/));
674  
675 unless (defined $streamHash{$stream}
676 || ($self->{'secure'} && $stream !~ /^https/o)) {
677 #JWT:NEXT TEST NEEDED BY RECENT libavformat CHANGES:
678 print STDERR "------found($ext) ext=".$ext{$stream}
679 ."= stream=$stream=\n" if ($DEBUG);
680 push @{$self->{'streams'}}, $stream;
681 $streamHash{$stream} = $stream;
682 }
683 }
684 }
685 }
686 }
687  
688 return $url2;
689 } else {
690 $url2fetch =~ s#\/embed\/#\/#;
691 print STDERR "---EMBED PAGE: NO HTML, TRY CHANNEL PAGE ($url2fetch)!...\n" if ($DEBUG);
692 return &getChannelPage($url2fetch);
693 }
694 return '';
695 };
696  
697 $url = "$baseURL/embed/${url}/" if ($url !~ m#http# && $url !~ m#\-#);
698 my $tried = 0;
699 TRYIT:
700 print STDERR "-${tried}(Rumble): URL=$url=\n" if ($DEBUG);
701 if ($url =~ m#\/embed\/#i) {
702 my $url2 = &getEmbedPage($url);
703 if ($url2) {
704 if (!$tried && $url2 =~ s/^from-channel\://) {
705 $url = $url2;
706 $tried++;
707 goto TRYIT;
708 }
709 &getHtmlPage($url2);
710 }
711 } else {
712 my $url2 = &getHtmlPage($url);
713 if ($url2) {
714 if (!$tried && $url2 =~ s/^from-channel\://) {
715 $url = $url2;
716 $tried++;
717 goto TRYIT;
718 }
719 &getEmbedPage($url2);
720 }
721 }
722  
723 $self->{'cnt'} = scalar @{$self->{'streams'}};
724 foreach my $field (qw(description artist title)) {
725 $self->{$field} = HTML::Entities::decode_entities($self->{$field});
726 $self->{$field} = uri_unescape($self->{$field});
727 $self->{$field} =~ s/(?:\%|\\[ux\%]?00|\bu00)([0-9A-Fa-f]{2})/chr(hex($1))/egs;
728 $self->{$field} =~ s/\\u\d\d\d\d/ /gs;
729 }
730 $self->{'title'} =~ s/\s+\-\s+$self->{'artist'}\s*$//; #CONVERT "Title - Artist" => "Title"
731 $self->{'iconurl'} ||= $self->{'articonurl'} if ($self->{'articonurl'});
732 $self->{'imageurl'} = $self->{'iconurl'};
733 $self->{'albumartist'} =~ s#\?.*$## unless ($self->{'notrim'}); #STRIP OFF ANY EXTRA ARGS, IE. "?e2s=blahblah"
734 $self->{'total'} = $self->{'cnt'};
735 $self->{'Url'} = ($self->{'cnt'} > 0) ? $self->{'streams'}->[0] : '';
736 if ($DEBUG) {
737 foreach my $i (sort keys %{$self}) {
738 print STDERR "--KEY=$i= VAL=".$self->{$i}."=\n";
739 }
740 print STDERR "--SUCCESS: 1st stream=".$self->{'Url'}."= total=".$self->{'total'}."=\n"
741 if ($self->{'cnt'} > 0);
742 }
743 $self->_log($url);
744  
745 bless $self, $class; #BLESS IT!
746  
747 return $self;
748 }
749  
750 sub getImageData
751 {
752 my $self = shift;
753 return $self->getIconData();
754 }
755  
756 1