#! /usr/bin/perl -w # This program is free software. It comes without any warranty, to the # extent permitted by applicable law. You can redistribute it and/or # modify it under the terms of the Do What The Fuck You Want To Public # License, Version 2, as published by Sam Hocevar. # See http://sam.zoy.org/wtfpl/COPYING for more details. use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat bundling auto_version auto_help); use DBI; use strict; # Database my $driver = "mysql"; my $database = "videodb"; my $hostname = "127.0.0.1"; my $user = "videodb"; my $port = 3306; my $password = "videodb"; my $videodata = "videodb_videodata"; ################################################################################ # Connect to database my $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port"; my $dbh = DBI->connect($dsn, $user, $password) or die "Failed to connect; have you tried `mktunnel --sql' first?"; # Use utf8 $dbh->do( "set names utf8" ) or die; my ($from, $to) = @ARGV; my $RES = $dbh->selectall_hashref ( "SELECT id,title,director FROM $videodata WHERE filename = ?", 'id', undef, $from ) or die "Can't select: " . $dbh->errstr; my $nRES = scalar (keys %$RES); if ($nRES == 0) { print STDERR "No entry found in the database: nothing to update there.\n"; } elsif ($nRES > 1) { print STDERR "$nRES > 1 entries found in the database: dunno what to update there.\n"; } else { my ($id,$v) = each %$RES; print STDERR "Update filename for " . $v->{director} . " - " . $v->{title} . ":\n"; print STDERR "`" . $from . "' -> `" . $to, "'\n"; $dbh->do ( "UPDATE $videodata SET filename = ? WHERE id = ?", undef, $to, $id ) or die "Can't update: " . $dbh->errstr; } # Disconnect $dbh->disconnect();