Skip to content

Instantly share code, notes, and snippets.

@jjok
Created November 16, 2011 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjok/1368960 to your computer and use it in GitHub Desktop.
Save jjok/1368960 to your computer and use it in GitHub Desktop.
Find duplicate recorded programmes on NPVR.
<?php
#header('Content-type: text/plain');
if(isset($_SERVER['argv'][1])) {
$db_file = $_SERVER['argv'][1];
}
else {
$db_file = '\\\\Npvr-server\\npvr\\npvr.db3';
}
try {
if(is_readable($db_file)) {
$db = new PDO("sqlite:$db_file");
$query = "SELECT event_details
FROM SCHEDULED_RECORDING
WHERE status = 2";
$statement = $db->query($query);
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$total_count = count($results);
if($total_count > 0) {
$unique = array();
$duplicates = array();
foreach($results as $result) {
$xml = new DOMDocument('1.0', 'UTF-8');
#echo $result['event_details'];exit();
$xml->loadXML($result['event_details']);
$title = $xml->getElementsByTagName('Title')->item(0)->nodeValue;
$description = $xml->getElementsByTagName('Description')->item(0)->nodeValue;
$parts = explode(':', $description);
if(strlen($parts[0]) < 70) {
$join = $title.' :: '.$parts[0];
if(!in_array($join, $unique)) {
$unique[] = $join;
}
else {
$duplicates[] = array(
'title' => $join,
'date' => substr($xml->getElementsByTagName('StartTime')->item(0)->nodeValue, 0, 10)
);
}
}
}
sort($duplicates);
$duplicate_count = count($duplicates);
echo "\n$total_count progammes found.\n";
echo "$duplicate_count duplicates.\n\n";
if($duplicate_count > 0) {
echo "Duplicates\n-----------------------------------------------------\n";
foreach($duplicates as $row) {
$title = $row['title'];
$date = $row['date'];
echo "$date - $title\n";
}
#sort($unique);
#print_r($unique);
}
}
else {
throw new Exception('No recorded programmes found.');
}
}
else {
throw new Exception("Database $db_file not found.");
}
}
catch(Exception $e) {
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment