From 1c398d5ea9dd6527f4e466a4bbb09c9a532b6f29 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 18 Feb 2012 17:16:42 +0100 Subject: remove useless queries to mplayer/imdb --- videoadd.pl | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/videoadd.pl b/videoadd.pl index 1914ddd..cc05d06 100755 --- a/videoadd.pl +++ b/videoadd.pl @@ -136,7 +136,7 @@ I, I, I, I, I, I. Update only the given fields of the database. Known fields are I, I<subtitle>, I<language>, I<imdbid>, I<year>, I<imgurl>, -I<director>, I<actors>, I<country>, I<plot>, I<genres>, I<rating>, +I<director>, I<actors>, I<country>, I<plot>, I<genres>, I<rating>, I<istv>, I<filename>, I<filesize>, I<filedate>, I<video_codec>, I<audio_codec>, I<video_width>, I<video_height>, I<runtime>, I<custom1>, I<custom2>, I<custom3>, I<custom4>. @@ -149,7 +149,8 @@ Two meta-fields are also available: I<imdb>, which stands for I<title>, I<subtitle>, I<language>, I<imdbid>, I<year>, I<imgurl>, -I<director>, I<actors>, I<country>, I<plot>, I<genres>, I<rating>, and +I<director>, I<actors>, I<country>, I<plot>, I<genres>, I<rating>, +I<istv>, and =item * @@ -251,8 +252,7 @@ my %new = ( owner_id => $config{userid} ################################################################################ # Look on-line for information on the movie -# TODO: don't look on-line if it's a db update with eg, only=video_codec -if (defined $imdb{crit}) { +if ( defined ($imdb{crit}) and &runIMDB() ) { # Look up the title/ID on IMDB my $single; @@ -329,13 +329,11 @@ foreach my $k (keys %options) { ################################################################################ # Run mplayer on the given file to get A/V codecs, etc. -# TODO: don't run mplayer if it's a db update with eg, only=title -if ( defined($file) ) { +if ( defined($file) and &runMplayer() ) { $new{filename} = basename ($file); $new{filesize} = (stat $file)[7]; $new{filedate} = (stat $file)[9]; # Last modify time in seconds since epoch - my @cmd = ('mplayer', '-identify', '-ao', 'null', '-vo', 'null', '-frames', '0', $file); @@ -402,7 +400,7 @@ unless ( defined $ignoredb_flag ) { # Get the genre IDs my @genres; - if (@{$new{genres}}) { + if (&include('genres') and @{$new{genres}}) { my $sth_selgenre = $dbh->prepare( "SELECT id FROM $config{prefix}genres WHERE name = ?" ) or die "Error: " .$dbh->errstr; my $sth_insgenre = $dbh->prepare( "INSERT INTO $config{prefix}genres SET name = ?" ) @@ -638,6 +636,7 @@ sub getfile { unless defined $imdbid; $imdb{crit} = $imdbid; } + undef $sort_flag; return catfile($config{videodir}, 'MOVIES', $res->[0]->[2]); } @@ -653,7 +652,7 @@ sub keywords { foreach my $k (@_) { if (lc $k eq 'imdb') { push @ret, qw/title subtitle language imdbid year imgurl - director actors country plot genres rating/; + director actors country plot genres rating istv/; } elsif (lc $k eq 'file') { push @ret, qw/filename filesize filedate @@ -661,10 +660,10 @@ sub keywords { runtime language/; } else { - die "Error: Unknown key `" .$k. "'.\n" + die "Error: Unknown field `" .$k. "'.\n" unless grep { $_ eq $k } qw/title subtitle language imdbid year imgurl - director actors country plot genres rating + director actors country plot genres rating istv filename filesize filedate video_codec audio_codec video_width video_height runtime custom1 custom2 custom3 custom4/; @@ -681,3 +680,26 @@ sub include { return 0 if @only and not (grep {$_ eq $k} @only); return 1; } + +sub runIMDB { + # Returns 1 if there is need to retrieve some data online, 0 otherwise + + foreach (qw/title subtitle language imdbid year imgurl + director actors country plot genres rating istv + custom1 custom2 custom3 custom4/) { + return 1 if &include($_); + } + return 0; +} + +sub runMplayer { + # Returns 1 if there is need to run mplayer, 0 otherwise + + foreach ( qw/filename filesize filedate + video_codec audio_codec video_width video_height + runtime language + custom1 custom2 custom3 custom4/) { + return 1 if &include($_); + } + return 0; +} -- cgit v1.2.3