| 1 | =head1 NAME | ||
| 2 | |||
| 3 | StreamFinder::BrandNewTube - Fetch actual raw streamable URLs from BrandNewTube.com. | ||
| 4 | |||
| 5 | =head1 AUTHOR | ||
| 6 | |||
| 7 | This module is Copyright (C) 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::BrandNewTube; | ||
| 26 | |||
| 27 | die "..usage: $0 ID|URL\n" unless ($ARGV[0]); | ||
| 28 | |||
| 29 | my $video = new StreamFinder::BrandNewTube($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 | NOTE: Ugetube.com appears to have closed up shop and brandnewtube.com has | ||
| 94 | renamed itself and redirects to onevsp.com". | ||
| 95 | |||
| 96 | StreamFinder::BrandNewTube accepts a valid brandnewtube.com video ID or | ||
| 97 | page URL (either one of their ".html" or "embed" | ||
| 98 | URL) and returns the actual stream URL, title, and cover art icon for that | ||
| 99 | video. The purpose is that one needs this URL in order to have the option to | ||
| 100 | stream the video in one's own choice of media player software rather than | ||
| 101 | using their web browser and accepting any / all flash, ads, javascript, | ||
| 102 | cookies, trackers, web-bugs, and other crapware that can come with that | ||
| 103 | method of play. The author uses his own custom all-purpose media player | ||
| 104 | called "fauxdacious" (his custom hacked version of the open-source | ||
| 105 | "audacious" audio player). "fauxdacious" incorporates this module to | ||
| 106 | decode and play brandnewtube.com (onevsp). This is a submodule | ||
| 107 | of the general StreamFinder module. | ||
| 108 | |||
| 109 | Depends: | ||
| 110 | |||
| 111 | L<URI::Escape>, L<HTML::Entities>, and L<LWP::UserAgent>. | ||
| 112 | |||
| 113 | =head1 SUBROUTINES/METHODS | ||
| 114 | |||
| 115 | =over 4 | ||
| 116 | |||
| 117 | =item B<new>(I<ID>|I<url> [, I<-secure> [ => 0|1 ]] | ||
| 118 | [, I<-debug> [ => 0|1|2 ]]) | ||
| 119 | |||
| 120 | Accepts a onevsp.com (previously brandnewtube.com) video ID or URL and creates | ||
| 121 | and returns a new video object, or I<undef> if the URL is not a valid | ||
| 122 | BrandNewTube video or no streams are found. For brandnewtube.com The URL can | ||
| 123 | be the full URL, ie. https://onevsp.com/B<video-id>.html, | ||
| 124 | https://onevsp.com/B<@channel-id>, | ||
| 125 | https://onevsp.com/embed/B<video-id> or just B<video-id> or | ||
| 126 | I<@channel-id>. If a channel URL is given, then the first (latest) video of | ||
| 127 | that channel will be returned. Note: Channel-ids are distinguished by the | ||
| 128 | "@"-sign. | ||
| 129 | |||
| 130 | The optional I<-secure> argument can be either 0 or 1 (I<false> or I<true>). | ||
| 131 | If 1 then only secure ("https://") streams will be returned. | ||
| 132 | |||
| 133 | DEFAULT I<-secure> is 0 (false) - return all streams (http and https). | ||
| 134 | |||
| 135 | Additional options: | ||
| 136 | |||
| 137 | I<-log> => "I<logfile>" | ||
| 138 | |||
| 139 | Specify path to a log file. If a valid and writable file is specified, A line | ||
| 140 | will be appended to this file every time one or more streams is successfully | ||
| 141 | fetched for a url. | ||
| 142 | |||
| 143 | DEFAULT I<-none-> (no logging). | ||
| 144 | |||
| 145 | I<-logfmt> specifies a format string for lines written to the log file. | ||
| 146 | |||
| 147 | DEFAULT "I<[time] [url] - [site]: [title] ([total])>". | ||
| 148 | |||
| 149 | The valid field I<[variables]> are: [stream]: The url of the first/best | ||
| 150 | stream found. [site]: The site name (BrandNewTube). [url]: The url searched for | ||
| 151 | streams. [time]: Perl timestamp when the line was logged. [title], [artist], | ||
| 152 | [album], [description], [year], [genre], [total], [albumartist]: | ||
| 153 | The corresponding field data returned (or "I<-na->", if no value). | ||
| 154 | |||
| 155 | =item $video->B<get>() | ||
| 156 | |||
| 157 | Returns an array of strings representing all stream URLs found. | ||
| 158 | |||
| 159 | =item $video->B<getURL>([I<options>]) | ||
| 160 | |||
| 161 | Similar to B<get>() except it only returns a single stream representing | ||
| 162 | the first valid stream found. | ||
| 163 | |||
| 164 | Current options are: I<"random">, I<"nopls">, and I<"noplaylists">. | ||
| 165 | By default, the first ("best"?) stream is returned. If I<"random"> is | ||
| 166 | specified, then a random one is selected from the list of streams found. | ||
| 167 | If I<"nopls"> is specified, and the stream to be returned is a ".pls" playlist, | ||
| 168 | it is first fetched and the first entry (or a random entry if I<"random"> is | ||
| 169 | specified) is returned. This is needed by Fauxdacious Mediaplayer. | ||
| 170 | If I<"noplaylists"> is specified, and the stream to be returned is a | ||
| 171 | "playlist" (either .pls or .m3u? extension), it is first fetched and the first | ||
| 172 | entry (or a random entry if I<"random"> is specified) in the playlist | ||
| 173 | is returned. | ||
| 174 | |||
| 175 | =item $video->B<count>() | ||
| 176 | |||
| 177 | Returns the number of streams found for the video. | ||
| 178 | |||
| 179 | =item $video->B<getID>() | ||
| 180 | |||
| 181 | Returns the video's BrandNewTube ID (alphanumeric). | ||
| 182 | |||
| 183 | =item $video->B<getTitle>(['desc']) | ||
| 184 | |||
| 185 | Returns the video's title, or (long description). | ||
| 186 | |||
| 187 | =item $video->B<getIconURL>(['artist']) | ||
| 188 | |||
| 189 | Returns the URL for the video's "cover art" icon image, if any. | ||
| 190 | If B<'artist'> is specified, the channel artist's icon url is returned, | ||
| 191 | if any. | ||
| 192 | |||
| 193 | =item $video->B<getIconData>(['artist']) | ||
| 194 | |||
| 195 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 196 | "gif", "jpeg", etc.) and the actual icon image (binary data), if any. | ||
| 197 | If B<'artist'> is specified, the channel artist's icon data is returned, | ||
| 198 | if any. | ||
| 199 | |||
| 200 | =item $video->B<getImageURL>() | ||
| 201 | |||
| 202 | Returns the URL for the video's "cover art" banner image, which for | ||
| 203 | BrandNewTube videos is always the icon image, as BrandNewTube does not | ||
| 204 | support a separate banner image at this time. | ||
| 205 | |||
| 206 | =item $video->B<getImageData>() | ||
| 207 | |||
| 208 | Returns a two-element array consisting of the extension (ie. "png", | ||
| 209 | "gif", "jpeg", etc.) and the actual video's banner image (binary data). | ||
| 210 | |||
| 211 | =item $video->B<getType>() | ||
| 212 | |||
| 213 | Returns the video's type ("BrandNewTube"). | ||
| 214 | |||
| 215 | =back | ||
| 216 | |||
| 217 | =head1 CONFIGURATION FILES | ||
| 218 | |||
| 219 | The default root location directory for StreamFinder configuration files | ||
| 220 | is "~/.config/StreamFinder". To use an alternate location directory, | ||
| 221 | specify it in the "I<STREAMFINDER>" environment variable, ie.: | ||
| 222 | B<$ENV{STREAMFINDER} = "/etc/StreamFinder">. | ||
| 223 | |||
| 224 | =over 4 | ||
| 225 | |||
| 226 | =item ~/.config/StreamFinder/BrandNewTube/config | ||
| 227 | |||
| 228 | Optional text file for specifying various configuration options | ||
| 229 | for a specific site (submodule). Each option is specified on a | ||
| 230 | separate line in the format below: | ||
| 231 | NOTE: Do not follow the lines with a semicolon, comma, or any other | ||
| 232 | separator. Non-numeric I<values> should be surrounded with quotes, either | ||
| 233 | single or double. Blank lines and lines beginning with a "#" sign as | ||
| 234 | their first non-blank character are ignored as comments. | ||
| 235 | |||
| 236 | 'option' => 'value' [,] | ||
| 237 | |||
| 238 | and the options are loaded into a hash used only by the specific | ||
| 239 | (submodule) specified. Valid options include | ||
| 240 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 241 | |||
| 242 | Options specified here override any specified in | ||
| 243 | I<~/.config/StreamFinder/config>. | ||
| 244 | |||
| 245 | =item ~/.config/StreamFinder/config | ||
| 246 | |||
| 247 | Optional text file for specifying various configuration options. | ||
| 248 | Each option is specified on a separate line in the format below: | ||
| 249 | |||
| 250 | 'option' => 'value' [,] | ||
| 251 | |||
| 252 | and the options are loaded into a hash used by all sites | ||
| 253 | (submodules) that support them. Valid options include | ||
| 254 | I<-debug> => [0|1|2] and most of the L<LWP::UserAgent> options. | ||
| 255 | |||
| 256 | =back | ||
| 257 | |||
| 258 | NOTE: Options specified in the options parameter list of the I<new()> | ||
| 259 | function will override those corresponding options specified in these files. | ||
| 260 | |||
| 261 | =head1 KEYWORDS | ||
| 262 | |||
| 263 | brandnewtube | ||
| 264 | |||
| 265 | =head1 DEPENDENCIES | ||
| 266 | |||
| 267 | L<URI::Escape>, L<HTML::Entities>, L<LWP::UserAgent> | ||
| 268 | |||
| 269 | =head1 RECCOMENDS | ||
| 270 | |||
| 271 | wget | ||
| 272 | |||
| 273 | =head1 BUGS | ||
| 274 | |||
| 275 | Please report any bugs or feature requests to C<bug-streamFinder-brandnewtube at rt.cpan.org>, or through | ||
| 276 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=StreamFinder-BrandNewTube>. I will be notified, and then you'll | ||
| 277 | automatically be notified of progress on your bug as I make changes. | ||
| 278 | |||
| 279 | =head1 SUPPORT | ||
| 280 | |||
| 281 | You can find documentation for this module with the perldoc command. | ||
| 282 | |||
| 283 | perldoc StreamFinder::BrandNewTube | ||
| 284 | |||
| 285 | You can also look for information at: | ||
| 286 | |||
| 287 | =over 4 | ||
| 288 | |||
| 289 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 290 | |||
| 291 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=StreamFinder-BrandNewTube> | ||
| 292 | |||
| 293 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 294 | |||
| 295 | L<http://annocpan.org/dist/StreamFinder-BrandNewTube> | ||
| 296 | |||
| 297 | =item * Search CPAN | ||
| 298 | |||
| 299 | L<http://search.cpan.org/dist/StreamFinder-BrandNewTube/> | ||
| 300 | |||
| 301 | =back | ||
| 302 | |||
| 303 | =head1 LICENSE AND COPYRIGHT | ||
| 304 | |||
| 305 | Copyright 2026 Jim Turner. | ||
| 306 | |||
| 307 | This program is free software; you can redistribute it and/or modify it | ||
| 308 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 309 | copy of the full license at: | ||
| 310 | |||
| 311 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 312 | |||
| 313 | Any use, modification, and distribution of the Standard or Modified | ||
| 314 | Versions is governed by this Artistic License. By using, modifying or | ||
| 315 | distributing the Package, you accept this license. Do not use, modify, | ||
| 316 | or distribute the Package, if you do not accept this license. | ||
| 317 | |||
| 318 | If your Modified Version has been derived from a Modified Version made | ||
| 319 | by someone other than you, you are nevertheless required to ensure that | ||
| 320 | your Modified Version complies with the requirements of this license. | ||
| 321 | |||
| 322 | This license does not grant you the right to use any trademark, service | ||
| 323 | mark, tradename, or logo of the Copyright Holder. | ||
| 324 | |||
| 325 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 326 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 327 | otherwise transfer the Package with respect to any patent claims | ||
| 328 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 329 | Package. If you institute patent litigation (including a cross-claim or | ||
| 330 | counterclaim) against any party alleging that the Package constitutes | ||
| 331 | direct or contributory patent infringement, then this Artistic License | ||
| 332 | to you shall terminate on the date that such litigation is filed. | ||
| 333 | |||
| 334 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 335 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 336 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 337 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 338 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 339 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 340 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 341 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 342 | |||
| 343 | =cut | ||
| 344 | |||
| 345 | package StreamFinder::BrandNewTube; | ||
| 346 | |||
| 347 | use strict; | ||
| 348 | use warnings; | ||
| 349 | use URI::Escape; | ||
| 350 | use HTML::Entities (); | ||
| 351 | use LWP::UserAgent (); | ||
| 352 | use parent 'StreamFinder::_Class'; | ||
| 353 | |||
| 354 | my $DEBUG = 0; | ||
| 355 | |||
| 356 | sub new | ||
| 357 | { | ||
| 358 | my $class = shift; | ||
| 359 | my $url = shift; | ||
| 360 | |||
| 361 | return undef unless ($url); | ||
| 362 | |||
| 363 | my $self = $class->SUPER::new('BrandNewTube', @_); | ||
| 364 | $DEBUG = $self->{'debug'} if (defined $self->{'debug'}); | ||
| 365 | |||
| 366 | my $ua = LWP::UserAgent->new(@{$self->{'_userAgentOps'}}); | ||
| 367 | $ua->timeout($self->{'timeout'}); | ||
| 368 | $ua->cookie_jar({}); | ||
| 369 | $ua->env_proxy; | ||
| 370 | my $response; | ||
| 371 | $self->{'genre'} = 'Video'; | ||
| 372 | |||
| 373 | my $url2fetch = $url; | ||
| 374 | if ($url =~ m#^https?\:#) { #NOTE: ASSUME brandnewtube ID!: | ||
| 375 | $url2fetch =~ s#brandnewtube.com#onevsp.com#; | ||
| 376 | } else { | ||
| 377 | $url2fetch = ($url =~ /^\@/) ? 'https://onevsp.com/' . $url | ||
| 378 | : "https://onevsp.com/watch/${url}/"; | ||
| 379 | } | ||
| 380 | |||
| 381 | my $baseURL = ($url2fetch =~ m#(https?\:\/\/[^\/]+)#) ? $1 : 'https://onevsp.com'; | ||
| 382 | |||
| 383 | print STDERR "-0(RadioNet): URL=$url2fetch=\n" if ($DEBUG); | ||
| 384 | if ($url2fetch =~ /\@/) { | ||
| 385 | my $html = ''; | ||
| 386 | print STDERR "-FETCHING CHANNEL URL=$url2fetch=\n" if ($DEBUG); | ||
| 387 | $response = $ua->get($url2fetch); | ||
| 388 | if ($response->is_success) { | ||
| 389 | $html = $response->decoded_content; | ||
| 390 | } else { | ||
| 391 | print STDERR $response->status_line if ($DEBUG); | ||
| 392 | my $no_wget = system('wget','-V'); | ||
| 393 | unless ($no_wget) { | ||
| 394 | print STDERR "\n..trying wget...\n" if ($DEBUG); | ||
| 395 | $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `; | ||
| 396 | } | ||
| 397 | } | ||
| 398 | if ($html =~ m#\<a\s+href\=\"([^\"]+)\"\s+class\=\"video\-title\-link\"\>#s) { | ||
| 399 | $url2fetch = $1; | ||
| 400 | print STDERR "---FOUND 1ST EPISODE URL=$url2fetch= IN CHANNEL PAGE, RUN WITH THAT!\n" if ($DEBUG); | ||
| 401 | } | ||
| 402 | } | ||
| 403 | |||
| 404 | my $html = ''; | ||
| 405 | if ($url2fetch =~ m#\/watch\/([^\/\.]+)#) { | ||
| 406 | $self->{'id'} = $1; | ||
| 407 | print STDERR "-FETCHING HTML URL=$url2fetch= ID=".$self->{'id'}."=\n" if ($DEBUG); | ||
| 408 | $response = $ua->get($url2fetch); | ||
| 409 | if ($response->is_success) { | ||
| 410 | $html = $response->decoded_content; | ||
| 411 | } else { | ||
| 412 | print STDERR $response->status_line if ($DEBUG); | ||
| 413 | my $no_wget = system('wget','-V'); | ||
| 414 | unless ($no_wget) { | ||
| 415 | print STDERR "\n..trying wget...\n" if ($DEBUG); | ||
| 416 | $html = `wget -t 2 -T 20 -O- -o /dev/null "$url2fetch" 2>/dev/null `; | ||
| 417 | } | ||
| 418 | } | ||
| 419 | if ($html) { | ||
| 420 | $self->{'title'} = ($html =~ m#\<title\>\s*([^\<]+)\<\/title\>#s) ? $1 : ''; | ||
| 421 | $self->{'title'} ||= $1 if ($html =~ m#\<meta\s+(?:name|property)\=\"?(?:og|twitter)\:title\"?\s+content\=\"(.+?)\"\s*\/?\>#s); | ||
| 422 | $self->{'title'} =~ s#\s+$##; | ||
| 423 | $self->{'title'} =~ s#\s*\-\s+Brand New Tube$##; | ||
| 424 | |||
| 425 | if ($html =~ m#\<div\s+class\=\"video\-date\"\>(.+?)\<\/div\>#s) { | ||
| 426 | ($self->{'created'} = $1) =~ s/^\s+//s; | ||
| 427 | $self->{'created'} =~ s/\s+$//s; | ||
| 428 | if ($self->{'created'} =~ /(\d\d\d\d)/) { | ||
| 429 | $self->{'year'} = $1; | ||
| 430 | } else { | ||
| 431 | #YES, THEY DO STUPID STUFF LIKE THIS!: | ||
| 432 | my @timestuff = localtime(time); | ||
| 433 | my $curyear = $timestuff[5] + 1900; | ||
| 434 | if ($self->{'created'} =~ /(\d)\s+years?\s+ago/) { | ||
| 435 | $self->{'year'} = $curyear - $1; | ||
| 436 | } elsif ($self->{'created'} =~ /months?\s+ago/) { | ||
| 437 | $self->{'year'} = $curyear; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | } | ||
| 441 | $self->{'description'} = $self->{'title'}; | ||
| 442 | $self->{'imageurl'} = $1 if ($html =~ m#\bdata\-poster\=\"([^\"]+)#s); | ||
| 443 | #THIS IS UGLY: | ||
| 444 | if ($html =~ m#\<div\s+class\=\"col\-md\-1\s+col\-sm\-2\s+col\-2\s+pb\-3\"\>(.+?)\<\/div\>#s) { | ||
| 445 | my $channelstuff = $1; | ||
| 446 | $self->{'albumartist'} = $1 if ($channelstuff =~ m#\<a\s+href\=\"([^\"]+)#s); | ||
| 447 | $self->{'articonurl'} = $1 if ($channelstuff =~ m#\<img\s+src\=\"([^\"]+)#s); | ||
| 448 | } | ||
| 449 | if ($html =~ m#\<a\s+href\=\"([^\"]+)\"\s+class\=\"video\-username\"\>\s*([^\<]+)#s) { | ||
| 450 | $self->{'albumartist'} ||= $1; | ||
| 451 | ($self->{'artist'} = $2) =~ s#\s+$##s; | ||
| 452 | } | ||
| 453 | |||
| 454 | #TRY TO FETCH STREAMS: | ||
| 455 | while ($html =~ s#\<source\s+.*?src\=\"([^\"]+)\"##s) { | ||
| 456 | my $one = $1; | ||
| 457 | push @{$self->{'streams'}}, $one unless ($self->{'secure'} && $one !~ /^https/); | ||
| 458 | $self->{'cnt'}++; | ||
| 459 | } | ||
| 460 | #STEP 2: TRY FETCHING THE EMBED URL UNLESS WE FOUND STREAM(S): | ||
| 461 | #DEPRECIATED? $url2fetch = $1 if ($self->{'cnt'} <= 0 | ||
| 462 | #DEPRECIATED? && $html =~ m#\<iframe\s+src\=\"($baseURL\/embed\/[^\"]+)#s); | ||
| 463 | print STDERR "*** EMBED PAGE URL($1) FOUND!\n" if ($self->{'cnt'} <= 0 | ||
| 464 | && $html =~ m#\<iframe\s+src\=\"($baseURL\/embed\/[^\"]+)#s); | ||
| 465 | } | ||
| 466 | } | ||
| 467 | |||
| 468 | $self->{'cnt'} = scalar @{$self->{'streams'}}; | ||
| 469 | $self->{'title'} =~ s/\s+\-\s+$self->{'artist'}\s*$//; #CONVERT "Title - Artist" => "Title" | ||
| 470 | foreach my $field (qw(description artist title)) { | ||
| 471 | $self->{$field} = HTML::Entities::decode_entities($self->{$field}); | ||
| 472 | $self->{$field} = uri_unescape($self->{$field}); | ||
| 473 | $self->{$field} =~ s/(?:\%|\\?u?00)([0-9A-Fa-f]{2})/chr(hex($1))/eg; | ||
| 474 | } | ||
| 475 | #SOME TITLES HAVE WIDE CHARACTERS, REMOVE 'EM!: | ||
| 476 | $self->{'title'} =~ s/(.)/'\x'.sprintf('%02x',ord($1))/eg; | ||
| 477 | $self->{'title'} =~ s/\\x[0-9a-f][0-9a-f][0-9a-f]+//g; | ||
| 478 | $self->{'title'} =~ s/\\x\{?([0-9A-Fa-f]{2})\}?/chr(hex($1))/eg; | ||
| 479 | |||
| 480 | $self->{'iconurl'} ||= $self->{'imageurl'}; | ||
| 481 | $self->{'iconurl'} ||= $self->{'articonurl'} if ($self->{'articonurl'}); | ||
| 482 | $self->{'artimageurl'} ||= $self->{'articonurl'}; | ||
| 483 | foreach my $field (qw(iconurl imageurl articonurl artimageurl)) { | ||
| 484 | $self->{$field} =~ s/\&\;/\&/g; | ||
| 485 | } | ||
| 486 | $self->{'total'} = $self->{'cnt'}; | ||
| 487 | $self->{'Url'} = ($self->{'cnt'} > 0) ? $self->{'streams'}->[0] : ''; | ||
| 488 | if ($DEBUG) { | ||
| 489 | foreach my $f (sort keys %{$self}) { | ||
| 490 | print STDERR "--KEY=$f= VAL=$$self{$f}=\n"; | ||
| 491 | } | ||
| 492 | print STDERR "-SUCCESS: 1st stream=".$self->{'Url'}."=\n" if ($self->{'cnt'} > 0);; | ||
| 493 | } | ||
| 494 | |||
| 495 | $self->_log($url); | ||
| 496 | |||
| 497 | bless $self, $class; #BLESS IT! | ||
| 498 | |||
| 499 | return $self; | ||
| 500 | } | ||
| 501 | |||
| 502 | 1 |