#!/usr/bin/php -q
<?php
require(dirname(__FILE__)."/./app.php");

$drmApiServer = $app->drmApiServer ;
$tempDir = $app->drmTempDir;
//$app->drmKeyServerUrl = "http://172.30.1.4:8080/epgm3u8server/drm.php";
//$app->drmPvrKeyServerUrl = "http://172.30.1.4:8080/epgm3u8server/pvrdrm3.php";


$of  = $tempDir."/keys.json";
$sf  = $tempDir."/subs.txt";
$pvrf = $tempDir."/pvrservers.json";
$sdir = $tempDir."/subs";
if ( !is_dir($sdir) ) { mkdir($sdir);}
dnl($drmApiServer."/api/getkeys", $of);
dnl($drmApiServer."/api/getsubs", $sf);
dnl($drmApiServer."/api/getpvrservers", $pvrf);
print "processing files...\n";
//index the subs for speed!
$fh = fopen($sf, "r");
while(!feof($fh) ) { 
	$l = trim(fgets($fh));
	
	list ($subId) = explode("|", $l);
	
	$subId1 = sprintf("%03d", $subId/1000/1000);
	$subId2 = sprintf("%03d", $subId/1000);

	if ( !is_dir("$sdir/$subId1" )) { mkdir("$sdir/$subId1");}
	if ( !is_dir("$sdir/$subId1/$subId2" )) { mkdir("$sdir/$subId1/$subId2");}
	$sof = "$sdir/$subId1/$subId2/$subId.txt";
	//print "$sof\n";
	file_put_contents($sof,$l);
}







?>
