| 1 | =head1 NAME | ||
| 2 | |||
| 3 | StreamFinder::Bitchute - Fetch actual raw streamable URLs from Bitchute.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::Bitchute; | ||
| 26 | |||
| 27 | die "..usage: $0 ID|URL\n" unless ($ARGV[0]); | ||
| 28 | |||
| 29 | my $video = new StreamFinder::Bitchute($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::Bitchute accepts a valid full Bitchute video ID or URL on | ||
| 94 | bitchute.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 bitchute.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: B<yt-dlp> (now required to fetch streams | ||
| 110 | from Bitchute). | ||
| 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 bitchute.com video ID or URL and creates and returns a new video | ||
| 121 | object, or I<undef> if the URL is not a valid Bitchute video or no streams are | ||
| 122 | found. The URL can be the full URL, ie. | ||
| 123 | https://www.bitchute.com/video/B<video-id>, | ||
| 124 | or https://www.bitchute.com/channel/B<channel-id>, | ||
| 125 | or just I<video-id> or I<channel-id>. If a I<channel-id> or channel URL is | ||
| 126 | given, then the first (latest) video of that channel will be returned. | ||
| 127 | |||
| 128 | The optional I<-keep> argument can be either a comma-separated string or an | ||
| 129 | array reference ([...]) of stream types to keep (include) and returned in | ||
| 130 | order specified (type1, type2...). Each "type" can be one of: extension | ||
| 131 | (ie. m4a, mp4, etc.), "playlist", "stream", or ("any" or "all"). | ||
| 132 | |||
| 133 | DEFAULT I<-keep> list is: 'm4a,mpd,stream,all', meaning that all m4a streams | ||
| 134 | followed by all "mpd" streams, followed by non-playlists, followed by all | ||
| 135 | remaining (playlists (pls)) streams. More than one value can be specified to | ||
| 136 | control order of search. | ||
| 137 | |||
| 138 | NOTE: I<-keep> is ignored if I<-youtube> is set to "I<only>". | ||
| 139 | |||
| 140 | The optional I<-youtube> argument can be set to "I<yes>" or "I<last>" - also | ||
| 141 | include streams B<yt-dlp> finds; "I<no>" - only include streams embedded in | ||
| 142 | the video's bitchute.com page, unless none are found; "I<only>" - only include | ||
| 143 | streams yt-dlp finds; or "I<first>" - include streams youtube-dl | ||
| 144 | finds first. Default is B<"yes">. | ||
| 145 | |||
| 146 | The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>). | ||
| 147 | If 1 then only secure ("https://") streams will be returned. | ||
| 148 | |||
| 149 | DEFAULT I<-secure> is 0 (false) - return all streams (http and https). | ||
| 150 | |||
| 151 | Additional options: | ||
| 152 | |||
| 153 | Certain yt-dlp (L<StreamFinder::Youtube>) configuration options, | ||
| 154 | namely I<format>, I<formatonly>, I<youtube-dl-args>, and I<youtube-dl-add-args> | ||
| 155 | can be overridden here by specifying I<youtube-format>, I<youtube-formatonly>, | ||
| 156 | I<youtube-dl-args>, and I<youtube-dl-add-args> arguments respectively. It is | ||
| 157 | however, recommended to specify these in the Bitchute-specific | ||
| 158 | configuration file (see B<CONFIGURATION FILES> below. NOTE: These are only | ||
| 159 | applicable when using the option: I<-youtube> => I<yes|only|top>, etc. | ||
| 160 | |||
| 161 | I<-log> => "I<logfile>" | ||
| 162 | |||
| 163 | Specify path to a log file. If a valid and writable file is specified, A line | ||
| 164 | will be appended to this file every time one or more streams is successfully | ||
| 165 | fetched for a url. | ||
| 166 | |||
| 167 | DEFAULT I<-none-> (no logging). | ||
| 168 | |||
| 169 | I<-logfmt> specifies a format string for lines written to the log file. | ||
| 170 | |||
| 171 | DEFAULT "I<[time] [url] - [site]: [title] ([total])>". | ||
| 172 | |||
| 173 | The valid field I<[variables]> are: [stream]: The url of the first/best | ||
| 174 | stream found. [site]: The site name (Bitchute). [url]: The url searched | ||
| 175 | for streams. [time]: Perl timestamp when the line was logged. [title], | ||
| 176 | [artist], [album], [description], [year], [genre], [total], [albumartist]: | ||
| 177 | The corresponding field data returned (or "I<-na->", if no value). | ||
| 178 | |||
| 179 | =item $video->B<get>() | ||
| 180 | |||
| 181 | Returns an array of strings representing all stream URLs found. | ||
| 182 | |||
| 183 | =item $video->B<getURL>([I<options>]) | ||
| 184 | |||
| 185 | Similar to B<get>() except it only returns a single stream representing | ||
| 186 | the first valid stream found. | ||
| 187 | |||
| 188 | Current options are: I<"random">, I<"nopls">, and I<"noplaylists">. | ||
| 189 | By default, the first ("best"?) stream is returned. If I<"random"> is | ||
| 190 | specified, then a random one is selected from the list of streams found. | ||
| 191 | If I<"nopls"> is specified, and the stream to be returned is a ".pls" playlist, | ||
| 192 | it is first fetched and the first entry (or a random entry if I<"random"> is | ||
| 193 | specified) is returned. This is needed by Fauxdacious Mediaplayer. | ||
| 194 | If I<"noplaylists"> is specified, and the stream to be returned is a | ||
| 195 | "playlist" (either .pls or .m3u? extension), it is first fetched and the first | ||
| 196 | entry (or a random entry if I<"random"> is specified) in the playlist | ||
| 197 | is returned. | ||
| 198 | |||
| 199 | =item $video->B<count>() | ||
| 200 | |||
| 201 | Returns the number of streams found for the video. | ||
| 202 | |||
| 203 | =item $video->B<getID>() | ||
| 204 | |||
| 205 | Returns the video's Bitchute ID (alphanumeric). | ||
| 206 | |||
| 207 | =item $video->B<getTitle>(['desc']) | ||
| 208 | |||
| 209 | Returns the video's title, or (long description). | ||
| 210 | |||
| 211 | =item $video->B<getIconURL>() | ||
| 212 | |||
| 213 | Returns the URL for the video's "cover art" icon image, if any. | ||
| 214 | |||
| 215 | =item $video->B<getIconData>() | ||
| 216 | |||
| 217 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 218 | "gif", "jpeg", etc.) and the actual icon image (binary data), if any. | ||
| 219 | |||
| 220 | =item $video->B<getImageURL>() | ||
| 221 | |||
| 222 | Returns the URL for the video's "cover art" banner image, which for | ||
| 223 | Bitchute videos is always the icon image, as Bitchute does not | ||
| 224 | support a separate banner image at this time. | ||
| 225 | |||
| 226 | =item $video->B<getImageData>() | ||
| 227 | |||
| 228 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 229 | "gif", "jpeg", etc.) and the actual video's banner image (binary data). | ||
| 230 | |||
| 231 | =item $video->B<getType>() | ||
| 232 | |||
| 233 | Returns the video's type ("Bitchute"). | ||
| 234 | |||
| 235 | =back | ||
| 236 | |||
| 237 | =head1 CONFIGURATION FILES | ||
| 238 | |||
| 239 | The default root location directory for StreamFinder configuration files | ||
| 240 | is "~/.config/StreamFinder". To use an alternate location directory, | ||
| 241 | specify it in the "I<STREAMFINDER>" environment variable, ie.: | ||
| 242 | B<$ENV{STREAMFINDER} = "/etc/StreamFinder">. | ||
| 243 | |||
| 244 | =over 4 | ||
| 245 | |||
| 246 | =item ~/.config/StreamFinder/Bitchute/config | ||
| 247 | |||
| 248 | Optional text file for specifying various configuration options | ||
| 249 | for a specific site (submodule). Each option is specified on a | ||
| 250 | separate line in the format below: | ||
| 251 | NOTE: Do not follow the lines with a semicolon, comma, or any other | ||
| 252 | separator. Non-numeric I<values> should be surrounded with quotes, either | ||
| 253 | single or double. Blank lines and lines beginning with a "#" sign as | ||
| 254 | their first non-blank character are ignored as comments. | ||
| 255 | |||
| 256 | 'option' => 'value' [,] | ||
| 257 | |||
| 258 | and the options are loaded into a hash used only by the specific | ||
| 259 | (submodule) specified. Valid options include | ||
| 260 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 261 | |||
| 262 | Options specified here override any specified in | ||
| 263 | I<~/.config/StreamFinder/config>. | ||
| 264 | |||
| 265 | Among options valid for Bitchute streams is the I<-keep> and | ||
| 266 | I<-youtube> options described in the B<new()> function. Also, | ||
| 267 | various yt-dlp (L<StreamFinder::Youtube>) configuration options, | ||
| 268 | namely I<format>, I<formatonly>, I<youtube-dl-args>, and I<youtube-dl-add-args> | ||
| 269 | can be overridden here by specifying I<youtube-format>, I<youtube-formatonly>, | ||
| 270 | I<youtube-dl-args>, and I<youtube-dl-add-args> arguments respectively. | ||
| 271 | NOTE: These are only applicable when using the option: | ||
| 272 | I<-youtube> => I<yes|only|top>, etc. | ||
| 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 | bitchute | ||
| 293 | |||
| 294 | =head1 DEPENDENCIES | ||
| 295 | |||
| 296 | L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent> | ||
| 297 | |||
| 298 | wget | ||
| 299 | |||
| 300 | =head1 BUGS | ||
| 301 | |||
| 302 | Please report any bugs or feature requests to C<bug-streamFinder-bitchute at rt.cpan.org>, or through | ||
| 303 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-Bitchute>. I will be notified, and then you'll | ||
| 304 | automatically be notified of progress on your bug as I make changes. | ||
| 305 | |||
| 306 | =head1 SUPPORT | ||
| 307 | |||
| 308 | You can find documentation for this module with the perldoc command. | ||
| 309 | |||
| 310 | perldoc StreamFinder::Bitchute | ||
| 311 | |||
| 312 | You can also look for information at: | ||
| 313 | |||
| 314 | =over 4 | ||
| 315 | |||
| 316 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 317 | |||
| 318 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-Bitchute> | ||
| 319 | |||
| 320 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 321 | |||
| 322 | L<http://annocpan.org/dist/StreamFinder-Bitchute> | ||
| 323 | |||
| 324 | =item * Search CPAN | ||
| 325 | |||
| 326 | L<http://search.cpan.org/dist/StreamFinder-Bitchute/> | ||
| 327 | |||
| 328 | =back | ||
| 329 | |||
| 330 | =head1 LICENSE AND COPYRIGHT | ||
| 331 | |||
| 332 | Copyright 2017-2026 Jim Turner. | ||
| 333 | |||
| 334 | This program is free software; you can redistribute it and/or modify it | ||
| 335 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 336 | copy of the full license at: | ||
| 337 | |||
| 338 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 339 | |||
| 340 | Any use, modification, and distribution of the Standard or Modified | ||
| 341 | Versions is governed by this Artistic License. By using, modifying or | ||
| 342 | distributing the Package, you accept this license. Do not use, modify, | ||
| 343 | or distribute the Package, if you do not accept this license. | ||
| 344 | |||
| 345 | If your Modified Version has been derived from a Modified Version made | ||
| 346 | by someone other than you, you are nevertheless required to ensure that | ||
| 347 | your Modified Version complies with the requirements of this license. | ||
| 348 | |||
| 349 | This license does not grant you the right to use any trademark, service | ||
| 350 | mark, tradename, or logo of the Copyright Holder. | ||
| 351 | |||
| 352 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 353 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 354 | otherwise transfer the Package with respect to any patent claims | ||
| 355 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 356 | Package. If you institute patent litigation (including a cross-claim or | ||
| 357 | counterclaim) against any party alleging that the Package constitutes | ||
| 358 | direct or contributory patent infringement, then this Artistic License | ||
| 359 | to you shall terminate on the date that such litigation is filed. | ||
| 360 | |||
| 361 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 362 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 363 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 364 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 365 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 366 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 367 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 368 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 369 | |||
| 370 | =cut | ||
| 371 | |||
| 372 | package StreamFinder::Bitchute; | ||
| 373 | |||
| 374 | use strict; | ||
| 375 | use warnings; | ||
| 376 | use URI::Escape; | ||
| 377 | use HTML::Entities (); | ||
| 378 | use LWP::UserAgent (); | ||
| 379 | use parent 'StreamFinder::_Class'; | ||
| 380 | |||
| 381 | my $DEBUG = 0; | ||
| 382 | |||
| 383 | sub new | ||
| 384 | { | ||
| 385 | my $class = shift; | ||
| 386 | my $url = shift; | ||
| 387 | |||
| 388 | return undef unless ($url); | ||
| 389 | |||
| 390 | my $self = $class->SUPER::new('Bitchute', @_); | ||
| 391 | $DEBUG = $self->{'debug'} if (defined $self->{'debug'}); | ||
| 392 | |||
| 393 | my @okStreams; | ||
| 394 | $self->{'youtube'} = 'yes' unless (defined $self->{'youtube'}); | ||
| 395 | while (@_) { | ||
| 396 | if ($_[0] =~ /^\-?youtube$/o) { | ||
| 397 | shift; | ||
| 398 | $self->{'youtube'} = (defined $_[0]) ? shift : 'yes'; | ||
| 399 | } elsif ($_[0] =~ /^\-?keep$/o) { | ||
| 400 | shift; | ||
| 401 | if (defined $_[0]) { | ||
| 402 | my $keeporder = shift; | ||
| 403 | @okStreams = (ref($keeporder) =~ /ARRAY/) ? @{$keeporder} : split(/\,\s*/, $keeporder); | ||
| 404 | } | ||
| 405 | } else { | ||
| 406 | shift; | ||
| 407 | } | ||
| 408 | } | ||
| 409 | if (!defined($okStreams[0]) && defined($self->{'keep'})) { | ||
| 410 | @okStreams = (ref($self->{'keep'}) =~ /ARRAY/) ? @{$self->{'keep'}} : split(/\,\s*/, $self->{'keep'}); | ||
| 411 | } | ||
| 412 | @okStreams = (qw(m4a mpd stream all)) unless (defined $okStreams[0]); # one of: {m4a, <ext>, direct, stream, any, all} | ||
| 413 | |||
| 414 | print STDERR "-0(Bitchute): URL=$url=\n" if ($DEBUG); | ||
| 415 | $url =~ s/\?autoplay\=true$//; #STRIP THIS OFF SO WE DON'T HAVE TO. | ||
| 416 | (my $url2fetch = $url); | ||
| 417 | #DEPRECIATED (VIDEO-IDS NOW INCLUDE STUFF BEFORE THE DASH: ($self->{'id'} = $url) =~ s#^.*\-([a-z]\d+)\/?$#$1#; | ||
| 418 | if ($url2fetch =~ m#^https?\:#) { | ||
| 419 | $self->{'id'} = $1 if ($url2fetch =~ m#\/([^\/]+)\/?$#); | ||
| 420 | $self->{'id'} =~ s/[\?\&].*$//; | ||
| 421 | } else { | ||
| 422 | $self->{'id'} = $url; | ||
| 423 | $url2fetch = ($url =~ /[A-Z]/) ? 'https://www.bitchute.com/video/' | ||
| 424 | : 'https://www.bitchute.com/channel/'; #CHANNEL IDS DON'T *SEEM* TO HAVE UPPER-CASE LETTERS. | ||
| 425 | $url2fetch .= $url; | ||
| 426 | } | ||
| 427 | $url2fetch =~ s#\/www\.#\/api\.#; #USE NEW api.bitchute.com (LESS JS'd & COOKIE'd UP!) | ||
| 428 | $url2fetch =~ s#\&.*$## if ($url2fetch =~ s#^.+?\/oembed\/\?url\=(.+?)#$1#); | ||
| 429 | $url2fetch =~ s#\/embed\/#\/video\/#; | ||
| 430 | $url2fetch =~ s#\?.+$##; | ||
| 431 | print STDERR "-1 FETCHING URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG); | ||
| 432 | $self->{'genre'} = 'Video'; | ||
| 433 | |||
| 434 | #FIRST TRY SCANNING MANUALLY!: | ||
| 435 | |||
| 436 | my $html = ''; | ||
| 437 | my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}}); | ||
| 438 | $ua->timeout($self->{'timeout'}); | ||
| 439 | $ua->cookie_jar({}); | ||
| 440 | $ua->env_proxy; | ||
| 441 | my $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 | if ($url2fetch =~ m#\/channel\/#) { #WE'RE A CHANNEL PAGE, GRAB 1ST VIDEO!: | ||
| 453 | print "--WE'RE A BITCHUTE CHANNEL URL!\n" if ($DEBUG); | ||
| 454 | if ($html =~ m#\<div\s+class\=\"channel\-videos\-image\-container\"\>([^\>]+)#s) { | ||
| 455 | my $divdata = $1; | ||
| 456 | ($url2fetch = $1) =~ s#^\/#https\:\/\/www\.bitchute\.com\/# | ||
| 457 | if ($divdata =~ m#\bhref\=\"([^\"]+)#s); | ||
| 458 | if ($url2fetch) { | ||
| 459 | $self->{'id'} = $1 if ($url2fetch =~ m#\/([^\/]+)\/?$#); | ||
| 460 | $self->{'id'} =~ s/[\?\&].*$//; | ||
| 461 | $url2fetch =~ s#\/www\.#\/api\.#; #USE NEW api.bitchute.com (LESS JS'd & COOKIE'd UP!) | ||
| 462 | $url2fetch =~ s#\&.*$## if ($url2fetch =~ s#^.+?\/oembed\/\?url\=(.+?)#$1#); | ||
| 463 | $url2fetch =~ s#\/embed\/#\/video\/#; | ||
| 464 | $url2fetch =~ s#\?.+$##; | ||
| 465 | print "---FOUND 1ST VIDEO! FETCHING=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG); | ||
| 466 | $response = $ua->get($url2fetch); | ||
| 467 | if ($response->is_success) { | ||
| 468 | $html = $response->decoded_content; | ||
| 469 | } else { | ||
| 470 | print STDERR $response->status_line if ($DEBUG); | ||
| 471 | my $no_wget = system('wget','-V'); | ||
| 472 | unless ($no_wget) { | ||
| 473 | print STDERR "\n..trying wget...\n" if ($DEBUG); | ||
| 474 | $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `; | ||
| 475 | } | ||
| 476 | } | ||
| 477 | return undef unless ($html); | ||
| 478 | } | ||
| 479 | } | ||
| 480 | } | ||
| 481 | |||
| 482 | $html =~ s/\\\"/\"\;/gs; | ||
| 483 | $html =~ s/\\u00([0-9A-Fa-f]{2})/chr(hex($1))/egs; | ||
| 484 | print STDERR "-1: html=$html=\n" if ($DEBUG > 1); | ||
| 485 | if ($html =~ m#\<video(.*?)\<\/video\>#s) { | ||
| 486 | my $videotag = $1; | ||
| 487 | my $streams = ''; | ||
| 488 | my ($one, $ext); | ||
| 489 | while ($videotag =~ s#\<source\s+src\=\"([^\"]+)\" type="[^\"]*\"\s*\/?\>##s) { | ||
| 490 | $one = $1; | ||
| 491 | $ext = ($one =~ /\.(\w+)$/) ? $1 : ''; | ||
| 492 | $streams .= "$ext=$one|"; | ||
| 493 | } | ||
| 494 | unless ($self->{'youtube'} =~ /only/io) { #DEPRECIATED (NO LONGER ANY IN-PAGE STREAMS)?: | ||
| 495 | my $stindex = 0; | ||
| 496 | my $savestreams = $streams; | ||
| 497 | my %havestreams = (); | ||
| 498 | foreach my $streamtype (@okStreams) { | ||
| 499 | $streams = $savestreams; | ||
| 500 | if ($streamtype =~ /^stream$/i) { | ||
| 501 | while ($streams =~ /^([^\=]*)\=([^\|]+)/o) { | ||
| 502 | $ext = $1; $one = $2; | ||
| 503 | if ($ext !~ /^pls$/i && !defined($havestreams{"$ext|$one"})) { | ||
| 504 | unless ($self->{'secure'} && $one !~ /^https/o) { | ||
| 505 | $self->{'streams'}->[$stindex++] = $one; | ||
| 506 | $havestreams{"$ext|$one"}++; | ||
| 507 | } | ||
| 508 | } | ||
| 509 | $streams =~ s/^[^\|]*\|//o; | ||
| 510 | } | ||
| 511 | } elsif ($streamtype =~ /^playlist$/io) { | ||
| 512 | while ($streams =~ /^([^\=]*)\=([^\|]+)/o) { | ||
| 513 | $ext = $1; $one = $2; | ||
| 514 | if ($ext =~ /^pls$/i && !defined($havestreams{"$ext|$one"})) { | ||
| 515 | unless ($self->{'secure'} && $one !~ /^https/o) { | ||
| 516 | $self->{'streams'}->[$stindex++] = $one; | ||
| 517 | $havestreams{"$ext|$one"}++; | ||
| 518 | } | ||
| 519 | } | ||
| 520 | $streams =~ s/^[^\|]*\|//o; | ||
| 521 | } | ||
| 522 | } elsif ($streamtype =~ /^a(?:ny|ll)$/io) { | ||
| 523 | while ($streams =~ /^([^\=]*)\=([^\|]+)/o) { | ||
| 524 | $ext = $1; $one = $2; | ||
| 525 | unless (defined($havestreams{"$ext|$one"})) { | ||
| 526 | unless ($self->{'secure'} && $one !~ /^https/o) { | ||
| 527 | $self->{'streams'}->[$stindex++] = $one; | ||
| 528 | $havestreams{"$ext|$one"}++; | ||
| 529 | } | ||
| 530 | } | ||
| 531 | $streams =~ s/^[^\|]*\|//o; | ||
| 532 | } | ||
| 533 | } else { | ||
| 534 | while ($streams =~ /^([^\=]*)\=([^\|]+)/o) { | ||
| 535 | $ext = $1; $one = $2; | ||
| 536 | if ($ext =~ /^${streamtype}$/i && !defined($havestreams{"$ext|$one"})) { | ||
| 537 | $self->{'streams'}->[$stindex++] = $one; | ||
| 538 | $havestreams{"$ext|$one"}++; | ||
| 539 | } | ||
| 540 | $streams =~ s/^[^\|]*\|//o; | ||
| 541 | } | ||
| 542 | } | ||
| 543 | } | ||
| 544 | $self->{'cnt'} = scalar @{$self->{'streams'}}; | ||
| 545 | } | ||
| 546 | } | ||
| 547 | if ($html =~ m#\<p\s+class\=\"name\"\>\<a\s+href\=\"([^\"]+)\"[^\>]*\>([^\<]+)\<\/a\>#) { | ||
| 548 | $self->{'albumartist'} = 'https://www.bitchute.com' . $1; | ||
| 549 | $self->{'artist'} = $2; | ||
| 550 | } | ||
| 551 | if ($html =~ m#First\s+published\s+(?:at\s+)?([^\<]+)#s) { | ||
| 552 | $self->{'created'} = $1; | ||
| 553 | $self->{'year'} = $1 if ($self->{'created'} =~ /(\d\d\d\d)\.?\s*$/); | ||
| 554 | } | ||
| 555 | if ($html =~ m#\<tr\>\<td\>Category\<\/td\>\<td\>\<a\s+(.+?)</a>#) { | ||
| 556 | my $genredata = $1; | ||
| 557 | my $genre = ($genredata =~ m#\bclass\=\"spa\"\>([^\<]+)#s) ? $1 : ''; | ||
| 558 | $self->{'genre'} = $genre if ($genre =~ /\w+/ && $genre !~ /^\s*none/i); | ||
| 559 | } | ||
| 560 | $self->{'title'} = $1 if ($html =~ m#\<title\>([^\<]+)\<#s); | ||
| 561 | $self->{'title'} ||= $1 if ($html =~ m#\<h1\s+id\=\"video\-title\"\s+class\=\"page\-title\"\>([^\<]+)\<#i); | ||
| 562 | $self->{'title'} ||= $1 if ($html =~ m#\<meta\s+name\=\"description\"\s+content\=\"([^\"]+)\"#); | ||
| 563 | $self->{'description'} = $1 if ($html =~ m#\<meta\s+name\=\"description\"\s+content\=\"([^\"]+)#s); | ||
| 564 | $self->{'description'} ||= $1 if ($html =~ m#\<div\s+class\=\"full\s+hidden\"\>(.+?)\<\/div\>#s); | ||
| 565 | $self->{'description'} ||= $self->{'title'}; | ||
| 566 | |||
| 567 | $self->{'iconurl'} = $1 if ($html =~ m#\"og\:image\:secure_url\"\s+content\=\"([^\"]+)#); | ||
| 568 | # $self->{'iconurl'} ||= $1 if ($html =~ m#\<img\s+class\=\"image\s+lazyload\"\s+src="[^\"]*"\s+data\-src\=\"([^\"]+)#); | ||
| 569 | if ($html =~ m#\<img\s+class\=\"image\s+lazyload([^\>]+)#) { | ||
| 570 | my $icondata = $1; | ||
| 571 | $self->{'articonurl'} = $1 if ($icondata =~ m#\bdata\-src\=\"([^\"]+)#); | ||
| 572 | print STDERR "--FOUND ARTICON URL=".$self->{'articonurl'}."=\n" if ($DEBUG); | ||
| 573 | } | ||
| 574 | $self->{'imageurl'} = ($html =~ m# poster\=\"([^\"]+)#) ? $1 : $self->{'iconurl'}; | ||
| 575 | |||
| 576 | print STDERR "\n--ID=".$self->{'id'}."=\n--ARTIST=".$self->{'artist'}."=\n--TITLE=".$self->{'title'}."=\n--CNT=".$self->{'cnt'}."=\n--ICON=".$self->{'iconurl'}."=\n--DESC=".$self->{'description'}."=\n--streams=".join('|',@{$self->{'streams'}})."=\n" if ($DEBUG); | ||
| 577 | |||
| 578 | #IF WE DIDN'T FIND ANY STREAMS IN THE PAGE, TRY youtube-dl: | ||
| 579 | |||
| 580 | my $haveYoutube = 0; | ||
| 581 | unless ($self->{'youtube'} =~ /no/i | ||
| 582 | || ($self->{'cnt'} > 0 && $self->{'youtube'} =~ /ifneeded/i)) { | ||
| 583 | eval { require 'StreamFinder/Youtube.pm'; $haveYoutube = 1; }; | ||
| 584 | } | ||
| 585 | print STDERR "\n-2 NO STREAMS FOUND IN PAGE (haveYoutube=$haveYoutube)\n" if ($DEBUG && $self->{'cnt'} <= 0); | ||
| 586 | if ($haveYoutube) { | ||
| 587 | print STDERR "\n-2 TRYING youtube-dl($self->{'youtube'})...\n" if ($DEBUG); | ||
| 588 | my %globalArgs = ( | ||
| 589 | '-noiframes' => 1, '-fast' => 1, '-debug' => $DEBUG | ||
| 590 | ); | ||
| 591 | foreach my $arg (qw(secure log logfmt youtube-format youtube-format-fallback | ||
| 592 | youtube-formatonly youtube-dl-args youtube-dl-add-args)) { | ||
| 593 | (my $arg0 = $arg) =~ s/^youtube\-(?!dl)//o; | ||
| 594 | $globalArgs{$arg0} = $self->{$arg} if (defined $self->{$arg}); | ||
| 595 | } | ||
| 596 | $url2fetch =~ s#api\.bitchute\.com#old\.bitchute\.com#i; | ||
| 597 | my $yt = new StreamFinder::Youtube($url2fetch, %globalArgs); | ||
| 598 | if ($yt && $yt->count() > 0) { | ||
| 599 | my @ytStreams = $yt->get(); | ||
| 600 | if ($self->{'youtube'} =~ /(?:top|first)/i) { #PUT youtube-dl STREAMS ON TOP: | ||
| 601 | unshift @{$self->{'streams'}}, @ytStreams; | ||
| 602 | } else { | ||
| 603 | push @{$self->{'streams'}}, @ytStreams; | ||
| 604 | } | ||
| 605 | foreach my $field (qw(title iconurl)) { | ||
| 606 | $self->{$field} ||= $yt->{$field} if (defined($yt->{$field}) && $yt->{$field}); | ||
| 607 | } | ||
| 608 | $self->{'description'} = $yt->{'description'} if (length($yt->{'description'}) > length($self->{'description'})); | ||
| 609 | $self->{'cnt'} = scalar @{$self->{'streams'}}; | ||
| 610 | print STDERR "i:Found stream(s) (".join('|',@ytStreams).") via youtube-dl.\n" if ($DEBUG); | ||
| 611 | } | ||
| 612 | print STDERR "-count=".$self->{'cnt'}."= iconurl=".$self->{'iconurl'}."=\n" if ($DEBUG); | ||
| 613 | } | ||
| 614 | if ($self->{'description'} =~ /\w/) { | ||
| 615 | $self->{'description'} =~ s/\s+$//; | ||
| 616 | } else { | ||
| 617 | $self->{'description'} = $self->{'title'}; | ||
| 618 | } | ||
| 619 | foreach my $i (qw(description title artist genre)) { | ||
| 620 | $self->{$i} = HTML::Entities::decode_entities($self->{$i}); | ||
| 621 | $self->{$i} = uri_unescape($self->{$i}); | ||
| 622 | $self->{$i} =~ s/(?:\%|\\[ux\%]?00|\bu00)([0-9A-Fa-f]{2})/chr(hex($1))/egs; | ||
| 623 | } | ||
| 624 | $self->{'imageurl'} = $self->{'iconurl'}; | ||
| 625 | $self->{'total'} = $self->{'cnt'}; | ||
| 626 | $self->{'Url'} = ($self->{'total'} > 0) ? $self->{'streams'}->[0] : ''; | ||
| 627 | if ($DEBUG) { | ||
| 628 | foreach my $i (sort keys %{$self}) { | ||
| 629 | print STDERR "--KEY=$i= VAL=".$self->{$i}."=\n"; | ||
| 630 | } | ||
| 631 | print STDERR "--SUCCESS: 1st stream=".$self->{'Url'}."= total=".$self->{'total'}."=\n" | ||
| 632 | if ($self->{'cnt'} > 0); | ||
| 633 | } | ||
| 634 | $self->_log($url); | ||
| 635 | |||
| 636 | bless $self, $class; #BLESS IT! | ||
| 637 | |||
| 638 | return $self; | ||
| 639 | } | ||
| 640 | |||
| 641 | sub getImageData | ||
| 642 | { | ||
| 643 | my $self = shift; | ||
| 644 | return $self->getIconData(); | ||
| 645 | } | ||
| 646 | |||
| 647 | 1 |