#!/usr/bin/perl -w # Return archived recordings to MythTV. my $password = "oxxzqsve"; my $mythdir = "/var/lib/mythtv"; my $archivedir = "/stuff/tv/recorded"; use strict; use DBI; use POSIX; my $dbh = DBI->connect("DBI:mysql:database=mythconverg", "mythtv", $password); sub mangle_time ($) { $_[0] =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ or die "Bad time $_[0]\n"; return "$1-$2-$3 $4:$5:$6"; } foreach my $arg (@ARGV) { print "Putting back $arg\n"; my @st = stat($arg) or die "Cannot stat $arg: $!\n"; my $size = $st[7]; my $mtime = POSIX::strftime("%Y%m%d%H%M%S", gmtime($st[9])); $arg =~ /^(?:.*\/)?(\d+)_(\d+)_(\d+)/ or die "Bad name $arg\n"; my ($chanid, $start, $end) = ($1, $2, $3); my $destname = "$mythdir/$chanid" . "_$start" . "_$end.nuv"; if (-f $destname) { print " $destname already exists; skipping\n"; next; } system("cp", "-v", $arg, $destname) == 0 or die "Copy failed"; my $sth = $dbh->prepare("select * from oldrecorded where chanid=? and starttime=?"); $sth->execute($chanid, mangle_time($start)); my $old = $sth->fetchrow_hashref(); unless ($old) { die "Cannot find matching program for $arg\n"; } print " Found match: $old->{title}: $old->{subtitle}\n"; my $airdate = mangle_time($start); $airdate =~ s/ .*//; my $query = "insert into recorded ( chanid, starttime, endtime, title, subtitle, description, category, hostname, bookmark, editing, cutlist, autoexpire, commflagged, recgroup, recordid, seriesid, programid, lastmodified, filesize, stars, previouslyshown, originalairdate, preserve, findid, deletepending ) values ( '$chanid', '" . mangle_time($start) . "', '" . mangle_time($end) . "', " . $dbh->quote($old->{title}) . ", " . $dbh->quote($old->{subtitle}) . ", " . $dbh->quote($old->{description}) . ", " . $dbh->quote($old->{category}) . ", 'pye', NULL, 0, NULL, 1, 0, 'Default', $old->{recordid}, $old->{seriesid}, " . $dbh->quote($old->{programid}) . ", " . $dbh->quote($mtime) . ", $size, 0, 0, " . $dbh->quote($airdate) . ", 0, $old->{findid}, 0 )"; $sth = $dbh->prepare($query); $sth->execute(); print " Added\n"; }