summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xvideoadd.pl47
1 files changed, 42 insertions, 5 deletions
diff --git a/videoadd.pl b/videoadd.pl
index c8eb415..99add62 100755
--- a/videoadd.pl
+++ b/videoadd.pl
@@ -178,11 +178,6 @@ GetOptions( "s|seen" => \$seen_flag
pod2usage(2) if $#ARGV != 0;
*LOG = *STDERR unless defined (fileno LOG);
-my $file = $ARGV[0];
-my %new = ( owner_id => $config{userid}
- , customs => {});
-
-
################################################################################
# Connection to the database
@@ -200,6 +195,13 @@ unless ( defined $ignoredb_flag ) {
$dbh->do( "SET NAMES UTF8" ) or die "Error: Can't set names to UTF-8.\n";
}
+my $id;
+my $imdbid;
+my $file = &getfile ($ARGV[0]);
+my %new = ( owner_id => $config{userid}
+ , customs => {});
+exit 0;
+
################################################################################
# Look on-line for information on the movie
@@ -522,3 +524,38 @@ sub mkcast {
no warnings 'uninitialized';
return $_->{name}. '::' .$_->{role}. '::imdb:' .$_->{id};
}
+
+# Try to find a matching entry in the database.
+sub getfile {
+ my $crit = $_[0];
+ return $crit if defined $ignoredb_flag;
+
+ my $SELECT = "SELECT id, imdbid, filename FROM $config{prefix}videodata
+ WHERE ";
+ if ($crit =~ /^[0-9]+$/) {
+ $SELECT .= "id = $crit OR imdbid = 'imdb:$crit'";
+ }
+ elsif ($crit =~ /.(avi|ogm|ogg|bin|mpe?g|ra?m|mov|asf|wmv|mkv)$/i) {
+ $SELECT .= "filename = " .$dbh->quote (basename ($crit));
+ }
+ else {
+ $SELECT .= "title LIKE " .$dbh->quote ('%'.$crit.'%');
+ }
+
+ my $res = $dbh->selectall_arrayref( $SELECT ) or die "Can't select: $!\n";
+
+ die "Error: Multiple entries found in the database. Try to refine your search.\n"
+ if $#$res > 0;
+
+ if ($#$res == 0) {
+ $id = $res->[0]->[0];
+ $imdbid = $res->[0]->[1];
+ print STDERR "Updating ID $id...\n";
+ return catfile($config{videodir}, 'MOVIES', $res->[0]->[2]);
+ }
+
+ # We have a new file to add to the database
+ die "Error: No such file `" .$crit. "' (and I can't find a matching entry in the database).\n"
+ unless -f $crit;
+ return $crit;
+}