From 92a1750b60381d03f1c1909f236055cfe7fdb0b1 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 18 Feb 2012 00:09:25 +0100 Subject: handle custom fields --- videoadd.pl | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/videoadd.pl b/videoadd.pl index 8bd726a..5aa0f03 100755 --- a/videoadd.pl +++ b/videoadd.pl @@ -178,7 +178,8 @@ pod2usage(2) if $#ARGV != 0; *LOG = *STDERR unless defined (fileno LOG); my $file = $ARGV[0]; -my %new = (owner_id => $config{userid}); +my %new = ( owner_id => $config{userid} + , customs => {}); ################################################################################ @@ -244,9 +245,9 @@ if (defined $imdb{crit}) { $new{imgurl} = $movie->cover(); $new{director} = join ', ', map {$_->{name}} @{$movie->directors()}; $new{actors} = join "\n", map {$_->{name}. '::' .$_->{role}. '::imdb:' .$_->{id}} - @{$movie->cast()}; + @{$movie->full_cast()}; $new{country} = join ', ', @{$movie->country()}; - $new{plot} = $movie->storyline(); + $new{plot} = $movie->full_plot(); $new{rating} = $movie->rating(); # Ignoring #votes and awards $new{istv} = 1 if $movie->kind() =~ /tv/; @@ -312,7 +313,8 @@ if ( defined($file) ) { }; $new{language} = lc join (', ', @alang) unless $#alang < 0 and defined $imdb{crit}; - $new{custom1} = lc join (', ', @slang); + # The "Subtitles" field is not hard-coded: insert it in the "custom" field instead + $new{customs}->{subtitles} = lc join (', ', @slang); } @@ -320,6 +322,17 @@ if ( defined($file) ) { # Insertion into the database unless ( defined $ignoredb_flag ) { + # Handle custom fields + my $customs = $dbh->selectall_arrayref ( "SELECT opt,value FROM $config{prefix}config + WHERE opt REGEXP '^custom[1-9]+\$'" ) + or die "Can't select: $!\n"; + foreach my $c (@$customs) { + if (grep {lc $_ eq lc $c->[1]} (keys %{$new{customs}})) { + $new{$c->[0]} = $new{customs}->{lc $c->[1]}; + } + } + delete $new{customs}; + my $INSERT = "INSERT INTO $config{prefix}videodata SET mediatype = 14, created = NOW()"; @@ -335,7 +348,8 @@ unless ( defined $ignoredb_flag ) { my $ids = $dbh->selectall_arrayref ( "SELECT id FROM $config{prefix}videodata WHERE filename = ? ", - undef, $new{filename} ); + undef, $new{filename} ) + or die "Can't select: $!\n"; if ($#$ids == 0) { my $id = $ids->[0]->[0]; $dbh->do( "INSERT INTO $config{prefix}userseen -- cgit v1.2.3