summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xvideoadd.pl41
1 files changed, 22 insertions, 19 deletions
diff --git a/videoadd.pl b/videoadd.pl
index 99926d6..8bd726a 100755
--- a/videoadd.pl
+++ b/videoadd.pl
@@ -34,8 +34,8 @@ my %config = do $confile;
die "Error in `" .$confile. "'.\n" if $@ || not %config;
map { exists $config{$_} || die "Error: Missing `${_}'.\n" }
- qw /videodir driver database hostname user port password videodata
- imdb url/;
+ qw /videodir driver database hostname user port password userid imdb url/;
+$config{prefix} = "" unless exists $config{prefix};
my $symlinks = catdir($config{videodir},'MOVIES'); # Symlinks folder
die "Error: No such directory: `" .$symlinks. "'.\n" unless -d $symlinks;
@@ -54,8 +54,8 @@ videoadd.pl - add movies to your collection
=head1 SYNOPSIS
-B<videoadd.pl> [B<-s>] [B<-i> I<crit>] [B<-o> I<key=value>...]
-[B<--ignore-db>] [B<--dont-sort>] [B<-q>] I<filename>
+B<videoadd.pl> [B<-s>] [B<--ignore-db>] [B<--dont-sort>] [B<-i> I<crit>]
+[B<-o> I<key=value>...] [B<-q>] I<filename>
=head1 DISCLAIMER
@@ -141,10 +141,10 @@ e.g.,
user => 'username',
port => 3306,
password => '******',
- videodata => "videodb_videodata",
+ prefix => "videodb_",
+ userid => 1
imdb => 'akas.imdb.com',
url => 'https://videodb.example.org',
- userid => 1
=head1 REQUIREMENTS
@@ -160,15 +160,15 @@ Copyright 2012 Guilhem Moulin. See the source for copying conditions.
################################################################################
my $ignoredb_flag;
+my $seen_flag;
my $sort_flag = 1;
my %options;
-GetOptions( #"s|seen" => sub { $options{seen} = 1 }
- "i|imdb=s"=> sub { $imdb{crit} = $_[1] }
-# , "u|update=s"=> update id/filename
+GetOptions( "s|seen" => \$seen_flag
+ , "ignore-db" => \$ignoredb_flag
+ , "dont-sort" => sub { undef $sort_flag }
+ , "i|imdb=s" => sub { $imdb{crit} = $_[1] }
, "o=s" => sub { my ($k,$v) = split /=/, $_[1], 2;
$options{lc $k} = $v; }
- , "dont-sort" => sub { undef $sort_flag }
- , "ignore-db" => \$ignoredb_flag
, "q|quiet=s" => sub { open LOG, '>', '/dev/null'
or die "Cannot open `/dev/null': $!" }
, "man" => sub { pod2usage(-exitstatus => 0, -verbose => 2) }
@@ -178,7 +178,7 @@ pod2usage(2) if $#ARGV != 0;
*LOG = *STDERR unless defined (fileno LOG);
my $file = $ARGV[0];
-my %new;
+my %new = (owner_id => $config{userid});
################################################################################
@@ -320,7 +320,7 @@ if ( defined($file) ) {
# Insertion into the database
unless ( defined $ignoredb_flag ) {
- my $INSERT = "INSERT INTO $config{videodata}
+ my $INSERT = "INSERT INTO $config{prefix}videodata
SET mediatype = 14,
created = NOW()";
if (defined $new{filedate}) {
@@ -329,21 +329,24 @@ unless ( defined $ignoredb_flag ) {
}
while (my ($k,$v) = each %new) {
- $INSERT .= ", " .$k. " = " .$dbh->quote ($v);
+ $INSERT .= ", " .$k. " = " .$dbh->quote ($v) if defined $v;
}
$dbh->do($INSERT) or die "Can't insert: $!\n";
-# print $INSERT, "\n";
- my $ids = $dbh->selectall_arrayref ( "SELECT id FROM $config{videodata}
+ my $ids = $dbh->selectall_arrayref ( "SELECT id FROM $config{prefix}videodata
WHERE filename = ? ",
undef, $new{filename} );
if ($#$ids == 0) {
- print LOG "Check it out! ",
- $config{url}, "/show.php?id=", $ids->[0]->[0], "\n"
+ 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";
+ print LOG "Check it out! ", $config{url}. "/show.php?id=" .$id, "\n"
or die "Can't print: $!";
}
else {
- warn "Warning: Something weird happened during the INSERT.\n";
+ warn "Warning: Something weird happened during the INSERT. You should probably check the sanity of your collection.\n";
}
$dbh->disconnect;