mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
thanks to kevin123 lots of changes
This commit is contained in:
@@ -6,7 +6,20 @@
|
||||
|
||||
`mysqldump --opt -u root -p newznab > ~/newznab_backup.sql`
|
||||
|
||||
* This first step will modify your setup using [andrewit's github](https://github.com/itandrew/Newznab-InnoDB-Dropin.git), if you want. If you do not convert, then use then use myisam when editing.
|
||||
* 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 [kevein123'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:
|
||||
|
||||
`cd to a location to store the git git repository.`
|
||||
|
||||
`git clone https://github.com/kevinlekiller/Newznab-Barracuda.git`
|
||||
|
||||
`cd Newznab-Barracuda/B\ +\ P/`
|
||||
|
||||
`php bpinnodb_compressed.php`
|
||||
|
||||
* Or, you can use [andrewit's github](https://github.com/itandrew/Newznab-InnoDB-Dropin.git). If you are using Innodb, this script uses some of [andrewit's](https://github.com/itandrew/Newznab-InnoDB-Dropin.git), so you will need to follow at least the next 2 commands.
|
||||
|
||||
* convert database to innodb, edit path if necessary
|
||||
|
||||
`cd /var/www/newznab/misc/testing/`
|
||||
@@ -47,9 +60,11 @@
|
||||
|
||||
* Now all panes should be running smoothly. If any of the scriptns in the top 3 panes crash, the panes should remain open and you should be able to view the error messages. I hope this helps.
|
||||
|
||||
* Join in the converstion at irc://moonlight.se.eu.synirc.net/newznab-tmux.
|
||||
|
||||
* Thanks go to all who offered their assistance and improvement to these scripts.
|
||||
|
||||
<hr>
|
||||
* Donations help to pay my hosting fees and server costs. Thank you
|
||||
* IOf, you find these scripts useful and would like to offer a donation. Danotions 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>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
@@ -69,3 +68,4 @@ sleep $NEWZNAB_POST_SLEEP_TIME
|
||||
|
||||
done
|
||||
|
||||
exit
|
||||
|
||||
Executable
+975
@@ -0,0 +1,975 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+975
@@ -0,0 +1,975 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+2016
File diff suppressed because it is too large
Load Diff
Executable
+2016
File diff suppressed because it is too large
Load Diff
Executable
+331
@@ -0,0 +1,331 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+331
@@ -0,0 +1,331 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
+112
-26
@@ -5,16 +5,23 @@ require_once(WWW_DIR."/lib/postprocess.php");
|
||||
$_php = getenv("PHP");
|
||||
|
||||
$db = new DB();
|
||||
//////////////amount of releases//////////////
|
||||
$query = "select count(*) from releases";
|
||||
//$query2 = "select format(count(*),0) 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 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);";
|
||||
|
||||
$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 = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
@@ -24,22 +31,63 @@ while ($row = mysql_fetch_assoc($result_begin)) {
|
||||
$count_begin = $row['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////presult_begin///////////////////////
|
||||
if (empty($presult_begin)) {
|
||||
$presult_begin = $db->queryDirect($pquery);
|
||||
if (empty($presult_begin)) {
|
||||
$pmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$pmessage .= 'Whole query: ' . $pquery;
|
||||
die($pmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($prow = mysql_fetch_assoc($presult_begin)) {
|
||||
$pcount_begin = $prow['count(*)'];
|
||||
}
|
||||
|
||||
///////////////////plresult_begin///////////////////////
|
||||
if (empty($plresult_begin)) {
|
||||
$plresult_begin = $db->queryDirect($plquery);
|
||||
if (empty($plresult_begin)) {
|
||||
$plmessage = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$plmessage .= 'Whole query: ' . $plquery;
|
||||
die($plmessage);
|
||||
}
|
||||
}
|
||||
|
||||
while ($plrow = mysql_fetch_assoc($plresult_begin)) {
|
||||
$plcount_begin = $plrow['count(*)'];
|
||||
}
|
||||
|
||||
////////////////////////time////////////////////////////
|
||||
$time = TIME();
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
$result_inner_loop = mysql_query($query);
|
||||
$presult_inner_loop = mysql_query($pquery);
|
||||
$plresult_inner_loop = mysql_query($plquery);
|
||||
//$result_inner_loop = $db->queryDirect($query);
|
||||
|
||||
sleep(60);
|
||||
////////////////////////////////////////////////////////
|
||||
//////////////////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 = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
@@ -49,10 +97,11 @@ while($i=1)
|
||||
$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 = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
@@ -62,6 +111,48 @@ while($i=1)
|
||||
$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);
|
||||
$hrs = floor($mins / 60);
|
||||
@@ -72,38 +163,33 @@ while($i=1)
|
||||
$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 in last minute\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");
|
||||
printf("***Info***\n");
|
||||
printf("Above left shows the current NFO's being analyzed. Above middle shows the the processing for. Above right show the lookups for TVRage, music, etc. Below left shows the activity of imports - it is looping nzb import, backfill and current fill. Below right shows the activity of applying regex's and creating releases.\n");
|
||||
|
||||
|
||||
//check if scripts are running
|
||||
exec("pgrep -f postprocess_nfo", $pids1);
|
||||
if (empty($pids1)) {
|
||||
echo "postprocess_nfo.php is not running, restarting\n";
|
||||
exec("tmux send-keys -t NewzNab:0.0 'clear && cd bin && $_php postprocess_nfo.php' C-m");
|
||||
}
|
||||
exec("pgrep -f processAlternate", $pids2);
|
||||
if (empty($pids2)) {
|
||||
echo "processAlternate.php is not running, restarting\n";
|
||||
exec("tmux send-keys -t NewzNab:0.1 'clear && cd bin && $_php processAlternate.php' C-m");
|
||||
}
|
||||
exec("pgrep -f postprocessing", $pids3);
|
||||
if (empty($pids3)) {
|
||||
echo "postprocessing.php is not running, restarting\n";
|
||||
exec("tmux send-keys -t NewzNab:0.2 'clear && cd bin && $_php postprocessing.php' C-m");
|
||||
}
|
||||
}
|
||||
|
||||
mysql_free_result($result_begin);
|
||||
mysql_free_result($result_loop);
|
||||
mysql_free_result($pcount_begin);
|
||||
mysql_free_result($presult_loop);
|
||||
mysql_free_result($plcount_begin);
|
||||
mysql_free_result($plresult_loop);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
class pidfile {
|
||||
private $_file;
|
||||
private $_running;
|
||||
|
||||
public function __construct($dir, $name) {
|
||||
$this->_file = "$dir/$name.pid";
|
||||
|
||||
if (file_exists($this->_file)) {
|
||||
$pid = trim(file_get_contents($this->_file));
|
||||
if (posix_kill($pid, 0)) {
|
||||
$this->_running = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->_running) {
|
||||
$pid = getmypid();
|
||||
file_put_contents($this->_file, $pid);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
if ((! $this->_running) && file_exists($this->_file)) {
|
||||
unlink($this->_file);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_already_running() {
|
||||
return $this->_running;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" $NEWZPATH/www/config.php )
|
||||
|
||||
while :
|
||||
do
|
||||
|
||||
echo "Processing Books.....";$PHP processBooks.php
|
||||
sleep 30
|
||||
|
||||
done
|
||||
exit
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" $NEWZPATH/www/config.php )
|
||||
|
||||
while :
|
||||
do
|
||||
|
||||
echo "Processing Games....."; $PHP processGames.php
|
||||
sleep 30
|
||||
|
||||
done
|
||||
exit
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" $NEWZPATH/www/config.php )
|
||||
|
||||
while :
|
||||
do
|
||||
|
||||
echo "Processing Movies.....";$PHP processMovies.php
|
||||
sleep 30
|
||||
|
||||
done
|
||||
exit
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" $NEWZPATH/www/config.php )
|
||||
|
||||
while :
|
||||
do
|
||||
|
||||
echo "Processing Music.....";$PHP processMusic.php
|
||||
sleep 30
|
||||
|
||||
done
|
||||
exit
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" $NEWZPATH/www/config.php )
|
||||
|
||||
while :
|
||||
do
|
||||
|
||||
echo "Processing TV....." && $PHP processTv.php
|
||||
sleep 30
|
||||
|
||||
done
|
||||
exit
|
||||
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
eval $( sed -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" $NEWZPATH/www/config.php )
|
||||
|
||||
while :
|
||||
do
|
||||
|
||||
echo "Processing Others....." && $PHP processOthers.php &
|
||||
echo "Processing Unwanted....." && $PHP processUnwanted.php &
|
||||
|
||||
wait
|
||||
sleep 30
|
||||
|
||||
done
|
||||
exit
|
||||
+1
-12
@@ -1,16 +1,7 @@
|
||||
<?php
|
||||
|
||||
require("config.php");
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
require("pid.php");
|
||||
|
||||
$filename = pathinfo(__FILE__, PATHINFO_FILENAME);
|
||||
|
||||
$pidfile = new pidfile("/tmp", $filename);
|
||||
if($pidfile->is_already_running()) {
|
||||
echo "Already running.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = new DB();
|
||||
$query = "select count(rn.releaseID) from releasenfo rn left outer join releases r ON r.ID = rn.releaseID WHERE rn.nfo IS NULL AND rn.attempts < 5";
|
||||
@@ -19,7 +10,6 @@ $i=1;
|
||||
while($i=1)
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
//$result = $db->queryDirect($query);
|
||||
|
||||
if (empty($result)) {
|
||||
$result = $db->queryDirect($query);
|
||||
@@ -33,7 +23,6 @@ while($i=1)
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$count = $row['count(rn.releaseID)'];
|
||||
}
|
||||
|
||||
if ($count > 0) {
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processNfos();
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
require("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
require("pid.php");
|
||||
|
||||
$filename = pathinfo(__FILE__, PATHINFO_FILENAME);
|
||||
|
||||
$pidfile = new pidfile("/tmp", $filename);
|
||||
if($pidfile->is_already_running()) {
|
||||
echo "Already running.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processTv();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processGames();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processMovies();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processMusic();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processBooks();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processUnwanted();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processMusicFromMediaInfo();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processOtherMiscCategory();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processUnknownCategory();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
require("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
require("pid.php");
|
||||
|
||||
$filename = pathinfo(__FILE__, PATHINFO_FILENAME);
|
||||
|
||||
$pidfile = new pidfile("/tmp", $filename);
|
||||
if($pidfile->is_already_running()) {
|
||||
echo "Already running.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processAdditional();
|
||||
}
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/postprocess2.php");
|
||||
|
||||
$db = new DB();
|
||||
$query = "select format(count(*),0) 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))";
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
|
||||
if (empty($result)) {
|
||||
$result = $db->queryDirect($query);
|
||||
if (empty($result)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$count = $row['format(count(*),0)'];
|
||||
}
|
||||
|
||||
if ($count > 50) {
|
||||
$postprocess = new PostProcess2(true);
|
||||
$postprocess->processAdditional2();
|
||||
} else {
|
||||
echo "$count releases left to process\n";
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
mysql_free_result($result);
|
||||
|
||||
?>
|
||||
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
$newzpath = getenv('NEWZPATH');
|
||||
require_once("$newzpath/www/config.php");
|
||||
require_once("lib/postprocess3.php");
|
||||
|
||||
$db = new DB();
|
||||
$query = "select format(count(*),0) 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))";
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
$result = mysql_query($query);
|
||||
|
||||
if (empty($result)) {
|
||||
$result = $db->queryDirect($query);
|
||||
if (empty($result)) {
|
||||
$message = 'Invalid query: ' . mysql_error() . "\n";
|
||||
$message .= 'Whole query: ' . $query;
|
||||
die($message);
|
||||
}
|
||||
}
|
||||
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$count = $row['format(count(*),0)'];
|
||||
}
|
||||
|
||||
if ($count > 200) {
|
||||
$postprocess = new PostProcess3(true);
|
||||
$postprocess->processAdditional3();
|
||||
} else {
|
||||
echo "$count releases left to process\n";
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
mysql_free_result($result);
|
||||
|
||||
?>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processBooks();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processGames();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processMovies();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processMusic();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processMusicFromMediaInfo();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processOtherMiscCategory();
|
||||
}
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processUnknownCategory();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processTv();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/postprocess.php");
|
||||
|
||||
$i=1;
|
||||
while($i=1)
|
||||
{
|
||||
{
|
||||
$postprocess = new PostProcess(true);
|
||||
$postprocess->processUnwanted();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
source ../edit_these.sh
|
||||
@@ -111,4 +110,4 @@ else
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
exit
|
||||
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once("/var/www/newznab/www/config.php");
|
||||
require_once("/var/www/newznab/www/lib/framework/db.php");
|
||||
|
||||
$db = new DB();
|
||||
|
||||
echo "This script will convert only your releases, parts and binaries table back to InnoDB.\n";
|
||||
echo "This may take a while depending on how large your tables are. Do not stop this script. It will finish.\n\n";
|
||||
|
||||
echo "Converting the binaries table back to InnoDB\n";
|
||||
$db->query("ALTER TABLE binaries ENGINE=InnoDB ROW_FORMAT=DYNAMIC;");
|
||||
echo "Finished converting the binaries table back to InnoDB.\n\n";
|
||||
|
||||
echo "Converting the parts table back to InnoDB\n";
|
||||
$db->query("ALTER TABLE parts ENGINE=InnoDB ROW_FORMAT=DYNAMIC;");
|
||||
echo "Finished converting the parts table back to InnoDB.\n\n";
|
||||
|
||||
echo "Converting the releases table back to InnoDB\n";
|
||||
$db->query("ALTER TABLE releases ENGINE=InnoDB ROW_FORMAT=DYNAMIC;");
|
||||
echo "Finished converting the releases table back to InnoDB.\n\n";
|
||||
|
||||
?>
|
||||
+5
-15
@@ -8,11 +8,11 @@ export NEWZNAB_PATH=$NEWZPATH"/misc/update_scripts"
|
||||
export INNODB_PATH=$NEWZPATH"/misc/testing/innodb"
|
||||
export TESTING_PATH=$NEWZPATH"/misc/testing"
|
||||
export ADMIN_PATH=$NEWZPATH"/www/admin"
|
||||
export USERNAME="whats 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"
|
||||
@@ -23,16 +23,10 @@ export INNODB="true"
|
||||
#Choose to run update_cleanup.php true/false
|
||||
export CLEANUP="true"
|
||||
|
||||
#Choose which app to run in the middle right pane, of course it must be installed. Your choices are mytop and bwm-ng.
|
||||
#Only have 1 uncommented at a time.
|
||||
|
||||
#export CHOICE_APP="bwm-ng"
|
||||
export CHOICE_APP="mytop"
|
||||
|
||||
#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##
|
||||
|
||||
@@ -41,10 +35,6 @@ 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`
|
||||
if [[ $CHOICE_APP == "bwm-ng" ]]; 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 [[ $CHOICE_APP == "mytop" ]]; 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
|
||||
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`
|
||||
|
||||
|
||||
@@ -78,3 +78,12 @@ chmod -R 777 $NEWZPATH/nzbfiles
|
||||
chmod 777 $NEWZPATH/nzbfiles/tmpunrar/
|
||||
|
||||
echo -e "\033[38;5;160mCompleted\033[39m"
|
||||
|
||||
echo -e "This script includes nmon and mytop. Please install them prior to running ./start.sh."
|
||||
echo -e "If the nmon pane close when you select networking, then you will need to use sudo or su."
|
||||
echo -e "Tmux is very easy to use. To detach from the current session, use Ctrl-a d. You can select"
|
||||
echo -e "simply by clicking in it and you can resize by dragging the borders."
|
||||
|
||||
|
||||
exit
|
||||
|
||||
|
||||
@@ -18,22 +18,32 @@ if [[ $AGREED == "no" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
$TMUX new-session -d -s NewzNab -n NewzNab 'echo "processNfos Working......" && $PHP bin/postprocess_nfo.php;exec bash -i'
|
||||
$TMUX new-session -d -s NewzNab -n NewzNab 'echo "processNfos Working......" && sleep 3 && $PHP bin/postprocess_nfo.php;exec bash -i'
|
||||
$TMUX selectp -t 0
|
||||
$TMUX splitw -v -p 82 'echo "monitor Working......" && $PHP bin/monitor.php;exec bash -i'
|
||||
$TMUX splitw -v -p 66 'cd bin && echo "imports Working......" && ./workhorse.sh;exec bash -i'
|
||||
$TMUX splitw -v -p 80 'echo "monitor Working......" && $PHP bin/monitor.php;exec bash -i'
|
||||
$TMUX selectp -t 0
|
||||
$TMUX splitw -h -p 66 'echo "processAdditional Working......" && $PHP bin/processAlternate.php;exec bash -i'
|
||||
$TMUX splitw -h -p 50 'echo "postProcessing Working......" && $PHP bin/postprocessing.php;exec bash -i'
|
||||
$TMUX splitw -h -p 80 'echo "processAdditional Thread #1 Working......" && sleep 6 && $PHP bin/processAlternate2.php;exec bash -i'
|
||||
$TMUX selectp -t 3
|
||||
if [[ $CHOICE_APP == "mytop" ]]; then
|
||||
$TMUX splitw -h -p 50 '$MYTOP -u $DB_USER -p $DB_PASSWORD -d $DB_NAME -h $DB_HOST'
|
||||
else
|
||||
$TMUX splitw -h -p 50 '$BWMNG'
|
||||
fi
|
||||
$TMUX selectp -t 5
|
||||
$TMUX splitw -h -p 50 'cd bin && echo "create Releases Working......" && ./cleanup_scripts.sh;exec bash -i'
|
||||
$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 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 50 '$MYTOP -u $DB_USER -p $DB_PASSWORD -d $DB_NAME -h $DB_HOST'
|
||||
$TMUX selectp -t 12
|
||||
$TMUX splitw -h -p 50 'cd bin && echo "create Releases Working......" && ./cleanup_scripts.sh;exec bash -i'
|
||||
|
||||
$TMUX select-window -tNewzNab:0
|
||||
$TMUX attach-session -d -tNewzNab
|
||||
|
||||
|
||||
Reference in New Issue
Block a user