"The Daily Show", "pattern" => "^The\.Daily\.Show.*", "insert" => true, "episode" => "\d{4}\.\d{2}\.(\d{2})", "season" => "(\d{4})\.(\d{2})\.\d{2}", "title" => "\d{4}\.\d{2}\.\d{2}\.(.*)\.[PH]DTV.*", "autodelete" => true ), array( "name" => "True Blood", "pattern" => "^True\.Blood\..*" ), array( "name" => "Dollhouse", "pattern" => "^Dollhouse\..*" ), array( "name" => "Heroes", "pattern" => "^Heroes\..*" ), array( "name" => "House", "pattern" => "^House\..*" ), array( "name" => "30 Rock", "pattern" => "^30\.Rock.*" ), array( "name" => "American Dad" ), array( "name" => "Mythbusters" ), array( "name" => "Family Guy" ), array( "name" => "Californication" ), array( "name" => "Dexter" ) ); $debug = true; require("boxee_db.php"); $db = new BoxeeDb($boxee_db); $db->debug = $debug; // List files in start dir $aFiles = array(); $dir = opendir( $start_dir ); while( $file = readdir( $dir ) ){ $aFiles[] = $file; } // Move files into dir foreach( $aShows as $show ){ if( $debug ) echo $show["name"]."\n"; if( !isset( $show["pattern"] ) ){ $show["pattern"] = str_replace( " ", "\.", $show["name"] ); if( $debug ) echo " Pattern: ".$show["pattern"]."\n"; } foreach( $aFiles as $file ){ if( preg_match( "/".$show["pattern"]."/", $file ) ){ if( !file_exists( $tv_dir.$show["name"] ) ){ mkdir( $tv_dir.$show["name"] ); } if( $debug ) echo " Moving ".$start_dir.$file." to ".$tv_dir.$show["name"]."\n"; rename( $start_dir.$file, $tv_dir.$show["name"]."/".$file ); // Force insert into Boxee if( $show["insert"] ){ // Get episode $episode = ""; if( preg_match( "/".$show["episode"]."/", $file, $m ) ){ for($i=1; $iinsertEpisode( $tv_dir.$show["name"]."/".$file, $show["name"], $season, $episode, $title ); } } } if( $show["autodelete"] ){ // Get list of watched shows $aPaths = $db->getWatchedEpisodePaths( $show["name"] ); foreach( $aPaths as $path ){ if( file_exists( $path ) ){ echo " deleting ".$path."\n"; unlink( $path ); } $db->removeEpisode( $path ); } } } ?>