summaryrefslogtreecommitdiffstats
path: root/videoadd.pl
diff options
context:
space:
mode:
Diffstat (limited to 'videoadd.pl')
-rwxr-xr-xvideoadd.pl30
1 files changed, 26 insertions, 4 deletions
diff --git a/videoadd.pl b/videoadd.pl
index add8f2a..b1ebb0f 100755
--- a/videoadd.pl
+++ b/videoadd.pl
@@ -48,8 +48,8 @@ $config{url} =~ s/\/*$//;
my $ignoredb_flag;
my $sort_flag = 1;
my %options;
-GetOptions( "seen" => sub { $options{seen} = 1 }
- , "s|search=s"=> sub { $imdb{crit} = $_[1] }
+GetOptions( #"seen" => sub { $options{seen} = 1 }
+ "s|search=s"=> sub { $imdb{crit} = $_[1] }
# , "u|update=s"=> update id/filename
, "o=s" => sub { my ($k,$v) = split /=/, $_[1], 2;
$options{lc $k} = $v; }
@@ -74,6 +74,11 @@ my $dbh;
unless ( defined $ignoredb_flag ) {
# Connect to database
my $dsn = "DBI:$config{driver}:database=$config{database};host=$config{hostname};port=$config{port}";
+ if (exists $config{dbi_misc}) {
+ while (my ($k,$v) = each $config{dbi_misc}) {
+ $dsn .= ";$k=$v";
+ }
+ }
$dbh = DBI->connect($dsn, $config{user}, $config{password})
or die "Error: Can't connect do database.\n";
$dbh->do( "SET NAMES UTF8" ) or die "Error: Can't set names to UTF-8.\n";
@@ -207,7 +212,8 @@ if ( defined($file) ) {
unless ( defined $ignoredb_flag ) {
my $INSERT = "INSERT INTO $config{videodata}
- SET mediatype = 14";
+ SET mediatype = 14,
+ created = NOW()";
if (defined $new{filedate}) {
$INSERT .= ", filedate = FROM_UNIXTIME($new{filedate})";
delete $new{filedate};
@@ -241,7 +247,23 @@ unless ( defined $ignoredb_flag ) {
if ( defined ($file) and defined ($sort_flag) ) {
if (defined $new{director}) {
- move ( $file, catfile ( $directors, $new{director}, $new{filename} ) )
+ my $dir = catdir ( $directors, $new{director} );
+ unless (-d $dir) {
+ print STDERR "Directory `$dir' does not exist. ";
+ until (-d $dir) {
+ print STDERR "Should I create it? (Y/n) ";
+ my $a = lc <STDIN>;
+ chomp $a;
+ if ($a eq 'y' or $a eq '') {
+ mkdir $dir
+ or die "Error: Cannot mkdir `$dir': $!\n";
+ }
+ elsif ($a eq 'n') {
+ exit 0;
+ }
+ }
+ }
+ move ( $file, catfile ( $dir, $new{filename} ) )
or warn "Warning: Cannot move file: $!.\n";
symlink catfile( updir(), 'DIRECTORS', $new{director}, $new{filename} ),