00001 # @(#)$Header: /home/mythtv/mythtvrep/scripts/nv_perl_libs/mnvcommonsubs.pm,v 1.10 2010/07/25 00:11:35 mythtv Exp $
00002 # Auric 2010/01/10 http://web.aanet.com.au/auric/
00003 #
00004 # MythNetvision Grabber Script utility subs
00005 #
00006 #################################### Util Subs ############################################
00007
00008 package mnvcommonsubs;
00009
00010 use strict;
00011 use warnings;
00012 use HTML::Entities;
00013 use Encode;
00014 use LWP::Simple;
00015 use File::stat;
00016 use File::Basename;
00017 use Sys::Hostname;
00018 # mythbackend sets HOME and MYTHCONFDIR to /var/lib/mythtv.
00019 # So have to hack it back to the real home for require MythTV to work.
00020 $ENV{'HOME'} = (getpwuid $>)[7];
00021 delete $ENV{'MYTHCONFDIR'};
00022 require MythTV;
00023 use Image::Magick;
00024 use File::Copy;
00025
00026 our(@ISA, @EXPORT, @EXPORT_OK, $VERSION);
00027 $VERSION = '$Revision: 1.10 $'; $VERSION =~ s/\D*([\d\.]+)\D*/$1/; # rcs tag populated
00028
00029 require Exporter;
00030 @ISA = qw(Exporter);
00031 @EXPORT = qw(mnvURLEncode mnvprintversion mnvcleanexit mnvinfomsg mnvcleantext mnvnumresults mnvfilter
00032 mnvprinttree mnvprintsearch mnvrssitem2mnv mnvistype mnvgetsetting mnvgeticonDir mnvrssheader mnvrssfooter
00033 mnvgetflashplayerurl mnvloadconfig mnvgetconfig mnvsetconfig);
00034 @EXPORT_OK = qw(); # symbols to export on request
00035
00036 my $mythobj;
00037 eval { $mythobj = MythTV->new(); };
00038 ($@) and die("Could not create MythTV-new() $@");
00039
00040 # Netvision version access as $mnvcommonsubs::netvisionver
00041 our $netvisionver = mnvgetnetvisionver();
00042
00043 # Get a mnv configuration
00044 # Default config values. These can be overridded by mnvsetconfig
00045 our %config = (
00046 'mnvinfo' => 0,
00047 'mnvinfoop' => "",
00048 'player' => "",
00049 'playerargs' => "",
00050 'download' => "",
00051 'downloadargs' => "",
00052 # A network player like a flash or html5 html. TODO 0.24 May not be approved
00053 'netplayer' => "",
00054 'netplayertype' => "",
00055 # Seconds to cache results
00056 'cachetime' => 72000,
00057 'defaultautoplay' => 'autostart=1&autoplay=1'
00058 );
00059
00060 sub mnvgetconfig {
00061 my $value = shift @_;
00062
00063 return $config{$value};
00064 }
00065
00066 # Set a mnv configuration
00067 sub mnvsetconfig {
00068 my $value = shift @_;
00069 my $data = shift @_;
00070
00071 if (ref($config{$value}) eq "ARRAY") {
00072 push(@{$config{$value}}, $data);
00073 } else {
00074 $config{$value} = $data;
00075 }
00076 }
00077
00078 # Load a mnv configuration file
00079 # $ENV{'HOME'}/.mythtv/MythNetvision/userGrabberPrefs/${configfile}.cfg
00080 # INI Format
00081 # # Default
00082 # player=mplayer
00083 # feedurl+url1 (Creates a array feedurl of all the entries)
00084 # feedurl+url2
00085 # # Section Specific
00086 # [Section A]
00087 # player=vlc
00088 # [Section B]
00089 # player=xine
00090 sub mnvloadconfig {
00091 my $configfile = shift @_;
00092 my $section = shift @_;
00093
00094 my $cfile = "/$ENV{'HOME'}/.mythtv/MythNetvision/userGrabberPrefs/${configfile}.cfg";
00095 my $ss = stat($cfile);
00096 if ($ss) {
00097 open(CF, "<$cfile") or warn "Could not load $cfile";
00098 my $in = 1; # In default section
00099 while(<CF>) {
00100 chomp;
00101 /^\s*#/ and next;
00102 s/\s*=\s*/=/g;
00103 if ($in == 1 && /=/) {
00104 my ($value, @data) = split('=', $_);
00105 $config{$value} = join('=', @data);
00106 next;
00107 }
00108 s/\s*\+\s*/\+/g;
00109 if ($in == 1 && /\+/) {
00110 my ($value, @data) = split('\+', $_);
00111 push(@{$config{$value}}, join('+', @data));
00112 next;
00113 }
00114 if (/^\s*\[(.*)\]\s*$/) {
00115 if ($1 eq $section) {
00116 $in = 1;
00117 } else {
00118 $in = 0;
00119 }
00120 }
00121 }
00122 close(CF);
00123 }
00124 }
00125
00126 # Get a mythdb setting
00127 sub mnvgetsetting {
00128 my $setting = shift @_;
00129 my $hostname = shift @_;
00130
00131 my $data;
00132 if ($hostname) {
00133 $data = $mythobj->backend_setting($setting, $hostname);
00134 } else {
00135 $data = $mythobj->backend_setting($setting);
00136 }
00137
00138 return $data;
00139 }
00140
00141 # Find netvision version
00142 sub mnvgetnetvisionver {
00143
00144 my $netvisionver = "NA";
00145 my $printerror = $mythobj->{'dbh'}->{'PrintError'};
00146 my $printwarn = $mythobj->{'dbh'}->{'PrintWarn'};
00147 $mythobj->{'dbh'}->{'PrintError'} = 0;
00148 $mythobj->{'dbh'}->{'PrintWarn'} = 0;
00149 eval { $mythobj->{'dbh'}->do("select count(*) from internetcontent where 1=0") };
00150 unless ($mythobj->{'dbh'}->err) {
00151 $netvisionver = "24";
00152 } else {
00153 eval { $mythobj->{'dbh'}->do("select count(*) from netvisiontreegrabbers where 1=0") };
00154 unless ($mythobj->{'dbh'}->err) {
00155 $netvisionver = "23";
00156 }
00157 }
00158 $mythobj->{'dbh'}->{'PrintError'} = $printerror;
00159 $mythobj->{'dbh'}->{'PrintWarn'} = $printwarn;
00160
00161 return $netvisionver;
00162 }
00163
00164 # Find netvision icon directory
00165 sub mnvgeticonDir {
00166
00167 # 0.23 mythnetvision.iconDir. 0.24 %SHAREDIR%
00168 my $icondir = mnvgetsetting('mythnetvision.iconDir', hostname());
00169 ($icondir) and return $icondir;
00170 return "%SHAREDIR%/mythnetvision/icons";
00171 }
00172
00173 # Encode a string
00174 sub mnvURLEncode {
00175 my $theURL = shift @_;
00176
00177 $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
00178 return $theURL;
00179 }
00180
00181 # print or return a typical <rss...> header
00182 #
00183 # in list context, return a list of lines with the header in it
00184 # in scalar context, return as a string
00185 # in void context, print the header to stdout
00186 #
00187 sub mnvrssheader {
00188
00189 my $header='<?xml version="1.0" encoding="UTF-8"?>
00190 <rss version="2.0"
00191 xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
00192 xmlns:content="http://purl.org/rss/1.0/modules/content/"
00193 xmlns:cnettv="http://cnettv.com/mrss/"
00194 xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
00195 xmlns:media="http://search.yahoo.com/mrss/"
00196 xmlns:atom="http://www.w3.org/2005/Atom"
00197 xmlns:amp="http://www.adobe.com/amp/1.0"
00198 xmlns:dc="http://purl.org/dc/elements/1.1/"
00199 xmlns:mythtv="http://www.mythtv.org/wiki/MythNetvision_Grabber_Script_Format">
00200 ';
00201
00202 if(wantarray()) {
00203 return split(/\n/,$header);
00204 } elsif(defined wantarray()) {
00205 return $header;
00206 } else {
00207 print $header;
00208 }
00209 }
00210
00211 # print or return a typical </rss> footer to close out an rss block
00212 #
00213 # in list context, return a list of lines with the footer in it
00214 # in scalar context, return as a string
00215 # in void context, print the header to stdout
00216 sub mnvrssfooter {
00217
00218 my $footer="</rss>\n";
00219 if(wantarray()) {
00220 return split(/\n/,$footer);
00221 } elsif(defined wantarray()) {
00222 return $footer;
00223 } else {
00224 print $footer;
00225 }
00226 }
00227
00228 sub mnvprintversion {
00229 my $site = shift @_;
00230 my $command = shift @_;
00231 my $author = shift @_;
00232 my $commandthumbnail = shift @_;
00233 my $version = shift @_;
00234 my $description = shift @_;
00235
00236 print '<grabber>'."\n";
00237 print ' <name>'.$site.'</name>'."\n";
00238 print ' <command>'.$command.'</command>'."\n";
00239 print ' <author>'.$author.'</author>'."\n";
00240 print ' <thumbnail>'.$commandthumbnail.'</thumbnail>'."\n";
00241 print ' <type>video</type>'."\n";
00242 print ' <description>'.$description.'</description>'."\n";
00243 print ' <version>'.$version.'</version>'."\n";
00244 print ' <search>true</search>'."\n";
00245 print ' <tree>true</tree>'."\n";
00246 print '</grabber>'."\n";
00247 }
00248
00249 # Download a icon from url
00250 sub downloadicon {
00251 my $url = shift @_;
00252 my $name = shift @_;
00253 my $icondir = shift @_;
00254
00255 # Only works for 0.23
00256 #my $icondir = mnvgeticonDir();
00257
00258 my $ss = stat("${icondir}/${name}");
00259 ($ss) and return "${icondir}/${name}";
00260
00261 my @imgexts = ('jpg', 'jpeg', 'png', 'gif');
00262 my $nameext = (fileparse($name, @imgexts))[2];
00263 my $urlext = (fileparse($url, @imgexts))[2];
00264
00265 mnvinfomsg(1, "Getting $url");
00266 my $content = get($url);
00267 unless ($content) {
00268 die "Could not retrieve $url";
00269 }
00270
00271 open(IC, ">${icondir}/.tmp") or return 0;
00272 print IC $content;
00273 close(IC);
00274
00275 if ($urlext eq $nameext) {
00276 copy("${icondir}/.tmp", "${icondir}/${name}");
00277 } else {
00278 my $image=Image::Magick->new;
00279 $image->Read(filename=>"${icondir}/.tmp");
00280 $image->Write(filename=>"${icondir}/${name}");
00281 }
00282 unlink("${icondir}/.tmp");
00283
00284 mnvinfomsg(1, "Saved icon ${icondir}/${name}");
00285 return "${icondir}/${name}";
00286 }
00287
00288 sub mnvcleanexit {
00289 my $esig = shift @_;
00290
00291 fileno(FH) and close(FH);
00292 if ($esig =~ /\D/) {
00293 # called by signalhandler
00294 exit 1;
00295 } else {
00296 exit $esig;
00297 }
00298 }
00299
00300 # Debug/Info message
00301 # $config{'mnvinfo'} specifies level of messages to print
00302 # $config{'mnvinfoop'} specifies o/p file
00303 sub mnvinfomsg {
00304 my $level = shift @_;
00305 my $mesg = shift @_;
00306
00307 ($config{'mnvinfo'} < $level) and return;
00308 $mesg = encode('utf8', $mesg);
00309 if ($config{'mnvinfoop'} =~ /\D/) {
00310 open(FH, ">$config{'mnvinfoop'}") unless fileno(FH);
00311 my $t = localtime();
00312 print FH "$t $level $mesg\n";
00313 } else {
00314 print STDERR "$mesg\n";
00315 }
00316 }
00317
00318 # Clean and encode a string
00319 sub mnvcleantext {
00320 my $text = shift @_;
00321
00322 ($text) or return;
00323 $text =~ s/\n/ /g;
00324 $text =~ s/^\s+|\s+$
00325 $text = encode_entities($text);
00326 return $text;
00327 }
00328
00329 # Number of items found
00330 sub mnvnumresults {
00331 my $diritemsref = shift @_;
00332
00333 my $nr = 0;
00334 foreach my $dir (keys(%$diritemsref)) {
00335 (@{$diritemsref->{$dir}}) or next;
00336 foreach my $item (@{$diritemsref->{$dir}}) {
00337 ($item) or next; # somewhere I get null references.
00338 $nr += 1;
00339 }
00340 }
00341 return $nr;
00342 }
00343
00344 # filter the items hash
00345 # input hash ref produced by builditems
00346 # output number of items
00347 sub mnvfilter {
00348 my $diritemsref = shift @_;
00349 my $search = shift @_;
00350
00351 my $filtereditems = 0;
00352
00353 foreach my $dir (keys(%$diritemsref)) {
00354 for (my $c = 0; $c <= $#{$diritemsref->{$dir}}; $c++) {
00355 if (${$diritemsref->{$dir}}[$c]->{'title'} =~ /$search/i || ${$diritemsref->{$dir}}[$c]->{'author'} =~ /$search/i ||
00356 ${$diritemsref->{$dir}}[$c]->{'description'} =~ /$search/i || ${$diritemsref->{$dir}}[$c]->{'link'} =~ /$search/i) {
00357 $filtereditems++;
00358 mnvinfomsg(2, "Saved $dir ".${$diritemsref->{$dir}}[$c]->{'title'});
00359 } else {
00360 mnvinfomsg(2, "Deleted $dir ".${$diritemsref->{$dir}}[$c]->{'title'});
00361 delete(${$diritemsref->{$dir}}[$c]);
00362 }
00363 }
00364 }
00365 return $filtereditems;
00366 }
00367
00368 # Print a item
00369 sub printitem {
00370 my $item = shift @_;
00371
00372 print " ".'<item>'."\n";
00373 print " ".'<title>'.$item->{'title'}.'</title>'."\n";
00374 print " ".'<mythtv:subtitle>'.$item->{'mythtv:subtitle'}.'</mythtv:subtitle>'."\n";
00375 print " ".'<author>'.$item->{'author'}.'</author>'."\n";
00376 print " ".'<pubDate>'.$item->{'pubDate'}.'</pubDate>'."\n";
00377 print " ".'<description>'.$item->{'description'}.'</description>'."\n";
00378 print " ".'<link>'.$item->{'link'}.'</link>'."\n";
00379 print " ".'<player>'.$item->{'player'}.'</player>'."\n";
00380 print " ".'<playerargs>'.$item->{'playerargs'}.'</playerargs>'."\n";
00381 print " ".'<download>'.$item->{'download'}.'</download>'."\n";
00382 print " ".'<downloadargs>'.$item->{'downloadargs'}.'</downloadargs>'."\n";
00383 print " ".'<media:group>'."\n";
00384 print " ".'<media:thumbnail url="'.$item->{'media:thumbnailurl'}.'"/>'."\n";
00385 print " ".'<media:content url="'.$item->{'media:contenturl'}.'" length="'.$item->{'media:contentlength'}.'" duration="'.$item->{'media:contentduration'}.'" width="'.$item->{'media:contentwidth'}.'" height="'.$item->{'media:contentheight'}.'" lang="'.$item->{'media:contentlanguage'}.'"/>'."\n";
00386 print " ".'</media:group>'."\n";
00387 print " ".'<rating>'.$item->{'rating'}.'</rating>'."\n";
00388 print " ".'<mythtv:country>'.$item->{'mythtv:country'}.'</mythtv:country>'."\n";
00389 print " ".'<mythtv:season>'.$item->{'mythtv:season'}.'</mythtv:season>'."\n";
00390 print " ".'<mythtv:episode>'.$item->{'mythtv:episode'}.'</mythtv:episode>'."\n";
00391 print " ".'<mythtv:customhtml>'.$item->{'mythtv:customhtml'}.'</mythtv:customhtml>'."\n";
00392 print " ".'</item>'."\n";
00393 return 1;
00394 }
00395
00396 # print tree
00397 # input hash ref produced by builditems
00398 sub mnvprinttree {
00399 my $diritemsref = shift @_;
00400 my $mostrecentnumber = shift @_;
00401
00402 my $icondir = mnvgeticonDir();
00403
00404 foreach my $dir (sort(keys(%$diritemsref))) {
00405 (@{$diritemsref->{$dir}}) or next;
00406 my $dirprinted = 0;
00407 if ($mostrecentnumber) {
00408 my $printcount = 0;
00409 foreach my $item (@{$diritemsref->{$dir}}) {
00410 ($item) or next; # somewhere I get null references.
00411 if ($dirprinted == 0) {
00412 $dirprinted = 1;
00413 # Need it here as don't have $item outside loop.
00414 print " ".'<directory name="'.mnvcleantext($dir).'" thumbnail="'.$item->{'dirthumbnail'}.'">'."\n";
00415 print " ".'<directory name="Most Recent" thumbnail="'.$icondir.'/directories/topics/most_recent.png">'."\n";
00416 }
00417 printitem($item);
00418 $printcount++;
00419 ($printcount >= $mostrecentnumber) and last;
00420 }
00421 print " ".'</directory>'."\n";
00422 }
00423 foreach my $item (@{$diritemsref->{$dir}}) {
00424 ($item) or next; # somewhere I get null references.
00425 if ($dirprinted == 0) {
00426 $dirprinted = 1;
00427 # Need it here as don't have $item outside loop.
00428 print " ".'<directory name="'.mnvcleantext($dir).'" thumbnail="'.$item->{'dirthumbnail'}.'">'."\n";
00429 }
00430 printitem($item);
00431 }
00432 print " ".'</directory>'."\n";
00433 }
00434 }
00435
00436 # print search
00437 # input hash ref produced by builditems
00438 sub mnvprintsearch {
00439 my $diritemsref = shift @_;
00440 my $page = shift @_;
00441
00442 my $numresults = mnvnumresults($diritemsref);
00443 if ($numresults < 1) {
00444 print " ".'<numresults>0</numresults>'."\n";
00445 print " ".'<returned>0</returned>'."\n";
00446 print " ".'<startindex>0</startindex>'."\n";
00447 return;
00448 }
00449 my $returned;
00450 if ($page > 1) {
00451 $returned = $numresults - (($page - 1) * 20);
00452 } else {
00453 $returned = $numresults;
00454 }
00455 ($returned > 20) and $returned = 20;
00456 ($returned < 0) and $returned = 0;
00457 my $startindex = ($page * 20) + 1;
00458 ($startindex >= $numresults) and $startindex = 0;
00459
00460 print " ".'<numresults>'.$numresults.'</numresults>'."\n";
00461 print " ".'<returned>'.$returned.'</returned>'."\n";
00462 print " ".'<startindex>'.$startindex.'</startindex>'."\n";
00463
00464 my $scount = 0; my $ecount = 0;
00465 L1: foreach my $dir (sort(keys(%$diritemsref))) {
00466 (@{$diritemsref->{$dir}}) or next;
00467 foreach my $item (@{$diritemsref->{$dir}}) {
00468 ($item) or next; # somewhere I get null references.
00469 if ($page > 1 && $scount < (($page - 1) * 20)) {
00470 $scount++;
00471 next;
00472 }
00473 $ecount++;
00474 printitem($item);
00475 ($ecount >= $returned) and last L1;
00476 }
00477 }
00478 }
00479
00480 # Parse a rss item.
00481 # input default icon
00482 # input rss->parse item
00483 # output ref to %mnvitem
00484 sub mnvrssitem2mnv {
00485 my $icon = shift @_;
00486 my $item = shift @_;
00487
00488 my %mnvitem = (
00489 'title' => "",
00490 'weburl' => "",
00491 'contenturl' => "",
00492 'author' => "",
00493 'pubDate' => "",
00494 'thumbnail' => "",
00495 'description' => "",
00496 'length' => "",
00497 'duration' => "",
00498 'rating' => "",
00499 'country' => ""
00500 );
00501
00502 #print Dumper($item);
00503
00504 ($item->{'title'}) or return 0;
00505 $mnvitem{'title'} = mnvcleantext($item->{'title'});
00506
00507 ($item->{'link'}) and $mnvitem{'weburl'} = mnvcleantext($item->{'link'});
00508 ($item->{'enclosure'}->{'url'}) and $mnvitem{'contenturl'} = mnvcleantext($item->{'enclosure'}->{'url'});
00509 (($mnvitem{'weburl'}) || ($mnvitem{'contenturl'})) or return 0;
00510 ($mnvitem{'contenturl'}) or $mnvitem{'contenturl'} = $mnvitem{'weburl'};
00511
00512 if ($item->{'itunes'}->{'author'}) {
00513 $mnvitem{'author'} = mnvcleantext($item->{'itunes'}->{'author'});
00514 } elsif ($item->{'dc'}->{'creator'}) {
00515 $mnvitem{'author'} = mnvcleantext($item->{'dc'}->{'creator'});
00516 } elsif ($item->{'author'}) {
00517 $mnvitem{'author'} = mnvcleantext($item->{'author'});
00518 }
00519
00520 ($item->{'pubDate'}) and $mnvitem{'pubDate'} = mnvcleantext($item->{'pubDate'});
00521
00522 $mnvitem{'thumbnail'} = $icon;
00523 if ($item->{'thumbnail'}) {
00524 $mnvitem{'thumbnail'} = mnvcleantext($item->{'thumbnail'});
00525 } elsif ($item->{'http://blip.tv/dtd/blip/1.0'}->{'smallThumbnail'}) {
00526 $mnvitem{'thumbnail'} = mnvcleantext($item->{'http://blip.tv/dtd/blip/1.0'}->{'smallThumbnail'});
00527 } elsif ($item->{'media'}->{'thumbnail'}) {
00528 # To get this need to hack xml before $rss->parse with following
00529 # $content =~ s/<media:thumbnail\s+url=\"([^\"]*)\"\s*\/>/<media:thumbnail>$1<\/media:thumbnail>/g;
00530 $mnvitem{'thumbnail'} = mnvcleantext($item->{'media'}->{'thumbnail'});
00531 } elsif ($item->{'description'}) {
00532 # Sometimes hide thumbernail in description.
00533 foreach my $line (split('\n', $item->{'description'})) {
00534 $line =~ s/.*src=\"(http:.*\.[jpg][pni][gf])\".*/$1/i and $mnvitem{'thumbnail'} = $line and last;
00535 }
00536 }
00537
00538 if ($item->{'media'}->{'description'}) {
00539 $mnvitem{'description'} = $item->{'media'}->{'description'};
00540 } elsif ($item->{'itunes'}->{'summary'}) {
00541 $mnvitem{'description'} = $item->{'itunes'}->{'summary'};
00542 } elsif ($item->{'description'}) {
00543 $mnvitem{'description'} = $item->{'description'};
00544 }
00545 if ($mnvitem{'description'}) {
00546 my $scrubber = HTML::Scrubber->new;
00547 $scrubber->default(0);
00548 $mnvitem{'description'} = $scrubber->scrub($mnvitem{'description'});
00549 $mnvitem{'description'} = mnvcleantext($mnvitem{'description'});
00550 ($mnvitem{'description'}) or $mnvitem{'description'} = "";
00551 $mnvitem{'description'} =~ s/\ / /g;
00552 }
00553
00554 ($item->{'enclosure'}->{'length'}) and $mnvitem{'length'} = mnvcleantext($item->{'enclosure'}->{'length'});
00555 if (($mnvitem{'length'}) && $mnvitem{'length'} < 5000) {
00556 $mnvitem{'duration'} = $mnvitem{'length'};
00557 $mnvitem{'length'} = "";
00558 }
00559 if ($item->{'itunes'}->{'duration'}) {
00560 my $tmpdur = mnvcleantext($item->{'itunes'}->{'duration'});
00561 my $count = $tmpdur =~ s/(:)/$1/g;
00562 if ($count == 1) {
00563 my ($mins, $secs) = split(':', $tmpdur);
00564 (($mins =~ /^\d+$/) && ($secs =~ /^\d+$/)) and $tmpdur = ($mins * 60) + $secs;
00565 } elsif ($count == 2) {
00566 my ($hours, $mins, $secs) = split(':', $tmpdur);
00567 (($hours =~ /^\d+$/) && ($mins =~ /^\d+$/) && ($secs =~ /^\d+$/)) and $tmpdur = ($hours * 60 * 60) + ($mins * 60) + $secs;
00568 }
00569 (($tmpdur =~ /^\d+$/) && $tmpdur > 0) and $mnvitem{'duration'} = $tmpdur;
00570 }
00571
00572 if ($item->{'media'}->{'restriction'}) {
00573 $mnvitem{'country'} = mnvcleantext($item->{'media'}->{'restriction'});
00574 }
00575
00576 return \%mnvitem;
00577 }
00578
00579 # return media type (Not very accurate).
00580 sub mnvistype {
00581 my $type = shift @_;
00582 my $file = shift @_;
00583
00584 $file =~ s/redirect\.mp3//g;
00585
00586 if ($type eq "flash") {
00587 $file =~ /\.flv/i and return 1;
00588 $file =~ /\.m[op4][34v]/i and return 1;
00589 } elsif ($type eq "html5") {
00590 $file =~ /\.m[op4][4v]/i and return 1;
00591 $file =~ /\.ogm/i and return 1;
00592 $file =~ /\.ogg/i and return 1;
00593 } elsif ($type eq "mp4html5") {
00594 $file =~ /\.m[op4][4v]/i and return 1;
00595 } elsif ($type eq "ogghtml5") {
00596 $file =~ /\.ogm/i and return 1;
00597 $file =~ /\.ogg/i and return 1;
00598 } elsif ($type eq "video") {
00599 $file =~ /\.flv/i and return 1;
00600 $file =~ /\.m[op4][4v]/i and return 1;
00601 $file =~ /\.mpg/i and return 1;
00602 $file =~ /\.mpeg/i and return 1;
00603 $file =~ /\.mkv/i and return 1;
00604 $file =~ /\.avi/i and return 1;
00605 $file =~ /\.wmv/i and return 1;
00606 $file =~ /\.as[xf]/i and return 1;
00607 $file =~ /\.divx/i and return 1;
00608 $file =~ /\.ogm/i and return 1;
00609 } elsif ($type eq "audio") {
00610 $file =~ /\.m4[ab]/i and return 1;
00611 $file =~ /\.mp[23]/i and return 1;
00612 $file =~ /\.og[ag]/i and return 1;
00613 $file =~ /\.aac/i and return 1;
00614 $file =~ /\.ram/i and return 1;
00615 $file =~ /\.rm/i and return 1;
00616 $file =~ /\.wav/i and return 1;
00617 $file =~ /\.flac/i and return 1;
00618 $file =~ /\.mka/i and return 1;
00619 $file =~ /\.au/i and return 1;
00620 }
00621 return 0;
00622 }
00623
00624 1;