@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param int $groupID |
| 114 | 114 | * @param string $groupName |
| 115 | 115 | * |
| 116 | - * @return bool |
|
| 116 | + * @return false|string |
|
| 117 | 117 | * |
| 118 | 118 | * @access public |
| 119 | 119 | */ |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param int $groupID |
| 162 | 162 | * @param bool $nfoCheck |
| 163 | 163 | * |
| 164 | - * @return array|bool |
|
| 164 | + * @return string |
|
| 165 | 165 | * |
| 166 | 166 | * @access public |
| 167 | 167 | */ |
@@ -197,8 +197,7 @@ |
||
| 197 | 197 | !preg_match('/\.(apk|bat|bmp|cbr|cbz|cfg|css|csv|cue|db|dll|doc|epub|exe|gif|htm|ico|idx|ini' . |
| 198 | 198 | '|jpg|lit|log|m3u|mid|mobi|mp3|nib|nzb|odt|opf|otf|par|par2|pdf|psd|pps|png|ppt|r\d{2,4}' . |
| 199 | 199 | '|rar|sfv|srr|sub|srt|sql|rom|rtf|tif|torrent|ttf|txt|vb|vol\d+\+\d+|wps|xml|zip)/i', |
| 200 | - $subject)) |
|
| 201 | - { |
|
| 200 | + $subject)) { |
|
| 202 | 201 | $hiddenID = (string)$nzbcontents->segments->segment; |
| 203 | 202 | $hiddenNFO = true; |
| 204 | 203 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | * |
| 11 | 11 | * Class NZBContents |
| 12 | 12 | */ |
| 13 | -Class NZBContents |
|
| 13 | +class NZBContents |
|
| 14 | 14 | { |
| 15 | 15 | /** |
| 16 | 16 | * @var \nntmux\db\Settings |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * |
| 347 | 347 | * @param int $limit The speed to limit it to. |
| 348 | 348 | * |
| 349 | - * @return bool |
|
| 349 | + * @return boolean|null |
|
| 350 | 350 | * |
| 351 | 351 | * @access public |
| 352 | 352 | */ |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | /** |
| 400 | 400 | * Request for current status (summary) information. Parts of informations returned by this method can be printed by command "nzbget -L". |
| 401 | 401 | * |
| 402 | - * @return array The status. |
|
| 402 | + * @return boolean The status. |
|
| 403 | 403 | * |
| 404 | 404 | * @access public |
| 405 | 405 | */ |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * |
| 429 | 429 | * @param string $url NZBGet URL to verify. |
| 430 | 430 | * |
| 431 | - * @return bool|string |
|
| 431 | + * @return string|false |
|
| 432 | 432 | * |
| 433 | 433 | * @access public |
| 434 | 434 | */ |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $this->rsstoken = $page->userdata['rsstoken']; |
| 89 | 89 | |
| 90 | 90 | if (!empty($page->userdata['nzbgeturl'])) { |
| 91 | - $this->url = $page->userdata['nzbgeturl']; |
|
| 91 | + $this->url = $page->userdata['nzbgeturl']; |
|
| 92 | 92 | $this->userName = (empty($page->userdata['nzbgetusername']) ? '' : $page->userdata['nzbgetusername']); |
| 93 | 93 | $this->password = (empty($page->userdata['nzbgetpassword']) ? '' : $page->userdata['nzbgetpassword']); |
| 94 | 94 | } |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | if ($xml) { |
| 382 | 382 | $retVal = []; |
| 383 | 383 | $i = 0; |
| 384 | - foreach($xml->params->param->value->array->data->value as $value) { |
|
| 384 | + foreach ($xml->params->param->value->array->data->value as $value) { |
|
| 385 | 385 | foreach ($value->struct->member as $member) { |
| 386 | 386 | $value = (array)$member->value; |
| 387 | 387 | $value = array_shift($value); |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | if ($data) { |
| 411 | 411 | $xml = simplexml_load_string($data); |
| 412 | 412 | if ($xml) { |
| 413 | - foreach($xml->params->param->value->struct->member as $member) { |
|
| 413 | + foreach ($xml->params->param->value->struct->member as $member) { |
|
| 414 | 414 | $value = (array)$member->value; |
| 415 | 415 | $value = array_shift($value); |
| 416 | 416 | if (!is_object($value)) { |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * |
| 433 | 433 | * @access public |
| 434 | 434 | */ |
| 435 | - public function verifyURL ($url) |
|
| 435 | + public function verifyURL($url) |
|
| 436 | 436 | { |
| 437 | 437 | if (preg_match('/(?P<protocol>https?):\/\/(?P<url>.+?)(:(?P<port>\d+\/)|\/)$/i', $url, $matches)) { |
| 438 | 438 | return |
@@ -68,6 +68,9 @@ |
||
| 68 | 68 | return $this->isLoaded; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | + /** |
|
| 72 | + * @param string $loc |
|
| 73 | + */ |
|
| 71 | 74 | public function loadFromFile($loc, $loadAllVars=false) |
| 72 | 75 | { |
| 73 | 76 | $this->source = $loc; |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | public $zipcount = 0; |
| 13 | 13 | public $videocount = 0; |
| 14 | 14 | public $audiocount = 0; |
| 15 | - public $imgcount = 0; |
|
| 16 | - public $srrcount = 0; |
|
| 17 | - public $txtcount = 0; |
|
| 18 | - public $sfvcount = 0; |
|
| 15 | + public $imgcount = 0; |
|
| 16 | + public $srrcount = 0; |
|
| 17 | + public $txtcount = 0; |
|
| 18 | + public $sfvcount = 0; |
|
| 19 | 19 | public $filesize = 0; |
| 20 | 20 | public $poster = ''; |
| 21 | 21 | public $postedfirst = 0; |
@@ -31,27 +31,27 @@ discard block |
||
| 31 | 31 | public $mediafiles = []; |
| 32 | 32 | public $audiofiles = []; |
| 33 | 33 | public $rarfiles = []; |
| 34 | - public $imgfiles = []; |
|
| 35 | - public $srrfiles = []; |
|
| 36 | - public $txtfiles = []; |
|
| 37 | - public $sfvfiles = []; |
|
| 34 | + public $imgfiles = []; |
|
| 35 | + public $srrfiles = []; |
|
| 36 | + public $txtfiles = []; |
|
| 37 | + public $sfvfiles = []; |
|
| 38 | 38 | public $segmentfiles = []; |
| 39 | - public $parfiles = []; |
|
| 39 | + public $parfiles = []; |
|
| 40 | 40 | |
| 41 | - private $isLoaded = false; |
|
| 41 | + private $isLoaded = false; |
|
| 42 | 42 | private $loadAllVars = false; |
| 43 | 43 | |
| 44 | 44 | public function __construct() |
| 45 | 45 | { |
| 46 | - $this->nfofileregex = '/[ "\(\[].*?\.(nfo|ofn)[ "\)\]]/iS'; |
|
| 47 | - $this->mediafileregex = '/.*\.(AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG)(\.001)?[ "\)\]]/iS'; |
|
| 48 | - $this->audiofileregex = '/\.(MP3|FLAC|AAC|OGG|AIFF)[ "\)\]]/iS'; |
|
| 49 | - $this->rarfileregex = '/.*\W(?:part0*1|(?!part\d+)[^.]+)\.(rar|001)[ "\)\]]/iS'; |
|
| 50 | - $this->imgfileregex = '/\.(jpe?g|gif)[ "\)\]]/iS'; |
|
| 51 | - $this->srrfileregex = '/\.(srr)[ "\)\]]/iS'; |
|
| 52 | - $this->txtfileregex = '/\.(txt)[ "\)\]]/iS'; |
|
| 53 | - $this->sfvfileregex = '/\.(sfv)[ "\)\]]/iS'; |
|
| 54 | - } |
|
| 46 | + $this->nfofileregex = '/[ "\(\[].*?\.(nfo|ofn)[ "\)\]]/iS'; |
|
| 47 | + $this->mediafileregex = '/.*\.(AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG)(\.001)?[ "\)\]]/iS'; |
|
| 48 | + $this->audiofileregex = '/\.(MP3|FLAC|AAC|OGG|AIFF)[ "\)\]]/iS'; |
|
| 49 | + $this->rarfileregex = '/.*\W(?:part0*1|(?!part\d+)[^.]+)\.(rar|001)[ "\)\]]/iS'; |
|
| 50 | + $this->imgfileregex = '/\.(jpe?g|gif)[ "\)\]]/iS'; |
|
| 51 | + $this->srrfileregex = '/\.(srr)[ "\)\]]/iS'; |
|
| 52 | + $this->txtfileregex = '/\.(txt)[ "\)\]]/iS'; |
|
| 53 | + $this->sfvfileregex = '/\.(sfv)[ "\)\]]/iS'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | public function loadFromString($str, $loadAllVars=false) |
| 57 | 57 | { |
@@ -68,39 +68,39 @@ discard block |
||
| 68 | 68 | return $this->isLoaded; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function loadFromFile($loc, $loadAllVars=false) |
|
| 72 | - { |
|
| 73 | - $this->source = $loc; |
|
| 74 | - $this->loadAllVars = $loadAllVars; |
|
| 75 | - |
|
| 76 | - if (file_exists($loc)) |
|
| 77 | - { |
|
| 78 | - if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) |
|
| 79 | - { |
|
| 80 | - switch(strtolower($ext[1])) |
|
| 81 | - { |
|
| 82 | - case 'gz': |
|
| 83 | - $loc = 'compress.zlib://'.$loc; |
|
| 84 | - break; |
|
| 85 | - case 'zip': |
|
| 86 | - $zip = new ZipArchive; |
|
| 87 | - if ($zip->open($loc) === true && $zip->numFiles == 1) |
|
| 88 | - return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
|
| 89 | - else |
|
| 90 | - $loc = 'zip://'.$loc; |
|
| 91 | - break; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - libxml_use_internal_errors(true); |
|
| 96 | - $xmlObj = @simplexml_load_file($loc); |
|
| 97 | - if ($this->isValidNzb($xmlObj)) |
|
| 98 | - $this->parseNzb($xmlObj); |
|
| 99 | - |
|
| 100 | - unset($xmlObj); |
|
| 101 | - } |
|
| 102 | - return $this->isLoaded; |
|
| 103 | - } |
|
| 71 | + public function loadFromFile($loc, $loadAllVars=false) |
|
| 72 | + { |
|
| 73 | + $this->source = $loc; |
|
| 74 | + $this->loadAllVars = $loadAllVars; |
|
| 75 | + |
|
| 76 | + if (file_exists($loc)) |
|
| 77 | + { |
|
| 78 | + if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) |
|
| 79 | + { |
|
| 80 | + switch(strtolower($ext[1])) |
|
| 81 | + { |
|
| 82 | + case 'gz': |
|
| 83 | + $loc = 'compress.zlib://'.$loc; |
|
| 84 | + break; |
|
| 85 | + case 'zip': |
|
| 86 | + $zip = new ZipArchive; |
|
| 87 | + if ($zip->open($loc) === true && $zip->numFiles == 1) |
|
| 88 | + return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
|
| 89 | + else |
|
| 90 | + $loc = 'zip://'.$loc; |
|
| 91 | + break; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + libxml_use_internal_errors(true); |
|
| 96 | + $xmlObj = @simplexml_load_file($loc); |
|
| 97 | + if ($this->isValidNzb($xmlObj)) |
|
| 98 | + $this->parseNzb($xmlObj); |
|
| 99 | + |
|
| 100 | + unset($xmlObj); |
|
| 101 | + } |
|
| 102 | + return $this->isLoaded; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | public function summarize() |
| 106 | 106 | { |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $out[] = ' -size: '.round(($this->filesize / 1048576), 2).' MB in '.$this->filecount.' Files'; |
| 130 | 130 | $out[] = ' -'.$this->rarcount.' rars'; |
| 131 | 131 | $out[] = ' -'.$this->parcount.' pars'; |
| 132 | - $out[] = ' -'.$this->sfvcount.' sfvs'; |
|
| 132 | + $out[] = ' -'.$this->sfvcount.' sfvs'; |
|
| 133 | 133 | $out[] = ' -'.$this->zipcount.' zips'; |
| 134 | 134 | $out[] = ' -'.$this->videocount.' videos'; |
| 135 | 135 | $out[] = ' -'.$this->audiocount.' audios'; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | if (!$xmlObj || strtolower($xmlObj->getName()) != 'nzb' || !isset($xmlObj->file)) |
| 147 | 147 | return false; |
| 148 | 148 | |
| 149 | - return true; |
|
| 149 | + return true; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | private function parseNzb($xmlObj) |
@@ -216,27 +216,27 @@ discard block |
||
| 216 | 216 | $fileArr['filesize'] += $bytes; |
| 217 | 217 | $fileArr['segmentactual']++; |
| 218 | 218 | $fileArr['segments'][$number] = (string) $segment; |
| 219 | - $fileArr['segmentbytes'][$number] = $bytes; |
|
| 219 | + $fileArr['segmentbytes'][$number] = $bytes; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $pattern = '|\((\d+)[\/](\d+)\)|i'; |
|
| 223 | + preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); |
|
| 224 | + $matchcnt = sizeof($matches[0]); |
|
| 225 | + $msgPart = $msgTotalParts = 0; |
|
| 226 | + for ($i=0; $i<$matchcnt; $i++) |
|
| 227 | + { |
|
| 228 | + //not (int)'d here because of the preg_replace later on |
|
| 229 | + $msgPart = $matches[1][$i]; |
|
| 230 | + $msgTotalParts = $matches[2][$i]; |
|
| 220 | 231 | } |
| 232 | + if((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
| 233 | + { |
|
| 234 | + $this->segmenttotal += (int) $msgTotalParts; |
|
| 235 | + $fileArr['segmenttotal'] = (int) $msgTotalParts; |
|
| 236 | + $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); |
|
| 221 | 237 | |
| 222 | - $pattern = '|\((\d+)[\/](\d+)\)|i'; |
|
| 223 | - preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); |
|
| 224 | - $matchcnt = sizeof($matches[0]); |
|
| 225 | - $msgPart = $msgTotalParts = 0; |
|
| 226 | - for ($i=0; $i<$matchcnt; $i++) |
|
| 227 | - { |
|
| 228 | - //not (int)'d here because of the preg_replace later on |
|
| 229 | - $msgPart = $matches[1][$i]; |
|
| 230 | - $msgTotalParts = $matches[2][$i]; |
|
| 231 | - } |
|
| 232 | - if((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
| 233 | - { |
|
| 234 | - $this->segmenttotal += (int) $msgTotalParts; |
|
| 235 | - $fileArr['segmenttotal'] = (int) $msgTotalParts; |
|
| 236 | - $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); |
|
| 237 | - |
|
| 238 | - $fileArr['subject'] = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $subject))); |
|
| 239 | - } |
|
| 238 | + $fileArr['subject'] = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $subject))); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | //file counts |
| 242 | 242 | $this->filecount++; |
@@ -268,36 +268,36 @@ discard block |
||
| 268 | 268 | $this->audiocount++; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if (preg_match($this->imgfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 272 | - { |
|
| 273 | - $this->imgfiles[] = $fileArr; |
|
| 274 | - $this->imgcount++; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - if (preg_match($this->srrfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 278 | - { |
|
| 279 | - $this->srrfiles[] = $fileArr; |
|
| 280 | - $this->srrcount++; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - if (preg_match($this->txtfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 284 | - { |
|
| 285 | - $this->txtfiles[] = $fileArr; |
|
| 286 | - $this->txtcount++; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (preg_match($this->sfvfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|nzb)/iS', $subject)) |
|
| 290 | - { |
|
| 291 | - $this->sfvfiles[] = $fileArr; |
|
| 292 | - $this->sfvcount++; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - if (preg_match('/\.par2(?!\.)/iS', $subject)) |
|
| 296 | - { |
|
| 297 | - $this->parcount++; |
|
| 298 | - if (!preg_match('/(vol\d+\+|vol[_\.\s]\d)/iS', $subject) && $fileArr['segmenttotal'] < 3) |
|
| 299 | - $this->parfiles[] = $fileArr; |
|
| 300 | - } |
|
| 271 | + if (preg_match($this->imgfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 272 | + { |
|
| 273 | + $this->imgfiles[] = $fileArr; |
|
| 274 | + $this->imgcount++; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + if (preg_match($this->srrfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 278 | + { |
|
| 279 | + $this->srrfiles[] = $fileArr; |
|
| 280 | + $this->srrcount++; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + if (preg_match($this->txtfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 284 | + { |
|
| 285 | + $this->txtfiles[] = $fileArr; |
|
| 286 | + $this->txtcount++; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (preg_match($this->sfvfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|nzb)/iS', $subject)) |
|
| 290 | + { |
|
| 291 | + $this->sfvfiles[] = $fileArr; |
|
| 292 | + $this->sfvcount++; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + if (preg_match('/\.par2(?!\.)/iS', $subject)) |
|
| 296 | + { |
|
| 297 | + $this->parcount++; |
|
| 298 | + if (!preg_match('/(vol\d+\+|vol[_\.\s]\d)/iS', $subject) && $fileArr['segmenttotal'] < 3) |
|
| 299 | + $this->parfiles[] = $fileArr; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | 302 | if (preg_match('/\.zip(?!\.)/i', $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) |
| 303 | 303 | $this->zipcount++; |
@@ -319,40 +319,40 @@ discard block |
||
| 319 | 319 | return $this->isLoaded; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - public function toNzb() |
|
| 323 | - { |
|
| 324 | - if ($this->loadAllVars === false) |
|
| 325 | - return false; |
|
| 326 | - |
|
| 327 | - $nzb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
|
| 328 | - $nzb .= "<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd\">\n"; |
|
| 329 | - $nzb .= "<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">\n\n"; |
|
| 330 | - if (!empty($this->metadata)) |
|
| 331 | - { |
|
| 332 | - $nzb .= "<head>\n"; |
|
| 322 | + public function toNzb() |
|
| 323 | + { |
|
| 324 | + if ($this->loadAllVars === false) |
|
| 325 | + return false; |
|
| 326 | + |
|
| 327 | + $nzb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
|
| 328 | + $nzb .= "<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd\">\n"; |
|
| 329 | + $nzb .= "<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">\n\n"; |
|
| 330 | + if (!empty($this->metadata)) |
|
| 331 | + { |
|
| 332 | + $nzb .= "<head>\n"; |
|
| 333 | 333 | $out = []; |
| 334 | - foreach($this->metadata as $mk=>$mv) |
|
| 335 | - $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
| 336 | - $nzb .= "</head>\n"; |
|
| 337 | - } |
|
| 338 | - foreach($this->nzb as $postFile) |
|
| 339 | - { |
|
| 340 | - $nzb .= "<file poster=\"".htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8')."\" date=\"".$postFile["posted"]."\" subject=\"".htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8')." (1/".$postFile["segmenttotal"].")\">\n"; |
|
| 341 | - $nzb .= " <groups>\n"; |
|
| 342 | - foreach($postFile['groups'] as $fileGroup) |
|
| 343 | - { |
|
| 344 | - $nzb .= " <group>".$fileGroup."</group>\n"; |
|
| 345 | - } |
|
| 346 | - $nzb .= " </groups>\n"; |
|
| 347 | - $nzb .= " <segments>\n"; |
|
| 348 | - foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
| 349 | - { |
|
| 350 | - $nzb .= " <segment bytes=\"".$postFile['segmentbytes'][$fileSegmentNum]."\" number=\"".$fileSegmentNum."\">".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."</segment>\n"; |
|
| 351 | - } |
|
| 352 | - $nzb .= " </segments>\n</file>\n"; |
|
| 353 | - } |
|
| 354 | - $nzb .= "<!-- nntmux ".date("Y-m-d H:i:s")." -->\n</nzb>"; |
|
| 355 | - |
|
| 356 | - return $nzb; |
|
| 357 | - } |
|
| 334 | + foreach($this->metadata as $mk=>$mv) |
|
| 335 | + $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
| 336 | + $nzb .= "</head>\n"; |
|
| 337 | + } |
|
| 338 | + foreach($this->nzb as $postFile) |
|
| 339 | + { |
|
| 340 | + $nzb .= "<file poster=\"".htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8')."\" date=\"".$postFile["posted"]."\" subject=\"".htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8')." (1/".$postFile["segmenttotal"].")\">\n"; |
|
| 341 | + $nzb .= " <groups>\n"; |
|
| 342 | + foreach($postFile['groups'] as $fileGroup) |
|
| 343 | + { |
|
| 344 | + $nzb .= " <group>".$fileGroup."</group>\n"; |
|
| 345 | + } |
|
| 346 | + $nzb .= " </groups>\n"; |
|
| 347 | + $nzb .= " <segments>\n"; |
|
| 348 | + foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
| 349 | + { |
|
| 350 | + $nzb .= " <segment bytes=\"".$postFile['segmentbytes'][$fileSegmentNum]."\" number=\"".$fileSegmentNum."\">".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."</segment>\n"; |
|
| 351 | + } |
|
| 352 | + $nzb .= " </segments>\n</file>\n"; |
|
| 353 | + } |
|
| 354 | + $nzb .= "<!-- nntmux ".date("Y-m-d H:i:s")." -->\n</nzb>"; |
|
| 355 | + |
|
| 356 | + return $nzb; |
|
| 357 | + } |
|
| 358 | 358 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | public $txtcount = 0; |
| 18 | 18 | public $sfvcount = 0; |
| 19 | 19 | public $filesize = 0; |
| 20 | - public $poster = ''; |
|
| 20 | + public $poster = ''; |
|
| 21 | 21 | public $postedfirst = 0; |
| 22 | 22 | public $postedlast = 0; |
| 23 | 23 | public $completion = 0; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $this->sfvfileregex = '/\.(sfv)[ "\)\]]/iS'; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function loadFromString($str, $loadAllVars=false) |
|
| 56 | + public function loadFromString($str, $loadAllVars = false) |
|
| 57 | 57 | { |
| 58 | 58 | if (empty($this->source)) |
| 59 | 59 | $this->source = 'string'; |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | return $this->isLoaded; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function loadFromFile($loc, $loadAllVars=false) |
|
| 71 | + public function loadFromFile($loc, $loadAllVars = false) |
|
| 72 | 72 | { |
| 73 | 73 | $this->source = $loc; |
| 74 | 74 | $this->loadAllVars = $loadAllVars; |
@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) |
| 79 | 79 | { |
| 80 | - switch(strtolower($ext[1])) |
|
| 80 | + switch (strtolower($ext[1])) |
|
| 81 | 81 | { |
| 82 | 82 | case 'gz': |
| 83 | - $loc = 'compress.zlib://'.$loc; |
|
| 83 | + $loc = 'compress.zlib://' . $loc; |
|
| 84 | 84 | break; |
| 85 | 85 | case 'zip': |
| 86 | 86 | $zip = new ZipArchive; |
| 87 | 87 | if ($zip->open($loc) === true && $zip->numFiles == 1) |
| 88 | 88 | return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
| 89 | 89 | else |
| 90 | - $loc = 'zip://'.$loc; |
|
| 90 | + $loc = 'zip://' . $loc; |
|
| 91 | 91 | break; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | public function summarize() |
| 106 | 106 | { |
| 107 | 107 | $out = []; |
| 108 | - $out[] = 'Reading from '.basename($this->source).'...'; |
|
| 108 | + $out[] = 'Reading from ' . basename($this->source) . '...'; |
|
| 109 | 109 | if (!empty($this->nfofiles)) |
| 110 | 110 | $out[] = ' -nfo detected'; |
| 111 | 111 | if (!empty($this->samplefiles)) |
@@ -118,23 +118,23 @@ discard block |
||
| 118 | 118 | if (!empty($this->metadata)) |
| 119 | 119 | { |
| 120 | 120 | $out[] = ' -metadata:'; |
| 121 | - foreach($this->metadata as $mk=>$mv) |
|
| 122 | - $out[] = ' -'.$mk.': '.$mv; |
|
| 121 | + foreach ($this->metadata as $mk=>$mv) |
|
| 122 | + $out[] = ' -' . $mk . ': ' . $mv; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $out[] = ' -sngl: '.sizeof($this->segmentfiles); |
|
| 126 | - |
|
| 127 | - $out[] = ' -pstr: '.$this->poster; |
|
| 128 | - $out[] = ' -grps: '.implode(', ', $this->groups); |
|
| 129 | - $out[] = ' -size: '.round(($this->filesize / 1048576), 2).' MB in '.$this->filecount.' Files'; |
|
| 130 | - $out[] = ' -'.$this->rarcount.' rars'; |
|
| 131 | - $out[] = ' -'.$this->parcount.' pars'; |
|
| 132 | - $out[] = ' -'.$this->sfvcount.' sfvs'; |
|
| 133 | - $out[] = ' -'.$this->zipcount.' zips'; |
|
| 134 | - $out[] = ' -'.$this->videocount.' videos'; |
|
| 135 | - $out[] = ' -'.$this->audiocount.' audios'; |
|
| 136 | - $out[] = ' -cmpltn: '.$this->completion.'% ('.$this->segmentactual.'/'.$this->segmenttotal.')'; |
|
| 137 | - $out[] = ' -pstd: '.date("Y-m-d H:i:s", $this->postedlast); |
|
| 125 | + $out[] = ' -sngl: ' . sizeof($this->segmentfiles); |
|
| 126 | + |
|
| 127 | + $out[] = ' -pstr: ' . $this->poster; |
|
| 128 | + $out[] = ' -grps: ' . implode(', ', $this->groups); |
|
| 129 | + $out[] = ' -size: ' . round(($this->filesize / 1048576), 2) . ' MB in ' . $this->filecount . ' Files'; |
|
| 130 | + $out[] = ' -' . $this->rarcount . ' rars'; |
|
| 131 | + $out[] = ' -' . $this->parcount . ' pars'; |
|
| 132 | + $out[] = ' -' . $this->sfvcount . ' sfvs'; |
|
| 133 | + $out[] = ' -' . $this->zipcount . ' zips'; |
|
| 134 | + $out[] = ' -' . $this->videocount . ' videos'; |
|
| 135 | + $out[] = ' -' . $this->audiocount . ' audios'; |
|
| 136 | + $out[] = ' -cmpltn: ' . $this->completion . '% (' . $this->segmentactual . '/' . $this->segmenttotal . ')'; |
|
| 137 | + $out[] = ' -pstd: ' . date("Y-m-d H:i:s", $this->postedlast); |
|
| 138 | 138 | $out[] = ''; |
| 139 | 139 | $out[] = ''; |
| 140 | 140 | |
@@ -154,27 +154,27 @@ discard block |
||
| 154 | 154 | //Metadata |
| 155 | 155 | if (isset($xmlObj->head->meta)) |
| 156 | 156 | { |
| 157 | - foreach($xmlObj->head->meta as $meta) |
|
| 157 | + foreach ($xmlObj->head->meta as $meta) |
|
| 158 | 158 | { |
| 159 | 159 | if (isset($meta->attributes()->type)) |
| 160 | 160 | { |
| 161 | - $metaKey = (string) $meta->attributes()->type; |
|
| 162 | - $this->metadata[$metaKey] = (string) $meta; |
|
| 161 | + $metaKey = (string)$meta->attributes()->type; |
|
| 162 | + $this->metadata[$metaKey] = (string)$meta; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | //NZB GID = first segment of first file |
| 168 | - $gid = (string) $xmlObj->file->segments->segment; |
|
| 168 | + $gid = (string)$xmlObj->file->segments->segment; |
|
| 169 | 169 | if (!empty($gid)) |
| 170 | 170 | $this->gid = md5($gid); |
| 171 | 171 | |
| 172 | - foreach($xmlObj->file as $file) |
|
| 172 | + foreach ($xmlObj->file as $file) |
|
| 173 | 173 | { |
| 174 | 174 | $fileArr = []; |
| 175 | - $fileArr['subject'] = (string) $file->attributes()->subject; |
|
| 176 | - $fileArr['poster'] = (string) $file->attributes()->poster; |
|
| 177 | - $fileArr['posted'] = (int) $file->attributes()->date; |
|
| 175 | + $fileArr['subject'] = (string)$file->attributes()->subject; |
|
| 176 | + $fileArr['poster'] = (string)$file->attributes()->poster; |
|
| 177 | + $fileArr['posted'] = (int)$file->attributes()->date; |
|
| 178 | 178 | $fileArr['groups'] = []; |
| 179 | 179 | $fileArr['filesize'] = 0; |
| 180 | 180 | $fileArr['segmenttotal'] = 0; |
@@ -200,22 +200,22 @@ discard block |
||
| 200 | 200 | //groups |
| 201 | 201 | foreach ($file->groups->group as $group) |
| 202 | 202 | { |
| 203 | - $this->groups[] = (string) $group; |
|
| 204 | - $fileArr['groups'][] = (string) $group; |
|
| 203 | + $this->groups[] = (string)$group; |
|
| 204 | + $fileArr['groups'][] = (string)$group; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | //file segments |
| 208 | - foreach($file->segments->segment as $segment) |
|
| 208 | + foreach ($file->segments->segment as $segment) |
|
| 209 | 209 | { |
| 210 | - $bytes = (int) $segment->attributes()->bytes; |
|
| 211 | - $number = (int) $segment->attributes()->number; |
|
| 210 | + $bytes = (int)$segment->attributes()->bytes; |
|
| 211 | + $number = (int)$segment->attributes()->number; |
|
| 212 | 212 | |
| 213 | 213 | $this->filesize += $bytes; |
| 214 | 214 | $this->segmentactual++; |
| 215 | 215 | |
| 216 | 216 | $fileArr['filesize'] += $bytes; |
| 217 | 217 | $fileArr['segmentactual']++; |
| 218 | - $fileArr['segments'][$number] = (string) $segment; |
|
| 218 | + $fileArr['segments'][$number] = (string)$segment; |
|
| 219 | 219 | $fileArr['segmentbytes'][$number] = $bytes; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -223,19 +223,19 @@ discard block |
||
| 223 | 223 | preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); |
| 224 | 224 | $matchcnt = sizeof($matches[0]); |
| 225 | 225 | $msgPart = $msgTotalParts = 0; |
| 226 | - for ($i=0; $i<$matchcnt; $i++) |
|
| 226 | + for ($i = 0; $i < $matchcnt; $i++) |
|
| 227 | 227 | { |
| 228 | 228 | //not (int)'d here because of the preg_replace later on |
| 229 | 229 | $msgPart = $matches[1][$i]; |
| 230 | 230 | $msgTotalParts = $matches[2][$i]; |
| 231 | 231 | } |
| 232 | - if((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
| 232 | + if ((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
| 233 | 233 | { |
| 234 | - $this->segmenttotal += (int) $msgTotalParts; |
|
| 235 | - $fileArr['segmenttotal'] = (int) $msgTotalParts; |
|
| 236 | - $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); |
|
| 234 | + $this->segmenttotal += (int)$msgTotalParts; |
|
| 235 | + $fileArr['segmenttotal'] = (int)$msgTotalParts; |
|
| 236 | + $fileArr['completion'] = number_format(($fileArr['segmentactual'] / $fileArr['segmenttotal']) * 100, 0); |
|
| 237 | 237 | |
| 238 | - $fileArr['subject'] = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $subject))); |
|
| 238 | + $fileArr['subject'] = utf8_encode(trim(preg_replace('|\(' . $msgPart . '[\/]' . $msgTotalParts . '\)|i', '', $subject))); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | //file counts |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | $this->groups = array_unique($this->groups); |
| 312 | 312 | |
| 313 | 313 | if ($this->segmenttotal > 0) |
| 314 | - $this->completion = number_format(($this->segmentactual/$this->segmenttotal)*100, 0); |
|
| 314 | + $this->completion = number_format(($this->segmentactual / $this->segmenttotal) * 100, 0); |
|
| 315 | 315 | |
| 316 | 316 | if (is_array($this->nzb) && !empty($this->nzb)) |
| 317 | 317 | $this->isLoaded = true; |
@@ -331,27 +331,27 @@ discard block |
||
| 331 | 331 | { |
| 332 | 332 | $nzb .= "<head>\n"; |
| 333 | 333 | $out = []; |
| 334 | - foreach($this->metadata as $mk=>$mv) |
|
| 335 | - $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
| 334 | + foreach ($this->metadata as $mk=>$mv) |
|
| 335 | + $out[] = ' <meta type="' . $mk . '">' . $mv . "</meta>\n"; |
|
| 336 | 336 | $nzb .= "</head>\n"; |
| 337 | 337 | } |
| 338 | - foreach($this->nzb as $postFile) |
|
| 338 | + foreach ($this->nzb as $postFile) |
|
| 339 | 339 | { |
| 340 | - $nzb .= "<file poster=\"".htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8')."\" date=\"".$postFile["posted"]."\" subject=\"".htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8')." (1/".$postFile["segmenttotal"].")\">\n"; |
|
| 340 | + $nzb .= "<file poster=\"" . htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8') . "\" date=\"" . $postFile["posted"] . "\" subject=\"" . htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8') . " (1/" . $postFile["segmenttotal"] . ")\">\n"; |
|
| 341 | 341 | $nzb .= " <groups>\n"; |
| 342 | - foreach($postFile['groups'] as $fileGroup) |
|
| 342 | + foreach ($postFile['groups'] as $fileGroup) |
|
| 343 | 343 | { |
| 344 | - $nzb .= " <group>".$fileGroup."</group>\n"; |
|
| 344 | + $nzb .= " <group>" . $fileGroup . "</group>\n"; |
|
| 345 | 345 | } |
| 346 | 346 | $nzb .= " </groups>\n"; |
| 347 | 347 | $nzb .= " <segments>\n"; |
| 348 | - foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
| 348 | + foreach ($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
| 349 | 349 | { |
| 350 | - $nzb .= " <segment bytes=\"".$postFile['segmentbytes'][$fileSegmentNum]."\" number=\"".$fileSegmentNum."\">".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."</segment>\n"; |
|
| 350 | + $nzb .= " <segment bytes=\"" . $postFile['segmentbytes'][$fileSegmentNum] . "\" number=\"" . $fileSegmentNum . "\">" . htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8') . "</segment>\n"; |
|
| 351 | 351 | } |
| 352 | 352 | $nzb .= " </segments>\n</file>\n"; |
| 353 | 353 | } |
| 354 | - $nzb .= "<!-- nntmux ".date("Y-m-d H:i:s")." -->\n</nzb>"; |
|
| 354 | + $nzb .= "<!-- nntmux " . date("Y-m-d H:i:s") . " -->\n</nzb>"; |
|
| 355 | 355 | |
| 356 | 356 | return $nzb; |
| 357 | 357 | } |
@@ -55,13 +55,15 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function loadFromString($str, $loadAllVars=false) |
| 57 | 57 | { |
| 58 | - if (empty($this->source)) |
|
| 59 | - $this->source = 'string'; |
|
| 58 | + if (empty($this->source)) { |
|
| 59 | + $this->source = 'string'; |
|
| 60 | + } |
|
| 60 | 61 | $this->loadAllVars = $loadAllVars; |
| 61 | 62 | |
| 62 | 63 | $xmlObj = @simplexml_load_string($str); |
| 63 | - if ($this->isValidNzb($xmlObj)) |
|
| 64 | - $this->parseNzb($xmlObj); |
|
| 64 | + if ($this->isValidNzb($xmlObj)) { |
|
| 65 | + $this->parseNzb($xmlObj); |
|
| 66 | + } |
|
| 65 | 67 | |
| 66 | 68 | unset($xmlObj); |
| 67 | 69 | |
@@ -73,29 +75,28 @@ discard block |
||
| 73 | 75 | $this->source = $loc; |
| 74 | 76 | $this->loadAllVars = $loadAllVars; |
| 75 | 77 | |
| 76 | - if (file_exists($loc)) |
|
| 77 | - { |
|
| 78 | - if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) |
|
| 79 | - { |
|
| 80 | - switch(strtolower($ext[1])) |
|
| 81 | - { |
|
| 78 | + if (file_exists($loc)) { |
|
| 79 | + if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) { |
|
| 80 | + switch(strtolower($ext[1])) { |
|
| 82 | 81 | case 'gz': |
| 83 | 82 | $loc = 'compress.zlib://'.$loc; |
| 84 | 83 | break; |
| 85 | 84 | case 'zip': |
| 86 | 85 | $zip = new ZipArchive; |
| 87 | - if ($zip->open($loc) === true && $zip->numFiles == 1) |
|
| 88 | - return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
|
| 89 | - else |
|
| 90 | - $loc = 'zip://'.$loc; |
|
| 86 | + if ($zip->open($loc) === true && $zip->numFiles == 1) { |
|
| 87 | + return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
|
| 88 | + } else { |
|
| 89 | + $loc = 'zip://'.$loc; |
|
| 90 | + } |
|
| 91 | 91 | break; |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | libxml_use_internal_errors(true); |
| 96 | 96 | $xmlObj = @simplexml_load_file($loc); |
| 97 | - if ($this->isValidNzb($xmlObj)) |
|
| 98 | - $this->parseNzb($xmlObj); |
|
| 97 | + if ($this->isValidNzb($xmlObj)) { |
|
| 98 | + $this->parseNzb($xmlObj); |
|
| 99 | + } |
|
| 99 | 100 | |
| 100 | 101 | unset($xmlObj); |
| 101 | 102 | } |
@@ -106,20 +107,24 @@ discard block |
||
| 106 | 107 | { |
| 107 | 108 | $out = []; |
| 108 | 109 | $out[] = 'Reading from '.basename($this->source).'...'; |
| 109 | - if (!empty($this->nfofiles)) |
|
| 110 | - $out[] = ' -nfo detected'; |
|
| 111 | - if (!empty($this->samplefiles)) |
|
| 112 | - $out[] = ' -sample detected'; |
|
| 113 | - if (!empty($this->mediafiles)) |
|
| 114 | - $out[] = ' -media detected'; |
|
| 115 | - if (!empty($this->audio)) |
|
| 116 | - $out[] = ' -audio detected'; |
|
| 117 | - |
|
| 118 | - if (!empty($this->metadata)) |
|
| 119 | - { |
|
| 110 | + if (!empty($this->nfofiles)) { |
|
| 111 | + $out[] = ' -nfo detected'; |
|
| 112 | + } |
|
| 113 | + if (!empty($this->samplefiles)) { |
|
| 114 | + $out[] = ' -sample detected'; |
|
| 115 | + } |
|
| 116 | + if (!empty($this->mediafiles)) { |
|
| 117 | + $out[] = ' -media detected'; |
|
| 118 | + } |
|
| 119 | + if (!empty($this->audio)) { |
|
| 120 | + $out[] = ' -audio detected'; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if (!empty($this->metadata)) { |
|
| 120 | 124 | $out[] = ' -metadata:'; |
| 121 | - foreach($this->metadata as $mk=>$mv) |
|
| 122 | - $out[] = ' -'.$mk.': '.$mv; |
|
| 125 | + foreach($this->metadata as $mk=>$mv) { |
|
| 126 | + $out[] = ' -'.$mk.': '.$mv; |
|
| 127 | + } |
|
| 123 | 128 | } |
| 124 | 129 | |
| 125 | 130 | $out[] = ' -sngl: '.sizeof($this->segmentfiles); |
@@ -143,8 +148,9 @@ discard block |
||
| 143 | 148 | |
| 144 | 149 | private function isValidNzb($xmlObj) |
| 145 | 150 | { |
| 146 | - if (!$xmlObj || strtolower($xmlObj->getName()) != 'nzb' || !isset($xmlObj->file)) |
|
| 147 | - return false; |
|
| 151 | + if (!$xmlObj || strtolower($xmlObj->getName()) != 'nzb' || !isset($xmlObj->file)) { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 148 | 154 | |
| 149 | 155 | return true; |
| 150 | 156 | } |
@@ -152,12 +158,9 @@ discard block |
||
| 152 | 158 | private function parseNzb($xmlObj) |
| 153 | 159 | { |
| 154 | 160 | //Metadata |
| 155 | - if (isset($xmlObj->head->meta)) |
|
| 156 | - { |
|
| 157 | - foreach($xmlObj->head->meta as $meta) |
|
| 158 | - { |
|
| 159 | - if (isset($meta->attributes()->type)) |
|
| 160 | - { |
|
| 161 | + if (isset($xmlObj->head->meta)) { |
|
| 162 | + foreach($xmlObj->head->meta as $meta) { |
|
| 163 | + if (isset($meta->attributes()->type)) { |
|
| 161 | 164 | $metaKey = (string) $meta->attributes()->type; |
| 162 | 165 | $this->metadata[$metaKey] = (string) $meta; |
| 163 | 166 | } |
@@ -166,11 +169,11 @@ discard block |
||
| 166 | 169 | |
| 167 | 170 | //NZB GID = first segment of first file |
| 168 | 171 | $gid = (string) $xmlObj->file->segments->segment; |
| 169 | - if (!empty($gid)) |
|
| 170 | - $this->gid = md5($gid); |
|
| 172 | + if (!empty($gid)) { |
|
| 173 | + $this->gid = md5($gid); |
|
| 174 | + } |
|
| 171 | 175 | |
| 172 | - foreach($xmlObj->file as $file) |
|
| 173 | - { |
|
| 176 | + foreach($xmlObj->file as $file) { |
|
| 174 | 177 | $fileArr = []; |
| 175 | 178 | $fileArr['subject'] = (string) $file->attributes()->subject; |
| 176 | 179 | $fileArr['poster'] = (string) $file->attributes()->poster; |
@@ -190,23 +193,23 @@ discard block |
||
| 190 | 193 | |
| 191 | 194 | //dates |
| 192 | 195 | $date = $fileArr['posted']; |
| 193 | - if ($date > $this->postedlast || $this->postedlast == 0) |
|
| 194 | - $this->postedlast = $date; |
|
| 196 | + if ($date > $this->postedlast || $this->postedlast == 0) { |
|
| 197 | + $this->postedlast = $date; |
|
| 198 | + } |
|
| 195 | 199 | |
| 196 | - if ($date < $this->postedfirst || $this->postedfirst == 0) |
|
| 197 | - $this->postedfirst = $date; |
|
| 200 | + if ($date < $this->postedfirst || $this->postedfirst == 0) { |
|
| 201 | + $this->postedfirst = $date; |
|
| 202 | + } |
|
| 198 | 203 | |
| 199 | 204 | |
| 200 | 205 | //groups |
| 201 | - foreach ($file->groups->group as $group) |
|
| 202 | - { |
|
| 206 | + foreach ($file->groups->group as $group) { |
|
| 203 | 207 | $this->groups[] = (string) $group; |
| 204 | 208 | $fileArr['groups'][] = (string) $group; |
| 205 | 209 | } |
| 206 | 210 | |
| 207 | 211 | //file segments |
| 208 | - foreach($file->segments->segment as $segment) |
|
| 209 | - { |
|
| 212 | + foreach($file->segments->segment as $segment) { |
|
| 210 | 213 | $bytes = (int) $segment->attributes()->bytes; |
| 211 | 214 | $number = (int) $segment->attributes()->number; |
| 212 | 215 | |
@@ -223,14 +226,12 @@ discard block |
||
| 223 | 226 | preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); |
| 224 | 227 | $matchcnt = sizeof($matches[0]); |
| 225 | 228 | $msgPart = $msgTotalParts = 0; |
| 226 | - for ($i=0; $i<$matchcnt; $i++) |
|
| 227 | - { |
|
| 229 | + for ($i=0; $i<$matchcnt; $i++) { |
|
| 228 | 230 | //not (int)'d here because of the preg_replace later on |
| 229 | 231 | $msgPart = $matches[1][$i]; |
| 230 | 232 | $msgTotalParts = $matches[2][$i]; |
| 231 | 233 | } |
| 232 | - if((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
| 233 | - { |
|
| 234 | + if((int)$msgPart > 0 && (int)$msgTotalParts > 0) { |
|
| 234 | 235 | $this->segmenttotal += (int) $msgTotalParts; |
| 235 | 236 | $fileArr['segmenttotal'] = (int) $msgTotalParts; |
| 236 | 237 | $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); |
@@ -241,112 +242,113 @@ discard block |
||
| 241 | 242 | //file counts |
| 242 | 243 | $this->filecount++; |
| 243 | 244 | |
| 244 | - if ($fileArr['segmenttotal'] == 1) |
|
| 245 | - $this->segmentfiles[] = $fileArr; |
|
| 245 | + if ($fileArr['segmenttotal'] == 1) { |
|
| 246 | + $this->segmentfiles[] = $fileArr; |
|
| 247 | + } |
|
| 246 | 248 | |
| 247 | - if (preg_match($this->nfofileregex, $subject)) |
|
| 248 | - $this->nfofiles[] = $fileArr; |
|
| 249 | + if (preg_match($this->nfofileregex, $subject)) { |
|
| 250 | + $this->nfofiles[] = $fileArr; |
|
| 251 | + } |
|
| 249 | 252 | |
| 250 | - if (preg_match($this->mediafileregex, $subject) && preg_match('/sample[\.\-]/i', $subject) && !preg_match('/\.par2|\.srs/i', $subject)) |
|
| 251 | - $this->samplefiles[] = $fileArr; |
|
| 253 | + if (preg_match($this->mediafileregex, $subject) && preg_match('/sample[\.\-]/i', $subject) && !preg_match('/\.par2|\.srs/i', $subject)) { |
|
| 254 | + $this->samplefiles[] = $fileArr; |
|
| 255 | + } |
|
| 252 | 256 | |
| 253 | - if (preg_match($this->mediafileregex, $subject) && !preg_match('/sample[\.\-]/i', $subject) && !preg_match('/\.par2|\.srs/i', $subject)) |
|
| 254 | - { |
|
| 257 | + if (preg_match($this->mediafileregex, $subject) && !preg_match('/sample[\.\-]/i', $subject) && !preg_match('/\.par2|\.srs/i', $subject)) { |
|
| 255 | 258 | $this->mediafiles[] = $fileArr; |
| 256 | 259 | $this->videocount++; |
| 257 | 260 | } |
| 258 | 261 | |
| 259 | - if (preg_match('/\.(rar|r\d{2,3})(?!\.)/i', $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) |
|
| 260 | - $this->rarcount++; |
|
| 262 | + if (preg_match('/\.(rar|r\d{2,3})(?!\.)/i', $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) { |
|
| 263 | + $this->rarcount++; |
|
| 264 | + } |
|
| 261 | 265 | |
| 262 | - if (preg_match($this->rarfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) |
|
| 263 | - $this->rarfiles[] = $fileArr; |
|
| 266 | + if (preg_match($this->rarfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) { |
|
| 267 | + $this->rarfiles[] = $fileArr; |
|
| 268 | + } |
|
| 264 | 269 | |
| 265 | - if (preg_match($this->audiofileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) |
|
| 266 | - { |
|
| 270 | + if (preg_match($this->audiofileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) { |
|
| 267 | 271 | $this->audiofiles[] = $fileArr; |
| 268 | 272 | $this->audiocount++; |
| 269 | 273 | } |
| 270 | 274 | |
| 271 | - if (preg_match($this->imgfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 272 | - { |
|
| 275 | + if (preg_match($this->imgfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) { |
|
| 273 | 276 | $this->imgfiles[] = $fileArr; |
| 274 | 277 | $this->imgcount++; |
| 275 | 278 | } |
| 276 | 279 | |
| 277 | - if (preg_match($this->srrfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 278 | - { |
|
| 280 | + if (preg_match($this->srrfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) { |
|
| 279 | 281 | $this->srrfiles[] = $fileArr; |
| 280 | 282 | $this->srrcount++; |
| 281 | 283 | } |
| 282 | 284 | |
| 283 | - if (preg_match($this->txtfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
| 284 | - { |
|
| 285 | + if (preg_match($this->txtfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) { |
|
| 285 | 286 | $this->txtfiles[] = $fileArr; |
| 286 | 287 | $this->txtcount++; |
| 287 | 288 | } |
| 288 | 289 | |
| 289 | - if (preg_match($this->sfvfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|nzb)/iS', $subject)) |
|
| 290 | - { |
|
| 290 | + if (preg_match($this->sfvfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|nzb)/iS', $subject)) { |
|
| 291 | 291 | $this->sfvfiles[] = $fileArr; |
| 292 | 292 | $this->sfvcount++; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if (preg_match('/\.par2(?!\.)/iS', $subject)) |
|
| 296 | - { |
|
| 295 | + if (preg_match('/\.par2(?!\.)/iS', $subject)) { |
|
| 297 | 296 | $this->parcount++; |
| 298 | - if (!preg_match('/(vol\d+\+|vol[_\.\s]\d)/iS', $subject) && $fileArr['segmenttotal'] < 3) |
|
| 299 | - $this->parfiles[] = $fileArr; |
|
| 297 | + if (!preg_match('/(vol\d+\+|vol[_\.\s]\d)/iS', $subject) && $fileArr['segmenttotal'] < 3) { |
|
| 298 | + $this->parfiles[] = $fileArr; |
|
| 299 | + } |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if (preg_match('/\.zip(?!\.)/i', $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) |
|
| 303 | - $this->zipcount++; |
|
| 302 | + if (preg_match('/\.zip(?!\.)/i', $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) { |
|
| 303 | + $this->zipcount++; |
|
| 304 | + } |
|
| 304 | 305 | |
| 305 | - if ($this->loadAllVars === true) |
|
| 306 | - $this->nzb[] = $fileArr; |
|
| 307 | - else |
|
| 308 | - $this->nzb[]['subject'] = $fileArr['subject']; |
|
| 306 | + if ($this->loadAllVars === true) { |
|
| 307 | + $this->nzb[] = $fileArr; |
|
| 308 | + } else { |
|
| 309 | + $this->nzb[]['subject'] = $fileArr['subject']; |
|
| 310 | + } |
|
| 309 | 311 | } |
| 310 | 312 | |
| 311 | 313 | $this->groups = array_unique($this->groups); |
| 312 | 314 | |
| 313 | - if ($this->segmenttotal > 0) |
|
| 314 | - $this->completion = number_format(($this->segmentactual/$this->segmenttotal)*100, 0); |
|
| 315 | + if ($this->segmenttotal > 0) { |
|
| 316 | + $this->completion = number_format(($this->segmentactual/$this->segmenttotal)*100, 0); |
|
| 317 | + } |
|
| 315 | 318 | |
| 316 | - if (is_array($this->nzb) && !empty($this->nzb)) |
|
| 317 | - $this->isLoaded = true; |
|
| 319 | + if (is_array($this->nzb) && !empty($this->nzb)) { |
|
| 320 | + $this->isLoaded = true; |
|
| 321 | + } |
|
| 318 | 322 | |
| 319 | 323 | return $this->isLoaded; |
| 320 | 324 | } |
| 321 | 325 | |
| 322 | 326 | public function toNzb() |
| 323 | 327 | { |
| 324 | - if ($this->loadAllVars === false) |
|
| 325 | - return false; |
|
| 328 | + if ($this->loadAllVars === false) { |
|
| 329 | + return false; |
|
| 330 | + } |
|
| 326 | 331 | |
| 327 | 332 | $nzb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
| 328 | 333 | $nzb .= "<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd\">\n"; |
| 329 | 334 | $nzb .= "<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">\n\n"; |
| 330 | - if (!empty($this->metadata)) |
|
| 331 | - { |
|
| 335 | + if (!empty($this->metadata)) { |
|
| 332 | 336 | $nzb .= "<head>\n"; |
| 333 | 337 | $out = []; |
| 334 | - foreach($this->metadata as $mk=>$mv) |
|
| 335 | - $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
| 338 | + foreach($this->metadata as $mk=>$mv) { |
|
| 339 | + $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
| 340 | + } |
|
| 336 | 341 | $nzb .= "</head>\n"; |
| 337 | 342 | } |
| 338 | - foreach($this->nzb as $postFile) |
|
| 339 | - { |
|
| 343 | + foreach($this->nzb as $postFile) { |
|
| 340 | 344 | $nzb .= "<file poster=\"".htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8')."\" date=\"".$postFile["posted"]."\" subject=\"".htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8')." (1/".$postFile["segmenttotal"].")\">\n"; |
| 341 | 345 | $nzb .= " <groups>\n"; |
| 342 | - foreach($postFile['groups'] as $fileGroup) |
|
| 343 | - { |
|
| 346 | + foreach($postFile['groups'] as $fileGroup) { |
|
| 344 | 347 | $nzb .= " <group>".$fileGroup."</group>\n"; |
| 345 | 348 | } |
| 346 | 349 | $nzb .= " </groups>\n"; |
| 347 | 350 | $nzb .= " <segments>\n"; |
| 348 | - foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
| 349 | - { |
|
| 351 | + foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) { |
|
| 350 | 352 | $nzb .= " <segment bytes=\"".$postFile['segmentbytes'][$fileSegmentNum]."\" number=\"".$fileSegmentNum."\">".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."</segment>\n"; |
| 351 | 353 | } |
| 352 | 354 | $nzb .= " </segments>\n</file>\n"; |
@@ -270,7 +270,7 @@ |
||
| 270 | 270 | /** |
| 271 | 271 | * sendRequest() |
| 272 | 272 | * |
| 273 | - * @param $path |
|
| 273 | + * @param string $path |
|
| 274 | 274 | * @param array $params |
| 275 | 275 | * |
| 276 | 276 | * @return array |
@@ -3,321 +3,321 @@ |
||
| 3 | 3 | |
| 4 | 4 | final class NZBVortex |
| 5 | 5 | { |
| 6 | - protected $nonce = null; |
|
| 7 | - protected $session = null; |
|
| 8 | - |
|
| 9 | - public function __construct() |
|
| 10 | - { |
|
| 11 | - if (is_null($this->session)) |
|
| 12 | - { |
|
| 13 | - $this->getNonce(); |
|
| 14 | - $this->login(); |
|
| 15 | - } |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * get text for state |
|
| 20 | - * @param int $code |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function getState($code = 0) |
|
| 24 | - { |
|
| 25 | - $states = array |
|
| 26 | - ( |
|
| 27 | - 0 => 'Waiting', |
|
| 28 | - 1 => 'Downloading', |
|
| 29 | - 2 => 'Waiting for save', |
|
| 30 | - 3 => 'Saving', |
|
| 31 | - 4 => 'Saved', |
|
| 32 | - 5 => 'Password request', |
|
| 33 | - 6 => 'Queued for processing', |
|
| 34 | - 7 => 'User wait for processing', |
|
| 35 | - 8 => 'Checking', |
|
| 36 | - 9 => 'Repairing', |
|
| 37 | - 10 => 'Joining', |
|
| 38 | - 11 => 'Wait for further processing', |
|
| 39 | - 12 => 'Joining', |
|
| 40 | - 13 => 'Wait for uncompress', |
|
| 41 | - 14 => 'Uncompressing', |
|
| 42 | - 15 => 'Wait for cleanup', |
|
| 43 | - 16 => 'Cleaning up', |
|
| 44 | - 17 => 'Cleaned up', |
|
| 45 | - 18 => 'Moving to completed', |
|
| 46 | - 19 => 'Move completed', |
|
| 47 | - 20 => 'Done', |
|
| 48 | - 21 => 'Uncompress failed', |
|
| 49 | - 22 => 'Check failed, data corrupt', |
|
| 50 | - 23 => 'Move failed', |
|
| 51 | - 24 => 'Badly encoded download (uuencoded)' |
|
| 52 | - ); |
|
| 53 | - |
|
| 54 | - return (isset($states[$code])) ? |
|
| 55 | - $states[$code] : -1; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * get overview of NZB's in queue |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function getOverview() |
|
| 63 | - { |
|
| 64 | - $params = array('sessionid' => $this->session); |
|
| 65 | - $response = $this->sendRequest(sprintf('app/webUpdate'), $params); |
|
| 66 | - foreach ($response['nzbs'] as &$nzb) |
|
| 67 | - { |
|
| 68 | - $nzb['original_state'] = $nzb['state']; |
|
| 69 | - $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return $response; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * add NZB to queue |
|
| 78 | - * @param string $nzb |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public function addQueue($nzb = '') |
|
| 82 | - { |
|
| 83 | - if (!empty($nzb)) |
|
| 84 | - { |
|
| 85 | - $page = new Page; |
|
| 86 | - $user = new Users; |
|
| 87 | - |
|
| 88 | - $host = $page->serverurl; |
|
| 89 | - $data = $user->getById($user->currentUserId()); |
|
| 90 | - $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); |
|
| 91 | - |
|
| 92 | - $params = array |
|
| 93 | - ( |
|
| 94 | - 'sessionid' => $this->session, |
|
| 95 | - 'url' => $url |
|
| 96 | - ); |
|
| 97 | - |
|
| 98 | - $response = $this->sendRequest('nzb/add', $params); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * resume NZB |
|
| 105 | - * @param int $id |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public function resume($id = 0) |
|
| 109 | - { |
|
| 110 | - if ($id > 0) |
|
| 111 | - { |
|
| 112 | - # /nzb/(id)/resume |
|
| 113 | - $params = array('sessionid' => $this->session); |
|
| 114 | - $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * pause NZB |
|
| 121 | - * @param int $id |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public function pause($id = 0) |
|
| 125 | - { |
|
| 126 | - if ($id > 0) |
|
| 127 | - { |
|
| 128 | - # /nzb/(id)/pause |
|
| 129 | - $params = array('sessionid' => $this->session); |
|
| 130 | - $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * move NZB up in queue |
|
| 137 | - * @param int $id |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - public function moveUp($id = 0) |
|
| 141 | - { |
|
| 142 | - if ($id > 0) |
|
| 143 | - { |
|
| 144 | - # nzb/(nzbid)/moveup |
|
| 145 | - $params = array('sessionid' => $this->session); |
|
| 146 | - $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * move NZB down in queue |
|
| 153 | - * @param int $id |
|
| 154 | - * @return void |
|
| 155 | - */ |
|
| 156 | - public function moveDown($id = 0) |
|
| 157 | - { |
|
| 158 | - if ($id > 0) |
|
| 159 | - { |
|
| 160 | - # nzb/(nzbid)/movedown |
|
| 161 | - $params = array('sessionid' => $this->session); |
|
| 162 | - $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * move NZB to bottom of queue |
|
| 169 | - * @param int $id |
|
| 170 | - * @return void |
|
| 171 | - */ |
|
| 172 | - public function moveBottom($id = 0) |
|
| 173 | - { |
|
| 174 | - if ($id > 0) |
|
| 175 | - { |
|
| 176 | - # nzb/(nzbid)/movebottom |
|
| 177 | - $params = array('sessionid' => $this->session); |
|
| 178 | - $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Remove a (finished/unfinished) NZB from queue and delete files |
|
| 185 | - * @param int $id |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - public function delete($id = 0) |
|
| 189 | - { |
|
| 190 | - if ($id > 0) |
|
| 191 | - { |
|
| 192 | - # nzb/(nzbid)/movebottom |
|
| 193 | - $params = array('sessionid' => $this->session); |
|
| 194 | - $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * move NZB to top of queue |
|
| 201 | - * @param int $id |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - public function moveTop($id = 0) |
|
| 205 | - { |
|
| 206 | - if ($id > 0) |
|
| 207 | - { |
|
| 208 | - # nzb/(nzbid)/movebottom |
|
| 209 | - $params = array('sessionid' => $this->session); |
|
| 210 | - $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * get filelist for nzb |
|
| 217 | - * @param int $id |
|
| 218 | - * @return array|bool |
|
| 219 | - */ |
|
| 220 | - public function getFilelist($id = 0) |
|
| 221 | - { |
|
| 222 | - if ($id > 0) |
|
| 223 | - { |
|
| 224 | - # file/(nzbid) |
|
| 225 | - $params = array('sessionid' => $this->session); |
|
| 226 | - $response = $this->sendRequest(sprintf('file/%s', $id), $params); |
|
| 227 | - return $response; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * get /auth/nonce |
|
| 236 | - * @return void |
|
| 237 | - */ |
|
| 238 | - protected function getNonce() |
|
| 239 | - { |
|
| 240 | - $response = $this->sendRequest('auth/nonce'); |
|
| 241 | - $this->nonce = $response['authNonce']; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - protected function login() |
|
| 248 | - { |
|
| 249 | - $user = new Users(); |
|
| 250 | - $data = $user->getById($user->currentUserId()); |
|
| 251 | - $cnonce = generateUuid(); |
|
| 252 | - $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); |
|
| 253 | - $hash = base64_encode($hash); |
|
| 254 | - |
|
| 255 | - $params = array |
|
| 256 | - ( |
|
| 257 | - 'nonce' => $this->nonce, |
|
| 258 | - 'cnonce' => $cnonce, |
|
| 259 | - 'hash' => $hash |
|
| 260 | - ); |
|
| 261 | - |
|
| 262 | - $response = $this->sendRequest('auth/login', $params); |
|
| 263 | - |
|
| 264 | - if ('successful' == $response['loginResult']) |
|
| 265 | - $this->session = $response['sessionID']; |
|
| 266 | - |
|
| 267 | - if ('failed' == $response['loginResult']) { } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * sendRequest() |
|
| 272 | - * |
|
| 273 | - * @param $path |
|
| 274 | - * @param array $params |
|
| 275 | - * |
|
| 276 | - * @return array |
|
| 277 | - * @throws \Exception |
|
| 278 | - */ |
|
| 279 | - protected function sendRequest($path, $params = []) |
|
| 280 | - { |
|
| 281 | - $user = new Users; |
|
| 282 | - $data = $user->getById($user->currentUserId()); |
|
| 283 | - |
|
| 284 | - $url = sprintf('%s/api', $data['nzbvortex_server_url']); |
|
| 285 | - $params = http_build_query($params); |
|
| 286 | - $ch = curl_init(sprintf("%s/%s?%s", $url, $path, $params)); |
|
| 287 | - |
|
| 288 | - curl_setopt($ch, CURLOPT_HEADER, 0); |
|
| 289 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
| 290 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 291 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 292 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
| 293 | - |
|
| 294 | - #curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); |
|
| 295 | - #curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888'); |
|
| 296 | - |
|
| 297 | - $response = curl_exec($ch); |
|
| 298 | - $response = json_decode($response, true); |
|
| 299 | - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 300 | - $error = curl_error($ch); |
|
| 301 | - |
|
| 302 | - curl_close($ch); |
|
| 303 | - |
|
| 304 | - switch ($status) |
|
| 305 | - { |
|
| 306 | - case 0: |
|
| 307 | - throw new \Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); |
|
| 308 | - break; |
|
| 309 | - |
|
| 310 | - case 200: |
|
| 311 | - return $response; |
|
| 312 | - break; |
|
| 313 | - |
|
| 314 | - case 403: |
|
| 315 | - throw new \Exception('Unable to login. Is your API key correct?'); |
|
| 316 | - break; |
|
| 317 | - |
|
| 318 | - default: |
|
| 319 | - throw new \Exception(sprintf("%s (%s): %s", $path, $status, $response['result'])); |
|
| 320 | - break; |
|
| 321 | - } |
|
| 322 | - } |
|
| 6 | + protected $nonce = null; |
|
| 7 | + protected $session = null; |
|
| 8 | + |
|
| 9 | + public function __construct() |
|
| 10 | + { |
|
| 11 | + if (is_null($this->session)) |
|
| 12 | + { |
|
| 13 | + $this->getNonce(); |
|
| 14 | + $this->login(); |
|
| 15 | + } |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * get text for state |
|
| 20 | + * @param int $code |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function getState($code = 0) |
|
| 24 | + { |
|
| 25 | + $states = array |
|
| 26 | + ( |
|
| 27 | + 0 => 'Waiting', |
|
| 28 | + 1 => 'Downloading', |
|
| 29 | + 2 => 'Waiting for save', |
|
| 30 | + 3 => 'Saving', |
|
| 31 | + 4 => 'Saved', |
|
| 32 | + 5 => 'Password request', |
|
| 33 | + 6 => 'Queued for processing', |
|
| 34 | + 7 => 'User wait for processing', |
|
| 35 | + 8 => 'Checking', |
|
| 36 | + 9 => 'Repairing', |
|
| 37 | + 10 => 'Joining', |
|
| 38 | + 11 => 'Wait for further processing', |
|
| 39 | + 12 => 'Joining', |
|
| 40 | + 13 => 'Wait for uncompress', |
|
| 41 | + 14 => 'Uncompressing', |
|
| 42 | + 15 => 'Wait for cleanup', |
|
| 43 | + 16 => 'Cleaning up', |
|
| 44 | + 17 => 'Cleaned up', |
|
| 45 | + 18 => 'Moving to completed', |
|
| 46 | + 19 => 'Move completed', |
|
| 47 | + 20 => 'Done', |
|
| 48 | + 21 => 'Uncompress failed', |
|
| 49 | + 22 => 'Check failed, data corrupt', |
|
| 50 | + 23 => 'Move failed', |
|
| 51 | + 24 => 'Badly encoded download (uuencoded)' |
|
| 52 | + ); |
|
| 53 | + |
|
| 54 | + return (isset($states[$code])) ? |
|
| 55 | + $states[$code] : -1; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * get overview of NZB's in queue |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function getOverview() |
|
| 63 | + { |
|
| 64 | + $params = array('sessionid' => $this->session); |
|
| 65 | + $response = $this->sendRequest(sprintf('app/webUpdate'), $params); |
|
| 66 | + foreach ($response['nzbs'] as &$nzb) |
|
| 67 | + { |
|
| 68 | + $nzb['original_state'] = $nzb['state']; |
|
| 69 | + $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return $response; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * add NZB to queue |
|
| 78 | + * @param string $nzb |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public function addQueue($nzb = '') |
|
| 82 | + { |
|
| 83 | + if (!empty($nzb)) |
|
| 84 | + { |
|
| 85 | + $page = new Page; |
|
| 86 | + $user = new Users; |
|
| 87 | + |
|
| 88 | + $host = $page->serverurl; |
|
| 89 | + $data = $user->getById($user->currentUserId()); |
|
| 90 | + $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); |
|
| 91 | + |
|
| 92 | + $params = array |
|
| 93 | + ( |
|
| 94 | + 'sessionid' => $this->session, |
|
| 95 | + 'url' => $url |
|
| 96 | + ); |
|
| 97 | + |
|
| 98 | + $response = $this->sendRequest('nzb/add', $params); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * resume NZB |
|
| 105 | + * @param int $id |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public function resume($id = 0) |
|
| 109 | + { |
|
| 110 | + if ($id > 0) |
|
| 111 | + { |
|
| 112 | + # /nzb/(id)/resume |
|
| 113 | + $params = array('sessionid' => $this->session); |
|
| 114 | + $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * pause NZB |
|
| 121 | + * @param int $id |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public function pause($id = 0) |
|
| 125 | + { |
|
| 126 | + if ($id > 0) |
|
| 127 | + { |
|
| 128 | + # /nzb/(id)/pause |
|
| 129 | + $params = array('sessionid' => $this->session); |
|
| 130 | + $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * move NZB up in queue |
|
| 137 | + * @param int $id |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + public function moveUp($id = 0) |
|
| 141 | + { |
|
| 142 | + if ($id > 0) |
|
| 143 | + { |
|
| 144 | + # nzb/(nzbid)/moveup |
|
| 145 | + $params = array('sessionid' => $this->session); |
|
| 146 | + $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * move NZB down in queue |
|
| 153 | + * @param int $id |
|
| 154 | + * @return void |
|
| 155 | + */ |
|
| 156 | + public function moveDown($id = 0) |
|
| 157 | + { |
|
| 158 | + if ($id > 0) |
|
| 159 | + { |
|
| 160 | + # nzb/(nzbid)/movedown |
|
| 161 | + $params = array('sessionid' => $this->session); |
|
| 162 | + $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * move NZB to bottom of queue |
|
| 169 | + * @param int $id |
|
| 170 | + * @return void |
|
| 171 | + */ |
|
| 172 | + public function moveBottom($id = 0) |
|
| 173 | + { |
|
| 174 | + if ($id > 0) |
|
| 175 | + { |
|
| 176 | + # nzb/(nzbid)/movebottom |
|
| 177 | + $params = array('sessionid' => $this->session); |
|
| 178 | + $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Remove a (finished/unfinished) NZB from queue and delete files |
|
| 185 | + * @param int $id |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + public function delete($id = 0) |
|
| 189 | + { |
|
| 190 | + if ($id > 0) |
|
| 191 | + { |
|
| 192 | + # nzb/(nzbid)/movebottom |
|
| 193 | + $params = array('sessionid' => $this->session); |
|
| 194 | + $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * move NZB to top of queue |
|
| 201 | + * @param int $id |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + public function moveTop($id = 0) |
|
| 205 | + { |
|
| 206 | + if ($id > 0) |
|
| 207 | + { |
|
| 208 | + # nzb/(nzbid)/movebottom |
|
| 209 | + $params = array('sessionid' => $this->session); |
|
| 210 | + $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * get filelist for nzb |
|
| 217 | + * @param int $id |
|
| 218 | + * @return array|bool |
|
| 219 | + */ |
|
| 220 | + public function getFilelist($id = 0) |
|
| 221 | + { |
|
| 222 | + if ($id > 0) |
|
| 223 | + { |
|
| 224 | + # file/(nzbid) |
|
| 225 | + $params = array('sessionid' => $this->session); |
|
| 226 | + $response = $this->sendRequest(sprintf('file/%s', $id), $params); |
|
| 227 | + return $response; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * get /auth/nonce |
|
| 236 | + * @return void |
|
| 237 | + */ |
|
| 238 | + protected function getNonce() |
|
| 239 | + { |
|
| 240 | + $response = $this->sendRequest('auth/nonce'); |
|
| 241 | + $this->nonce = $response['authNonce']; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + protected function login() |
|
| 248 | + { |
|
| 249 | + $user = new Users(); |
|
| 250 | + $data = $user->getById($user->currentUserId()); |
|
| 251 | + $cnonce = generateUuid(); |
|
| 252 | + $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); |
|
| 253 | + $hash = base64_encode($hash); |
|
| 254 | + |
|
| 255 | + $params = array |
|
| 256 | + ( |
|
| 257 | + 'nonce' => $this->nonce, |
|
| 258 | + 'cnonce' => $cnonce, |
|
| 259 | + 'hash' => $hash |
|
| 260 | + ); |
|
| 261 | + |
|
| 262 | + $response = $this->sendRequest('auth/login', $params); |
|
| 263 | + |
|
| 264 | + if ('successful' == $response['loginResult']) |
|
| 265 | + $this->session = $response['sessionID']; |
|
| 266 | + |
|
| 267 | + if ('failed' == $response['loginResult']) { } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * sendRequest() |
|
| 272 | + * |
|
| 273 | + * @param $path |
|
| 274 | + * @param array $params |
|
| 275 | + * |
|
| 276 | + * @return array |
|
| 277 | + * @throws \Exception |
|
| 278 | + */ |
|
| 279 | + protected function sendRequest($path, $params = []) |
|
| 280 | + { |
|
| 281 | + $user = new Users; |
|
| 282 | + $data = $user->getById($user->currentUserId()); |
|
| 283 | + |
|
| 284 | + $url = sprintf('%s/api', $data['nzbvortex_server_url']); |
|
| 285 | + $params = http_build_query($params); |
|
| 286 | + $ch = curl_init(sprintf("%s/%s?%s", $url, $path, $params)); |
|
| 287 | + |
|
| 288 | + curl_setopt($ch, CURLOPT_HEADER, 0); |
|
| 289 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
| 290 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 291 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 292 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
| 293 | + |
|
| 294 | + #curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); |
|
| 295 | + #curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888'); |
|
| 296 | + |
|
| 297 | + $response = curl_exec($ch); |
|
| 298 | + $response = json_decode($response, true); |
|
| 299 | + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 300 | + $error = curl_error($ch); |
|
| 301 | + |
|
| 302 | + curl_close($ch); |
|
| 303 | + |
|
| 304 | + switch ($status) |
|
| 305 | + { |
|
| 306 | + case 0: |
|
| 307 | + throw new \Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); |
|
| 308 | + break; |
|
| 309 | + |
|
| 310 | + case 200: |
|
| 311 | + return $response; |
|
| 312 | + break; |
|
| 313 | + |
|
| 314 | + case 403: |
|
| 315 | + throw new \Exception('Unable to login. Is your API key correct?'); |
|
| 316 | + break; |
|
| 317 | + |
|
| 318 | + default: |
|
| 319 | + throw new \Exception(sprintf("%s (%s): %s", $path, $status, $response['result'])); |
|
| 320 | + break; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | 323 | } |
@@ -22,8 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function getState($code = 0) |
| 24 | 24 | { |
| 25 | - $states = array |
|
| 26 | - ( |
|
| 25 | + $states = array( |
|
| 27 | 26 | 0 => 'Waiting', |
| 28 | 27 | 1 => 'Downloading', |
| 29 | 28 | 2 => 'Waiting for save', |
@@ -89,8 +88,7 @@ discard block |
||
| 89 | 88 | $data = $user->getById($user->currentUserId()); |
| 90 | 89 | $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); |
| 91 | 90 | |
| 92 | - $params = array |
|
| 93 | - ( |
|
| 91 | + $params = array( |
|
| 94 | 92 | 'sessionid' => $this->session, |
| 95 | 93 | 'url' => $url |
| 96 | 94 | ); |
@@ -252,8 +250,7 @@ discard block |
||
| 252 | 250 | $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); |
| 253 | 251 | $hash = base64_encode($hash); |
| 254 | 252 | |
| 255 | - $params = array |
|
| 256 | - ( |
|
| 253 | + $params = array( |
|
| 257 | 254 | 'nonce' => $this->nonce, |
| 258 | 255 | 'cnonce' => $cnonce, |
| 259 | 256 | 'hash' => $hash |
@@ -8,8 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function __construct() |
| 10 | 10 | { |
| 11 | - if (is_null($this->session)) |
|
| 12 | - { |
|
| 11 | + if (is_null($this->session)) { |
|
| 13 | 12 | $this->getNonce(); |
| 14 | 13 | $this->login(); |
| 15 | 14 | } |
@@ -63,8 +62,7 @@ discard block |
||
| 63 | 62 | { |
| 64 | 63 | $params = array('sessionid' => $this->session); |
| 65 | 64 | $response = $this->sendRequest(sprintf('app/webUpdate'), $params); |
| 66 | - foreach ($response['nzbs'] as &$nzb) |
|
| 67 | - { |
|
| 65 | + foreach ($response['nzbs'] as &$nzb) { |
|
| 68 | 66 | $nzb['original_state'] = $nzb['state']; |
| 69 | 67 | $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); |
| 70 | 68 | } |
@@ -80,8 +78,7 @@ discard block |
||
| 80 | 78 | */ |
| 81 | 79 | public function addQueue($nzb = '') |
| 82 | 80 | { |
| 83 | - if (!empty($nzb)) |
|
| 84 | - { |
|
| 81 | + if (!empty($nzb)) { |
|
| 85 | 82 | $page = new Page; |
| 86 | 83 | $user = new Users; |
| 87 | 84 | |
@@ -107,8 +104,7 @@ discard block |
||
| 107 | 104 | */ |
| 108 | 105 | public function resume($id = 0) |
| 109 | 106 | { |
| 110 | - if ($id > 0) |
|
| 111 | - { |
|
| 107 | + if ($id > 0) { |
|
| 112 | 108 | # /nzb/(id)/resume |
| 113 | 109 | $params = array('sessionid' => $this->session); |
| 114 | 110 | $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); |
@@ -123,8 +119,7 @@ discard block |
||
| 123 | 119 | */ |
| 124 | 120 | public function pause($id = 0) |
| 125 | 121 | { |
| 126 | - if ($id > 0) |
|
| 127 | - { |
|
| 122 | + if ($id > 0) { |
|
| 128 | 123 | # /nzb/(id)/pause |
| 129 | 124 | $params = array('sessionid' => $this->session); |
| 130 | 125 | $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); |
@@ -139,8 +134,7 @@ discard block |
||
| 139 | 134 | */ |
| 140 | 135 | public function moveUp($id = 0) |
| 141 | 136 | { |
| 142 | - if ($id > 0) |
|
| 143 | - { |
|
| 137 | + if ($id > 0) { |
|
| 144 | 138 | # nzb/(nzbid)/moveup |
| 145 | 139 | $params = array('sessionid' => $this->session); |
| 146 | 140 | $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); |
@@ -155,8 +149,7 @@ discard block |
||
| 155 | 149 | */ |
| 156 | 150 | public function moveDown($id = 0) |
| 157 | 151 | { |
| 158 | - if ($id > 0) |
|
| 159 | - { |
|
| 152 | + if ($id > 0) { |
|
| 160 | 153 | # nzb/(nzbid)/movedown |
| 161 | 154 | $params = array('sessionid' => $this->session); |
| 162 | 155 | $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); |
@@ -171,8 +164,7 @@ discard block |
||
| 171 | 164 | */ |
| 172 | 165 | public function moveBottom($id = 0) |
| 173 | 166 | { |
| 174 | - if ($id > 0) |
|
| 175 | - { |
|
| 167 | + if ($id > 0) { |
|
| 176 | 168 | # nzb/(nzbid)/movebottom |
| 177 | 169 | $params = array('sessionid' => $this->session); |
| 178 | 170 | $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); |
@@ -187,8 +179,7 @@ discard block |
||
| 187 | 179 | */ |
| 188 | 180 | public function delete($id = 0) |
| 189 | 181 | { |
| 190 | - if ($id > 0) |
|
| 191 | - { |
|
| 182 | + if ($id > 0) { |
|
| 192 | 183 | # nzb/(nzbid)/movebottom |
| 193 | 184 | $params = array('sessionid' => $this->session); |
| 194 | 185 | $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); |
@@ -203,8 +194,7 @@ discard block |
||
| 203 | 194 | */ |
| 204 | 195 | public function moveTop($id = 0) |
| 205 | 196 | { |
| 206 | - if ($id > 0) |
|
| 207 | - { |
|
| 197 | + if ($id > 0) { |
|
| 208 | 198 | # nzb/(nzbid)/movebottom |
| 209 | 199 | $params = array('sessionid' => $this->session); |
| 210 | 200 | $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); |
@@ -219,8 +209,7 @@ discard block |
||
| 219 | 209 | */ |
| 220 | 210 | public function getFilelist($id = 0) |
| 221 | 211 | { |
| 222 | - if ($id > 0) |
|
| 223 | - { |
|
| 212 | + if ($id > 0) { |
|
| 224 | 213 | # file/(nzbid) |
| 225 | 214 | $params = array('sessionid' => $this->session); |
| 226 | 215 | $response = $this->sendRequest(sprintf('file/%s', $id), $params); |
@@ -261,8 +250,9 @@ discard block |
||
| 261 | 250 | |
| 262 | 251 | $response = $this->sendRequest('auth/login', $params); |
| 263 | 252 | |
| 264 | - if ('successful' == $response['loginResult']) |
|
| 265 | - $this->session = $response['sessionID']; |
|
| 253 | + if ('successful' == $response['loginResult']) { |
|
| 254 | + $this->session = $response['sessionID']; |
|
| 255 | + } |
|
| 266 | 256 | |
| 267 | 257 | if ('failed' == $response['loginResult']) { } |
| 268 | 258 | } |
@@ -301,8 +291,7 @@ discard block |
||
| 301 | 291 | |
| 302 | 292 | curl_close($ch); |
| 303 | 293 | |
| 304 | - switch ($status) |
|
| 305 | - { |
|
| 294 | + switch ($status) { |
|
| 306 | 295 | case 0: |
| 307 | 296 | throw new \Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); |
| 308 | 297 | break; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | /** |
| 126 | 126 | * Go through every type of post proc. |
| 127 | 127 | * |
| 128 | - * @param $nntp |
|
| 128 | + * @param \nntmux\NNTP $nntp |
|
| 129 | 129 | * |
| 130 | 130 | * @return void |
| 131 | 131 | */ |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * |
| 255 | 255 | * @param string $groupID (Optional) ID of a group to work on. |
| 256 | 256 | * @param string $guidChar (Optional) First letter of a release GUID to use to get work. |
| 257 | - * @param string|int $processTV (Optional) 0 Don't process, 1 process all releases, |
|
| 257 | + * @param integer $processTV (Optional) 0 Don't process, 1 process all releases, |
|
| 258 | 258 | * 2 process renamed releases only, '' check site setting |
| 259 | 259 | * |
| 260 | 260 | * @return void |
@@ -91,8 +91,8 @@ |
||
| 91 | 91 | * Main processing director function for scrapers |
| 92 | 92 | * Calls work query function and initiates processing |
| 93 | 93 | * |
| 94 | - * @param $groupID |
|
| 95 | - * @param $guidChar |
|
| 94 | + * @param string $groupID |
|
| 95 | + * @param string $guidChar |
|
| 96 | 96 | * @param $process |
| 97 | 97 | * @param bool $local |
| 98 | 98 | */ |
@@ -379,7 +379,7 @@ |
||
| 379 | 379 | /** |
| 380 | 380 | * Sets the TV show's image column to found (1) |
| 381 | 381 | * |
| 382 | - * @param $videoId |
|
| 382 | + * @param integer $videoId |
|
| 383 | 383 | */ |
| 384 | 384 | public function setCoverFound($videoId) |
| 385 | 385 | { |
@@ -127,16 +127,16 @@ |
||
| 127 | 127 | abstract protected function formatEpisodeInfo($episode); |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * Retrieve releases for TV processing |
|
| 131 | - * Returns a PDO Object of rows or false if none found |
|
| 132 | - * |
|
| 133 | - * @param string $groupID -- ID of the usenet group to process |
|
| 134 | - * @param string $guidChar -- threading method by first guid character |
|
| 135 | - * @param int $lookupSetting -- whether or not to use the API |
|
| 136 | - * @param int $status -- release processing status of tv_episodes_id |
|
| 137 | - * |
|
| 138 | - * @return false|int|\PDOStatement |
|
| 139 | - */ |
|
| 130 | + * Retrieve releases for TV processing |
|
| 131 | + * Returns a PDO Object of rows or false if none found |
|
| 132 | + * |
|
| 133 | + * @param string $groupID -- ID of the usenet group to process |
|
| 134 | + * @param string $guidChar -- threading method by first guid character |
|
| 135 | + * @param int $lookupSetting -- whether or not to use the API |
|
| 136 | + * @param int $status -- release processing status of tv_episodes_id |
|
| 137 | + * |
|
| 138 | + * @return false|int|\PDOStatement |
|
| 139 | + */ |
|
| 140 | 140 | public function getTvReleases($groupID = '', $guidChar = '', $lookupSetting = 1, $status = 0) |
| 141 | 141 | { |
| 142 | 142 | $ret = 0; |
@@ -13,25 +13,25 @@ discard block |
||
| 13 | 13 | abstract class TV extends Videos |
| 14 | 14 | { |
| 15 | 15 | // Television Sources |
| 16 | - const SOURCE_NONE = 0; // No Scrape source |
|
| 17 | - const SOURCE_TVDB = 1; // Scrape source was TVDB |
|
| 18 | - const SOURCE_TVMAZE = 2; // Scrape source was TVMAZE |
|
| 19 | - const SOURCE_TMDB = 3; // Scrape source was TMDB |
|
| 20 | - const SOURCE_TRAKT = 4; // Scrape source was Trakt |
|
| 21 | - const SOURCE_IMDB = 5; // Scrape source was IMDB |
|
| 22 | - const SOURCE_TVRAGE = 6; // Scrape source was TvRage |
|
| 16 | + const SOURCE_NONE = 0; // No Scrape source |
|
| 17 | + const SOURCE_TVDB = 1; // Scrape source was TVDB |
|
| 18 | + const SOURCE_TVMAZE = 2; // Scrape source was TVMAZE |
|
| 19 | + const SOURCE_TMDB = 3; // Scrape source was TMDB |
|
| 20 | + const SOURCE_TRAKT = 4; // Scrape source was Trakt |
|
| 21 | + const SOURCE_IMDB = 5; // Scrape source was IMDB |
|
| 22 | + const SOURCE_TVRAGE = 6; // Scrape source was TvRage |
|
| 23 | 23 | |
| 24 | 24 | // Anime Sources |
| 25 | - const SOURCE_ANIDB = 10; // Scrape source was AniDB |
|
| 25 | + const SOURCE_ANIDB = 10; // Scrape source was AniDB |
|
| 26 | 26 | |
| 27 | 27 | // Processing signifiers |
| 28 | - const PROCESS_TVDB = 0; // Process TVDB First |
|
| 29 | - const PROCESS_TVMAZE = -1; // Process TVMaze Second |
|
| 30 | - const PROCESS_TMDB = -2; // Process TMDB Third |
|
| 31 | - const PROCESS_TRAKT = -3; // Process Trakt Fourth |
|
| 32 | - const PROCESS_IMDB = -4; // Process IMDB Fifth |
|
| 33 | - const PROCESS_TVRAGE = -5; // Process TvRage Sixth |
|
| 34 | - const NO_MATCH_FOUND = -6; // Failed All Methods |
|
| 28 | + const PROCESS_TVDB = 0; // Process TVDB First |
|
| 29 | + const PROCESS_TVMAZE = -1; // Process TVMaze Second |
|
| 30 | + const PROCESS_TMDB = -2; // Process TMDB Third |
|
| 31 | + const PROCESS_TRAKT = -3; // Process Trakt Fourth |
|
| 32 | + const PROCESS_IMDB = -4; // Process IMDB Fifth |
|
| 33 | + const PROCESS_TVRAGE = -5; // Process TvRage Sixth |
|
| 34 | + const NO_MATCH_FOUND = -6; // Failed All Methods |
|
| 35 | 35 | const FAILED_PARSE = -100; // Failed Parsing |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | { |
| 536 | 536 | $showName = ''; |
| 537 | 537 | |
| 538 | - $following = '[^a-z0-9](\d\d-\d\d|\d{1,3}x\d{2,3}|\(?(19|20)\d{2}\)?|(480|720|1080)[ip]|AAC2?|BD-?Rip|Blu-?Ray|D0?\d' . |
|
| 538 | + $following = '[^a-z0-9](\d\d-\d\d|\d{1,3}x\d{2,3}|\(?(19|20)\d{2}\)?|(480|720|1080)[ip]|AAC2?|BD-?Rip|Blu-?Ray|D0?\d' . |
|
| 539 | 539 | '|DD5|DiVX|DLMux|DTS|DVD(-?Rip)?|E\d{2,3}|[HX][-_. ]?26[45]|ITA(-ENG)?|HEVC|[HPS]DTV|PROPER|REPACK|Season|Episode|' . |
| 540 | 540 | 'S\d+[^a-z0-9]?((E\d+)[abr]?)*|WEB[-_. ]?(DL|Rip)|XViD)[^a-z0-9]?'; |
| 541 | 541 | |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | |
| 805 | 805 | if (is_array($required)) { |
| 806 | 806 | foreach ($required as $req) { |
| 807 | - if (!in_array($type, ['tmdbS', 'tmdbE', 'traktS', 'traktE'])){ |
|
| 807 | + if (!in_array($type, ['tmdbS', 'tmdbE', 'traktS', 'traktE'])) { |
|
| 808 | 808 | if (!isset($array->$req)) { |
| 809 | 809 | return false; |
| 810 | 810 | } |
@@ -174,7 +174,8 @@ discard block |
||
| 174 | 174 | * @param $releaseId |
| 175 | 175 | * @param int $episodeId |
| 176 | 176 | */ |
| 177 | - public function setVideoIdFound($videoId, $releaseId, $episodeId) { |
|
| 177 | + public function setVideoIdFound($videoId, $releaseId, $episodeId) |
|
| 178 | + { |
|
| 178 | 179 | $this->pdo->queryExec( |
| 179 | 180 | sprintf(' |
| 180 | 181 | UPDATE releases |
@@ -804,7 +805,7 @@ discard block |
||
| 804 | 805 | |
| 805 | 806 | if (is_array($required)) { |
| 806 | 807 | foreach ($required as $req) { |
| 807 | - if (!in_array($type, ['tmdbS', 'tmdbE', 'traktS', 'traktE'])){ |
|
| 808 | + if (!in_array($type, ['tmdbS', 'tmdbE', 'traktS', 'traktE'])) { |
|
| 808 | 809 | if (!isset($array->$req)) { |
| 809 | 810 | return false; |
| 810 | 811 | } |
@@ -229,7 +229,7 @@ |
||
| 229 | 229 | |
| 230 | 230 | // Check if video already exists based on site ID info |
| 231 | 231 | // if that fails be sure we're not inserting duplicates by checking the title |
| 232 | - foreach ($this->siteColumns AS $column) { |
|
| 232 | + foreach ($this->siteColumns as $column) { |
|
| 233 | 233 | if ($show[$column] > 0) { |
| 234 | 234 | $videoId = $this->getVideoIDFromSiteID($column, $show[$column]); |
| 235 | 235 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * Main processing director function for scrapers |
| 56 | 56 | * Calls work query function and initiates processing |
| 57 | 57 | * |
| 58 | - * @param $groupID |
|
| 59 | - * @param $guidChar |
|
| 58 | + * @param string $groupID |
|
| 59 | + * @param string $guidChar |
|
| 60 | 60 | * @param $process |
| 61 | 61 | * @param bool $local |
| 62 | 62 | */ |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * @param $shows |
| 267 | - * @param $cleanName |
|
| 267 | + * @param string $cleanName |
|
| 268 | 268 | * |
| 269 | 269 | * @return array|bool |
| 270 | 270 | */ |
@@ -203,7 +203,6 @@ |
||
| 203 | 203 | /** |
| 204 | 204 | * Calls the API to lookup the TvMaze info for a given TVDB or TVRage ID |
| 205 | 205 | * Returns a formatted array of show data or false if no match |
| 206 | - |
|
| 207 | 206 | * @param $site |
| 208 | 207 | * @param $siteId |
| 209 | 208 | * |
@@ -273,7 +273,7 @@ |
||
| 273 | 273 | $return = false; |
| 274 | 274 | $highestMatch = 0; |
| 275 | 275 | |
| 276 | - foreach ($shows AS $show) { |
|
| 276 | + foreach ($shows as $show) { |
|
| 277 | 277 | if ($this->checkRequiredAttr($show, 'tvmazeS')) { |
| 278 | 278 | // Check for exact title match first and then terminate if found |
| 279 | 279 | if (strtolower($show->name) === strtolower($cleanName)) { |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param $process |
| 54 | 54 | * @param bool $local |
| 55 | 55 | */ |
| 56 | - public function processSite ($groupID, $guidChar, $process, $local = false) |
|
| 56 | + public function processSite($groupID, $guidChar, $process, $local = false) |
|
| 57 | 57 | { |
| 58 | 58 | $res = $this->getTvReleases($groupID, $guidChar, $process, parent::PROCESS_TMDB); |
| 59 | 59 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $this->setVideoNotFound(parent::PROCESS_TRAKT, $row['id']); |
| 183 | 183 | $this->titleCache[] = $release['cleanname']; |
| 184 | 184 | } |
| 185 | - } else{ |
|
| 185 | + } else { |
|
| 186 | 186 | //Processing failed, set the episode ID to the next processing group |
| 187 | 187 | $this->setVideoNotFound(parent::PROCESS_TRAKT, $row['id']); |
| 188 | 188 | $this->titleCache[] = $release['cleanname']; |
@@ -182,7 +182,7 @@ |
||
| 182 | 182 | $this->setVideoNotFound(parent::PROCESS_TRAKT, $row['id']); |
| 183 | 183 | $this->titleCache[] = $release['cleanname']; |
| 184 | 184 | } |
| 185 | - } else{ |
|
| 185 | + } else { |
|
| 186 | 186 | //Processing failed, set the episode ID to the next processing group |
| 187 | 187 | $this->setVideoNotFound(parent::PROCESS_TRAKT, $row['id']); |
| 188 | 188 | $this->titleCache[] = $release['cleanname']; |
@@ -448,7 +448,7 @@ |
||
| 448 | 448 | * |
| 449 | 449 | * @param $episode |
| 450 | 450 | * |
| 451 | - * @return array |
|
| 451 | + * @return boolean |
|
| 452 | 452 | */ |
| 453 | 453 | protected function formatEpisodeInfo($episode) |
| 454 | 454 | { |
@@ -17,27 +17,27 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * @var string |
| 19 | 19 | */ |
| 20 | - public $showInfoUrl = 'http://www.tvrage.com/shows/id-'; |
|
| 20 | + public $showInfoUrl = 'http://www.tvrage.com/shows/id-'; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @var string |
| 24 | 24 | */ |
| 25 | - public $showQuickInfoURL = 'http://services.tvrage.com/tools/quickinfo.php?show='; |
|
| 25 | + public $showQuickInfoURL = 'http://services.tvrage.com/tools/quickinfo.php?show='; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @var string |
| 29 | 29 | */ |
| 30 | - public $xmlFullSearchUrl = 'http://services.tvrage.com/feeds/full_search.php?show='; |
|
| 30 | + public $xmlFullSearchUrl = 'http://services.tvrage.com/feeds/full_search.php?show='; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * @var string |
| 34 | 34 | */ |
| 35 | - public $xmlShowInfoUrl = 'http://services.tvrage.com/feeds/showinfo.php?sid='; |
|
| 35 | + public $xmlShowInfoUrl = 'http://services.tvrage.com/feeds/showinfo.php?sid='; |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * @var string |
| 39 | 39 | */ |
| 40 | - public $xmlFullShowInfoUrl = 'http://services.tvrage.com/feeds/full_show_info.php?sid='; |
|
| 40 | + public $xmlFullShowInfoUrl = 'http://services.tvrage.com/feeds/full_show_info.php?sid='; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @var string |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | public function __construct(array $options = []) |
| 71 | 71 | { |
| 72 | 72 | parent::__construct($options); |
| 73 | - $this->xmlEpisodeInfoUrl = "http://services.tvrage.com/myfeeds/episodeinfo.php?key=" . TvRage::APIKEY; |
|
| 73 | + $this->xmlEpisodeInfoUrl = "http://services.tvrage.com/myfeeds/episodeinfo.php?key=" . TvRage::APIKEY; |
|
| 74 | 74 | $this->imgSavePath = NN_COVERS . 'tvrage' . DS; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $this->pdo->log->headerOver($show['cleanname']) . |
| 129 | 129 | $this->pdo->log->primary(" found in local db, setting tvrage ID and attempting episode lookup."); |
| 130 | 130 | } |
| 131 | - $episodeId = $this->getBySeasonEp($this->videoId, $show['season'], $show['episode']); |
|
| 131 | + $episodeId = $this->getBySeasonEp($this->videoId, $show['season'], $show['episode']); |
|
| 132 | 132 | if ($episodeId === false) { |
| 133 | 133 | $epinfo = $this->getEpisodeInfo($this->rageId, $show['season'], $show['episode']); |
| 134 | 134 | if ($epinfo !== false && isset($epinfo['airdate']) && !empty($epinfo['title'])) { |