summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xvideoadd.pl51
1 files changed, 46 insertions, 5 deletions
diff --git a/videoadd.pl b/videoadd.pl
index 94debac..eafb85c 100755
--- a/videoadd.pl
+++ b/videoadd.pl
@@ -248,8 +248,8 @@ if (defined $imdb{crit}) {
@{$movie->full_cast()};
$new{country} = join ', ', @{$movie->country()};
$new{plot} = $movie->full_plot();
+ $new{genres} = $movie->genres();
$new{rating} = $movie->rating(); # Ignoring #votes and awards
-
$new{istv} = 1 if $movie->kind() =~ /tv/;
}
elsif (defined $file) {
@@ -338,6 +338,32 @@ unless ( defined $ignoredb_flag ) {
WHERE name = ?", undef, 'HDD' )
or die "Can't select: $!\n";
+ # Get the genre IDs
+ my @genres;
+ if (@{$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 = ?" )
+ or die "Error: " .$dbh->errstr;
+ foreach my $g (@{$new{genres}}) {
+ $sth_selgenre->execute ($g);
+ my @gids = $sth_selgenre->fetchrow_array;
+ die $sth_selgenre->errstr if $sth_selgenre->err;
+ unless (@gids) {
+ # Insert non existing genres
+ $sth_insgenre->execute ($g);
+ die $sth_insgenre->errstr if $sth_insgenre->err;
+ $sth_selgenre->execute ($g);
+ @gids = $sth_selgenre->fetchrow_array;
+ die $sth_selgenre->errstr if $sth_selgenre->err;
+ }
+ push @genres, @gids;
+ }
+ $sth_selgenre->finish;
+ $sth_insgenre->finish;
+ }
+ delete $new{genres};
+
my $INSERT = "INSERT INTO $config{prefix}videodata
SET created = NOW()";
if (defined $new{filedate}) {
@@ -356,12 +382,27 @@ unless ( defined $ignoredb_flag ) {
WHERE filename = ? ",
undef, $new{filename} )
or die "Can't select: $!\n";
+
+ # Retrive the freshly added ID, and update the userseen & videogenre
+ # tables
if ($#$ids == 0) {
my $id = $ids->[0]->[0];
- $dbh->do( "INSERT INTO $config{prefix}userseen
- SET video_id = $id,
- user_id = $config{userid}" )
- or die "Can't insert: $!\n";
+ if ($seen_flag) {
+ $dbh->do( "INSERT INTO $config{prefix}userseen
+ SET video_id = $id,
+ user_id = $config{userid}" )
+ or die "Can't insert: $!\n";
+ }
+ my $sth_insgenre = $dbh->prepare( "INSERT INTO $config{prefix}videogenre
+ SET video_id = $id,
+ genre_id = ?" )
+ or die "Error: " .$dbh->errstr;
+ foreach (@genres) {
+ $sth_insgenre->execute ($_);
+ die $sth_insgenre->errstr if $sth_insgenre->err;
+ }
+ $sth_insgenre->finish;
+
print LOG "Check it out! ", $config{url}. "/show.php?id=" .$id, "\n"
or die "Can't print: $!";
}