Add last rar/zip file checking support.

(cherry picked from commit 9bb992c)
This commit is contained in:
Darko
2015-06-19 08:59:30 +02:00
parent e6ec95ec8f
commit 456a67ec8c
5 changed files with 92 additions and 17 deletions
+41 -8
View File
@@ -606,6 +606,11 @@ class ProcessAdditional
// Download the RARs/ZIPs, extract the files inside them and insert the file info into the DB.
$this->_processNZBCompressedFiles();
// Download rar/zip in reverse order, to get the last rar or zip file.
if ($this->pdo->getSetting('fetchlastcompressedfiles') == 1) {
$this->_processNZBCompressedFiles(true);
}
if ($this->_releaseHasPassword === false) {
// Process the extracted files to get video/audio samples/etc.
$this->_processExtractedFiles();
@@ -706,8 +711,8 @@ class ProcessAdditional
return $this->_decrementPasswordStatus();
}
// Sort the files inside the NZB.
usort($this->_nzbContents, ['\newznab\processing\post\ProcessAdditional', '_sortNZB']);
// Sort keys.
ksort($this->_nzbContents, SORT_NATURAL);
return true;
}
@@ -761,7 +766,7 @@ class ProcessAdditional
// Check if it's a rar/zip.
if ($this->_NZBHasCompressedFile === false &&
preg_match(
'/\.(part0*1|part0+|r0+|r0*1|rar|0+|0*10?|zipr\d{2,3}|zipx?)(\s*\.rar)*($|[ ")\]-])|"[a-f0-9]{32}\.[1-9]\d{1,2}".*\(\d+\/\d{2,}\)$/i',
'/\.(part\d+|r\d+|rar|0+|0*10?|zipr\d{2,3}|zipx?)(\s*\.rar)*($|[ ")\]-])|"[a-f0-9]{32}\.[1-9]\d{1,2}".*\(\d+\/\d{2,}\)$/i',
$this->_currentNZBFile['title']
)
) {
@@ -842,13 +847,30 @@ class ProcessAdditional
}
/**
* Process the NZB contents, find RAR/ZIP files, download them and extract them.
* List of message-id's we have tried for rar/zip files.
* @var array
*/
protected function _processNZBCompressedFiles()
protected $_triedCompressedMids = [];
/**
* Process the NZB contents, find RAR/ZIP files, download them and extract them.
*
* @param bool $reverse Reverse sort $this->_nzbContents ? - To find the largest rar / zip file first.
*/
protected function _processNZBCompressedFiles($reverse = false)
{
if ($reverse) {
if (!krsort($this->_nzbContents)) {
return;
}
} else {
$this->_triedCompressedMids = [];
}
$failed = $downloaded = 0;
// Loop through the files, attempt to find if password-ed and files. Starting with what not to process.
foreach ($this->_nzbContents as $nzbFile) {
// TODO change this to max calculated size, as segments vary in size greatly.
if ($downloaded >= $this->_maximumRarSegments) {
break;
} else if ($failed >= $this->_maximumRarPasswordChecks) {
@@ -862,7 +884,7 @@ class ProcessAdditional
// Probably not a rar/zip.
if (!preg_match(
'/\.(part0*1|part0+|r0+|r0*1|rar|0+|0*10?|zipr\d{2,3}|zipx?)(\s*\.rar)*($|[ ")\]-])|"[a-f0-9]{32}\.[1-9]\d{1,2}".*\(\d+\/\d{2,}\)$/i',
'/\.(part\d+|r\d+|rar|0+|0*10?|zipr\d{2,3}|zipx?)(\s*\.rar)*($|[ ")\]-])|"[a-f0-9]{32}\.[1-9]\d{1,2}".*\(\d+\/\d{2,}\)$/i',
$nzbFile['title']
)
) {
@@ -871,12 +893,23 @@ class ProcessAdditional
// Get message-id's for the rar file.
$segCount = (count($nzbFile['segments']) - 1);
$mID = array();
$mID = [];
for ($i = 0; $i < $this->_maximumRarSegments; $i++) {
if ($i > $segCount) {
break;
}
$mID[] = (string)$nzbFile['segments'][$i];
$segment = (string)$nzbFile['segments'][$i];
if (!$reverse) {
$this->_triedCompressedMids[] = $segment;
} else if (in_array($segment, $this->_triedCompressedMids)) {
// We already downloaded this file.
continue 2;
}
$mID[] = $segment;
}
// Nothing to download.
if (empty($mID)) {
continue;
}
// Download the article(s) from usenet.