#!/usr/bin/perl -w

#
# dumprecorded.pl
#
# $Id$
#
# Copyright (C) 2005, Mike Frisch <mfrisch@isurfer.ca>
#
# !!! USE AT YOUR OWN RISK !!!
#
# usage: ./dumprecorded.pl
#
# displays list of recorded shows in MythTV database
#
# TODO:
#
#   * extract database settings from system
#   * dump shows in some sort order
#   * XML output?
#

use DBI;
use Date::Manip;

## !!! CONFIGURE FOR YOUR SYSTEM HERE !!!

## User to connect to MythTV 'mythconverg' database as
##   ** change this for your system **
$user = "mythtv";

## Password
##   ** change this for your system **
$pass = "mythtv";

## Host name of MySQL server
##   ** change this for your system **
$server = "server";

## Name of MythTV database, this should work for everybody
$db = "mythconverg";

## Path where MythTV recordings are stored
$path = "/mnt/storage/mythtv";

## --- no user configuration below this line ---

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$server", $user, $pass) or
	die "Couldn't connect to database: " . DBI->errstr;

my $sth = $dbh->prepare("SELECT title,description,starttime,endtime,chanid FROM recorded");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
	$disp_date = UnixDate("$ref->{'starttime'}", "%c");
	print "$ref->{'title'} ($disp_date)\n";

	if ($ref->{'description'}) {
		print "$ref->{'description'}\n";
	}

	$start_date = UnixDate("$ref->{'starttime'}", "%Y%m%d%H%M%S");
	$end_date = UnixDate("$ref->{'endtime'}", "%Y%m%d%H%M%S");

	my $filename = "$ref->{'chanid'}" . "_" . $start_date . "_" .
		$end_date . ".nuv";

	print "$path/$filename\n";
	print "\n";
}

$sth->finish();

$dbh->disconnect();
