mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 02:01:33 +00:00
fixed mulptiple path problems
rearranged the panels
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
`mysqldump --opt -u root -p newznab > ~/newznab_backup.sql`
|
||||
|
||||
|
||||
|
||||
* The first step is to decide whether or not you will convert your database to the InnoDB engine. The InnoDB has a lot of benefits, too many to list here, but more ram is required. How much exactly, depends on too many things to list here.
|
||||
|
||||
* If you decide to convert your database, I recommend using [kevin123's github](https://github.com/kevinlekiller/Newznab-Barracuda.git). I recommend only converting the binaries a parts table, using compressed tables. But, there are many choices. I suggest you read his README and follow his recommendations. Or, simply:
|
||||
@@ -21,7 +20,6 @@
|
||||
`php convertToInnoDB.php`
|
||||
|
||||
|
||||
|
||||
* If, you have already converted your database, and didn't to the steps above. You will need to clone [kevin123's github](https://github.com/kevinlekiller/Newznab-InnoDB-Dropin.git) and get the scripts.
|
||||
|
||||
`cd /var/www/newznab/misc/testing/`
|
||||
@@ -29,7 +27,6 @@
|
||||
`git clone https://github.com/kevinlekiller/Newznab-InnoDB-Dropin.git innodb`
|
||||
|
||||
|
||||
|
||||
* Clone my github
|
||||
|
||||
`cd /var/www/newznab/misc/update_scripts/nix_scripts/`
|
||||
@@ -41,19 +38,16 @@
|
||||
`nano edit_these.sh`
|
||||
|
||||
|
||||
|
||||
* Edit some permissions, run as root.
|
||||
|
||||
`./set_perms.sh`
|
||||
|
||||
|
||||
|
||||
* Run my script, as user.
|
||||
|
||||
`./start.sh`
|
||||
|
||||
|
||||
|
||||
* If you connect using **putty**, then under Window/Translation set Remote character set to UTF-8.
|
||||
|
||||
* If something looks stalled, it probably isn't. If all 13 panes are still there, it is most likely, as it should be.
|
||||
@@ -68,8 +62,7 @@
|
||||
|
||||
* Thanks go to all who offered their assistance and improvement to these scripts.
|
||||
|
||||
|
||||
<hr>
|
||||
* If, you find these scripts useful, please consider a donation. They are greatly appreciated. Thank you
|
||||
* If, you find these scripts useful and would like to offer a donation, they are greatly appreciated. Thank you
|
||||
|
||||
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=N4AJV5FHZDBFE"><img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="PayPal - The safer, easier way to pay online!" /></a><a href='http://www.pledgie.com/campaigns/18980'><img alt='Click here to lend your support to: Newznab-tmux and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/18980.png?skin_name=chrome' border='0' /></a>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require("lib/innodb/config.php");
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/backfill.php");
|
||||
|
||||
if (isset($argv[1]))
|
||||
|
||||
Regular → Executable
+5
-3
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
require("config.php");
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/groups.php");
|
||||
require_once("lib/innodb/binaries.php");
|
||||
require_once(dirname(__FILE__)."/../../../www/lib/powerspawn.php");
|
||||
require_once("lib/binaries.php");
|
||||
require_once(WWW_DIR."lib/powerspawn.php");
|
||||
|
||||
$groups = new Groups;
|
||||
$groupList = $groups->getActive();
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/../../../www/config.php");
|
||||
?>
|
||||
Regular → Executable
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/innodb/config.php");
|
||||
require_once(dirname(__FILE__)."/framework/db.php");
|
||||
require_once(dirname(__FILE__)."/groups.php");
|
||||
require_once(dirname(__FILE__)."/site.php");
|
||||
require_once(dirname(__FILE__)."/nntp.php");
|
||||
require_once(dirname(__FILE__)."/innodb/binaries.php");
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("framework/db.php");
|
||||
require_once("groups.php");
|
||||
require_once("site.php");
|
||||
require_once("nntp.php");
|
||||
require_once("binaries.php");
|
||||
|
||||
/**
|
||||
* Retrieves messages from usenet based on provided backfill-to date.
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
require_once(dirname(__FILE__)."/../framework/db.php");
|
||||
require_once(dirname(__FILE__)."/../nntp.php");
|
||||
require_once(dirname(__FILE__)."/../groups.php");
|
||||
require_once(dirname(__FILE__)."/../site.php");
|
||||
require_once(dirname(__FILE__)."/../backfill.php");
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("framework/db.php");
|
||||
require_once("nntp.php");
|
||||
require_once("groups.php");
|
||||
require_once("site.php");
|
||||
require_once("backfill.php");
|
||||
|
||||
/**
|
||||
* This class manages the downloading of binaries and parts from usenet, and the
|
||||
@@ -1,300 +0,0 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
require_once(dirname(__FILE__)."/../framework/db.php");
|
||||
require_once(dirname(__FILE__)."/../groups.php");
|
||||
require_once(dirname(__FILE__)."/../site.php");
|
||||
require_once(dirname(__FILE__)."/../nntp.php");
|
||||
require_once("binaries.php");
|
||||
|
||||
/**
|
||||
* Retrieves messages from usenet based on provided backfill-to date.
|
||||
*/
|
||||
class Backfill
|
||||
{
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
function Backfill($db = null)
|
||||
{
|
||||
if($db == null)
|
||||
{
|
||||
$this->db = new DB();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
$this->n = "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all active groups categories and descriptions.
|
||||
*/
|
||||
function backfillAllGroups($groupName='', $backfillDate=null)
|
||||
{
|
||||
$n = $this->n;
|
||||
$groups = new Groups;
|
||||
$res = false;
|
||||
if ($groupName != '')
|
||||
{
|
||||
$grp = $groups->getByName($groupName);
|
||||
if ($grp)
|
||||
$res = array($grp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res = $groups->getActive();
|
||||
}
|
||||
|
||||
if ($res)
|
||||
{
|
||||
$nntp = new Nntp();
|
||||
$nntp->doConnect();
|
||||
|
||||
foreach($res as $groupArr)
|
||||
{
|
||||
$this->backfillGroup($nntp, $groupArr, $backfillDate);
|
||||
}
|
||||
|
||||
$nntp->doQuit();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "No groups specified. Ensure groups are added to newznab's database for updating.$n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a group back to a specified date.
|
||||
*/
|
||||
function backfillGroup($nntp, $groupArr, $backfillDate=null)
|
||||
{
|
||||
$this->db->disableAutoCommit(); //Turn off auto committing
|
||||
|
||||
$binaries = new Binaries($this->db);
|
||||
|
||||
$n = $this->n;
|
||||
$this->startGroup = microtime(true);
|
||||
|
||||
echo 'Processing '.$groupArr['name'].$n;
|
||||
|
||||
$data = $nntp->selectGroup($groupArr['name']);
|
||||
if(PEAR::isError($data))
|
||||
{
|
||||
echo "Could not select group (bad name?): {$groupArr['name']}$n";
|
||||
|
||||
$this->db->rollback(); //Rollback and re-enable autocommitting
|
||||
$this->db->enableAutoCommit();
|
||||
return;
|
||||
}
|
||||
if ($backfillDate)
|
||||
$targetpost = $this->daytopost($nntp,$groupArr['name'],$this->dateToDays($backfillDate),TRUE); // get targetpost based on date
|
||||
else
|
||||
$targetpost = $this->daytopost($nntp,$groupArr['name'],$groupArr['backfill_target'],TRUE); //get targetpost based on days target
|
||||
if($groupArr['first_record'] == 0 || $groupArr['backfill_target'] == 0)
|
||||
{
|
||||
echo "Group ".$groupArr['name']." has invalid numbers. Have you run update on it? Have you set the backfill days amount?$n";
|
||||
|
||||
$this->db->rollback(); //Rollback and re-enable autocommitting
|
||||
$this->db->enableAutoCommit();
|
||||
return;
|
||||
}
|
||||
|
||||
echo "Group ".$data["group"].": server has ".$data['first']." - ".$data['last'].", or ~";
|
||||
echo((int) (($this->postdate($nntp,$data['last'],FALSE) - $this->postdate($nntp,$data['first'],FALSE))/86400));
|
||||
echo " days.".$n."Local first = ".$groupArr['first_record']." (";
|
||||
echo((int) ((date('U') - $this->postdate($nntp,$groupArr['first_record'],FALSE))/86400));
|
||||
echo " days). Backfill target of ".$groupArr['backfill_target']."days is post $targetpost.$n";
|
||||
|
||||
if($targetpost >= $groupArr['first_record']) //if our estimate comes back with stuff we already have, finish
|
||||
{
|
||||
echo "Nothing to do, we already have the target post.$n $n";
|
||||
|
||||
$this->db->commit(); //Not an error so commit and re-enable autocommitting
|
||||
$this->db->enableAutoCommit();
|
||||
return "";
|
||||
}
|
||||
//get first and last part numbers from newsgroup
|
||||
if($targetpost < $data['first'])
|
||||
{
|
||||
echo "WARNING: Backfill came back as before server's first. Setting targetpost to server first.$n";
|
||||
echo "Skipping Group $n";
|
||||
|
||||
$this->db->rollback(); //Rollback and re-enable autocommitting
|
||||
$this->db->enableAutoCommit();
|
||||
return "";
|
||||
}
|
||||
//calculate total number of parts
|
||||
$total = $groupArr['first_record'] - $targetpost;
|
||||
$done = false;
|
||||
//set first and last, moving the window by maxxMssgs
|
||||
$last = $groupArr['first_record'] - 1;
|
||||
$first = $last - $binaries->messagebuffer + 1; //set initial "chunk"
|
||||
if($targetpost > $first) //just in case this is the last chunk we needed
|
||||
$first = $targetpost;
|
||||
while($done === false)
|
||||
{
|
||||
$binaries->startLoop = microtime(true);
|
||||
echo "Getting ".($last-$first+1)." parts (".($first-$targetpost)." in queue)".$n;
|
||||
flush();
|
||||
$success = $binaries->scan($nntp, $groupArr, $first, $last, 'backfill');
|
||||
if (!$success)
|
||||
{
|
||||
$this->db->rollback(); //Rollback and re-enable autocommitting
|
||||
$this->db->enableAutoCommit();
|
||||
return "";
|
||||
}
|
||||
|
||||
$this->db->mysqliQuery(sprintf("UPDATE groups SET first_record = %s, last_updated = now() WHERE ID = %d", $this->db->escapeString($first), $groupArr['ID']));
|
||||
|
||||
$this->db->commit(); //At this point we are ready to commit a set up updates to the db.
|
||||
|
||||
if($first==$targetpost)
|
||||
$done = true;
|
||||
else
|
||||
{ //Keep going: set new last, new first, check for last chunk.
|
||||
$last = $first - 1;
|
||||
$first = $last - $binaries->messagebuffer + 1;
|
||||
if($targetpost > $first)
|
||||
$first = $targetpost;
|
||||
}
|
||||
}
|
||||
$first_record_postdate = $this->postdate($nntp,$first,false);
|
||||
$this->db->mysqliQuery(sprintf("UPDATE groups SET first_record_postdate = FROM_UNIXTIME(".$first_record_postdate."), last_updated = now() WHERE ID = %d", $groupArr['ID'])); //Set group's first postdate
|
||||
|
||||
$this->db->commit(); //Commit and re-enable auto committing we are done with this group.
|
||||
$this->db->enableAutoCommit();
|
||||
|
||||
$timeGroup = number_format(microtime(true) - $this->startGroup, 2);
|
||||
echo "Group processed in $timeGroup seconds $n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns single timestamp from a local article number.
|
||||
*/
|
||||
function postdate($nntp,$post,$debug=true)
|
||||
{
|
||||
$n = $this->n;
|
||||
$attempts=0;
|
||||
do
|
||||
{
|
||||
$msgs = $nntp->getOverview($post."-".$post,true,false);
|
||||
if(PEAR::isError($msgs))
|
||||
{
|
||||
echo "Error {$msgs->code}: {$msgs->message}$n";
|
||||
echo "Returning from postdate$n";
|
||||
return "";
|
||||
}
|
||||
|
||||
if(!isset($msgs[0]['Date']) || $msgs[0]['Date']=="" || is_null($msgs[0]['Date']))
|
||||
{
|
||||
$success=false;
|
||||
} else {
|
||||
$date = $msgs[0]['Date'];
|
||||
$success=true;
|
||||
}
|
||||
if($debug && $attempts > 0) echo "retried $attempts time(s)".$n;
|
||||
$attempts++;
|
||||
} while($attempts <= 3 && $success == false);
|
||||
|
||||
if (!$success) { return ""; }
|
||||
|
||||
if($debug) echo "DEBUG: postdate for post: $post came back $date (";
|
||||
$date = strtotime($date);
|
||||
if($debug) echo "$date seconds unixtime or ".$this->daysOld($date)." days)".$n;
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the post number for a given number of days back in a group.
|
||||
*/
|
||||
function daytopost($nntp, $group, $days, $debug=true)
|
||||
{
|
||||
$n = $this->n;
|
||||
$pddebug = false; //DEBUG every postdate call?!?!
|
||||
if ($debug) echo "INFO: daytopost finding post for $group $days days back.".$n;
|
||||
|
||||
$data = $nntp->selectGroup($group);
|
||||
if(PEAR::isError($data))
|
||||
{
|
||||
echo "Error {$data->code}: {$data->message}$n";
|
||||
echo "Returning from daytopost$n";
|
||||
return "";
|
||||
}
|
||||
$goaldate = date('U')-(86400*$days); //goaltimestamp
|
||||
$totalnumberofarticles = $data['last'] - $data['first'];
|
||||
$upperbound = $data['last'];
|
||||
$lowerbound = $data['first'];
|
||||
|
||||
if ($debug) echo "Total Articles: $totalnumberofarticles $n Upper: $upperbound $n Lower: $lowerbound $n Goal: ".date("r", $goaldate)." ($goaldate) $n";
|
||||
if ($data['last']==PHP_INT_MAX) { echo "ERROR: Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug.$n"; die(); }
|
||||
|
||||
$firstDate = $this->postdate($nntp, $data['first'], $pddebug);
|
||||
$lastDate = $this->postdate($nntp, $data['last'], $pddebug);
|
||||
if ($goaldate < $firstDate)
|
||||
{
|
||||
echo "WARNING: Backfill target of $days day(s) is older than the first article stored on your news server.$n";
|
||||
echo "Starting from the first available article (".date("r", $firstDate)." or ".$this->daysOld($firstDate)." days).$n";
|
||||
return $data['first'];
|
||||
}
|
||||
elseif ($goaldate > $lastDate)
|
||||
{
|
||||
echo "ERROR: Backfill target of $days day(s) is newer than the last article stored on your news server.$n";
|
||||
echo "To backfill this group you need to set Backfill Days to at least ".ceil($this->daysOld($lastDate)+1)." days (".date("r", $lastDate-86400).").$n";
|
||||
return "";
|
||||
}
|
||||
if ($debug) echo "DEBUG: Searching for postdate $n Goaldate: $goaldate (".date("r", $goaldate).") $n Firstdate: $firstDate (".((is_int($firstDate))?date("r", $firstDate):'n/a').") $n Lastdate: $lastDate (".date("r", $lastDate).") $n";
|
||||
|
||||
$interval = floor(($upperbound - $lowerbound) * 0.5);
|
||||
$dateofnextone = "";
|
||||
$templowered = "";
|
||||
|
||||
if ($debug) echo "Start: ".$data['first']." $n End: ".$data['last']." $n Interval: $interval $n";
|
||||
|
||||
$dateofnextone = $lastDate;
|
||||
|
||||
while($this->daysOld($dateofnextone) < $days) //match on days not timestamp to speed things up
|
||||
{
|
||||
$nskip = 1;
|
||||
while(($tmpDate = $this->postdate($nntp,($upperbound-$interval),$pddebug))>$goaldate)
|
||||
{
|
||||
$upperbound = $upperbound - $interval - ($nskip - 1);
|
||||
if($debug) echo "New upperbound ($upperbound) is ".$this->daysOld($tmpDate)." days old. $n";
|
||||
$nskip = $nskip * 2;
|
||||
}
|
||||
if(!$templowered)
|
||||
{
|
||||
$interval = ceil(($interval/2));
|
||||
if($debug) echo "Set interval to $interval articles. $n";
|
||||
}
|
||||
$dateofnextone = $this->postdate($nntp,($upperbound-1),$pddebug);
|
||||
|
||||
$skip = 1;
|
||||
while(!$dateofnextone)
|
||||
{
|
||||
$upperbound = $upperbound - $skip;
|
||||
$skip = $skip * 2;
|
||||
if($debug) echo "Getting next article date... $upperbound\n";
|
||||
$dateofnextone = $this->postdate($nntp,($upperbound-1),$pddebug);
|
||||
}
|
||||
}
|
||||
echo "Determined to be article $upperbound which is ".$this->daysOld($dateofnextone)." days old (".date("r", $dateofnextone).") $n";
|
||||
return $upperbound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of days from a timestamp.
|
||||
*/
|
||||
private function daysOld($timestamp)
|
||||
{
|
||||
return round((time()-$timestamp)/86400, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of days from a date.
|
||||
*/
|
||||
private function dateToDays($backfillDate)
|
||||
{
|
||||
return floor(-($backfillDate - time())/(60*60*24));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/../../../../../www/config.php");
|
||||
?>
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
require_once("/var/www/newznab/www/config.php");
|
||||
require_once("/var/www/newznab/www/lib/framework/db.php");
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once(WWW_DIR."/lib/framework/db.php");
|
||||
|
||||
$db = new DB();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("innodb/binaries.php");
|
||||
require_once("binaries.php");
|
||||
require_once("framework/db.php");
|
||||
require_once(WWW_DIR."/lib/Net_NNTP/NNTP/Client.php");
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once("lib/innodb/config.php");
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/framework/db.php");
|
||||
|
||||
$db = new DB();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
require("lib/innodb/config.php");
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/groups.php");
|
||||
require_once("lib/innodb/binaries.php");
|
||||
require_once("lib/binaries.php");
|
||||
|
||||
if (isset($argv[1]))
|
||||
{
|
||||
|
||||
Regular → Executable
+7
-5
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
require("config.php");
|
||||
require_once(dirname(__FILE__)."/lib/framework/db.php");
|
||||
require_once(dirname(__FILE__)."/lib/groups.php");
|
||||
require_once(dirname(__FILE__)."/lib/innodb/binaries.php");
|
||||
require_once(dirname(__FILE__)."/lib/PowerProcess.class.php");
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require("$newzpath/www/config.php");
|
||||
require_once("lib/framework/db.php");
|
||||
require_once("lib/groups.php");
|
||||
require_once("lib/binaries.php");
|
||||
require_once("lib/PowerProcess.class.php");
|
||||
|
||||
$groups = new Groups;
|
||||
$groupList = $groups->getActive();
|
||||
|
||||
@@ -1,975 +0,0 @@
|
||||
<?php
|
||||
require_once(WWW_DIR."/lib/framework/db.php");
|
||||
require_once(WWW_DIR."/lib/site.php");
|
||||
require_once(WWW_DIR."/lib/util.php");
|
||||
require_once("releases2.php");
|
||||
require_once(WWW_DIR."/lib/rarinfo.php");
|
||||
require_once(WWW_DIR."/lib/releasefiles.php");
|
||||
require_once(WWW_DIR."/lib/releaseextra.php");
|
||||
require_once(WWW_DIR."/lib/releaseimage.php");
|
||||
require_once(WWW_DIR."/lib/tvrage.php");
|
||||
require_once("thetvdb2.php");
|
||||
require_once(WWW_DIR."/lib/anidb.php");
|
||||
require_once(WWW_DIR."/lib/movie.php");
|
||||
require_once(WWW_DIR."/lib/music.php");
|
||||
require_once(WWW_DIR."/lib/console.php");
|
||||
require_once(WWW_DIR."/lib/nfo.php");
|
||||
require_once(WWW_DIR."/lib/category.php");
|
||||
require_once(WWW_DIR."/lib/book.php");
|
||||
require_once(WWW_DIR."/lib/nzbinfo.php");
|
||||
|
||||
/**
|
||||
* This class handles all post processing performed during update_releases process.
|
||||
*/
|
||||
class PostProcess2
|
||||
{
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
function PostProcess2($echooutput=false)
|
||||
{
|
||||
$this->echooutput = $echooutput;
|
||||
$s = new Sites();
|
||||
$this->site = $s->get();
|
||||
|
||||
$this->mediafileregex = 'AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG';
|
||||
$this->audiofileregex = 'MP3|AAC|OGG';
|
||||
$this->mp3SavePath = WWW_DIR.'covers/audio/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform all post processing.
|
||||
*/
|
||||
public function processAll()
|
||||
{
|
||||
//$this->>processAdditional2();
|
||||
//$this->processNfos();
|
||||
//$this->processUnwanted();
|
||||
//$this->processMovies();
|
||||
//$this->processMusic();
|
||||
//$this->processBooks();
|
||||
//$this->processGames();
|
||||
//$this->processTv();
|
||||
//$this->processMusicFromMediaInfo();
|
||||
//$this->processOtherMiscCategory();
|
||||
//$this->processUnknownCategory();
|
||||
}
|
||||
|
||||
public function processUnwanted()
|
||||
{
|
||||
$r = new Releases;
|
||||
$db = new DB;
|
||||
$currTime_ori = $db->queryOneRow("SELECT NOW() as now");
|
||||
|
||||
//
|
||||
// Delete any passworded releases
|
||||
//
|
||||
if($this->site->deletepasswordedrelease == 1)
|
||||
{
|
||||
echo "PostPrc : Removing unwanted releases\n";
|
||||
$result = $db->query("select ID from releases where passwordstatus > 0");
|
||||
foreach ($result as $row)
|
||||
$r->delete($row["ID"]);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete any releases which are older than site's release retention days
|
||||
//
|
||||
if($this->site->releaseretentiondays != 0)
|
||||
{
|
||||
echo "PostPrc : Deleting releases older than ".$this->site->releaseretentiondays." days\n";
|
||||
|
||||
$result = $db->query(sprintf("select ID from releases where postdate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->releaseretentiondays));
|
||||
foreach ($result as $row)
|
||||
$r->delete($row["ID"]);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete any audiopreviews older than site->audiopreviewprune days
|
||||
//
|
||||
if($this->site->audiopreviewprune > 0)
|
||||
{
|
||||
$result = $db->query(sprintf("select guid from releases where categoryID like '3%%' and haspreview = 2 and adddate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->audiopreviewprune));
|
||||
|
||||
echo "PostPrc : Deleting ".count($result)." audio previews older than ".$this->site->audiopreviewprune." days\n";
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$r->updateHasPreview($row["guid"], 0);
|
||||
$this->deleteAudioSample($row["guid"]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Delete any releases suspected of being spam/virus
|
||||
//
|
||||
if($this->site->removespam != 0)
|
||||
{
|
||||
$spamIDs = array();
|
||||
|
||||
//
|
||||
// all releases where the only file inside the rars is *.exe and they are not in the PC category
|
||||
//
|
||||
$sql = "select releasefiles.releaseID as ID from releasefiles inner join ( select releaseID, count(*) as totnum from releasefiles group by releaseID ) x on x.releaseID = releasefiles.releaseID and x.totnum = 1 inner join releases on releases.ID = releasefiles.releaseID left join releasenfo on releasenfo.releaseID = releases.ID where (releasefiles.name like '%.exe' or releasefiles.name like '%.scr') and (releases.categoryID not in (4000,4010,4020,4030,4040,4050) or (releases.categoryID in (4000,4010,4020,4030,4040,4050) and releasenfo.ID is null)) group by releasefiles.releaseID";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
//
|
||||
// all releases containing exe not in permitted categories
|
||||
//
|
||||
if ($this->site->exepermittedcategories != '')
|
||||
{
|
||||
$sql = sprintf("select releasefiles.releaseID as ID from releasefiles inner join releases on releases.ID = releasefiles.releaseID left join releasenfo on releasenfo.releaseID = releases.ID where releasefiles.name like '%%.exe' and releases.categoryID not in (%s) group by releasefiles.releaseID", $this->site->exepermittedcategories);
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
}
|
||||
|
||||
//
|
||||
// delete all releases which contain a file with password.url in it
|
||||
//
|
||||
$sql = "select distinct releasefiles.releaseID as ID from releasefiles where name = 'password.url'";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
//
|
||||
// all releases where the only file inside the rars is *.rar
|
||||
//
|
||||
$sql = "select releasefiles.releaseID as ID from releasefiles inner join ( select releaseID, count(*) as totnum from releasefiles group by releaseID ) x on x.releaseID = releasefiles.releaseID and x.totnum = 1 inner join releases on releases.ID = releasefiles.releaseID where releasefiles.name like '%.rar' group by releasefiles.releaseID";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
//
|
||||
// all audio which contains a file with .exe in
|
||||
//
|
||||
$sql = "select distinct r.ID from releasefiles rf inner join releases r on r.id = rf.releaseID and r.categoryID like '3%' where rf.name like '%.exe'";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
if (count($spamIDs) > 0)
|
||||
{
|
||||
echo "PostPrc : Deleting ".count($spamIDs)." spam releases\n" ;
|
||||
foreach ($spamIDs as $row)
|
||||
$r->delete($row["ID"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process nfo files
|
||||
*/
|
||||
public function processNfos()
|
||||
{
|
||||
if ($this->site->lookupnfo == 1)
|
||||
{
|
||||
$nfo = new Nfo($this->echooutput);
|
||||
$nfo->processNfoFiles($this->site->lookupimdb, $this->site->lookuptvrage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup imdb if enabled
|
||||
*/
|
||||
public function processMovies()
|
||||
{
|
||||
if ($this->site->lookupimdb == 1)
|
||||
{
|
||||
$movie = new Movie($this->echooutput);
|
||||
$movie->processMovieReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup music if enabled
|
||||
*/
|
||||
public function processMusic()
|
||||
{
|
||||
if ($this->site->lookupmusic == 1)
|
||||
{
|
||||
$music = new Music($this->echooutput);
|
||||
$music->processMusicReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup book if enabled
|
||||
*/
|
||||
public function processBooks()
|
||||
{
|
||||
if ($this->site->lookupbooks == 1)
|
||||
{
|
||||
$book = new Book($this->echooutput);
|
||||
$book->processBookReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup games if enabled
|
||||
*/
|
||||
public function processGames()
|
||||
{
|
||||
if ($this->site->lookupgames == 1)
|
||||
{
|
||||
$console = new Console($this->echooutput);
|
||||
$console->processConsoleReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out any categories which were not assigned by regex or determinecategory
|
||||
* Done in post process as releasevideo/audio will have been performed by now.
|
||||
*/
|
||||
public function processUnknownCategory()
|
||||
{
|
||||
$db = new DB;
|
||||
$sql = sprintf("select ID from releases where categoryID = %d", Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
$rescount = sizeof($result);
|
||||
if ($rescount > 0)
|
||||
{
|
||||
echo "PostPrc : Attempting to fix ".$rescount." uncategorised release(s)\n";
|
||||
|
||||
$sql = sprintf("update releases inner join releasevideo rv on rv.releaseID = releases.ID set releases.categoryID = %d where imdbid is not null and categoryid = %d and videocodec = 'XVID'", Category::CAT_MOVIE_SD, Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
|
||||
$sql = sprintf("update releases inner join releasevideo rv on rv.releaseID = releases.ID set releases.categoryID = %d where imdbid is not null and categoryid = %d and videocodec = 'V_MPEG4/ISO/AVC'", Category::CAT_MOVIE_HD, Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
|
||||
$sql = sprintf("update releases set categoryID = %d where categoryID = %d", Category::CAT_MISC, Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all TV related releases which will assign their series/episode/rage data
|
||||
*/
|
||||
public function processTv()
|
||||
{
|
||||
if ($this->site->lookupanidb == 1)
|
||||
{
|
||||
$anidb = new AniDB($this->echooutput);
|
||||
$anidb->animetitlesUpdate();
|
||||
$anidb->processAnimeReleases();
|
||||
}
|
||||
|
||||
if ($this->site->lookuptvrage == 1)
|
||||
{
|
||||
$tvrage = new TVRage($this->echooutput);
|
||||
$tvrage->processTvReleases(($this->site->lookuptvrage==1));
|
||||
}
|
||||
|
||||
if ($this->site->lookupthetvdb == 1)
|
||||
{
|
||||
$thetvdb = new TheTVDB($this->echooutput);
|
||||
$thetvdb->processReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process releases without a proper name and try to look it up in the nfo
|
||||
*/
|
||||
public function processOtherMiscCategory($numToProcess = 10)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$res = $db->query(sprintf("select r.searchname, r.ID, r.guid, g.name as groupname from releases r inner join releasenfo rn on rn.releaseID = r.ID left join groups g on g.ID = r.groupID where (r.categoryID = %d or r.categoryID = %d) order by r.ID desc limit %d", Category::CAT_MISC, Category::CAT_NOT_DETERMINED, $numToProcess));
|
||||
|
||||
if ($res)
|
||||
{
|
||||
$rescount = sizeof($res);
|
||||
|
||||
if ($this->echooutput)
|
||||
echo "PostPrc : Attempting to categorise ".$rescount." Other-Misc releases\n";
|
||||
|
||||
foreach($res as $rel)
|
||||
{
|
||||
$filenameRes = $db->query(sprintf("select dirname from predb where filename = %s limit 2", $db->escapeString($rel['searchname'])));
|
||||
if (count($filenameRes) == 1)
|
||||
$foundName = $filenameRes[0]['dirname'];
|
||||
else
|
||||
{
|
||||
$nfoRes = $db->queryOneRow(sprintf("select uncompress(nfo) as nfo from releasenfo where releaseID = %d", $rel['ID']));
|
||||
$nfo = $nfoRes['nfo'];
|
||||
|
||||
$foundName = '';
|
||||
//Typical scene regex
|
||||
if (preg_match('/(?P<source>Source\s*?:|fix fornuke)?(?:\s|\]|\[)?(?P<name>[a-z0-9\']+(?:\.|_)[a-z0-9\.\-_\'&]+\-[a-z0-9&]+)(?:\s|\[|\])/i', $nfo, $matches))
|
||||
{
|
||||
if (empty($matches['source']))
|
||||
$foundName = $matches['name'];
|
||||
}
|
||||
//IMAGiNE releases
|
||||
elseif(preg_match('/\*\s+([a-z0-9]+(?:\.|_| )[a-z0-9\.\_\- ]+ \- imagine)\s+\*/i', $nfo, $matches))
|
||||
{
|
||||
$foundName = $matches[1];
|
||||
}
|
||||
//SANTi releases
|
||||
elseif(preg_match('/\b([a-z0-9]+(?:\.|_| )[a-z0-9\.\_\- \']+\-santi)\b/i', $nfo, $matches))
|
||||
{
|
||||
$foundName = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($foundName != '')
|
||||
{
|
||||
$category = new Category();
|
||||
$categoryID = $category->determineCategory($rel['groupname'], $foundName);
|
||||
$name = str_replace(' ', '_', $foundName);
|
||||
$searchname = str_replace('_', ' ', $foundName);
|
||||
|
||||
$db->query(sprintf("UPDATE releases SET name = %s, searchname = %s, categoryID = %d WHERE ID = %d", $db->escapeString($name), $db->escapeString($searchname), $categoryID, $rel['ID']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for passworded releases, RAR contents and Sample/Media info
|
||||
*/
|
||||
public function processAdditional2()
|
||||
{
|
||||
require_once(WWW_DIR."/lib/nntp.php");
|
||||
|
||||
$maxattemptstocheckpassworded = 5;
|
||||
$numtoProcess = 100;
|
||||
$processVideoSample = ($this->site->ffmpegpath != '') ? true : false;
|
||||
$processMediainfo = ($this->site->mediainfopath != '') ? true : false;
|
||||
$processPasswords = ($this->site->unrarpath != '') ? true : false;
|
||||
$processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false;
|
||||
|
||||
$tmpPath = $this->site->tmpunrarpath;
|
||||
$tmpPath .= '2';
|
||||
if (substr($tmpPath, -strlen( '/' ) ) != '/')
|
||||
{
|
||||
$tmpPath = $tmpPath.'/';
|
||||
}
|
||||
|
||||
if (!file_exists($tmpPath))
|
||||
mkdir($tmpPath, 0766, true);
|
||||
|
||||
$db = new DB;
|
||||
$nntp = new Nntp;
|
||||
$nzb = new Nzb;
|
||||
|
||||
//
|
||||
// Get out all releases which have not been checked more than max attempts for password.
|
||||
//
|
||||
$result = $db->query(sprintf("select r.ID, r.guid, r.name, c.disablepreview from releases r
|
||||
left join category c on c.ID = r.categoryID
|
||||
where (r.passwordstatus between %d and -1)
|
||||
or (r.haspreview = -1 and c.disablepreview = 0) order by r.guid desc limit %d ", ($maxattemptstocheckpassworded + 1) * -1, $numtoProcess));
|
||||
|
||||
$iteration = $rescount = sizeof($result);
|
||||
if ($rescount > 0)
|
||||
{
|
||||
echo "Post processing by guid on ".$rescount." releases ...";
|
||||
$nntpconnected = false;
|
||||
|
||||
foreach ($result as $rel)
|
||||
{
|
||||
echo $iteration--.".";
|
||||
|
||||
// Per release defaults
|
||||
$passStatus = array(Releases::PASSWD_NONE);
|
||||
$blnTookMediainfo = false;
|
||||
$blnTookSample = ($rel['disablepreview'] == 1) ? true : false; //only attempt sample if not disabled
|
||||
|
||||
if ($blnTookSample)
|
||||
$db->query(sprintf("update releases set haspreview = 0 where id = %d", $rel['ID']));
|
||||
|
||||
//
|
||||
// Go through the binaries for this release looking for a rar, a sample, and a mediafile
|
||||
//
|
||||
$nzbInfo = new nzbInfo;
|
||||
$nzbfile = $nzb->getNZBPath($rel['guid'], $this->site->nzbpath);
|
||||
if (!$nzbInfo->loadFromFile($nzbfile))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$norar = 0;
|
||||
|
||||
foreach($nzbInfo->nzb as $nzbsubject)
|
||||
{
|
||||
if (preg_match("/\w\.r00/i", $nzbsubject['subject']))
|
||||
$norar= 1;
|
||||
}
|
||||
|
||||
// attempt to process video sample file
|
||||
if(!empty($nzbInfo->samplefiles) && $processVideoSample && $blnTookSample === false)
|
||||
{
|
||||
$sampleFile = $nzbInfo->samplefiles[0]; //first detected sample
|
||||
$sampleMsgids = array_slice($sampleFile['segments'], 0, 1); //get first segment, increase to get more of the sample
|
||||
$sampleGroup = $sampleFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($sampleMsgids, ', ')." from {$sampleGroup}\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
|
||||
$sampleBinary = $nntp->getMessages($sampleGroup, $sampleMsgids);
|
||||
if ($sampleBinary === false)
|
||||
echo "\nPostPrc : Couldnt fetch sample\n";
|
||||
else
|
||||
{
|
||||
$samplefile = $tmpPath.'sample.avi';
|
||||
|
||||
file_put_contents($samplefile, $sampleBinary);
|
||||
|
||||
$blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
$this->updateReleaseHasPreview($rel['guid']);
|
||||
|
||||
unlink($samplefile);
|
||||
}
|
||||
unset($sampleBinary);
|
||||
}
|
||||
|
||||
// attempt to process loose media file
|
||||
if(!empty($nzbInfo->mediafiles) && (($processVideoSample && $blnTookSample === false) || $processMediainfo))
|
||||
{
|
||||
$mediaFile = $nzbInfo->mediafiles[0]; //first detected media file
|
||||
$mediaMsgids = array_slice($mediaFile['segments'], 0, 2); //get first two segments
|
||||
$mediaGroup = $mediaFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($mediaMsgids, ', ')." from {$mediaGroup}\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
$mediaBinary = $nntp->getMessages($mediaGroup, $mediaMsgids);
|
||||
if ($mediaBinary === false)
|
||||
echo "\nPostPrc : Couldnt fetch media file\n";
|
||||
else
|
||||
{
|
||||
$mediafile = $tmpPath.'sample.avi';
|
||||
|
||||
file_put_contents($mediafile, $mediaBinary);
|
||||
|
||||
if ($processVideoSample && $blnTookSample === false)
|
||||
{
|
||||
$blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
$this->updateReleaseHasPreview($rel['guid']);
|
||||
}
|
||||
|
||||
if ($processMediainfo)
|
||||
$blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']);
|
||||
|
||||
unlink($mediafile);
|
||||
}
|
||||
unset($mediaBinary);
|
||||
}
|
||||
|
||||
// attempt to process audio sample file
|
||||
if(!empty($nzbInfo->audiofiles) && $processAudioSample && $blnTookSample === false)
|
||||
{
|
||||
$audioFile = $nzbInfo->audiofiles[0]; //first detected audio file
|
||||
$audioMsgids = array_slice($audioFile['segments'], 0, 1); //get first segment
|
||||
$audioGroup = $audioFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($audioMsgids, ', ')." from {$audioGroup}\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
$audioBinary = $nntp->getMessages($audioGroup, $audioMsgids);
|
||||
if ($audioBinary === false)
|
||||
echo "\nPostPrc : Couldnt fetch audio sample\n";
|
||||
else
|
||||
{
|
||||
$audiofile = $tmpPath.'sample.mp3';
|
||||
|
||||
file_put_contents($audiofile, $audioBinary);
|
||||
|
||||
$blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']);
|
||||
if ($blnTookSample !== false)
|
||||
$this->updateReleaseHasPreview($rel['guid'], 2);
|
||||
|
||||
if ($processMediainfo)
|
||||
$blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']);
|
||||
|
||||
if ($this->site->lamepath != "")
|
||||
$this->lameAudioSample($this->site->lamepath, $rel['guid']);
|
||||
|
||||
unlink($audiofile);
|
||||
}
|
||||
unset($audioBinary);
|
||||
}
|
||||
|
||||
if (!empty($nzbInfo->rarfiles) && ($this->site->checkpasswordedrar > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo))
|
||||
{
|
||||
$mysqlkeepalive = 0;
|
||||
foreach($nzbInfo->rarfiles as $rarFile)
|
||||
{
|
||||
//dont process any more rars if a passworded rar has been detected and the site is set to automatically delete them
|
||||
if ($this->site->deletepasswordedrelease == 1 && max($passStatus) == Releases::PASSWD_RAR)
|
||||
{
|
||||
echo "-Skipping processing of rar {$rarFile['subject']} as this release has already been marked as passworded.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$rarMsgids = array_slice($rarFile['segments'], 0, 1); //get first segment
|
||||
$rarGroup = $rarFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($rarMsgids, ', ')." from {$rarGroup} (".++$mysqlkeepalive.")\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
$fetchedBinary = $nntp->getMessages($rarGroup, $rarMsgids);
|
||||
if ($fetchedBinary === false)
|
||||
{
|
||||
echo "\nPostPrc : Failed fetching rar file\n";
|
||||
$db->query(sprintf("update releases set passwordstatus = passwordstatus - 1 where ID = %d", $rel['ID']));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
$relFiles = $this->processReleaseFiles($fetchedBinary, $rel['ID']);
|
||||
|
||||
if ($this->site->checkpasswordedrar > 0 && $processPasswords)
|
||||
{
|
||||
$passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->site->unrarpath, $this->site->checkpasswordedrar);
|
||||
}
|
||||
|
||||
// we need to unrar the fetched binary if checkpasswordedrar wasnt 2
|
||||
if ($this->site->checkpasswordedrar < 2 && $processPasswords)
|
||||
{
|
||||
$rarfile = $tmpPath.'rarfile.rar';
|
||||
file_put_contents($rarfile, $fetchedBinary);
|
||||
$execstring = '"'.$this->site->unrarpath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$rarfile.'" "'.$tmpPath.'"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
unlink($rarfile);
|
||||
}
|
||||
|
||||
if ($processVideoSample && $blnTookSample === false)
|
||||
{
|
||||
$blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
$this->updateReleaseHasPreview($rel['guid']);
|
||||
}
|
||||
|
||||
$blnTookAudioSample = false;
|
||||
if ($processAudioSample && $blnTookSample === false)
|
||||
{
|
||||
$blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
{
|
||||
$blnTookAudioSample = true;
|
||||
$this->updateReleaseHasPreview($rel['guid'], 2);
|
||||
}
|
||||
}
|
||||
|
||||
if ($processMediainfo && $blnTookMediainfo === false)
|
||||
{
|
||||
$blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']);
|
||||
}
|
||||
|
||||
//
|
||||
// Has to be done after mediainfo
|
||||
//
|
||||
if ($blnTookAudioSample && $this->site->lamepath != "")
|
||||
$this->lameAudioSample($this->site->lamepath, $rel['guid']);
|
||||
|
||||
if ($mysqlkeepalive % 25 == 0)
|
||||
$db->query("select 1");
|
||||
}
|
||||
|
||||
//clean up all files
|
||||
foreach(glob($tmpPath.'*') as $v)
|
||||
{
|
||||
unlink($v);
|
||||
}
|
||||
|
||||
} //end foreach msgid
|
||||
}
|
||||
elseif(empty($nzbInfo->rarfiles) && $norar == 1)
|
||||
{
|
||||
$passStatus[] = Releases::PASSWD_POTENTIAL;
|
||||
}
|
||||
|
||||
$hpsql = '';
|
||||
if (!$blnTookSample)
|
||||
$hpsql = ', haspreview = 0';
|
||||
|
||||
$sql = sprintf("update releases set passwordstatus = %d %s where ID = %d", max($passStatus), $hpsql, $rel["ID"]);
|
||||
$db->query($sql);
|
||||
|
||||
} //end foreach result
|
||||
|
||||
if ($nntpconnected)
|
||||
{
|
||||
$nntp->doQuit();
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out all files contained inside a rar
|
||||
*/
|
||||
public function processReleaseFiles($fetchedBinary, $relid)
|
||||
{
|
||||
$retval = array();
|
||||
$rar = new RarInfo;
|
||||
$rf = new ReleaseFiles;
|
||||
$db = new DB;
|
||||
|
||||
if ($rar->setData($fetchedBinary))
|
||||
{
|
||||
$files = $rar->getFileList();
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$rf->add($relid, $file['name'], $file['size'], $file['date'], $file['pass'] );
|
||||
$retval[] = $file['name'];
|
||||
}
|
||||
|
||||
}
|
||||
unset($fetchedBinary);
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out if a release is passworded
|
||||
*/
|
||||
public function processReleasePasswords($fetchedBinary, $tmpPath, $unrarPath, $checkpasswordedrar)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_NONE;
|
||||
$potentiallypasswordedfileregex = "/\.(ace|cab|tar|gz)$/i";
|
||||
$definetlypasswordedfileregex = "/password/i";
|
||||
$rar = new RarInfo;
|
||||
$filecount = 0;
|
||||
|
||||
$rarfile = $tmpPath.'rarfile.rar';
|
||||
file_put_contents($rarfile, $fetchedBinary);
|
||||
|
||||
if ($rar->open($rarfile))
|
||||
{
|
||||
if ($rar->isEncrypted)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_RAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
$files = $rar->getFileList(true);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filecount++;
|
||||
//
|
||||
// individual file rar passworded
|
||||
//
|
||||
if ($file['pass'] == 1 || preg_match($definetlypasswordedfileregex, $file["name"]))
|
||||
{
|
||||
$passStatus = Releases::PASSWD_RAR;
|
||||
}
|
||||
|
||||
//
|
||||
// individual file looks suspect
|
||||
//
|
||||
elseif (preg_match($potentiallypasswordedfileregex, $file["name"]) && $passStatus != Releases::PASSWD_RAR)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_POTENTIAL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Deep Checking
|
||||
//
|
||||
if ($checkpasswordedrar == 2)
|
||||
{
|
||||
|
||||
$israr = $this->isRar($rarfile);
|
||||
for ($i=0;$i<sizeof($israr);$i++)
|
||||
{
|
||||
if (preg_match('/\\\\/',$israr[$i]))
|
||||
{
|
||||
$israr[$i] = ltrim((strrchr($israr[$i],"\\")),"\\");
|
||||
}
|
||||
}
|
||||
|
||||
$execstring = '"'.$unrarPath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$rarfile.'" "'.$tmpPath.'"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
|
||||
// delete the rar
|
||||
unlink($rarfile);
|
||||
|
||||
// ok, now we have all the files extracted from the rar into the tempdir and
|
||||
// the rar file deleted, now to loop through the files and recursively unrar
|
||||
// if any of those are rars, we don't trust their names and we test every file
|
||||
// for the rar header
|
||||
for ($i=0;$i<sizeof($israr);$i++)
|
||||
{
|
||||
// even though its in the rar filelist there may not have been enough data
|
||||
// to extract this file so dont attempt to read the file if it doesnt exist
|
||||
if (!file_exists($tmpPath.$israr[$i]))
|
||||
continue;
|
||||
|
||||
$tmp = $this->isRar($tmpPath.$israr[$i]);
|
||||
|
||||
if (is_array($tmp))
|
||||
// it's a rar
|
||||
{
|
||||
for ($x=0;$x<sizeof($tmp);$x++)
|
||||
{
|
||||
if (preg_match('/\\\\/',$tmp[$x]))
|
||||
{
|
||||
$tmp[$x] = ltrim((strrchr($tmp[$x],"\\")),"\\");
|
||||
}
|
||||
$israr[] = $tmp[$x];
|
||||
}
|
||||
|
||||
$execstring = '"'.$unrarPath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$tmpPath.$israr[$i].'" "'.$tmpPath.'"';
|
||||
$output2 = runCmd($execstring, false, true);
|
||||
unlink($tmpPath.$israr[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($tmp == 1 || $tmp == 2)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_RAR;
|
||||
unlink($tmpPath.$israr[$i]);
|
||||
}
|
||||
}
|
||||
unset($tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@unlink($rarfile);
|
||||
unset($fetchedBinary);
|
||||
return $passStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out if a rar is passworded
|
||||
*/
|
||||
public function isRar($rarfile)
|
||||
{
|
||||
// returns 0 if not rar
|
||||
// returns 1 if encrypted rar
|
||||
// returns 2 if passworded rar
|
||||
// returns array of files in the rar if normal rar
|
||||
unset($filelist);
|
||||
$rar = new RarInfo;
|
||||
if ($rar->open($rarfile))
|
||||
{
|
||||
if ($rar->isEncrypted)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$files = $rar->getFileList(true);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filelist[] = $file['name'];
|
||||
if ($file['pass'] == true)
|
||||
//
|
||||
// individual file rar passworded
|
||||
//
|
||||
{
|
||||
return 2;
|
||||
// passworded
|
||||
}
|
||||
}
|
||||
return ($filelist);
|
||||
// normal rar
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
// not a rar
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out all files contained inside a rar
|
||||
*/
|
||||
public function getMediainfo($ramdrive,$mediainfo,$releaseID)
|
||||
{
|
||||
$retval = false;
|
||||
$mediafiles = glob($ramdrive.'*.*');
|
||||
if (is_array($mediafiles))
|
||||
{
|
||||
foreach($mediafiles as $mediafile)
|
||||
{
|
||||
if (preg_match("/\.(".$this->mediafileregex.'|'.$this->audiofileregex.")$/i",$mediafile))
|
||||
{
|
||||
$execstring = '"'.$mediainfo.'" --Output=XML "'.$mediafile.'"';
|
||||
$xmlarray = runCmd($execstring);
|
||||
|
||||
if (is_array($xmlarray))
|
||||
{
|
||||
$xmlarray = implode("\n",$xmlarray);
|
||||
$re = new ReleaseExtra();
|
||||
$re->addFull($releaseID,$xmlarray);
|
||||
$re->addFromXml($releaseID,$xmlarray);
|
||||
$retval = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc : Failed to process mediainfo for ".$mediafile." release (".$releaseID.")\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n";
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sample from a release using ffmpeg
|
||||
*/
|
||||
public function getSample($ramdrive, $ffmpeginfo, $releaseguid)
|
||||
{
|
||||
$ri = new ReleaseImage();
|
||||
$retval = false;
|
||||
|
||||
$samplefiles = glob($ramdrive.'*.*');
|
||||
if (is_array($samplefiles))
|
||||
{
|
||||
foreach($samplefiles as $samplefile)
|
||||
{
|
||||
if (preg_match("/\.(".$this->mediafileregex.")$/i",$samplefile))
|
||||
{
|
||||
$execstring = '"'.$ffmpeginfo.'" -q:v 0 -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
$all_files = scandir($ramdrive,1);
|
||||
if(preg_match("/zzzz\d{3}\.jpg/",$all_files[1]))
|
||||
{
|
||||
$ri->saveImage($releaseguid.'_thumb', $ramdrive.$all_files[1], $ri->imgSavePath, 800, 600);
|
||||
$retval = true;
|
||||
}
|
||||
|
||||
//clean up all files
|
||||
foreach(glob($ramdrive.'*.jpg') as $v)
|
||||
{
|
||||
unlink($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n";
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has to be performed after mediainfo, as lame strips id3 tags.
|
||||
*/
|
||||
public function lameAudioSample($lameinfo, $releaseguid)
|
||||
{
|
||||
$minacceptableencodefilesize = 10000;
|
||||
$samplefile = $this->mp3SavePath.$releaseguid.'.mp3';
|
||||
|
||||
if (file_exists($samplefile))
|
||||
{
|
||||
$outfile = $this->mp3SavePath.$releaseguid.'_l.mp3';
|
||||
|
||||
//
|
||||
// lame the sample down to 96kb and replace it. alternatives could be
|
||||
// V8 for low quality variable.
|
||||
//
|
||||
$execstring = '"'.$lameinfo.'" -b 96 "'.$samplefile.'" "'.$outfile.'"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
|
||||
//
|
||||
// lame can create bad/small files if the source was corrupt
|
||||
// if it creates a file thats surprisingly small, then ignore it and retain
|
||||
// original
|
||||
//
|
||||
if (file_exists($outfile))
|
||||
{
|
||||
if (filesize($outfile) < $minacceptableencodefilesize)
|
||||
unlink($outfile);
|
||||
else
|
||||
{
|
||||
unlink($samplefile);
|
||||
rename($outfile, $samplefile);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an audio sample from a release.
|
||||
*/
|
||||
public function getAudioSample($ramdrive, $releaseguid)
|
||||
{
|
||||
$retval = false;
|
||||
|
||||
$audiofiles = glob($ramdrive.'*.*');
|
||||
if (is_array($audiofiles))
|
||||
{
|
||||
foreach($audiofiles as $audiofile)
|
||||
{
|
||||
if (preg_match("/\.(".$this->audiofileregex.")$/i",$audiofile))
|
||||
{
|
||||
if (copy($audiofile, $this->mp3SavePath.$releaseguid.'.mp3') !== false)
|
||||
$retval = true;
|
||||
else
|
||||
echo "PostPrc : Failed to get audio sample from ".$audiofile."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n";
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an audio sample from a release.
|
||||
*/
|
||||
public function deleteAudioSample($releaseguid)
|
||||
{
|
||||
$preview = $this->mp3SavePath.$releaseguid.'.mp3';
|
||||
if (file_exists($preview))
|
||||
unlink($preview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update release to indicate a preview has been obtained.
|
||||
*/
|
||||
public function updateReleaseHasPreview($guid, $prevtype=1)
|
||||
{
|
||||
$rel = new Releases;
|
||||
$rel->updateHasPreview($guid, $prevtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process untagged music releases using information from mediainfo if config permits.
|
||||
*/
|
||||
public function processMusicFromMediaInfo()
|
||||
{
|
||||
$processMediainfo = ($this->site->mediainfopath != '') ? true : false;
|
||||
$processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false;
|
||||
$processMusic = ($this->site->lookupmusic == 1) ? true : false;
|
||||
|
||||
if ($processMusic && $processMediainfo && $processAudioSample)
|
||||
{
|
||||
$music = new Music($this->echooutput);
|
||||
$ret = $music->processMusicReleaseFromMediaInfo();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,975 +0,0 @@
|
||||
<?php
|
||||
require_once(WWW_DIR."/lib/framework/db.php");
|
||||
require_once(WWW_DIR."/lib/site.php");
|
||||
require_once(WWW_DIR."/lib/util.php");
|
||||
require_once("releases3.php");
|
||||
require_once(WWW_DIR."/lib/rarinfo.php");
|
||||
require_once(WWW_DIR."/lib/releasefiles.php");
|
||||
require_once(WWW_DIR."/lib/releaseextra.php");
|
||||
require_once(WWW_DIR."/lib/releaseimage.php");
|
||||
require_once(WWW_DIR."/lib/tvrage.php");
|
||||
require_once("thetvdb3.php");
|
||||
require_once(WWW_DIR."/lib/anidb.php");
|
||||
require_once(WWW_DIR."/lib/movie.php");
|
||||
require_once(WWW_DIR."/lib/music.php");
|
||||
require_once(WWW_DIR."/lib/console.php");
|
||||
require_once(WWW_DIR."/lib/nfo.php");
|
||||
require_once(WWW_DIR."/lib/category.php");
|
||||
require_once(WWW_DIR."/lib/book.php");
|
||||
require_once(WWW_DIR."/lib/nzbinfo.php");
|
||||
|
||||
/**
|
||||
* This class handles all post processing performed during update_releases process.
|
||||
*/
|
||||
class PostProcess3
|
||||
{
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
function PostProcess3($echooutput=false)
|
||||
{
|
||||
$this->echooutput = $echooutput;
|
||||
$s = new Sites();
|
||||
$this->site = $s->get();
|
||||
|
||||
$this->mediafileregex = 'AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG';
|
||||
$this->audiofileregex = 'MP3|AAC|OGG';
|
||||
$this->mp3SavePath = WWW_DIR.'covers/audio/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform all post processing.
|
||||
*/
|
||||
public function processAll()
|
||||
{
|
||||
//$this->>processAdditional3();
|
||||
//$this->processNfos();
|
||||
//$this->processUnwanted();
|
||||
//$this->processMovies();
|
||||
//$this->processMusic();
|
||||
//$this->processBooks();
|
||||
//$this->processGames();
|
||||
//$this->processTv();
|
||||
//$this->processMusicFromMediaInfo();
|
||||
//$this->processOtherMiscCategory();
|
||||
//$this->processUnknownCategory();
|
||||
}
|
||||
|
||||
public function processUnwanted()
|
||||
{
|
||||
$r = new Releases;
|
||||
$db = new DB;
|
||||
$currTime_ori = $db->queryOneRow("SELECT NOW() as now");
|
||||
|
||||
//
|
||||
// Delete any passworded releases
|
||||
//
|
||||
if($this->site->deletepasswordedrelease == 1)
|
||||
{
|
||||
echo "PostPrc : Removing unwanted releases\n";
|
||||
$result = $db->query("select ID from releases where passwordstatus > 0");
|
||||
foreach ($result as $row)
|
||||
$r->delete($row["ID"]);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete any releases which are older than site's release retention days
|
||||
//
|
||||
if($this->site->releaseretentiondays != 0)
|
||||
{
|
||||
echo "PostPrc : Deleting releases older than ".$this->site->releaseretentiondays." days\n";
|
||||
|
||||
$result = $db->query(sprintf("select ID from releases where postdate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->releaseretentiondays));
|
||||
foreach ($result as $row)
|
||||
$r->delete($row["ID"]);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete any audiopreviews older than site->audiopreviewprune days
|
||||
//
|
||||
if($this->site->audiopreviewprune > 0)
|
||||
{
|
||||
$result = $db->query(sprintf("select guid from releases where categoryID like '3%%' and haspreview = 2 and adddate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->audiopreviewprune));
|
||||
|
||||
echo "PostPrc : Deleting ".count($result)." audio previews older than ".$this->site->audiopreviewprune." days\n";
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$r->updateHasPreview($row["guid"], 0);
|
||||
$this->deleteAudioSample($row["guid"]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Delete any releases suspected of being spam/virus
|
||||
//
|
||||
if($this->site->removespam != 0)
|
||||
{
|
||||
$spamIDs = array();
|
||||
|
||||
//
|
||||
// all releases where the only file inside the rars is *.exe and they are not in the PC category
|
||||
//
|
||||
$sql = "select releasefiles.releaseID as ID from releasefiles inner join ( select releaseID, count(*) as totnum from releasefiles group by releaseID ) x on x.releaseID = releasefiles.releaseID and x.totnum = 1 inner join releases on releases.ID = releasefiles.releaseID left join releasenfo on releasenfo.releaseID = releases.ID where (releasefiles.name like '%.exe' or releasefiles.name like '%.scr') and (releases.categoryID not in (4000,4010,4020,4030,4040,4050) or (releases.categoryID in (4000,4010,4020,4030,4040,4050) and releasenfo.ID is null)) group by releasefiles.releaseID";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
//
|
||||
// all releases containing exe not in permitted categories
|
||||
//
|
||||
if ($this->site->exepermittedcategories != '')
|
||||
{
|
||||
$sql = sprintf("select releasefiles.releaseID as ID from releasefiles inner join releases on releases.ID = releasefiles.releaseID left join releasenfo on releasenfo.releaseID = releases.ID where releasefiles.name like '%%.exe' and releases.categoryID not in (%s) group by releasefiles.releaseID", $this->site->exepermittedcategories);
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
}
|
||||
|
||||
//
|
||||
// delete all releases which contain a file with password.url in it
|
||||
//
|
||||
$sql = "select distinct releasefiles.releaseID as ID from releasefiles where name = 'password.url'";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
//
|
||||
// all releases where the only file inside the rars is *.rar
|
||||
//
|
||||
$sql = "select releasefiles.releaseID as ID from releasefiles inner join ( select releaseID, count(*) as totnum from releasefiles group by releaseID ) x on x.releaseID = releasefiles.releaseID and x.totnum = 1 inner join releases on releases.ID = releasefiles.releaseID where releasefiles.name like '%.rar' group by releasefiles.releaseID";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
//
|
||||
// all audio which contains a file with .exe in
|
||||
//
|
||||
$sql = "select distinct r.ID from releasefiles rf inner join releases r on r.id = rf.releaseID and r.categoryID like '3%' where rf.name like '%.exe'";
|
||||
$result = $db->query($sql);
|
||||
$spamIDs = array_merge($result, $spamIDs);
|
||||
|
||||
if (count($spamIDs) > 0)
|
||||
{
|
||||
echo "PostPrc : Deleting ".count($spamIDs)." spam releases\n" ;
|
||||
foreach ($spamIDs as $row)
|
||||
$r->delete($row["ID"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process nfo files
|
||||
*/
|
||||
public function processNfos()
|
||||
{
|
||||
if ($this->site->lookupnfo == 1)
|
||||
{
|
||||
$nfo = new Nfo($this->echooutput);
|
||||
$nfo->processNfoFiles($this->site->lookupimdb, $this->site->lookuptvrage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup imdb if enabled
|
||||
*/
|
||||
public function processMovies()
|
||||
{
|
||||
if ($this->site->lookupimdb == 1)
|
||||
{
|
||||
$movie = new Movie($this->echooutput);
|
||||
$movie->processMovieReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup music if enabled
|
||||
*/
|
||||
public function processMusic()
|
||||
{
|
||||
if ($this->site->lookupmusic == 1)
|
||||
{
|
||||
$music = new Music($this->echooutput);
|
||||
$music->processMusicReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup book if enabled
|
||||
*/
|
||||
public function processBooks()
|
||||
{
|
||||
if ($this->site->lookupbooks == 1)
|
||||
{
|
||||
$book = new Book($this->echooutput);
|
||||
$book->processBookReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup games if enabled
|
||||
*/
|
||||
public function processGames()
|
||||
{
|
||||
if ($this->site->lookupgames == 1)
|
||||
{
|
||||
$console = new Console($this->echooutput);
|
||||
$console->processConsoleReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out any categories which were not assigned by regex or determinecategory
|
||||
* Done in post process as releasevideo/audio will have been performed by now.
|
||||
*/
|
||||
public function processUnknownCategory()
|
||||
{
|
||||
$db = new DB;
|
||||
$sql = sprintf("select ID from releases where categoryID = %d", Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
$rescount = sizeof($result);
|
||||
if ($rescount > 0)
|
||||
{
|
||||
echo "PostPrc : Attempting to fix ".$rescount." uncategorised release(s)\n";
|
||||
|
||||
$sql = sprintf("update releases inner join releasevideo rv on rv.releaseID = releases.ID set releases.categoryID = %d where imdbid is not null and categoryid = %d and videocodec = 'XVID'", Category::CAT_MOVIE_SD, Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
|
||||
$sql = sprintf("update releases inner join releasevideo rv on rv.releaseID = releases.ID set releases.categoryID = %d where imdbid is not null and categoryid = %d and videocodec = 'V_MPEG4/ISO/AVC'", Category::CAT_MOVIE_HD, Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
|
||||
$sql = sprintf("update releases set categoryID = %d where categoryID = %d", Category::CAT_MISC, Category::CAT_NOT_DETERMINED);
|
||||
$result = $db->query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all TV related releases which will assign their series/episode/rage data
|
||||
*/
|
||||
public function processTv()
|
||||
{
|
||||
if ($this->site->lookupanidb == 1)
|
||||
{
|
||||
$anidb = new AniDB($this->echooutput);
|
||||
$anidb->animetitlesUpdate();
|
||||
$anidb->processAnimeReleases();
|
||||
}
|
||||
|
||||
if ($this->site->lookuptvrage == 1)
|
||||
{
|
||||
$tvrage = new TVRage($this->echooutput);
|
||||
$tvrage->processTvReleases(($this->site->lookuptvrage==1));
|
||||
}
|
||||
|
||||
if ($this->site->lookupthetvdb == 1)
|
||||
{
|
||||
$thetvdb = new TheTVDB($this->echooutput);
|
||||
$thetvdb->processReleases();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process releases without a proper name and try to look it up in the nfo
|
||||
*/
|
||||
public function processOtherMiscCategory($numToProcess = 10)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$res = $db->query(sprintf("select r.searchname, r.ID, r.guid, g.name as groupname from releases r inner join releasenfo rn on rn.releaseID = r.ID left join groups g on g.ID = r.groupID where (r.categoryID = %d or r.categoryID = %d) order by r.ID desc limit %d", Category::CAT_MISC, Category::CAT_NOT_DETERMINED, $numToProcess));
|
||||
|
||||
if ($res)
|
||||
{
|
||||
$rescount = sizeof($res);
|
||||
|
||||
if ($this->echooutput)
|
||||
echo "PostPrc : Attempting to categorise ".$rescount." Other-Misc releases\n";
|
||||
|
||||
foreach($res as $rel)
|
||||
{
|
||||
$filenameRes = $db->query(sprintf("select dirname from predb where filename = %s limit 2", $db->escapeString($rel['searchname'])));
|
||||
if (count($filenameRes) == 1)
|
||||
$foundName = $filenameRes[0]['dirname'];
|
||||
else
|
||||
{
|
||||
$nfoRes = $db->queryOneRow(sprintf("select uncompress(nfo) as nfo from releasenfo where releaseID = %d", $rel['ID']));
|
||||
$nfo = $nfoRes['nfo'];
|
||||
|
||||
$foundName = '';
|
||||
//Typical scene regex
|
||||
if (preg_match('/(?P<source>Source\s*?:|fix fornuke)?(?:\s|\]|\[)?(?P<name>[a-z0-9\']+(?:\.|_)[a-z0-9\.\-_\'&]+\-[a-z0-9&]+)(?:\s|\[|\])/i', $nfo, $matches))
|
||||
{
|
||||
if (empty($matches['source']))
|
||||
$foundName = $matches['name'];
|
||||
}
|
||||
//IMAGiNE releases
|
||||
elseif(preg_match('/\*\s+([a-z0-9]+(?:\.|_| )[a-z0-9\.\_\- ]+ \- imagine)\s+\*/i', $nfo, $matches))
|
||||
{
|
||||
$foundName = $matches[1];
|
||||
}
|
||||
//SANTi releases
|
||||
elseif(preg_match('/\b([a-z0-9]+(?:\.|_| )[a-z0-9\.\_\- \']+\-santi)\b/i', $nfo, $matches))
|
||||
{
|
||||
$foundName = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($foundName != '')
|
||||
{
|
||||
$category = new Category();
|
||||
$categoryID = $category->determineCategory($rel['groupname'], $foundName);
|
||||
$name = str_replace(' ', '_', $foundName);
|
||||
$searchname = str_replace('_', ' ', $foundName);
|
||||
|
||||
$db->query(sprintf("UPDATE releases SET name = %s, searchname = %s, categoryID = %d WHERE ID = %d", $db->escapeString($name), $db->escapeString($searchname), $categoryID, $rel['ID']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for passworded releases, RAR contents and Sample/Media info
|
||||
*/
|
||||
public function processAdditional3()
|
||||
{
|
||||
require_once(WWW_DIR."/lib/nntp.php");
|
||||
|
||||
$maxattemptstocheckpassworded = 5;
|
||||
$numtoProcess = 100;
|
||||
$processVideoSample = ($this->site->ffmpegpath != '') ? true : false;
|
||||
$processMediainfo = ($this->site->mediainfopath != '') ? true : false;
|
||||
$processPasswords = ($this->site->unrarpath != '') ? true : false;
|
||||
$processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false;
|
||||
|
||||
$tmpPath = $this->site->tmpunrarpath;
|
||||
$tmpPath .= '3';
|
||||
if (substr($tmpPath, -strlen( '/' ) ) != '/')
|
||||
{
|
||||
$tmpPath = $tmpPath.'/';
|
||||
}
|
||||
|
||||
if (!file_exists($tmpPath))
|
||||
mkdir($tmpPath, 0766, true);
|
||||
|
||||
$db = new DB;
|
||||
$nntp = new Nntp;
|
||||
$nzb = new Nzb;
|
||||
|
||||
//
|
||||
// Get out all releases which have not been checked more than max attempts for password.
|
||||
//
|
||||
$result = $db->query(sprintf("select r.ID, r.guid, r.name, c.disablepreview from releases r
|
||||
left join category c on c.ID = r.categoryID
|
||||
where (r.passwordstatus between %d and -1)
|
||||
or (r.haspreview = -1 and c.disablepreview = 0) order by r.guid asc limit %d ", ($maxattemptstocheckpassworded + 1) * -1, $numtoProcess));
|
||||
|
||||
$iteration = $rescount = sizeof($result);
|
||||
if ($rescount > 0)
|
||||
{
|
||||
echo "Post processing by guid inversly on ".$rescount." releases ...";
|
||||
$nntpconnected = false;
|
||||
|
||||
foreach ($result as $rel)
|
||||
{
|
||||
echo $iteration--.".";
|
||||
|
||||
// Per release defaults
|
||||
$passStatus = array(Releases::PASSWD_NONE);
|
||||
$blnTookMediainfo = false;
|
||||
$blnTookSample = ($rel['disablepreview'] == 1) ? true : false; //only attempt sample if not disabled
|
||||
|
||||
if ($blnTookSample)
|
||||
$db->query(sprintf("update releases set haspreview = 0 where id = %d", $rel['ID']));
|
||||
|
||||
//
|
||||
// Go through the binaries for this release looking for a rar, a sample, and a mediafile
|
||||
//
|
||||
$nzbInfo = new nzbInfo;
|
||||
$nzbfile = $nzb->getNZBPath($rel['guid'], $this->site->nzbpath);
|
||||
if (!$nzbInfo->loadFromFile($nzbfile))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$norar = 0;
|
||||
|
||||
foreach($nzbInfo->nzb as $nzbsubject)
|
||||
{
|
||||
if (preg_match("/\w\.r00/i", $nzbsubject['subject']))
|
||||
$norar= 1;
|
||||
}
|
||||
|
||||
// attempt to process video sample file
|
||||
if(!empty($nzbInfo->samplefiles) && $processVideoSample && $blnTookSample === false)
|
||||
{
|
||||
$sampleFile = $nzbInfo->samplefiles[0]; //first detected sample
|
||||
$sampleMsgids = array_slice($sampleFile['segments'], 0, 1); //get first segment, increase to get more of the sample
|
||||
$sampleGroup = $sampleFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($sampleMsgids, ', ')." from {$sampleGroup}\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
|
||||
$sampleBinary = $nntp->getMessages($sampleGroup, $sampleMsgids);
|
||||
if ($sampleBinary === false)
|
||||
echo "\nPostPrc : Couldnt fetch sample\n";
|
||||
else
|
||||
{
|
||||
$samplefile = $tmpPath.'sample.avi';
|
||||
|
||||
file_put_contents($samplefile, $sampleBinary);
|
||||
|
||||
$blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
$this->updateReleaseHasPreview($rel['guid']);
|
||||
|
||||
unlink($samplefile);
|
||||
}
|
||||
unset($sampleBinary);
|
||||
}
|
||||
|
||||
// attempt to process loose media file
|
||||
if(!empty($nzbInfo->mediafiles) && (($processVideoSample && $blnTookSample === false) || $processMediainfo))
|
||||
{
|
||||
$mediaFile = $nzbInfo->mediafiles[0]; //first detected media file
|
||||
$mediaMsgids = array_slice($mediaFile['segments'], 0, 2); //get first two segments
|
||||
$mediaGroup = $mediaFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($mediaMsgids, ', ')." from {$mediaGroup}\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
$mediaBinary = $nntp->getMessages($mediaGroup, $mediaMsgids);
|
||||
if ($mediaBinary === false)
|
||||
echo "\nPostPrc : Couldnt fetch media file\n";
|
||||
else
|
||||
{
|
||||
$mediafile = $tmpPath.'sample.avi';
|
||||
|
||||
file_put_contents($mediafile, $mediaBinary);
|
||||
|
||||
if ($processVideoSample && $blnTookSample === false)
|
||||
{
|
||||
$blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
$this->updateReleaseHasPreview($rel['guid']);
|
||||
}
|
||||
|
||||
if ($processMediainfo)
|
||||
$blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']);
|
||||
|
||||
unlink($mediafile);
|
||||
}
|
||||
unset($mediaBinary);
|
||||
}
|
||||
|
||||
// attempt to process audio sample file
|
||||
if(!empty($nzbInfo->audiofiles) && $processAudioSample && $blnTookSample === false)
|
||||
{
|
||||
$audioFile = $nzbInfo->audiofiles[0]; //first detected audio file
|
||||
$audioMsgids = array_slice($audioFile['segments'], 0, 1); //get first segment
|
||||
$audioGroup = $audioFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($audioMsgids, ', ')." from {$audioGroup}\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
$audioBinary = $nntp->getMessages($audioGroup, $audioMsgids);
|
||||
if ($audioBinary === false)
|
||||
echo "\nPostPrc : Couldnt fetch audio sample\n";
|
||||
else
|
||||
{
|
||||
$audiofile = $tmpPath.'sample.mp3';
|
||||
|
||||
file_put_contents($audiofile, $audioBinary);
|
||||
|
||||
$blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']);
|
||||
if ($blnTookSample !== false)
|
||||
$this->updateReleaseHasPreview($rel['guid'], 2);
|
||||
|
||||
if ($processMediainfo)
|
||||
$blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']);
|
||||
|
||||
if ($this->site->lamepath != "")
|
||||
$this->lameAudioSample($this->site->lamepath, $rel['guid']);
|
||||
|
||||
unlink($audiofile);
|
||||
}
|
||||
unset($audioBinary);
|
||||
}
|
||||
|
||||
if (!empty($nzbInfo->rarfiles) && ($this->site->checkpasswordedrar > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo))
|
||||
{
|
||||
$mysqlkeepalive = 0;
|
||||
foreach($nzbInfo->rarfiles as $rarFile)
|
||||
{
|
||||
//dont process any more rars if a passworded rar has been detected and the site is set to automatically delete them
|
||||
if ($this->site->deletepasswordedrelease == 1 && max($passStatus) == Releases::PASSWD_RAR)
|
||||
{
|
||||
echo "-Skipping processing of rar {$rarFile['subject']} as this release has already been marked as passworded.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$rarMsgids = array_slice($rarFile['segments'], 0, 1); //get first segment
|
||||
$rarGroup = $rarFile['groups'][0];
|
||||
|
||||
//echo "PostPrc : Fetching ".implode($rarMsgids, ', ')." from {$rarGroup} (".++$mysqlkeepalive.")\n";
|
||||
if (!$nntpconnected)
|
||||
{
|
||||
$nntp->doConnect();
|
||||
$nntpconnected = true;
|
||||
}
|
||||
$fetchedBinary = $nntp->getMessages($rarGroup, $rarMsgids);
|
||||
if ($fetchedBinary === false)
|
||||
{
|
||||
echo "\nPostPrc : Failed fetching rar file\n";
|
||||
$db->query(sprintf("update releases set passwordstatus = passwordstatus - 1 where ID = %d", $rel['ID']));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
$relFiles = $this->processReleaseFiles($fetchedBinary, $rel['ID']);
|
||||
|
||||
if ($this->site->checkpasswordedrar > 0 && $processPasswords)
|
||||
{
|
||||
$passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->site->unrarpath, $this->site->checkpasswordedrar);
|
||||
}
|
||||
|
||||
// we need to unrar the fetched binary if checkpasswordedrar wasnt 2
|
||||
if ($this->site->checkpasswordedrar < 2 && $processPasswords)
|
||||
{
|
||||
$rarfile = $tmpPath.'rarfile.rar';
|
||||
file_put_contents($rarfile, $fetchedBinary);
|
||||
$execstring = '"'.$this->site->unrarpath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$rarfile.'" "'.$tmpPath.'"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
unlink($rarfile);
|
||||
}
|
||||
|
||||
if ($processVideoSample && $blnTookSample === false)
|
||||
{
|
||||
$blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
$this->updateReleaseHasPreview($rel['guid']);
|
||||
}
|
||||
|
||||
$blnTookAudioSample = false;
|
||||
if ($processAudioSample && $blnTookSample === false)
|
||||
{
|
||||
$blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']);
|
||||
if ($blnTookSample)
|
||||
{
|
||||
$blnTookAudioSample = true;
|
||||
$this->updateReleaseHasPreview($rel['guid'], 2);
|
||||
}
|
||||
}
|
||||
|
||||
if ($processMediainfo && $blnTookMediainfo === false)
|
||||
{
|
||||
$blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']);
|
||||
}
|
||||
|
||||
//
|
||||
// Has to be done after mediainfo
|
||||
//
|
||||
if ($blnTookAudioSample && $this->site->lamepath != "")
|
||||
$this->lameAudioSample($this->site->lamepath, $rel['guid']);
|
||||
|
||||
if ($mysqlkeepalive % 25 == 0)
|
||||
$db->query("select 1");
|
||||
}
|
||||
|
||||
//clean up all files
|
||||
foreach(glob($tmpPath.'*') as $v)
|
||||
{
|
||||
unlink($v);
|
||||
}
|
||||
|
||||
} //end foreach msgid
|
||||
}
|
||||
elseif(empty($nzbInfo->rarfiles) && $norar == 1)
|
||||
{
|
||||
$passStatus[] = Releases::PASSWD_POTENTIAL;
|
||||
}
|
||||
|
||||
$hpsql = '';
|
||||
if (!$blnTookSample)
|
||||
$hpsql = ', haspreview = 0';
|
||||
|
||||
$sql = sprintf("update releases set passwordstatus = %d %s where ID = %d", max($passStatus), $hpsql, $rel["ID"]);
|
||||
$db->query($sql);
|
||||
|
||||
} //end foreach result
|
||||
|
||||
if ($nntpconnected)
|
||||
{
|
||||
$nntp->doQuit();
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out all files contained inside a rar
|
||||
*/
|
||||
public function processReleaseFiles($fetchedBinary, $relid)
|
||||
{
|
||||
$retval = array();
|
||||
$rar = new RarInfo;
|
||||
$rf = new ReleaseFiles;
|
||||
$db = new DB;
|
||||
|
||||
if ($rar->setData($fetchedBinary))
|
||||
{
|
||||
$files = $rar->getFileList();
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$rf->add($relid, $file['name'], $file['size'], $file['date'], $file['pass'] );
|
||||
$retval[] = $file['name'];
|
||||
}
|
||||
|
||||
}
|
||||
unset($fetchedBinary);
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out if a release is passworded
|
||||
*/
|
||||
public function processReleasePasswords($fetchedBinary, $tmpPath, $unrarPath, $checkpasswordedrar)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_NONE;
|
||||
$potentiallypasswordedfileregex = "/\.(ace|cab|tar|gz)$/i";
|
||||
$definetlypasswordedfileregex = "/password/i";
|
||||
$rar = new RarInfo;
|
||||
$filecount = 0;
|
||||
|
||||
$rarfile = $tmpPath.'rarfile.rar';
|
||||
file_put_contents($rarfile, $fetchedBinary);
|
||||
|
||||
if ($rar->open($rarfile))
|
||||
{
|
||||
if ($rar->isEncrypted)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_RAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
$files = $rar->getFileList(true);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filecount++;
|
||||
//
|
||||
// individual file rar passworded
|
||||
//
|
||||
if ($file['pass'] == 1 || preg_match($definetlypasswordedfileregex, $file["name"]))
|
||||
{
|
||||
$passStatus = Releases::PASSWD_RAR;
|
||||
}
|
||||
|
||||
//
|
||||
// individual file looks suspect
|
||||
//
|
||||
elseif (preg_match($potentiallypasswordedfileregex, $file["name"]) && $passStatus != Releases::PASSWD_RAR)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_POTENTIAL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Deep Checking
|
||||
//
|
||||
if ($checkpasswordedrar == 2)
|
||||
{
|
||||
|
||||
$israr = $this->isRar($rarfile);
|
||||
for ($i=0;$i<sizeof($israr);$i++)
|
||||
{
|
||||
if (preg_match('/\\\\/',$israr[$i]))
|
||||
{
|
||||
$israr[$i] = ltrim((strrchr($israr[$i],"\\")),"\\");
|
||||
}
|
||||
}
|
||||
|
||||
$execstring = '"'.$unrarPath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$rarfile.'" "'.$tmpPath.'"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
|
||||
// delete the rar
|
||||
unlink($rarfile);
|
||||
|
||||
// ok, now we have all the files extracted from the rar into the tempdir and
|
||||
// the rar file deleted, now to loop through the files and recursively unrar
|
||||
// if any of those are rars, we don't trust their names and we test every file
|
||||
// for the rar header
|
||||
for ($i=0;$i<sizeof($israr);$i++)
|
||||
{
|
||||
// even though its in the rar filelist there may not have been enough data
|
||||
// to extract this file so dont attempt to read the file if it doesnt exist
|
||||
if (!file_exists($tmpPath.$israr[$i]))
|
||||
continue;
|
||||
|
||||
$tmp = $this->isRar($tmpPath.$israr[$i]);
|
||||
|
||||
if (is_array($tmp))
|
||||
// it's a rar
|
||||
{
|
||||
for ($x=0;$x<sizeof($tmp);$x++)
|
||||
{
|
||||
if (preg_match('/\\\\/',$tmp[$x]))
|
||||
{
|
||||
$tmp[$x] = ltrim((strrchr($tmp[$x],"\\")),"\\");
|
||||
}
|
||||
$israr[] = $tmp[$x];
|
||||
}
|
||||
|
||||
$execstring = '"'.$unrarPath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$tmpPath.$israr[$i].'" "'.$tmpPath.'"';
|
||||
$output2 = runCmd($execstring, false, true);
|
||||
unlink($tmpPath.$israr[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($tmp == 1 || $tmp == 2)
|
||||
{
|
||||
$passStatus = Releases::PASSWD_RAR;
|
||||
unlink($tmpPath.$israr[$i]);
|
||||
}
|
||||
}
|
||||
unset($tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@unlink($rarfile);
|
||||
unset($fetchedBinary);
|
||||
return $passStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out if a rar is passworded
|
||||
*/
|
||||
public function isRar($rarfile)
|
||||
{
|
||||
// returns 0 if not rar
|
||||
// returns 1 if encrypted rar
|
||||
// returns 2 if passworded rar
|
||||
// returns array of files in the rar if normal rar
|
||||
unset($filelist);
|
||||
$rar = new RarInfo;
|
||||
if ($rar->open($rarfile))
|
||||
{
|
||||
if ($rar->isEncrypted)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$files = $rar->getFileList(true);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filelist[] = $file['name'];
|
||||
if ($file['pass'] == true)
|
||||
//
|
||||
// individual file rar passworded
|
||||
//
|
||||
{
|
||||
return 2;
|
||||
// passworded
|
||||
}
|
||||
}
|
||||
return ($filelist);
|
||||
// normal rar
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
// not a rar
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out all files contained inside a rar
|
||||
*/
|
||||
public function getMediainfo($ramdrive,$mediainfo,$releaseID)
|
||||
{
|
||||
$retval = false;
|
||||
$mediafiles = glob($ramdrive.'*.*');
|
||||
if (is_array($mediafiles))
|
||||
{
|
||||
foreach($mediafiles as $mediafile)
|
||||
{
|
||||
if (preg_match("/\.(".$this->mediafileregex.'|'.$this->audiofileregex.")$/i",$mediafile))
|
||||
{
|
||||
$execstring = '"'.$mediainfo.'" --Output=XML "'.$mediafile.'"';
|
||||
$xmlarray = runCmd($execstring);
|
||||
|
||||
if (is_array($xmlarray))
|
||||
{
|
||||
$xmlarray = implode("\n",$xmlarray);
|
||||
$re = new ReleaseExtra();
|
||||
$re->addFull($releaseID,$xmlarray);
|
||||
$re->addFromXml($releaseID,$xmlarray);
|
||||
$retval = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc : Failed to process mediainfo for ".$mediafile." release (".$releaseID.")\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n";
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sample from a release using ffmpeg
|
||||
*/
|
||||
public function getSample($ramdrive, $ffmpeginfo, $releaseguid)
|
||||
{
|
||||
$ri = new ReleaseImage();
|
||||
$retval = false;
|
||||
|
||||
$samplefiles = glob($ramdrive.'*.*');
|
||||
if (is_array($samplefiles))
|
||||
{
|
||||
foreach($samplefiles as $samplefile)
|
||||
{
|
||||
if (preg_match("/\.(".$this->mediafileregex.")$/i",$samplefile))
|
||||
{
|
||||
$execstring = '"'.$ffmpeginfo.'" -q:v 0 -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
$all_files = scandir($ramdrive,1);
|
||||
if(preg_match("/zzzz\d{3}\.jpg/",$all_files[1]))
|
||||
{
|
||||
$ri->saveImage($releaseguid.'_thumb', $ramdrive.$all_files[1], $ri->imgSavePath, 800, 600);
|
||||
$retval = true;
|
||||
}
|
||||
|
||||
//clean up all files
|
||||
foreach(glob($ramdrive.'*.jpg') as $v)
|
||||
{
|
||||
unlink($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n";
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has to be performed after mediainfo, as lame strips id3 tags.
|
||||
*/
|
||||
public function lameAudioSample($lameinfo, $releaseguid)
|
||||
{
|
||||
$minacceptableencodefilesize = 10000;
|
||||
$samplefile = $this->mp3SavePath.$releaseguid.'.mp3';
|
||||
|
||||
if (file_exists($samplefile))
|
||||
{
|
||||
$outfile = $this->mp3SavePath.$releaseguid.'_l.mp3';
|
||||
|
||||
//
|
||||
// lame the sample down to 96kb and replace it. alternatives could be
|
||||
// V8 for low quality variable.
|
||||
//
|
||||
$execstring = '"'.$lameinfo.'" -b 96 "'.$samplefile.'" "'.$outfile.'"';
|
||||
$output = runCmd($execstring, false, true);
|
||||
|
||||
//
|
||||
// lame can create bad/small files if the source was corrupt
|
||||
// if it creates a file thats surprisingly small, then ignore it and retain
|
||||
// original
|
||||
//
|
||||
if (file_exists($outfile))
|
||||
{
|
||||
if (filesize($outfile) < $minacceptableencodefilesize)
|
||||
unlink($outfile);
|
||||
else
|
||||
{
|
||||
unlink($samplefile);
|
||||
rename($outfile, $samplefile);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an audio sample from a release.
|
||||
*/
|
||||
public function getAudioSample($ramdrive, $releaseguid)
|
||||
{
|
||||
$retval = false;
|
||||
|
||||
$audiofiles = glob($ramdrive.'*.*');
|
||||
if (is_array($audiofiles))
|
||||
{
|
||||
foreach($audiofiles as $audiofile)
|
||||
{
|
||||
if (preg_match("/\.(".$this->audiofileregex.")$/i",$audiofile))
|
||||
{
|
||||
if (copy($audiofile, $this->mp3SavePath.$releaseguid.'.mp3') !== false)
|
||||
$retval = true;
|
||||
else
|
||||
echo "PostPrc : Failed to get audio sample from ".$audiofile."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n";
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an audio sample from a release.
|
||||
*/
|
||||
public function deleteAudioSample($releaseguid)
|
||||
{
|
||||
$preview = $this->mp3SavePath.$releaseguid.'.mp3';
|
||||
if (file_exists($preview))
|
||||
unlink($preview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update release to indicate a preview has been obtained.
|
||||
*/
|
||||
public function updateReleaseHasPreview($guid, $prevtype=1)
|
||||
{
|
||||
$rel = new Releases;
|
||||
$rel->updateHasPreview($guid, $prevtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process untagged music releases using information from mediainfo if config permits.
|
||||
*/
|
||||
public function processMusicFromMediaInfo()
|
||||
{
|
||||
$processMediainfo = ($this->site->mediainfopath != '') ? true : false;
|
||||
$processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false;
|
||||
$processMusic = ($this->site->lookupmusic == 1) ? true : false;
|
||||
|
||||
if ($processMusic && $processMediainfo && $processAudioSample)
|
||||
{
|
||||
$music = new Music($this->echooutput);
|
||||
$ret = $music->processMusicReleaseFromMediaInfo();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,331 +0,0 @@
|
||||
<?php
|
||||
require_once(WWW_DIR."/lib/util.php");
|
||||
require_once(WWW_DIR."/lib/framework/db.php");
|
||||
require_once("postprocess2.php");
|
||||
require_once(WWW_DIR."/lib/episode.php");
|
||||
require_once(WWW_DIR."/lib/category.php");
|
||||
|
||||
|
||||
class TheTVDB2
|
||||
{
|
||||
const PROJECT = 'newznab';
|
||||
const APIKEY = '5F84ECB91B42D719';
|
||||
|
||||
public function TheTVDB($echooutput=true)
|
||||
{
|
||||
$this->echooutput = $echooutput;
|
||||
$this->MIRROR = 'http://www.thetvdb.com';
|
||||
}
|
||||
|
||||
public function addSeries($TheTVDBAPIArray)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->queryInsert(sprintf("INSERT INTO thetvdb
|
||||
(tvdbID, actors, airsday, airstime, contentrating, firstaired, genre, imdbID, network, overview, rating, ratingcount, runtime, seriesname, status, createddate)
|
||||
VALUES (%d, %s, %s, %s, %s, %s, %s, %d, %s, %s, %F, %d, %d, %s, %s, now())",
|
||||
$TheTVDBAPIArray['tvdbID'], $db->escapeString($TheTVDBAPIArray['actors']), $db->escapeString($TheTVDBAPIArray['airsday']),
|
||||
$db->escapeString($TheTVDBAPIArray['airstime']), $db->escapeString($TheTVDBAPIArray['contentrating']), $db->escapeString($TheTVDBAPIArray['firstaired']),
|
||||
$db->escapeString($TheTVDBAPIArray['genre']), $TheTVDBAPIArray['imdbID'], $db->escapeString($TheTVDBAPIArray['network']), $db->escapeString($TheTVDBAPIArray['overview']),
|
||||
$db->escapeString($TheTVDBAPIArray['rating']), $TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $db->escapeString($TheTVDBAPIArray['seriesname']),
|
||||
$db->escapeString($TheTVDBAPIArray['status'])));
|
||||
}
|
||||
|
||||
public function addEpisodes($TheTVDBAPIArray)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
for($i=0; $i < count($TheTVDBAPIArray['episodetvdbID']); $i++) {
|
||||
$airdate = strftime('%Y-%m-%d %H:%M:%S', strtotime($TheTVDBAPIArray['episodefirstaired'][$i].' '.$TheTVDBAPIArray['airstime']));
|
||||
if(!$airdate)
|
||||
continue;
|
||||
|
||||
$db->queryInsert(sprintf('INSERT INTO episodeinfo
|
||||
(tvdbID, imdbID, showtitle, airdate, fullep, eptitle, director, gueststars, overview, rating, writer, epabsolute)
|
||||
VALUES (%d, %d, %s, %s, %s, %s, %s, %s, %s, %F, %s, %d)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
tvdbID=%1$d, imdbID=%2$d, showtitle=%3$s, airdate=%4$s, fullep=%5$s, eptitle=%6$s, director=%7$s,
|
||||
gueststars=%8$s, overview=%9$s, rating=%10$F, writer=%11$s, epabsolute=%12$s',
|
||||
$TheTVDBAPIArray['episodetvdbID'][$i], $TheTVDBAPIArray['episodeimdbID'][$i], $db->escapeString($TheTVDBAPIArray['seriesname']), $db->escapeString($airdate),
|
||||
$db->escapeString(str_pad($TheTVDBAPIArray['episodeseason'][$i], 2, '0', STR_PAD_LEFT).'x'.str_pad($TheTVDBAPIArray['episodenumber'][$i], 2, '0', STR_PAD_LEFT)),
|
||||
$db->escapeString($TheTVDBAPIArray['episodename'][$i]), $db->escapeString($TheTVDBAPIArray['episodedirector'][$i]),
|
||||
$db->escapeString($TheTVDBAPIArray['episodegueststars'][$i]), $db->escapeString($TheTVDBAPIArray['episodeoverview'][$i]),
|
||||
$TheTVDBAPIArray['episoderating'][$i], $db->escapeString($TheTVDBAPIArray['episodewriter'][$i]), $TheTVDBAPIArray['episodeabsolutenumber'][$i]));
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSeries($tvdbID, $actors, $airsday, $airstime, $contentrating, $firstaired, $genre, $imdbID, $network, $overview, $rating, $ratingcount, $runtime, $seriesname, $status)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->query(sprintf('UPDATE thetvdb
|
||||
SET actors=%s, airsday=%s, airstime=%s, contentrating=%s, firstaired=%s, genre=%s, imdbID=%d, network=%s,
|
||||
overview=%s, rating=%s, ratingcount=%d, runtime=%d, seriesname=%s, status=%s, createddate=now()
|
||||
WHERE tvdbID = %d', $db->escapeString($actors), $db->escapeString($airsday), $db->escapeString($airstime), $db->escapeString($contentrating),
|
||||
$db->escapeString($firstaired), $db->escapeString($genre), $imdbID, $db->escapeString($network), $db->escapeString($overview), $db->escapeString($rating),
|
||||
$ratingcount, $runtime, $db->escapeString($seriesname), $db->escapeString($status), $tvdbID));
|
||||
}
|
||||
|
||||
public function deleteTitle($tvdbID)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->query(sprintf("DELETE FROM thetvdb WHERE tvdbID = %d", $tvdbID));
|
||||
}
|
||||
|
||||
public function addEmptySeries($seriesname)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->queryInsert(sprintf("INSERT INTO thetvdb (tvdbID, seriesname, createddate) VALUES (0, %s, now())", $db->escapeString($seriesname)));
|
||||
}
|
||||
|
||||
public function getSeriesInfoByID($tvdbID)
|
||||
{
|
||||
$db = new DB();
|
||||
return $db->queryOneRow(sprintf("SELECT * FROM thetvdb WHERE tvdbID = %d", $tvdbID));
|
||||
}
|
||||
|
||||
public function getSeriesInfoByName($seriesname)
|
||||
{
|
||||
$db = new DB();
|
||||
return $db->queryOneRow(sprintf("SELECT * FROM thetvdb WHERE seriesname = %s", $db->escapeString($seriesname)));
|
||||
}
|
||||
|
||||
public function getSeriesRange($start, $num, $seriesname='')
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$limit = ($start === false) ? '' : " LIMIT ".$start.",".$num;
|
||||
|
||||
$rsql = '';
|
||||
if ($seriesname != '')
|
||||
$rsql .= sprintf("AND thetvdb.seriesname LIKE %s ", $db->escapeString("%".$seriesname."%"));
|
||||
|
||||
return $db->query(sprintf(" SELECT ID, tvdbID, seriesname, overview FROM thetvdb WHERE 1=1 %s AND tvdbID > %d ORDER BY tvdbID ASC".$limit, $rsql, 0));
|
||||
}
|
||||
|
||||
public function getSeriesCount($seriesname='')
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$rsql = '';
|
||||
if ($seriesname != '')
|
||||
$rsql .= sprintf("AND thetvdb.seriesname LIKE %s ", $db->escapeString("%".$seriesname."%"));
|
||||
|
||||
$res = $db->queryOneRow(sprintf("SELECT count(ID) AS num FROM thetvdb WHERE 1=1 %s ", $rsql));
|
||||
|
||||
return $res["num"];
|
||||
}
|
||||
|
||||
public function lookupSeriesID($seriesname)
|
||||
{
|
||||
$apiresponse = getUrl($this->MIRROR.'/api/GetSeries.php?seriesname='.preg_replace('/\s+/', '+', $seriesname).'&language=all');
|
||||
|
||||
if(!$apiresponse)
|
||||
return false;
|
||||
|
||||
$seriesidXML = @simplexml_load_string($apiresponse);
|
||||
if(!$seriesidXML)
|
||||
return false;
|
||||
|
||||
$seriesid = 0;
|
||||
foreach($seriesidXML as $item)
|
||||
if(preg_match('/^'.preg_replace('/\+/', ' ', str_replace('/', '\/', $seriesname)).'$/i', (string) $item->SeriesName)) {
|
||||
$seriesid = (int) $item->seriesid;
|
||||
break;
|
||||
}
|
||||
|
||||
return $seriesid;
|
||||
}
|
||||
|
||||
public function notFound($seriesName, $fullep, $releaseID, $echooutput=true)
|
||||
{
|
||||
if($this->echooutput && $echooutput)
|
||||
echo 'TheTVDB : '.$seriesName.' '.$fullep." Not found\n";
|
||||
|
||||
$db = new DB();
|
||||
$db->query(sprintf('UPDATE releases SET episodeinfoID = %d WHERE ID = %d', -2, $releaseID));
|
||||
}
|
||||
|
||||
public function processReleases()
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$results = $db->queryDirect(sprintf("SELECT ID, searchname, rageID, anidbID, seriesfull, season, episode, tvtitle FROM releases WHERE episodeinfoID IS NULL AND categoryID IN ( SELECT ID FROM category WHERE parentID = %d ) LIMIT 150", Category::CAT_PARENT_TV));
|
||||
|
||||
if (mysql_num_rows($results) > 0)
|
||||
{
|
||||
if ($this->echooutput)
|
||||
echo "TheTVDB : Looking up last ".mysql_num_rows($results)." releases\n";
|
||||
|
||||
while ($arr = mysql_fetch_assoc($results))
|
||||
{
|
||||
unset($TheTVDBAPIArray, $episodeArray, $fullep, $epabsolute, $additionalSql);
|
||||
|
||||
$seriesName = '';
|
||||
if($arr['rageID'] > 0) {
|
||||
$seriesName = $db->queryOneRow(sprintf('SELECT releasetitle AS seriesName FROM tvrage WHERE rageID = %d', $arr['rageID']));
|
||||
}
|
||||
elseif($arr['anidbID'] > 0) {
|
||||
$seriesName = $db->queryOneRow(sprintf('SELECT title AS seriesName FROM anidb WHERE anidbID = %d', $arr['anidbID']));
|
||||
}
|
||||
|
||||
if(empty($seriesName) || !$seriesName)
|
||||
{
|
||||
$this->notFound($seriesName, "", $arr['ID'], false);
|
||||
continue;
|
||||
}
|
||||
|
||||
$seriesName = str_replace('`', '\'', $seriesName['seriesName']);
|
||||
if(!preg_match('/[21]\d{3}\/\d{2}\/\d{2}/', $arr['seriesfull']))
|
||||
$fullep = str_pad(str_replace('S', '', $arr['season']), 2, '0', STR_PAD_LEFT).'x'.str_pad(str_replace('E', '', $arr['episode']), 2, '0', STR_PAD_LEFT);
|
||||
else
|
||||
$fullep = str_replace('/', '-', $arr['seriesfull']);
|
||||
|
||||
$TheTVDBAPIArray = $this->getSeriesInfoByName($seriesName);
|
||||
if(!$TheTVDBAPIArray)
|
||||
{
|
||||
$seriesid = $this->lookupSeriesID($seriesName);
|
||||
if($seriesid > 0)
|
||||
{
|
||||
if($TheTVDBAPIArray = $this->TheTVDBAPI($seriesid, $seriesName))
|
||||
{
|
||||
$this->addSeries($TheTVDBAPIArray);
|
||||
$this->addEpisodes($TheTVDBAPIArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addEmptySeries($seriesName);
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addEmptySeries($seriesName);
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if($TheTVDBAPIArray['tvdbID'] >= 0 && ((time() - strtotime($TheTVDBAPIArray['createddate'])) > 604800))
|
||||
{
|
||||
$TheTVDBAPIArray = $this->TheTVDBAPI($TheTVDBAPIArray['tvdbID'], $seriesName);
|
||||
|
||||
$this->updateSeries($TheTVDBAPIArray['tvdbID'], $TheTVDBAPIArray['actors'], $TheTVDBAPIArray['airsday'],
|
||||
$TheTVDBAPIArray['airstime'], $TheTVDBAPIArray['contentrating'], $TheTVDBAPIArray['firstaired'], $TheTVDBAPIArray['genre'],
|
||||
$TheTVDBAPIArray['imdbID'], $TheTVDBAPIArray['network'], $TheTVDBAPIArray['overview'], $TheTVDBAPIArray['rating'],
|
||||
$TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $TheTVDBAPIArray['seriesname'], $TheTVDBAPIArray['status']);
|
||||
|
||||
$this->addEpisodes($TheTVDBAPIArray);
|
||||
}
|
||||
|
||||
if($TheTVDBAPIArray['tvdbID'] > 0)
|
||||
{
|
||||
$epabsolute = '0';
|
||||
if($arr['anidbID'] > 0)
|
||||
{
|
||||
if(preg_match('/S(?P<season>\d+)[ED](?P<episode>\d+)/', $arr['episode'], $seasonEpisode))
|
||||
{
|
||||
$arr['season'] = $seasonEpisode['season'];
|
||||
$arr['episode'] = $seasonEpisode['episode'];
|
||||
}
|
||||
else
|
||||
$epabsolute = $arr['episode'];
|
||||
}
|
||||
|
||||
$Episode = new Episode();
|
||||
$episodeArray = $Episode->getEpisodeInfoByName($seriesName, $fullep, (string) $epabsolute);
|
||||
if(!$episodeArray)
|
||||
{
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$additionalSql = '';
|
||||
if($arr['anidbID'] > 0 && $episodeArray['epabsolute'] > 0)
|
||||
{
|
||||
$additionalSql = sprintf(', season = NULL, episode = %d, tvtitle = %s, tvairdate = %s',
|
||||
$episodeArray['epabsolute'],
|
||||
$db->escapeString($episodeArray['epabsolute'].' - '.str_replace('\'', '`', $episodeArray['eptitle'])),
|
||||
$db->escapeString($episodeArray['airdate']));
|
||||
}
|
||||
|
||||
$db->query(sprintf('UPDATE releases SET tvdbID = %d, episodeinfoID = %d %s WHERE ID = %d',
|
||||
$TheTVDBAPIArray['tvdbID'], $episodeArray['ID'], $additionalSql, $arr['ID']));
|
||||
|
||||
//if($this->echooutput)
|
||||
//{
|
||||
// echo 'TheTVDB : '.$seriesName.' '.$fullep." returned ".$episodeArray['tvdbID']."\n";
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function TheTVDBAPI($seriesid, $seriesName)
|
||||
{
|
||||
$apiresponse = getUrl($this->MIRROR.'/api/'.self::APIKEY.'/series/'.$seriesid.'/all/en.xml'); //.zip?
|
||||
|
||||
if(!$apiresponse)
|
||||
return false;
|
||||
|
||||
$TheTVDBAPIXML = @simplexml_load_string($apiresponse);
|
||||
if(!$TheTVDBAPIXML)
|
||||
return false;
|
||||
|
||||
foreach($TheTVDBAPIXML->Episode as $episode) {
|
||||
$episodetvdbIDArray[] = (int) $episode->id;
|
||||
$episodenumberArray[] = (int) $episode->Combined_episodenumber;
|
||||
$episodeseasonArray[] = (int) $episode->Combined_season;
|
||||
$episodedirectorArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Director);
|
||||
$episodenameArray[] = preg_replace('/^\||\|$/', '', (string) $episode->EpisodeName);
|
||||
$episodefirstairedArray[] = (string) $episode->FirstAired;
|
||||
$episodegueststarsArray[] = preg_replace('/^\||\|$/', '', (string) $episode->GuestStars);
|
||||
$episodeimdbID[] = str_replace('tt', '', (string) $episode->IMDB_ID);
|
||||
$episodeoverviewArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Overview);
|
||||
$episoderatingArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Rating);
|
||||
$episodewriterArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Writer);
|
||||
$episodeabsolutenumberArray[] = (int) $episode->absolute_number;
|
||||
}
|
||||
|
||||
$TheTVDBAPIArray = array(
|
||||
'tvdbID' => $seriesid,
|
||||
'actors' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Actors),
|
||||
'airsday' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Airs_DayOfWeek),
|
||||
'airstime' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Airs_Time),
|
||||
'contentrating' => (string) $TheTVDBAPIXML->Series->ContentRating,
|
||||
'firstaired' => (string) $TheTVDBAPIXML->Series->FirstAired,
|
||||
'genre' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Genre),
|
||||
'imdbID' => (int) preg_replace('/^[^\d]+/', '', (string) $TheTVDBAPIXML->Series->IMDB_ID),
|
||||
'network' => (string) $TheTVDBAPIXML->Series->Network,
|
||||
'overview' => (string) $TheTVDBAPIXML->Series->Overview,
|
||||
'rating' => (float) $TheTVDBAPIXML->Series->Rating,
|
||||
'ratingcount' => (int) $TheTVDBAPIXML->Series->RatingCount,
|
||||
'runtime' => (int) $TheTVDBAPIXML->Series->Runtime,
|
||||
//'seriesname' => ((string) $TheTVDBAPIXML->Series->SeriesName != '') ? (string) $TheTVDBAPIXML->Series->SeriesName : $seriesName,
|
||||
'seriesname' => $seriesName,
|
||||
'status' => (string) $TheTVDBAPIXML->Series->Status,
|
||||
'episodetvdbID' => isset($episodetvdbIDArray) ? $episodetvdbIDArray : array(),
|
||||
'episodenumber' => isset($episodenumberArray) ? $episodenumberArray : array(),
|
||||
'episodeseason' => isset($episodeseasonArray) ? $episodeseasonArray : array(),
|
||||
'episodedirector' => isset($episodedirectorArray) ? $episodedirectorArray : array(),
|
||||
'episodename' => isset($episodenameArray) ? $episodenameArray : array(),
|
||||
'episodefirstaired' => isset($episodefirstairedArray) ? $episodefirstairedArray : array(),
|
||||
'episodegueststars' => isset($episodegueststarsArray) ? $episodegueststarsArray : array(),
|
||||
'episodeimdbID' => isset($episodeimdbID) ? $episodeimdbID : array(),
|
||||
'episodeoverview' => isset($episodeoverviewArray) ? $episodeoverviewArray : array(),
|
||||
'episoderating' => isset($episoderatingArray) ? $episoderatingArray : array(),
|
||||
'episodewriter' => isset($episodewriterArray) ? $episodewriterArray : array(),
|
||||
'episodeabsolutenumber' => isset($episodeabsolutenumberArray) ? $episodeabsolutenumberArray : array(),
|
||||
);
|
||||
|
||||
return $TheTVDBAPIArray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,331 +0,0 @@
|
||||
<?php
|
||||
require_once(WWW_DIR."/lib/util.php");
|
||||
require_once(WWW_DIR."/lib/framework/db.php");
|
||||
require_once("postprocess3.php");
|
||||
require_once(WWW_DIR."/lib/episode.php");
|
||||
require_once(WWW_DIR."/lib/category.php");
|
||||
|
||||
|
||||
class TheTVDB3
|
||||
{
|
||||
const PROJECT = 'newznab';
|
||||
const APIKEY = '5F84ECB91B42D719';
|
||||
|
||||
public function TheTVDB($echooutput=true)
|
||||
{
|
||||
$this->echooutput = $echooutput;
|
||||
$this->MIRROR = 'http://www.thetvdb.com';
|
||||
}
|
||||
|
||||
public function addSeries($TheTVDBAPIArray)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->queryInsert(sprintf("INSERT INTO thetvdb
|
||||
(tvdbID, actors, airsday, airstime, contentrating, firstaired, genre, imdbID, network, overview, rating, ratingcount, runtime, seriesname, status, createddate)
|
||||
VALUES (%d, %s, %s, %s, %s, %s, %s, %d, %s, %s, %F, %d, %d, %s, %s, now())",
|
||||
$TheTVDBAPIArray['tvdbID'], $db->escapeString($TheTVDBAPIArray['actors']), $db->escapeString($TheTVDBAPIArray['airsday']),
|
||||
$db->escapeString($TheTVDBAPIArray['airstime']), $db->escapeString($TheTVDBAPIArray['contentrating']), $db->escapeString($TheTVDBAPIArray['firstaired']),
|
||||
$db->escapeString($TheTVDBAPIArray['genre']), $TheTVDBAPIArray['imdbID'], $db->escapeString($TheTVDBAPIArray['network']), $db->escapeString($TheTVDBAPIArray['overview']),
|
||||
$db->escapeString($TheTVDBAPIArray['rating']), $TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $db->escapeString($TheTVDBAPIArray['seriesname']),
|
||||
$db->escapeString($TheTVDBAPIArray['status'])));
|
||||
}
|
||||
|
||||
public function addEpisodes($TheTVDBAPIArray)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
for($i=0; $i < count($TheTVDBAPIArray['episodetvdbID']); $i++) {
|
||||
$airdate = strftime('%Y-%m-%d %H:%M:%S', strtotime($TheTVDBAPIArray['episodefirstaired'][$i].' '.$TheTVDBAPIArray['airstime']));
|
||||
if(!$airdate)
|
||||
continue;
|
||||
|
||||
$db->queryInsert(sprintf('INSERT INTO episodeinfo
|
||||
(tvdbID, imdbID, showtitle, airdate, fullep, eptitle, director, gueststars, overview, rating, writer, epabsolute)
|
||||
VALUES (%d, %d, %s, %s, %s, %s, %s, %s, %s, %F, %s, %d)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
tvdbID=%1$d, imdbID=%2$d, showtitle=%3$s, airdate=%4$s, fullep=%5$s, eptitle=%6$s, director=%7$s,
|
||||
gueststars=%8$s, overview=%9$s, rating=%10$F, writer=%11$s, epabsolute=%12$s',
|
||||
$TheTVDBAPIArray['episodetvdbID'][$i], $TheTVDBAPIArray['episodeimdbID'][$i], $db->escapeString($TheTVDBAPIArray['seriesname']), $db->escapeString($airdate),
|
||||
$db->escapeString(str_pad($TheTVDBAPIArray['episodeseason'][$i], 2, '0', STR_PAD_LEFT).'x'.str_pad($TheTVDBAPIArray['episodenumber'][$i], 2, '0', STR_PAD_LEFT)),
|
||||
$db->escapeString($TheTVDBAPIArray['episodename'][$i]), $db->escapeString($TheTVDBAPIArray['episodedirector'][$i]),
|
||||
$db->escapeString($TheTVDBAPIArray['episodegueststars'][$i]), $db->escapeString($TheTVDBAPIArray['episodeoverview'][$i]),
|
||||
$TheTVDBAPIArray['episoderating'][$i], $db->escapeString($TheTVDBAPIArray['episodewriter'][$i]), $TheTVDBAPIArray['episodeabsolutenumber'][$i]));
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSeries($tvdbID, $actors, $airsday, $airstime, $contentrating, $firstaired, $genre, $imdbID, $network, $overview, $rating, $ratingcount, $runtime, $seriesname, $status)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->query(sprintf('UPDATE thetvdb
|
||||
SET actors=%s, airsday=%s, airstime=%s, contentrating=%s, firstaired=%s, genre=%s, imdbID=%d, network=%s,
|
||||
overview=%s, rating=%s, ratingcount=%d, runtime=%d, seriesname=%s, status=%s, createddate=now()
|
||||
WHERE tvdbID = %d', $db->escapeString($actors), $db->escapeString($airsday), $db->escapeString($airstime), $db->escapeString($contentrating),
|
||||
$db->escapeString($firstaired), $db->escapeString($genre), $imdbID, $db->escapeString($network), $db->escapeString($overview), $db->escapeString($rating),
|
||||
$ratingcount, $runtime, $db->escapeString($seriesname), $db->escapeString($status), $tvdbID));
|
||||
}
|
||||
|
||||
public function deleteTitle($tvdbID)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->query(sprintf("DELETE FROM thetvdb WHERE tvdbID = %d", $tvdbID));
|
||||
}
|
||||
|
||||
public function addEmptySeries($seriesname)
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$db->queryInsert(sprintf("INSERT INTO thetvdb (tvdbID, seriesname, createddate) VALUES (0, %s, now())", $db->escapeString($seriesname)));
|
||||
}
|
||||
|
||||
public function getSeriesInfoByID($tvdbID)
|
||||
{
|
||||
$db = new DB();
|
||||
return $db->queryOneRow(sprintf("SELECT * FROM thetvdb WHERE tvdbID = %d", $tvdbID));
|
||||
}
|
||||
|
||||
public function getSeriesInfoByName($seriesname)
|
||||
{
|
||||
$db = new DB();
|
||||
return $db->queryOneRow(sprintf("SELECT * FROM thetvdb WHERE seriesname = %s", $db->escapeString($seriesname)));
|
||||
}
|
||||
|
||||
public function getSeriesRange($start, $num, $seriesname='')
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$limit = ($start === false) ? '' : " LIMIT ".$start.",".$num;
|
||||
|
||||
$rsql = '';
|
||||
if ($seriesname != '')
|
||||
$rsql .= sprintf("AND thetvdb.seriesname LIKE %s ", $db->escapeString("%".$seriesname."%"));
|
||||
|
||||
return $db->query(sprintf(" SELECT ID, tvdbID, seriesname, overview FROM thetvdb WHERE 1=1 %s AND tvdbID > %d ORDER BY tvdbID ASC".$limit, $rsql, 0));
|
||||
}
|
||||
|
||||
public function getSeriesCount($seriesname='')
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$rsql = '';
|
||||
if ($seriesname != '')
|
||||
$rsql .= sprintf("AND thetvdb.seriesname LIKE %s ", $db->escapeString("%".$seriesname."%"));
|
||||
|
||||
$res = $db->queryOneRow(sprintf("SELECT count(ID) AS num FROM thetvdb WHERE 1=1 %s ", $rsql));
|
||||
|
||||
return $res["num"];
|
||||
}
|
||||
|
||||
public function lookupSeriesID($seriesname)
|
||||
{
|
||||
$apiresponse = getUrl($this->MIRROR.'/api/GetSeries.php?seriesname='.preg_replace('/\s+/', '+', $seriesname).'&language=all');
|
||||
|
||||
if(!$apiresponse)
|
||||
return false;
|
||||
|
||||
$seriesidXML = @simplexml_load_string($apiresponse);
|
||||
if(!$seriesidXML)
|
||||
return false;
|
||||
|
||||
$seriesid = 0;
|
||||
foreach($seriesidXML as $item)
|
||||
if(preg_match('/^'.preg_replace('/\+/', ' ', str_replace('/', '\/', $seriesname)).'$/i', (string) $item->SeriesName)) {
|
||||
$seriesid = (int) $item->seriesid;
|
||||
break;
|
||||
}
|
||||
|
||||
return $seriesid;
|
||||
}
|
||||
|
||||
public function notFound($seriesName, $fullep, $releaseID, $echooutput=true)
|
||||
{
|
||||
if($this->echooutput && $echooutput)
|
||||
echo 'TheTVDB : '.$seriesName.' '.$fullep." Not found\n";
|
||||
|
||||
$db = new DB();
|
||||
$db->query(sprintf('UPDATE releases SET episodeinfoID = %d WHERE ID = %d', -2, $releaseID));
|
||||
}
|
||||
|
||||
public function processReleases()
|
||||
{
|
||||
$db = new DB();
|
||||
|
||||
$results = $db->queryDirect(sprintf("SELECT ID, searchname, rageID, anidbID, seriesfull, season, episode, tvtitle FROM releases WHERE episodeinfoID IS NULL AND categoryID IN ( SELECT ID FROM category WHERE parentID = %d ) LIMIT 150", Category::CAT_PARENT_TV));
|
||||
|
||||
if (mysql_num_rows($results) > 0)
|
||||
{
|
||||
if ($this->echooutput)
|
||||
echo "TheTVDB : Looking up last ".mysql_num_rows($results)." releases\n";
|
||||
|
||||
while ($arr = mysql_fetch_assoc($results))
|
||||
{
|
||||
unset($TheTVDBAPIArray, $episodeArray, $fullep, $epabsolute, $additionalSql);
|
||||
|
||||
$seriesName = '';
|
||||
if($arr['rageID'] > 0) {
|
||||
$seriesName = $db->queryOneRow(sprintf('SELECT releasetitle AS seriesName FROM tvrage WHERE rageID = %d', $arr['rageID']));
|
||||
}
|
||||
elseif($arr['anidbID'] > 0) {
|
||||
$seriesName = $db->queryOneRow(sprintf('SELECT title AS seriesName FROM anidb WHERE anidbID = %d', $arr['anidbID']));
|
||||
}
|
||||
|
||||
if(empty($seriesName) || !$seriesName)
|
||||
{
|
||||
$this->notFound($seriesName, "", $arr['ID'], false);
|
||||
continue;
|
||||
}
|
||||
|
||||
$seriesName = str_replace('`', '\'', $seriesName['seriesName']);
|
||||
if(!preg_match('/[21]\d{3}\/\d{2}\/\d{2}/', $arr['seriesfull']))
|
||||
$fullep = str_pad(str_replace('S', '', $arr['season']), 2, '0', STR_PAD_LEFT).'x'.str_pad(str_replace('E', '', $arr['episode']), 2, '0', STR_PAD_LEFT);
|
||||
else
|
||||
$fullep = str_replace('/', '-', $arr['seriesfull']);
|
||||
|
||||
$TheTVDBAPIArray = $this->getSeriesInfoByName($seriesName);
|
||||
if(!$TheTVDBAPIArray)
|
||||
{
|
||||
$seriesid = $this->lookupSeriesID($seriesName);
|
||||
if($seriesid > 0)
|
||||
{
|
||||
if($TheTVDBAPIArray = $this->TheTVDBAPI($seriesid, $seriesName))
|
||||
{
|
||||
$this->addSeries($TheTVDBAPIArray);
|
||||
$this->addEpisodes($TheTVDBAPIArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addEmptySeries($seriesName);
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addEmptySeries($seriesName);
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if($TheTVDBAPIArray['tvdbID'] >= 0 && ((time() - strtotime($TheTVDBAPIArray['createddate'])) > 604800))
|
||||
{
|
||||
$TheTVDBAPIArray = $this->TheTVDBAPI($TheTVDBAPIArray['tvdbID'], $seriesName);
|
||||
|
||||
$this->updateSeries($TheTVDBAPIArray['tvdbID'], $TheTVDBAPIArray['actors'], $TheTVDBAPIArray['airsday'],
|
||||
$TheTVDBAPIArray['airstime'], $TheTVDBAPIArray['contentrating'], $TheTVDBAPIArray['firstaired'], $TheTVDBAPIArray['genre'],
|
||||
$TheTVDBAPIArray['imdbID'], $TheTVDBAPIArray['network'], $TheTVDBAPIArray['overview'], $TheTVDBAPIArray['rating'],
|
||||
$TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $TheTVDBAPIArray['seriesname'], $TheTVDBAPIArray['status']);
|
||||
|
||||
$this->addEpisodes($TheTVDBAPIArray);
|
||||
}
|
||||
|
||||
if($TheTVDBAPIArray['tvdbID'] > 0)
|
||||
{
|
||||
$epabsolute = '0';
|
||||
if($arr['anidbID'] > 0)
|
||||
{
|
||||
if(preg_match('/S(?P<season>\d+)[ED](?P<episode>\d+)/', $arr['episode'], $seasonEpisode))
|
||||
{
|
||||
$arr['season'] = $seasonEpisode['season'];
|
||||
$arr['episode'] = $seasonEpisode['episode'];
|
||||
}
|
||||
else
|
||||
$epabsolute = $arr['episode'];
|
||||
}
|
||||
|
||||
$Episode = new Episode();
|
||||
$episodeArray = $Episode->getEpisodeInfoByName($seriesName, $fullep, (string) $epabsolute);
|
||||
if(!$episodeArray)
|
||||
{
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->notFound($seriesName, $fullep, $arr['ID']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$additionalSql = '';
|
||||
if($arr['anidbID'] > 0 && $episodeArray['epabsolute'] > 0)
|
||||
{
|
||||
$additionalSql = sprintf(', season = NULL, episode = %d, tvtitle = %s, tvairdate = %s',
|
||||
$episodeArray['epabsolute'],
|
||||
$db->escapeString($episodeArray['epabsolute'].' - '.str_replace('\'', '`', $episodeArray['eptitle'])),
|
||||
$db->escapeString($episodeArray['airdate']));
|
||||
}
|
||||
|
||||
$db->query(sprintf('UPDATE releases SET tvdbID = %d, episodeinfoID = %d %s WHERE ID = %d',
|
||||
$TheTVDBAPIArray['tvdbID'], $episodeArray['ID'], $additionalSql, $arr['ID']));
|
||||
|
||||
//if($this->echooutput)
|
||||
//{
|
||||
// echo 'TheTVDB : '.$seriesName.' '.$fullep." returned ".$episodeArray['tvdbID']."\n";
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function TheTVDBAPI($seriesid, $seriesName)
|
||||
{
|
||||
$apiresponse = getUrl($this->MIRROR.'/api/'.self::APIKEY.'/series/'.$seriesid.'/all/en.xml'); //.zip?
|
||||
|
||||
if(!$apiresponse)
|
||||
return false;
|
||||
|
||||
$TheTVDBAPIXML = @simplexml_load_string($apiresponse);
|
||||
if(!$TheTVDBAPIXML)
|
||||
return false;
|
||||
|
||||
foreach($TheTVDBAPIXML->Episode as $episode) {
|
||||
$episodetvdbIDArray[] = (int) $episode->id;
|
||||
$episodenumberArray[] = (int) $episode->Combined_episodenumber;
|
||||
$episodeseasonArray[] = (int) $episode->Combined_season;
|
||||
$episodedirectorArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Director);
|
||||
$episodenameArray[] = preg_replace('/^\||\|$/', '', (string) $episode->EpisodeName);
|
||||
$episodefirstairedArray[] = (string) $episode->FirstAired;
|
||||
$episodegueststarsArray[] = preg_replace('/^\||\|$/', '', (string) $episode->GuestStars);
|
||||
$episodeimdbID[] = str_replace('tt', '', (string) $episode->IMDB_ID);
|
||||
$episodeoverviewArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Overview);
|
||||
$episoderatingArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Rating);
|
||||
$episodewriterArray[] = preg_replace('/^\||\|$/', '', (string) $episode->Writer);
|
||||
$episodeabsolutenumberArray[] = (int) $episode->absolute_number;
|
||||
}
|
||||
|
||||
$TheTVDBAPIArray = array(
|
||||
'tvdbID' => $seriesid,
|
||||
'actors' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Actors),
|
||||
'airsday' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Airs_DayOfWeek),
|
||||
'airstime' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Airs_Time),
|
||||
'contentrating' => (string) $TheTVDBAPIXML->Series->ContentRating,
|
||||
'firstaired' => (string) $TheTVDBAPIXML->Series->FirstAired,
|
||||
'genre' => preg_replace('/^\||\|$/', '', (string) $TheTVDBAPIXML->Series->Genre),
|
||||
'imdbID' => (int) preg_replace('/^[^\d]+/', '', (string) $TheTVDBAPIXML->Series->IMDB_ID),
|
||||
'network' => (string) $TheTVDBAPIXML->Series->Network,
|
||||
'overview' => (string) $TheTVDBAPIXML->Series->Overview,
|
||||
'rating' => (float) $TheTVDBAPIXML->Series->Rating,
|
||||
'ratingcount' => (int) $TheTVDBAPIXML->Series->RatingCount,
|
||||
'runtime' => (int) $TheTVDBAPIXML->Series->Runtime,
|
||||
//'seriesname' => ((string) $TheTVDBAPIXML->Series->SeriesName != '') ? (string) $TheTVDBAPIXML->Series->SeriesName : $seriesName,
|
||||
'seriesname' => $seriesName,
|
||||
'status' => (string) $TheTVDBAPIXML->Series->Status,
|
||||
'episodetvdbID' => isset($episodetvdbIDArray) ? $episodetvdbIDArray : array(),
|
||||
'episodenumber' => isset($episodenumberArray) ? $episodenumberArray : array(),
|
||||
'episodeseason' => isset($episodeseasonArray) ? $episodeseasonArray : array(),
|
||||
'episodedirector' => isset($episodedirectorArray) ? $episodedirectorArray : array(),
|
||||
'episodename' => isset($episodenameArray) ? $episodenameArray : array(),
|
||||
'episodefirstaired' => isset($episodefirstairedArray) ? $episodefirstairedArray : array(),
|
||||
'episodegueststars' => isset($episodegueststarsArray) ? $episodegueststarsArray : array(),
|
||||
'episodeimdbID' => isset($episodeimdbID) ? $episodeimdbID : array(),
|
||||
'episodeoverview' => isset($episodeoverviewArray) ? $episodeoverviewArray : array(),
|
||||
'episoderating' => isset($episoderatingArray) ? $episoderatingArray : array(),
|
||||
'episodewriter' => isset($episodewriterArray) ? $episodewriterArray : array(),
|
||||
'episodeabsolutenumber' => isset($episodeabsolutenumberArray) ? $episodeabsolutenumberArray : array(),
|
||||
);
|
||||
|
||||
return $TheTVDBAPIArray;
|
||||
}
|
||||
}
|
||||
|
||||
+342
-145
@@ -5,153 +5,166 @@ require_once(WWW_DIR."/lib/postprocess.php");
|
||||
$_php = getenv("PHP");
|
||||
|
||||
$db = new DB();
|
||||
//////////////amount of releases//////////////
|
||||
$query = "select count(*) from releases";
|
||||
/////////////amount of books left to do//////
|
||||
$book_query = "select count(searchname), ID from releases use index (ix_releases_categoryID) where bookinfoID IS NULL and categoryID = 7020;";
|
||||
/////////////amount of games left to do//////
|
||||
$console_query = "SELECT count(searchname), ID from releases use index (ix_releases_categoryID) where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = 1000 );";
|
||||
/////////////amount of movies left to do//////
|
||||
$movies_query = "SELECT count(searchname), ID from releases use index (ix_releases_categoryID) where imdbID IS NULL and categoryID in ( select ID from category where parentID = 2000 );";
|
||||
/////////////amount of music left to do//////
|
||||
$music_query = "SELECT count(searchname), ID from releases use index (ix_releases_categoryID) where musicinfoID IS NULL and categoryID in ( select ID from category where parentID = 3000 );";
|
||||
///////////amount of post processing left/////
|
||||
$pquery = "select count(*) from releases r left join category c on c.ID = r.categoryID where (r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0);";
|
||||
/////////////amount of post processing to do//
|
||||
$plquery = "select count(*) from releases r left join category c on c.ID = r.categoryID where (r.passwordstatus=0);";
|
||||
$postprocessing_count_remaining_query = "select count(*) from releases r left join category c on c.ID = r.categoryID where (r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0);";
|
||||
/////////////amount of post processing completed//
|
||||
$postprocessing_completed_count_query = "select count(*) from releases r left join category c on c.ID = r.categoryID where (r.passwordstatus=0);";
|
||||
//////////////amount of releases//////////////
|
||||
$releases_query = "select count(*) from releases";
|
||||
/////////////amount of tv left to do/////////
|
||||
$tvrage_query = "SELECT count(searchname), ID from releases where rageID = -1 and categoryID in ( select ID from category where parentID = 5000 );";
|
||||
|
||||
$result_begin = mysql_query($query);
|
||||
//$result_begin = $db->queryDirect($query);
|
||||
$presult_begin = mysql_query($pquery);
|
||||
$plresult_begin = mysql_query($plquery);
|
||||
|
||||
/////////////////result_begin////////////////////////
|
||||
if (empty($result_begin)) {
|
||||
$result_begin = $db->queryDirect($query);
|
||||
if (empty($result_begin)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
//////////////set up initial counts////
|
||||
$book_count_start = mysql_query($book_query);
|
||||
$console_count_start = mysql_query($console_query);
|
||||
$movie_count_start = mysql_query($movies_query);
|
||||
$music_count_start = mysql_query($music_query);
|
||||
$tvrage_count_start = mysql_query($tvrage_query);
|
||||
$postprocessing_remaining_count_start = mysql_query($postprocessing_count_remaining_query);
|
||||
$postprocessing_completed_count_start = mysql_query($postprocessing_completed_count_query);
|
||||
$releases_count_start = mysql_query($releases_query);
|
||||
|
||||
/////////////////bresult_begin////////////////////////
|
||||
if (empty($book_count_start)) {
|
||||
$book_count_start = $db->queryDirect($book_query);
|
||||
if (empty($book_count_start)) {
|
||||
$bmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$bmessage .= 'Whole query: ' . $book_query;
|
||||
die($bmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($result_begin)) {
|
||||
$count_begin = $row['count(*)'];
|
||||
while ($brow = mysql_fetch_assoc($book_count_start)) {
|
||||
$bcount_begin = $brow['count(searchname)'];
|
||||
}
|
||||
|
||||
///////////////////presult_begin///////////////////////
|
||||
if (empty($presult_begin)) {
|
||||
$presult_begin = $db->queryDirect($pquery);
|
||||
if (empty($presult_begin)) {
|
||||
/////////////////cresult_begin////////////////////////
|
||||
if (empty($cresult_begin)) {
|
||||
$cresult_begin = $db->queryDirect($releases_query);
|
||||
if (empty($cresult_begin)) {
|
||||
$cmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$cmessage .= 'Whole query: ' . $releases_query;
|
||||
die($cmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($crow = mysql_fetch_assoc($cresult_begin)) {
|
||||
$ccount_begin = $crow['count(*)'];
|
||||
}
|
||||
|
||||
/////////////////gresult_begin////////////////////////
|
||||
if (empty($console_count_start)) {
|
||||
$console_count_start = $db->queryDirect($console_query);
|
||||
if (empty($console_count_start)) {
|
||||
$gmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$gmessage .= 'Whole query: ' . $console_query;
|
||||
die($gmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($grow = mysql_fetch_assoc($console_count_start)) {
|
||||
$gcount_begin = $grow['count(searchname)'];
|
||||
}
|
||||
|
||||
/////////////////moresult_begin////////////////////////
|
||||
if (empty($movie_count_start)) {
|
||||
$movie_count_start = $db->queryDirect($movies_query);
|
||||
if (empty($movie_count_start)) {
|
||||
$momessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$momessage .= 'Whole query: ' . $movies_query;
|
||||
die($momessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($morow = mysql_fetch_assoc($movie_count_start)) {
|
||||
$mocount_begin = $morow['count(searchname)'];
|
||||
}
|
||||
|
||||
/////////////////muresult_begin////////////////////////
|
||||
if (empty($music_count_start)) {
|
||||
$music_count_start = $db->queryDirect($music_query);
|
||||
if (empty($music_count_start)) {
|
||||
$mumessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$mumessage .= 'Whole query: ' . $music_query;
|
||||
die($mumessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($murow = mysql_fetch_assoc($music_count_start)) {
|
||||
$mucount_begin = $murow['count(searchname)'];
|
||||
}
|
||||
|
||||
///////////////////presult_begin///////////////////////
|
||||
if (empty($postprocessing_remaining_count_start)) {
|
||||
$postprocessing_remaining_count_start = $db->queryDirect($postprocessing_count_remaining_query);
|
||||
if (empty($postprocessing_remaining_count_start)) {
|
||||
$pmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$pmessage .= 'Whole query: ' . $pquery;
|
||||
$pmessage .= 'Whole query: ' . $postprocessing_count_remaining_query;
|
||||
die($pmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($prow = mysql_fetch_assoc($presult_begin)) {
|
||||
$pcount_begin = $prow['count(*)'];
|
||||
while ($prow = mysql_fetch_assoc($postprocessing_remaining_count_start)) {
|
||||
$postprocessing_remaining_count_loop_start = $prow['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////plresult_begin///////////////////////
|
||||
if (empty($plresult_begin)) {
|
||||
$plresult_begin = $db->queryDirect($plquery);
|
||||
if (empty($plresult_begin)) {
|
||||
///////////////////plresult_begin///////////////////////
|
||||
if (empty($postprocessing_completed_count_start)) {
|
||||
$postprocessing_completed_count_start = $db->queryDirect($postprocessing_completed_count_query);
|
||||
if (empty($postprocessing_completed_count_start)) {
|
||||
$plmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$plmessage .= 'Whole query: ' . $plquery;
|
||||
$plmessage .= 'Whole query: ' . $postprocessing_completed_count_query;
|
||||
die($plmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($plrow = mysql_fetch_assoc($plresult_begin)) {
|
||||
while ($plrow = mysql_fetch_assoc($postprocessing_completed_count_start)) {
|
||||
$plcount_begin = $plrow['count(*)'];
|
||||
}
|
||||
|
||||
/////////////////result_begin////////////////////////
|
||||
if (empty($releases_count_start)) {
|
||||
$releases_count_start = $db->queryDirect($releases_query);
|
||||
if (empty($releases_count_start)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $releases_query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($releases_count_start)) {
|
||||
$count_begin = $row['count(*)'];
|
||||
}
|
||||
|
||||
/////////////////tresult_begin////////////////////////
|
||||
if (empty($tvrage_count_start)) {
|
||||
$tvrage_count_start = $db->queryDirect($tvrage_query);
|
||||
if (empty($releases_count_start)) {
|
||||
$tmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$tmessage .= 'Whole query: ' . $tvrage_query;
|
||||
die($tmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($trow = mysql_fetch_assoc($tvrage_count_start)) {
|
||||
$tcount_begin = $trow['count(searchname)'];
|
||||
}
|
||||
|
||||
////////////////////////time////////////////////////////
|
||||
$time = TIME();
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
while($i>0)
|
||||
{
|
||||
$result_inner_loop = mysql_query($query);
|
||||
$presult_inner_loop = mysql_query($pquery);
|
||||
$plresult_inner_loop = mysql_query($plquery);
|
||||
//$result_inner_loop = $db->queryDirect($query);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//////////////////Change these for sleep time///////////
|
||||
$sleeptime = "15";
|
||||
$sleeptext = "in the past $sleeptime seconds";
|
||||
////////////////////////////////////////////////////////
|
||||
////////////////////////print///////////////////////////
|
||||
|
||||
sleep($sleeptime);
|
||||
$result_loop = mysql_query($query);
|
||||
$presult_loop = mysql_query($pquery);
|
||||
$plresult_loop = mysql_query($plquery);
|
||||
//$result_loop = $db->queryDirect($query);
|
||||
|
||||
////////////////result_inner_loop///////////////////////
|
||||
if (empty($result_inner_loop)) {
|
||||
$result_inner_loop = $db->queryDirect($query);
|
||||
if (empty($result_inner_loop)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($result_inner_loop)) {
|
||||
$count_inner_loop = $row['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////result_loop/////////////////////////
|
||||
if (empty($result_loop)) {
|
||||
$result_loop = $db->queryDirect($query);
|
||||
if (empty($result_loop)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($result_loop)) {
|
||||
$count_loop = $row['count(*)'];
|
||||
}
|
||||
|
||||
////////////////presult_inner_loop///////////////////////
|
||||
if (empty($presult_inner_loop)) {
|
||||
$presult_inner_loop = $db->queryDirect($pquery);
|
||||
if (empty($presult_inner_loop)) {
|
||||
$pmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$pmessage .= 'Whole query: ' . $pquery;
|
||||
die($pmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($prow = mysql_fetch_assoc($presult_inner_loop)) {
|
||||
$pcount_inner_loop = $prow['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////presult_loop////////////////////////
|
||||
if (empty($presult_loop)) {
|
||||
$presult_loop = $db->queryDirect($pquery);
|
||||
if (empty($result_loop)) {
|
||||
$pmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$pmessage .= 'Whole query: ' . $pquery;
|
||||
die($pmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($prow = mysql_fetch_assoc($presult_loop)) {
|
||||
$pcount_loop = $prow['count(*)'];
|
||||
}
|
||||
|
||||
/////////////////////plresult_loop//////////////////////
|
||||
if (empty($pdresult_loop)) {
|
||||
$plresult_loop = $db->queryDirect($plquery);
|
||||
if (empty($plresult_loop)) {
|
||||
$plmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$plmessage .= 'Whole query: ' . $plquery;
|
||||
die($plmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($plrow = mysql_fetch_assoc($plresult_loop)) {
|
||||
$plcount_loop = $plrow['count(*)'];
|
||||
}
|
||||
|
||||
$secs = TIME() - $time;
|
||||
$mins = floor($secs / 60);
|
||||
@@ -161,35 +174,219 @@ while($i=1)
|
||||
$min = ($mins % 60);
|
||||
$hr = ($hrs % 60);
|
||||
$day = ($days % 24);
|
||||
$total_start = $count_loop - $count_begin;
|
||||
$total_loop = $count_loop - $count_inner_loop;
|
||||
$ptotal_start = -$pcount_loop - -$pcount_begin;
|
||||
$ptotal_loop = -$pcount_loop - -$pcount_inner_loop;
|
||||
passthru('clear');
|
||||
printf("Monitoring total releases in your database\n");
|
||||
printf("$total_loop releases added $sleeptext\n");
|
||||
printf("$total_start releases added in the last \033[38;5;160m$day\033[0m");printf(" Days ");
|
||||
printf("\033[38;5;208m$hr\033[0m");printf(" Hours ");
|
||||
printf("\033[38;5;020m$min\033[0m");printf(" Minutes ");
|
||||
printf("\033[38;5;063m$sec\033[0m");printf(" Seconds\n");
|
||||
printf("$ptotal_loop releases post processed $sleeptext\n");
|
||||
printf("$ptotal_start releases post processed in the last \033[38;5;160m$day\033[0m");printf(" Days ");
|
||||
printf("\033[38;5;208m$hr\033[0m");printf(" Hours ");
|
||||
printf("\033[38;5;020m$min\033[0m");printf(" Minutes ");
|
||||
printf("\033[38;5;063m$sec\033[0m");printf(" Seconds\n");
|
||||
printf("$plcount_loop have been post processed thus far\n");
|
||||
printf("$pcount_loop releases left to post process\n");
|
||||
printf("$count_loop releases currently in your database\n\n");
|
||||
|
||||
$book_count_loop_start = mysql_query($book_query);
|
||||
$console_count_loop_start = mysql_query($console_query);
|
||||
$movies_count_loop_start = mysql_query($movies_query);
|
||||
$music_count_loop_start = mysql_query($music_query);
|
||||
$postprocessing_count_remaining_loop_start = mysql_query($postprocessing_count_remaining_query);
|
||||
$postprocessing_count_completed_loop_start = mysql_query($postprocessing_completed_count_query);
|
||||
$releases_count_loop_start = mysql_query($releases_query);
|
||||
$tvrage_count_loop_start = mysql_query($tvrage_query);
|
||||
|
||||
//////////////////Change this for sleep time////////////
|
||||
$sleeptime = "60";
|
||||
if ($i!=1) {
|
||||
sleep($sleeptime);
|
||||
}
|
||||
|
||||
$book_count_inner_loop = mysql_query($book_query);
|
||||
$console_count_inner_loop = mysql_query($console_query);
|
||||
$movies_count_inner_loop = mysql_query($movies_query);
|
||||
$music_count_inner_loop = mysql_query($music_query);
|
||||
$postprocessing_count_remaining_inner_loop = mysql_query($postprocessing_count_remaining_query);
|
||||
$postprocessing_count_completed_inner_loop = mysql_query($postprocessing_completed_count_query);
|
||||
$releases_count_inner_loop = mysql_query($releases_query);
|
||||
$tvrage_count_inner_loop = mysql_query($tvrage_query);
|
||||
|
||||
///////////////////bresult_loop/////////////////////////
|
||||
if (empty($book_count_inner_loop)) {
|
||||
$book_count_inner_loop = $db->queryDirect($book_query);
|
||||
if (empty($book_count_inner_loop)) {
|
||||
$bmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$bmessage .= 'Whole query: ' . $book_query;
|
||||
die($bmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($brow = mysql_fetch_assoc($book_count_inner_loop)) {
|
||||
$bcount_loop = $brow['count(searchname)'];
|
||||
}
|
||||
|
||||
///////////////////gresult_loop/////////////////////////
|
||||
if (empty($console_count_inner_loop)) {
|
||||
$console_count_inner_loop = $db->queryDirect($console_query);
|
||||
if (empty($console_count_inner_loop)) {
|
||||
$gmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$gmessage .= 'Whole query: ' . $console_query;
|
||||
die($gmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($grow = mysql_fetch_assoc($console_count_inner_loop)) {
|
||||
$gcount_loop = $grow['count(searchname)'];
|
||||
}
|
||||
|
||||
///////////////////moresult_loop/////////////////////////
|
||||
if (empty($movies_count_inner_loop)) {
|
||||
$movies_count_inner_loop = $db->queryDirect($movies_query);
|
||||
if (empty($movies_count_inner_loop)) {
|
||||
$momessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$momessage .= 'Whole query: ' . $movies_query;
|
||||
die($momessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($morow = mysql_fetch_assoc($movies_count_inner_loop)) {
|
||||
$mocount_loop = $morow['count(searchname)'];
|
||||
}
|
||||
|
||||
///////////////////muresult_loop/////////////////////////
|
||||
if (empty($music_count_inner_loop)) {
|
||||
$music_count_inner_loop = $db->queryDirect($music_query);
|
||||
if (empty($music_count_inner_loop)) {
|
||||
$mumessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$mumessage .= 'Whole query: ' . $releases_query;
|
||||
die($mumessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($murow = mysql_fetch_assoc($music_count_inner_loop)) {
|
||||
$mucount_loop = $murow['count(searchname)'];
|
||||
}
|
||||
|
||||
////////////////presult_inner_loop///////////////////////
|
||||
if (empty($postprocessing_count_remaining_loop_start)) {
|
||||
$postprocessing_count_remaining_loop_start = $db->queryDirect($postprocessing_count_remaining_query);
|
||||
if (empty($postprocessing_count_remaining_loop_start)) {
|
||||
$pmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$pmessage .= 'Whole query: ' . $postprocessing_count_remaining_query;
|
||||
die($pmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($prow = mysql_fetch_assoc($postprocessing_count_remaining_loop_start)) {
|
||||
$pcount_inner_loop = $prow['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////presult_loop////////////////////////
|
||||
if (empty($postprocessing_count_remaining_inner_loop)) {
|
||||
$postprocessing_count_remaining_inner_loop = $db->queryDirect($postprocessing_count_remaining_query);
|
||||
if (empty($releases_count_inner_loop)) {
|
||||
$pmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$pmessage .= 'Whole query: ' . $postprocessing_count_remaining_query;
|
||||
die($pmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($prow = mysql_fetch_assoc($postprocessing_count_remaining_inner_loop)) {
|
||||
$postprocessing_count_remaining_this_loop = $prow['count(*)'];
|
||||
}
|
||||
|
||||
/////////////////////plresult_loop//////////////////////
|
||||
if (empty($pdresult_loop)) {
|
||||
$postprocessing_count_completed_inner_loop = $db->queryDirect($postprocessing_completed_count_query);
|
||||
if (empty($postprocessing_count_completed_inner_loop)) {
|
||||
$plmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$plmessage .= 'Whole query: ' . $postprocessing_completed_count_query;
|
||||
die($plmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($plrow = mysql_fetch_assoc($postprocessing_count_completed_inner_loop)) {
|
||||
$plcount_loop = $plrow['count(*)'];
|
||||
}
|
||||
|
||||
////////////////result_inner_loop///////////////////////
|
||||
if (empty($releases_count_loop_start)) {
|
||||
$releases_count_loop_start = $db->queryDirect($releases_query);
|
||||
if (empty($releases_count_loop_start)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $releases_query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($releases_count_loop_start)) {
|
||||
$count_inner_loop = $row['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////result_loop/////////////////////////
|
||||
if (empty($releases_count_inner_loop)) {
|
||||
$releases_count_inner_loop = $db->queryDirect($releases_query);
|
||||
if (empty($releases_count_inner_loop)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $releases_query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($releases_count_inner_loop)) {
|
||||
$count_loop = $row['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////tresult_loop/////////////////////////
|
||||
if (empty($tvrage_count_inner_loop)) {
|
||||
$tvrage_count_inner_loop = $db->queryDirect($tvrage_query);
|
||||
if (empty($releases_count_inner_loop)) {
|
||||
$tmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$tmessage .= 'Whole query: ' . $tvrage_query;
|
||||
die($tmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($trow = mysql_fetch_assoc($tvrage_count_inner_loop)) {
|
||||
$tcount_loop = $trow['count(searchname)'];
|
||||
}
|
||||
|
||||
$btotal_start = $bcount_loop - $bcount_begin;if ($btotal_start < 0) $btotal_start = 0;
|
||||
$gtotal_start = $gcount_loop - $gcount_begin;if ($gtotal_start < 0) $gtotal_start = 0;
|
||||
$mototal_start = $mocount_loop - $mocount_begin;if ($mototal_start < 0) $mototal_start = 0;
|
||||
$mutotal_start = $mucount_loop - $mucount_begin;if ($mutotal_start < 0) $mutotal_start = 0;
|
||||
|
||||
//calculate the difference from start to now
|
||||
$ptotal_start = $postprocessing_count_remaining_this_loop - $postprocessing_remaining_count_loop_start;if ($ptotal_start < 0) $ptotal_start = 0;
|
||||
|
||||
$ptotal_loop = $postprocessing_count_remaining_this_loop - $pcount_inner_loop;if ($ptotal_loop < 0) $ptotal_loop = 0;
|
||||
$total_start = $count_loop - $count_begin;if ($total_start < 0) $total_start = 0;
|
||||
$total_loop = $count_loop - $count_inner_loop;if ($total_loop < 0) $total_loop = 0;
|
||||
$ttotal_start = $tcount_loop - $tcount_begin;if ($ttotal_start < 0) $ttotal_start = 0;
|
||||
$sleeptext = "in the past $sleeptime seconds.";
|
||||
|
||||
passthru('clear');
|
||||
|
||||
printf("Monitoring the releases in your database.\n\n");
|
||||
printf("The script was started: \033[38;5;160m$day\033[0m");printf(" Days ");
|
||||
printf("\033[38;5;208m$hr\033[0m");printf(" Hours ");
|
||||
printf("\033[38;5;020m$min\033[0m");printf(" Minutes ");
|
||||
printf("\033[38;5;063m$sec\033[0m");printf(" Seconds Ago.\n");
|
||||
printf("The script updates every $sleeptime seconds.\n");
|
||||
printf("$ptotal_loop releases post processed since last update.\n");
|
||||
printf("$total_loop releases added since last update.\n");
|
||||
|
||||
//printf("$ccount_begin releases at start.\n");
|
||||
//printf("$count_loop releases in your database.\n");
|
||||
//printf("$total_start releases have been added.\n\n");
|
||||
//printf("$btotal_start1 books, $gtotal_start1 games, $mototal_start1 movies, $mutotal_start1 music, $ttotal_start1 TV shows have been processed.\n\n");
|
||||
//printf("Adittional Post Processing:\n");
|
||||
//printf("$ptotal_start1 since script start.\n");
|
||||
//printf("$postprocessing_count_remaining_this_loop left to do.\n");
|
||||
//printf("$plcount_loop since installing newznab.\n");
|
||||
|
||||
$i=$i+1;
|
||||
}
|
||||
mysql_free_result($result_begin);
|
||||
mysql_free_result($result_loop);
|
||||
mysql_free_result($pcount_begin);
|
||||
mysql_free_result($presult_loop);
|
||||
|
||||
mysql_free_result($book_count_inner_loop);
|
||||
mysql_free_result($console_count_inner_loop);
|
||||
mysql_free_result($movies_count_inner_loop);
|
||||
mysql_free_result($music_count_inner_loop);
|
||||
mysql_free_result($postprocessing_remaining_count_loop_start);
|
||||
mysql_free_result($plcount_begin);
|
||||
mysql_free_result($plresult_loop);
|
||||
mysql_free_result($postprocessing_count_completed_inner_loop);
|
||||
mysql_free_result($postprocessing_count_remaining_inner_loop);
|
||||
mysql_free_result($releases_count_start);
|
||||
mysql_free_result($releases_count_inner_loop);
|
||||
mysql_free_result($tvrage_count_inner_loop);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
Regular → Executable
Regular → Executable
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/../../../www/config.php");
|
||||
?>
|
||||
Regular → Executable
@@ -1,8 +1,7 @@
|
||||
<?php
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/postprocess2.php");
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$db = new DB();
|
||||
$query = "select count(*) from releases r left join category c on c.ID = r.categoryID where ((r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0))";
|
||||
@@ -26,8 +25,8 @@ while($i=1)
|
||||
}
|
||||
|
||||
if ($count > 10) {
|
||||
$postprocess = new PostProcess2(true);
|
||||
$postprocess->processAdditional2();
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processAdditional();
|
||||
} else {
|
||||
echo "$count releases left to process\n";
|
||||
sleep(15);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<?php
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/postprocess3.php");
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$db = new DB();
|
||||
$query = "select count(*) from releases r left join category c on c.ID = r.categoryID where ((r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0))";
|
||||
@@ -26,8 +25,8 @@ while($i=1)
|
||||
}
|
||||
|
||||
if ($count > 200) {
|
||||
$postprocess = new PostProcess3(true);
|
||||
$postprocess->processAdditional3();
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processAdditional();
|
||||
} else {
|
||||
echo "$count releases left to process\n";
|
||||
sleep(15);
|
||||
|
||||
+3
-3
@@ -13,17 +13,17 @@ if [ "$THREADS" == "true" -a "$INNODB" == "true" ]; then
|
||||
#import nzb's
|
||||
if [[ $IMPORT == "true" ]] ; then
|
||||
cd $INNODB_PATH
|
||||
[ -f $INNODB_PATH/nzb-import.php ] && $PHP $INNODB_PATH/nzb-import.php ${NZBS} &
|
||||
[ -f nzb-import.php ] && $PHP nzb-import.php ${NZBS} &
|
||||
fi
|
||||
|
||||
#make active groups current
|
||||
cd $INNODB_PATH
|
||||
[ -f $INNODB_PATH/update_binaries_threaded.php ] && $PHP $INNODB_PATH/update_binaries_threaded.php &
|
||||
[ -f update_binaries_threaded.php ] && $PHP update_binaries_threaded.php &
|
||||
|
||||
#get backfill for all active groups
|
||||
if [[ $BACKFILL == "true" ]] ; then
|
||||
cd $INNODB_PATH
|
||||
[ -f $INNODB_PATH/backfill_threaded.php ] && $PHP $INNODB_PATH/backfill_threaded.php &
|
||||
[ -f backfill_threaded.php ] && $PHP backfill_threaded.php &
|
||||
|
||||
#increment backfill days
|
||||
$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -e "${MYSQL_CMD}"
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ set-option -g status-interval 30
|
||||
# Example of using a shell command in the status line
|
||||
#set -g status-right "#[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
#set -g status-right "#[fg=red]#(ls -1 changeme | wc -l) NZB's left to process #[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
set -g status-right "#[fg=red]#(find changeme -maxdepth 1 -type f -iname "*nzb" | wc -l) NZB's left to process #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Used: \"$3\" MB\";}') #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Free: \"$4\" MB\";}') #[fg=yellow]#(free -m | grep 'Swap' | awk '{ print \"Swap Used: \"$3\" MB\";}') #[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
set -g status-right "#[fg=red]#(find changeme -maxdepth 1 -type f -iname "*nzb" | wc -l | wc -l) NZB's left to process #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Used: \"$3\" MB\";}') #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Free: \"$4\" MB\";}') #[fg=yellow]#(free -m | grep 'Swap' | awk '{ print \"Swap Used: \"$3\" MB\";}') #[fg=yellow]#(uptime | cut -d ',' -f 2-)"
|
||||
|
||||
set-option -g status-right-length 200
|
||||
#set -g status-right '#[fg=green][#[fg=blue]%Y-%m-%d #[fg=white]%H:%M#[default] #($HOME/bin/battery)#[fg=green]]'
|
||||
|
||||
+25
-7
@@ -5,15 +5,13 @@
|
||||
export NEWZPATH="/var/www/newznab"
|
||||
|
||||
export NEWZNAB_PATH=$NEWZPATH"/misc/update_scripts"
|
||||
export INNODB_PATH="bin/innodb"
|
||||
export POWERPROCESS_PATH="bin/powerprocess"
|
||||
export TESTING_PATH=$NEWZPATH"/misc/testing"
|
||||
export ADMIN_PATH=$NEWZPATH"/www/admin"
|
||||
export USERNAME="what is your name" # this is the user name that will run these scripts
|
||||
export USERNAME="jonnyboy" # this is the user name that will run these scripts
|
||||
export NEWZNAB_IMPORT_SLEEP_TIME="60" # in seconds - this includes import_nzb backfill and current fill
|
||||
export NEWZNAB_POST_SLEEP_TIME="1" # in seconds - this is for post processing - sleep between loops
|
||||
export MAXDAYS="200" #max days for backfill
|
||||
export NZBS="/path/to/nzbs" #path to your nzb files to be imported
|
||||
export NZBS="/home/jonnyboy/nzbs/batch" #path to your nzb files to be imported
|
||||
|
||||
#Choose to run the threaded or non-threaded newznab scripts true/false
|
||||
export THREADS="true"
|
||||
@@ -30,11 +28,17 @@ export BACKFILL="true"
|
||||
#Choose to run import nzb script true/false
|
||||
export IMPORT="true"
|
||||
|
||||
#Select some monitoring script, if they are not installed, it will not affect the running of the scripts
|
||||
export USE_HTOP="true"
|
||||
export USE_NMON="true"
|
||||
export USE_BWMNG="true"
|
||||
export USE_IOTOP="true"
|
||||
export USE_MYTOP="true"
|
||||
|
||||
#By using this script you understand that the programmer is not responsible for any loss of data, users, or sanity.
|
||||
#You also agree that you were smart enough to make a backup of your database and files. Do you agree? yes/no
|
||||
|
||||
export AGREED="no"
|
||||
export AGREED="yes"
|
||||
|
||||
##END OF EDITS##
|
||||
|
||||
@@ -43,6 +47,20 @@ command -v mysql >/dev/null 2>&1 || { echo >&2 "I require mysql but it's not ins
|
||||
command -v sed >/dev/null 2>&1 || { echo >&2 "I require sed but it's not installed. Aborting."; exit 1; } && export SED=`command -v sed`
|
||||
command -v php5 >/dev/null 2>&1 && export PHP=`command -v php5` || { export PHP=`command -v php`; }
|
||||
command -v tmux >/dev/null 2>&1 || { echo >&2 "I require tmux but it's not installed. Aborting."; exit 1; } && export TMUX=`command -v tmux`
|
||||
command -v nmon >/dev/null 2>&1 || { echo >&2 "I require nmon but it's not installed. Aborting."; exit 1; } && export NMON=`command -v nmon`
|
||||
command -v mytop >/dev/null 2>&1|| { echo >&2 "I require mytop but it's not installed. Aborting."; exit 1; } && export MYTOP=`command -v mytop`
|
||||
|
||||
|
||||
if [[ $USE_HTOP == "true" ]]; then
|
||||
command -v htop >/dev/null 2>&1|| { echo >&2 "I require htop but it's not installed. Aborting."; exit 1; } && export HTOP=`command -v htop`
|
||||
fi
|
||||
if [[ $USE_NMON == "true" ]]; then
|
||||
command -v nmon >/dev/null 2>&1 || { echo >&2 "I require nmon but it's not installed. Aborting."; exit 1; } && export NMON=`command -v nmon`
|
||||
fi
|
||||
if [[ $USE_BWMNG == "true" ]]; then
|
||||
command -v bwm-ng >/dev/null 2>&1|| { echo >&2 "I require bwm-ng but it's not installed. Aborting."; exit 1; } && export BWMNG=`command -v bwm-ng`
|
||||
fi
|
||||
if [[ $USE_IOTOP == "true" ]]; then
|
||||
command -v iotop >/dev/null 2>&1|| { echo >&2 "I require iotop but it's not installed. Aborting."; exit 1; } && export IOTOP=`command -v iotop`
|
||||
fi
|
||||
if [[ $USE_MYTOP == "true" ]]; then
|
||||
command -v mytop >/dev/null 2>&1|| { echo >&2 "I require mytop but it's not installed. Aborting."; exit 1; } && export MYTOP=`command -v mytop`
|
||||
fi
|
||||
|
||||
@@ -18,31 +18,47 @@ if [[ $AGREED == "no" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
$TMUX new-session -d -s NewzNab -n NewzNab 'echo "processNfos Working......" && sleep 3 && $PHP bin/postprocess_nfo.php;exec bash -i'
|
||||
export INNODB_PATH=$DIR"/bin/innodb"
|
||||
export POWERPROCESS_PATH=$DIR"/bin/powerprocess"
|
||||
export START_PATH=$DIR
|
||||
|
||||
$TMUX new-session -d -s NewzNab -n NewzNab 'echo "monitor Working......" && nice -n 19 $PHP bin/monitor.php;nice -n 19 $PHP bin/monitor.php;exec bash -i'
|
||||
$TMUX selectp -t 0
|
||||
$TMUX splitw -v -p 80 'echo "monitor Working......" && $PHP bin/monitor.php;exec bash -i'
|
||||
$TMUX splitw -h -p 67 'cd bin && echo "Processing Books....." && sleep 12 && nice -n 19 ./postProcessing1.sh;nice -n 19 ./postProcessing1.sh;exec bash -i'
|
||||
$TMUX splitw -h -p 50 'cd bin && echo "imports Working......" && nice -n 10 ./workhorse.sh;nice -n 10 ./workhorse.sh;exec bash -i'
|
||||
$TMUX selectp -t 0
|
||||
$TMUX splitw -h -p 80 'echo "processAdditional Thread #1 Working......" && sleep 6 && $PHP bin/processAlternate2.php;exec bash -i'
|
||||
$TMUX selectp -t 3
|
||||
$TMUX splitw -h -p 67 'cd bin && echo "Processing Books....." && sleep 12 && ./postProcessing1.sh;exec bash -i'
|
||||
$TMUX splitw -h -p 50 'cd bin && echo "Processing Music....." && sleep 21 && ./postProcessing4.sh;exec bash -i'
|
||||
$TMUX selectp -t 1
|
||||
$TMUX splitw -v -p 50 'echo "processAdditional Thread #2 Working......" && sleep 9 && $PHP bin/processAlternate3.php;exec bash -i'
|
||||
$TMUX splitw -v -p 65 'echo "processNfos Working......" && sleep 3 && nice -n 19 $PHP bin/postprocess_nfo.php;nice -n 19 $PHP bin/postprocess_nfo.php;exec bash -i'
|
||||
$TMUX splitw -v -p 67 'echo "processAdditional Thread #1 Working......" && sleep 6 && nice -n 19 $PHP bin/processAlternate2.php;nice -n 19 $PHP bin/processAlternate2.php;exec bash -i'
|
||||
$TMUX splitw -v -p 50 'echo "processAdditional Thread #2 Working......" && sleep 9 && nice -n 19 $PHP bin/processAlternate3.php;nice -n 19 $PHP bin/processAlternate3.php;exec bash -i'
|
||||
$TMUX selectp -t 4
|
||||
$TMUX splitw -v -p 83 'cd bin && echo "Processing Games....." && sleep 15 && nice -n 19 ./postProcessing2.sh;nice -n 19 ./postProcessing2.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 80 'cd bin && echo "Processing Movies....." && sleep 18 && nice -n 19 ./postProcessing3.sh;nice -n 19 ./postProcessing3.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 75 'cd bin && echo "Processing Music....." && sleep 21 && nice -n 19 ./postProcessing4.sh;nice -n 19 ./postProcessing4.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 67 'cd bin && echo "Processing TV....." && sleep 24 && nice -n 19 ./postProcessing5.sh;nice -n 19 ./postProcessing5.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 50 'cd bin && echo "Processing Other....." && sleep 27 && nice -n 19 ./postProcessing6.sh;nice -n 19 ./postProcessing6.sh;exec bash -i'
|
||||
$TMUX selectp -t 10
|
||||
$TMUX splitw -v -p 50 'cd bin && echo "create Releases Working......" && nice -n 15 ./cleanup_scripts.sh;nice -n 15 ./cleanup_scripts.sh;exec bash -i'
|
||||
|
||||
|
||||
$TMUX selectp -t 3
|
||||
$TMUX splitw -v -p 67 'cd bin && echo "Processing Games....." && sleep 15 && ./postProcessing2.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 50 'cd bin && echo "Processing Movies....." && sleep 18 && ./postProcessing3.sh;exec bash -i'
|
||||
$TMUX selectp -t 6
|
||||
$TMUX splitw -v -p 67 'cd bin && echo "Processing TV....." && sleep 24 && ./postProcessing5.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 50 'cd bin && echo "Processing Other....." && sleep 27 && ./postProcessing6.sh;exec bash -i'
|
||||
$TMUX selectp -t 9
|
||||
$TMUX splitw -v -p 63 'cd bin && echo "imports Working......" && ./workhorse.sh;exec bash -i'
|
||||
$TMUX selectp -t 9
|
||||
#$TMUX splitw -h -p 67 'nmon'
|
||||
$TMUX splitw -h -p 67 '$MYTOP -u $DB_USER -p $DB_PASSWORD -d $DB_NAME -h $DB_HOST'
|
||||
$TMUX selectp -t 11
|
||||
$TMUX splitw -h -p 50 'cd bin && echo "create Releases Working......" && ./cleanup_scripts.sh;exec bash -i'
|
||||
if [[ $USE_HTOP == "true" ]]; then
|
||||
$TMUX new-window -n htop '$HTOP'
|
||||
fi
|
||||
|
||||
if [[ $USE_NMON == "true" ]]; then
|
||||
$TMUX new-window -n nmom '$NMON'
|
||||
fi
|
||||
|
||||
if [[ $USE_BWMNG == "true" ]]; then
|
||||
$TMUX new-window -n bwm-ng '$BWMNG'
|
||||
fi
|
||||
|
||||
if [[ $USE_IOTOP == "true" ]]; then
|
||||
$TMUX new-window -n iotop '$IOTOP -o'
|
||||
fi
|
||||
|
||||
if [[ $USE_MYTOP == "true" ]]; then
|
||||
$TMUX new-window -n mytop '$MYTOP -u $DB_USER -p $DB_PASSWORD -d $DB_NAME -h $DB_HOST'
|
||||
fi
|
||||
|
||||
$TMUX select-window -tNewzNab:0
|
||||
$TMUX attach-session -d -tNewzNab
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
DIR="$( dirname "$SOURCE" )"
|
||||
while [ -h "$SOURCE" ]
|
||||
do
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
source edit_these.sh
|
||||
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p; }" $NEWZPATH/www/config.php )
|
||||
|
||||
if [[ $AGREED == "no" ]]; then
|
||||
echo "Please edit the edit_these.sh file"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
$TMUX new-session -d -s NewzNab -n NewzNab 'echo "monitor Working......" && nice -n 19 $PHP bin/monitor.php;nice -n 19 $PHP bin/monitor.php;exec bash -i'
|
||||
$TMUX selectp -t 0
|
||||
$TMUX splitw -h -p 67 'cd bin && echo "Processing Books....." && sleep 12 && nice -n 19 ./postProcessing1.sh;nice -n 19 ./postProcessing1.sh;exec bash -i'
|
||||
$TMUX splitw -h -p 50 'cd bin && echo "imports Working......" && nice -n 10 ./workhorse.sh;nice -n 10 ./workhorse.sh;exec bash -i'
|
||||
$TMUX selectp -t 0
|
||||
$TMUX splitw -v -p 65 'echo "processNfos Working......" && sleep 3 && nice -n 19 $PHP bin/postprocess_nfo.php;nice -n 19 $PHP bin/postprocess_nfo.php;exec bash -i'
|
||||
$TMUX splitw -v -p 67 'echo "processAdditional Thread #1 Working......" && sleep 6 && nice -n 19 $PHP bin/processAlternate2.php;nice -n 19 $PHP bin/processAlternate2.php;exec bash -i'
|
||||
$TMUX splitw -v -p 50 'echo "processAdditional Thread #2 Working......" && sleep 9 && nice -n 19 $PHP bin/processAlternate3.php;nice -n 19 $PHP bin/processAlternate3.php;exec bash -i'
|
||||
$TMUX selectp -t 4
|
||||
$TMUX splitw -v -p 83 'cd bin && echo "Processing Games....." && sleep 15 && nice -n 19 ./postProcessing2.sh;nice -n 19 ./postProcessing2.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 80 'cd bin && echo "Processing Movies....." && sleep 18 && nice -n 19 ./postProcessing3.sh;nice -n 19 ./postProcessing3.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 75 'cd bin && echo "Processing Music....." && sleep 21 && nice -n 19 ./postProcessing4.sh;nice -n 19 ./postProcessing4.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 67 'cd bin && echo "Processing TV....." && sleep 24 && nice -n 19 ./postProcessing5.sh;nice -n 19 ./postProcessing5.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 50 'cd bin && echo "Processing Other....." && sleep 27 && nice -n 19 ./postProcessing6.sh;nice -n 19 ./postProcessing6.sh;exec bash -i'
|
||||
$TMUX selectp -t 10
|
||||
$TMUX splitw -v -p 50 'cd bin && echo "create Releases Working......" && nice -n 15 ./cleanup_scripts.sh;nice -n 15 ./cleanup_scripts.sh;exec bash -i'
|
||||
|
||||
|
||||
if [[ $USE_HTOP == "true" ]]; then
|
||||
$TMUX new-window -n htop '$HTOP'
|
||||
fi
|
||||
|
||||
if [[ $USE_NMON == "true" ]]; then
|
||||
$TMUX new-window -n nmom '$NMON'
|
||||
fi
|
||||
|
||||
if [[ $USE_BWMNG == "true" ]]; then
|
||||
$TMUX new-window -n bwm-ng '$BWMNG'
|
||||
fi
|
||||
|
||||
if [[ $USE_IOTOP == "true" ]]; then
|
||||
$TMUX new-window -n iotop '$IOTOP -o'
|
||||
fi
|
||||
|
||||
if [[ $USE_MYTOP == "true" ]]; then
|
||||
$TMUX new-window -n mytop '$MYTOP -u $DB_USER -p $DB_PASSWORD -d $DB_NAME -h $DB_HOST'
|
||||
fi
|
||||
|
||||
$TMUX select-window -tNewzNab:0
|
||||
$TMUX attach-session -d -tNewzNab
|
||||
|
||||
Reference in New Issue
Block a user