Hello,
Sorry for the delay. Here's the script:
For this script you need an Apache web server on your system with Php installed. for help look at:
http://www.apache.org/ and
http://www.php.net/
Find the root folder for your apache server and create a new folder in it. Name it 'XBMC' or whatever. In this folder you need 3 files: index.php, synchronizePlaycount.psp and xbmc_movie_list.php
.php files are simple text files. the contents are listed below.
If you need help with php, look at:
http://www.w3schools.com/php/default.asp
(it's easy! you can learn it in 1 weekend)
Now open your php-site in a browser:
http://localhost/<folder name you just created>
Contents of index.php:
<!DOCTYPE HTML>
<html>
<head>
<title>XBMC Video Database</title>
</head>
<body>
<h1>XBMC Video Database</h1>
<hr>
<form action="xbmc_movie_list.php" method="post">
Path to XMBC video database:<input type="text" name="file" id="file" size="60" value=<?php echo "'".$_COOKIE["pad"]."'";?> /><br>
<br><input type="submit" value="Open Database"/>
</form><br><br>
<hr>
<p>This script iterates through the 'paths' in the xbmc-database. It looks for an [xmlFileName] in the folder (path). If this file is found, it looks for a [tagName]valueWatched[/tagName] in the file, and updates the XBMC database.
It then sets the 'playCount' field in the 'FILES' table to "1", and the 'lastPlayed' field to 'today'.</p>
<p>Make sure to set the permissions of the database file and the database-folder to read/write !!!</p>
</body>
</html>
Contents of synchronizePlaycount.psp
<!DOCTYPE HTML>
<html>
<body>
<?php
//iterate through paths
$db = new PDO('sqlite:'.$_COOKIE['pad']);
$sqlString='SELECT "idPath", "strPath"
FROM PATH
ORDER BY "strPath" ASC';
$counter=1;
$db2 = new PDO('sqlite:'.$_COOKIE['pad']);
echo 'Open Database: sqlite:'.$_COOKIE['pad']."<br>";
try {
chown($_COOKIE['pad'], "Jos");
} catch (Exception $e) {
}
echo "Begin transaction...<br>";
$db2->beginTransaction();
foreach ($db->query($sqlString) as $row){
//find xml file and update movie in database
$xmlDoc = new DOMDocument();
if ($xmlDoc->load($row['strPath']."/".$_POST['xmlFileName'])){
$x=$xmlDoc->documentElement;
foreach ($x->childNodes as $item){
if ($item->nodeName == $_POST['tagName']){
if ($item->nodeValue == $_POST['valueWatched']){
$q="UPDATE FILES SET playCount = 1, lastPlayed=date() WHERE idPath=".$row['idPath'];
}
else{
$q="UPDATE FILES SET playCount = NULL, lastPlayed=NULL WHERE idPath=".$row['idPath'];
}
echo $row['strPath']." > ".$q."<br>";
try {
$r= $db2->exec($q);
} catch (Exception $e) {
echo "fout: ";
echo $e;
}
}
}
}
$counter+=1;
}
$db2->commit();
$db=NULL;
$db=NULL;
echo '<br><br>'.$counter." movies in database synchronized with xml-files!";
echo "<br><br>";
?>
</body>
</html>
Contents of xbmc_movie_list.php
<!DOCTYPE HTML>
<?php setcookie("pad", $_POST["file"], time()+60*60*24*60);?>
<html>
<head>
<title>XBMC movie list</title>
</head>
<body>
<?php
echo "<table width='100%'><tr><td valign='top'><h1>XBMC Movie List</h1>";
echo "<i>".$_POST["file"]."</i>
</td><td align='right'>
<form action='synchronizePlaycount.php' method='post'>
Xml file name:<input type='text' name='xmlFileName' value='mymovies.xml'/><br>
Tagname:<input type='text' name='tagName' value='Watched'/><br>
Tag value watched:<input type='text' name='valueWatched' value='True'/><br>
<input type='submit' value='Write watched status to XMBC Database' />
</form></td></tr></table>
<hr>";
$db = new PDO('sqlite:'.$_COOKIE['pad']);
$sqlString='SELECT MOVIE."c00", PATH."strPath", FILES."playCount", FILES."strFilename"
FROM
MOVIE JOIN FILES ON MOVIE."idFile" = FILES."idFile" JOIN PATH ON FILES."idPath" = PATH."idPath"
ORDER BY MOVIE."c00"
';
echo "<table><tr>
<th width='350px' align='left'>Title</th>
<th align='left'>playCount</th>
<th align='left'>Path/File</th>
</tr>";
foreach ($db->query($sqlString) as $row){
echo "<tr><td>".$row['c00']."</td><td>".$row['playCount']."</td><td>".$row['strPath'].$row['strFilename']."</td></tr>";
}
echo "</table>";
$db=NULL;
?>
</body>
</html>