Skip to content

Commit

Permalink
Merge branch 'dev' into 0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Sep 13, 2018
2 parents 9e3bbeb + 3f0b2fe commit 3bd4f1c
Show file tree
Hide file tree
Showing 43 changed files with 997 additions and 944 deletions.
15 changes: 4 additions & 11 deletions Blacklight/AniDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ class AniDB
public $pdo;

/**
* @param array $options Class instances / Echo to cli.
* @throws \Exception
* AniDB constructor.
*/
public function __construct(array $options = [])
public function __construct()
{
$defaults = [
'Echo' => false,
'Settings' => null,
];
$options += $defaults;

$this->pdo = DB::connection()->getPdo();
}

Expand Down Expand Up @@ -109,7 +102,7 @@ public function deleteTitle($anidbID): void
*
* @return array
*/
public function getAnimeList($letter = '', $animetitle = '')
public function getAnimeList($letter = '', $animetitle = ''): array
{
$rsql = $tsql = '';

Expand Down Expand Up @@ -151,7 +144,7 @@ public function getAnimeList($letter = '', $animetitle = '')
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getAnimeRange($animetitle = '')
public function getAnimeRange($animetitle = ''): \Illuminate\Contracts\Pagination\LengthAwarePaginator
{
$query = AnidbTitle::query()
->where('at.lang', '=', 'en');
Expand Down
18 changes: 9 additions & 9 deletions Blacklight/Binaries.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ public function updateGroup($groupMySQL, $maxHeaders = 0): void
ColorCLI::doEcho(
ColorCLI::primary(
(
(int) $groupMySQL['last_record'] === 0
(int) $groupMySQL['last_record'] === 0
? 'New group '.$groupNNTP['group'].' starting with '.
(
$this->_newGroupScanByDays
$this->_newGroupScanByDays
? $this->_newGroupDaysToScan.' days'
: number_format($this->_newGroupMessagesToScan).' messages'
).' worth.'
Expand Down Expand Up @@ -1239,13 +1239,13 @@ public function partRepair($groupArr, $tables = ''): void
// Remove articles that we cant fetch after x attempts.
DB::transaction(function () use ($groupArr, $tableNames) {
DB::delete(
sprintf(
'DELETE FROM %s WHERE attempts >= %d AND groups_id = %d',
$tableNames['prname'],
$this->_partRepairMaxTries,
$groupArr['id']
)
);
sprintf(
'DELETE FROM %s WHERE attempts >= %d AND groups_id = %d',
$tableNames['prname'],
$this->_partRepairMaxTries,
$groupArr['id']
)
);
}, 3);
}

Expand Down
5 changes: 2 additions & 3 deletions Blacklight/Books.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ public function getBrowseBy(): string
/**
* @param $title
*
* @return bool|mixed
* @throws \Exception
* @return false|mixed,
*/
public function fetchAmazonProperties($title)
{
Expand All @@ -339,7 +338,7 @@ public function fetchAmazonProperties($title)
->setAssociateTag($this->asstag)
->setRequest($request)
->setResponseTransformer(new XmlToSimpleXmlObject());
} catch (\Exception $e) {
} catch (\Throwable $e) {
echo $e->getMessage();
}

Expand Down
4 changes: 1 addition & 3 deletions Blacklight/CollectionsCleaning.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ protected function generic(): ?array
}

/**
* Generic regexes for music groups.
*
* @return bool
* @return string|false
*/
protected function musicSubject()
{
Expand Down
6 changes: 3 additions & 3 deletions Blacklight/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ protected function _updateConsoleTable(array $con = [])
/**
* @param $title
* @param $node
* @return bool|mixed
* @throws \Exception
*
* @return false|mixed
*/
public function fetchAmazonProperties($title, $node)
{
Expand All @@ -747,7 +747,7 @@ public function fetchAmazonProperties($title, $node)
->setAssociateTag($this->asstag)
->setRequest($request)
->setResponseTransformer(new XmlToSimpleXmlObject());
} catch (\Exception $e) {
} catch (\Throwable $e) {
echo $e->getMessage();
}

Expand Down
13 changes: 6 additions & 7 deletions Blacklight/Music.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ public function updateMusicInfo($title, $year, $amazdata = null)
/**
* @param $title
*
* @return bool|mixed
* @throws \Exception
* @return false|mixed
*/
public function fetchAmazonProperties($title)
{
Expand All @@ -562,7 +561,7 @@ public function fetchAmazonProperties($title)
->setAssociateTag($this->asstag)
->setRequest($request)
->setResponseTransformer(new XmlToSimpleXmlObject());
} catch (\Exception $e) {
} catch (\Throwable $e) {
echo $e->getMessage();
}

Expand All @@ -574,7 +573,7 @@ public function fetchAmazonProperties($title)
$search->setKeywords($title);
$search->setResponseGroup(['Large']);
$responses = $apaiIo->runOperation($search);
} catch (\Exception $e) {
} catch (\Throwable $e) {
// Empty because we try another method.
}

Expand All @@ -587,7 +586,7 @@ public function fetchAmazonProperties($title)
$search->setKeywords($title);
$search->setResponseGroup(['Large']);
$responses = $apaiIo->runOperation($search);
} catch (\Exception $e) {
} catch (\Throwable $e) {
// Empty because we try another method.
}
}
Expand All @@ -601,7 +600,7 @@ public function fetchAmazonProperties($title)
$search->setKeywords($title);
$search->setResponseGroup(['Large']);
$responses = $apaiIo->runOperation($search);
} catch (\Exception $e) {
} catch (\Throwable $e) {
// Empty because we try another method.
}
}
Expand All @@ -615,7 +614,7 @@ public function fetchAmazonProperties($title)
$search->setKeywords($title);
$search->setResponseGroup(['Large']);
$responses = $apaiIo->runOperation($search);
} catch (\Exception $e) {
} catch (\Throwable $e) {
// Empty because we exhausted all possibilities.
}
}
Expand Down
5 changes: 3 additions & 2 deletions Blacklight/NZBImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ protected function insertNZB($nzbDetails): bool
]
);
} else {
//$this->echoOut('This release is already in our DB so skipping: ' . $subject);
$this->echoOut('This release is already in our DB so skipping: '.$subject);

return false;
}

Expand Down Expand Up @@ -457,7 +458,7 @@ protected function echoOut($message): void
if ($this->browser) {
$this->retVal .= $message.'<br />';
} elseif ($this->echoCLI) {
echo $message.PHP_EOL;
ColorCLI::doEcho(ColorCLI::notice($message), true);
}
}

Expand Down
18 changes: 9 additions & 9 deletions Blacklight/NameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ public function getPreFileNames(array $args = []): void
ColorCLI::doEcho(ColorCLI::primary('Matching predb filename to cleaned release_files.name.'), true);

$counter = $counted = 0;
$timestart = time();
$timestart = now();

$query = DB::select(
sprintf(
Expand Down Expand Up @@ -1184,7 +1184,7 @@ public function getPreFileNames(array $args = []): void
$this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($counted).'] '.$this->consoletools->percentString(++$counter, $total));
}
}
echo ColorCLI::header($n.'Renamed '.number_format($counted).' releases in '.$this->consoletools->convertTime(time() - $timestart).'.');
echo ColorCLI::header($n.'Renamed '.number_format($counted).' releases in '.now()->diffInSeconds($timestart).' seconds'.'.');
} else {
ColorCLI::doEcho(ColorCLI::info($n.'Nothing to do.'), true);
}
Expand Down Expand Up @@ -1988,11 +1988,11 @@ public function fileCheck($release, $echo, $type, $nameStatus, $show): bool
case preg_match('/^(.+?(19|20)\d\d\-([a-z0-9]{3}|[a-z]{2,}|C4))\\\\/i', $release->textstring, $result):
$this->updateRelease($release, $result['1'], $method = 'fileCheck: music groups', $echo, $type, $nameStatus, $show);
break;
case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.avi)/i', $release->textstring, $result):
case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.avi)$/i', $release->textstring, $result):
$newname = str_replace('.avi', ' DVDRip XVID NoGroup', $result['1']);
$this->updateRelease($release, $newname, $method = 'fileCheck: Movie (year) avi', $echo, $type, $nameStatus, $show);
break;
case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.iso)/i', $release->textstring, $result):
case preg_match('/.+\\\\(.+\((19|20)\d\d\)\.iso)$/i', $release->textstring, $result):
$newname = str_replace('.iso', ' DVD NoGroup', $result['1']);
$this->updateRelease($release, $newname, $method = 'fileCheck: Movie (year) iso', $echo, $type, $nameStatus, $show);
break;
Expand All @@ -2005,14 +2005,14 @@ public function fileCheck($release, $echo, $type, $nameStatus, $show): bool
case preg_match('/^.+?SDPORN/i', $release->textstring, $result):
$this->updateRelease($release, $result['0'], $method = 'fileCheck: XXX SDPORN', $echo, $type, $nameStatus, $show);
break;
case preg_match('/\w[-\w.\',;& ]+1080i[._ -]DD5[._ -]1[._ -]MPEG2-R&C(?=\.ts)/i', $release->textstring, $result):
case preg_match('/\w[-\w.\',;& ]+1080i[._ -]DD5[._ -]1[._ -]MPEG2-R&C(?=\.ts)$/i', $release->textstring, $result):
$result = str_replace('MPEG2', 'MPEG2.HDTV', $result['0']);
$this->updateRelease($release, $result, $method = 'fileCheck: R&C', $echo, $type, $nameStatus, $show);
break;
case preg_match('/\w[-\w.\',;& ]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](480|720|1080)[ip][._ -](BD(-?(25|50|RIP))?|Blu-?Ray ?(3D)?|BRRIP|CAM(RIP)?|DBrip|DTV|DVD\-?(5|9|(R(IP)?|scr(eener)?))?|[HPS]D?(RIP|TV(RIP)?)?|NTSC|PAL|R5|Ripped |S?VCD|scr(eener)?|SAT(RIP)?|TS|VHS(RIP)?|VOD|WEB-DL)[._ -]nSD[._ -](DivX|[HX][._ -]?264|MPEG2|XviD(HD)?|WMV)[._ -]NhaNC3[-\w.\',;& ]+\w/i', $release->textstring, $result):
$this->updateRelease($release, $result['0'], $method = 'fileCheck: NhaNc3', $echo, $type, $nameStatus, $show);
break;
case preg_match('/\wtvp-[\w.\-\',;]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](720p|1080p|xvid)(?=\.(avi|mkv))/i', $release->textstring, $result):
case preg_match('/\wtvp-[\w.\-\',;]+((s\d{1,2}[._ -]?[bde]\d{1,2})|\d{1,2}x\d{2}|ep[._ -]?\d{2})[._ -](720p|1080p|xvid)(?=\.(avi|mkv))$/i', $release->textstring, $result):
$result = str_replace('720p', '720p.HDTV.X264', $result['0']);
$result = str_replace('1080p', '1080p.Bluray.X264', $result['0']);
$result = str_replace('xvid', 'XVID.DVDrip', $result['0']);
Expand All @@ -2027,7 +2027,7 @@ public function fileCheck($release, $echo, $type, $nameStatus, $show): bool
case preg_match('/\S.*[\w.\-\',;]+\s\-\ss\d{2}[ex]\d{2}\s\-\s[\w.\-\',;].+\./i', $release->textstring, $result):
$this->updateRelease($release, $result['0'], $method = 'fileCheck: Title - SxxExx - Eptitle', $echo, $type, $nameStatus, $show);
break;
case preg_match('/\w.+?\)\.nds/i', $release->textstring, $result):
case preg_match('/\w.+?\)\.nds$/i', $release->textstring, $result):
$this->updateRelease($release, $result['0'], $method = 'fileCheck: ).nds Nintendo DS', $echo, $type, $nameStatus, $show);
break;
case preg_match('/3DS_\d{4}.+\d{4} - (.+?)\.3ds/i', $release->textstring, $result):
Expand Down Expand Up @@ -2121,7 +2121,7 @@ public function mediaMovieNameCheck($release, $echo, $type, $nameStatus, $show):
$media = $match[1];
if (preg_match(self::PREDB_REGEX, $media, $match)) {
$newName = $match[1];
} elseif (preg_match('/(.+)[\,](\sRMZ\.cr)?/i', $media, $match)) {
} elseif (preg_match('/(.+)[\,](\sRMZ\.cr)?$/i', $media, $match)) {
$newName = $match[1];
} else {
$newName = $media;
Expand Down Expand Up @@ -2225,7 +2225,7 @@ public function srrNameCheck($release, $echo, $type, $nameStatus, $show): bool
);

foreach ($result as $res) {
if (preg_match('/^(.*)\.srr/i', $res->textstring, $match)) {
if (preg_match('/^(.*)\.srr$/i', $res->textstring, $match)) {
$this->updateRelease(
$release,
$match['1'],
Expand Down
5 changes: 2 additions & 3 deletions Blacklight/ReleaseCleaning.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ class ReleaseCleaning
/**
* ReleaseCleaning constructor.
*
* @param null $settings
* @throws \Exception
*/
public function __construct($settings = null)
public function __construct()
{
// Extensions.
$this->e0 = CollectionsCleaning::REGEX_FILE_EXTENSIONS;
Expand Down Expand Up @@ -185,7 +184,7 @@ public function releaseCleaner($subject, $fromName, $groupName, $usePre = false)
}

//if www.town.ag releases check against generic_town regexes
if (preg_match('/www\.town\.ag/i', $subject)) {
if (preg_match('/www\.town\.ag$/i', $subject)) {
return $this->generic_town();
}
if ($groupName === 'alt.binaries.teevee') {
Expand Down
34 changes: 4 additions & 30 deletions Blacklight/ReleaseImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,13 @@ public function __construct()

/**
* @param $imgLoc
* @param string $token
*
* @return bool|\Intervention\Image\Image
*/
protected function fetchImage($imgLoc, $token = '')
protected function fetchImage($imgLoc)
{
try {
if ($token !== '') {
$file_data = file_get_contents(
$imgLoc,
false,
stream_context_create(
[
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
'http' => [
'method' => 'GET',
'header' => [
'Accept-language: en',
'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2',
'Authorization: Bearer '.$token,
],
],
]
)
);
} else {
$file_data = $imgLoc;
}
$img = Image::make($file_data);
$img = Image::make($imgLoc);
} catch (NotFoundException $e) {
if ($e->getCode() === 404) {
ColorCLI::doEcho(ColorCLI::notice('Data not available on server'), true);
Expand Down Expand Up @@ -131,13 +106,12 @@ protected function fetchImage($imgLoc, $token = '')
* @param string $imgMaxHeight Max height to resize image to. (OPTIONAL)
* @param bool $saveThumb Save a thumbnail of this image? (OPTIONAL)
*
* @param string $token
*
* @return int 1 on success, 0 on failure Used on site to check if there is an image.
*/
public function saveImage($imgName, $imgLoc, $imgSavePath, $imgMaxWidth = '', $imgMaxHeight = '', $saveThumb = false, $token = ''): int
public function saveImage($imgName, $imgLoc, $imgSavePath, $imgMaxWidth = '', $imgMaxHeight = '', $saveThumb = false): int
{
$cover = $this->fetchImage($imgLoc, $token);
$cover = $this->fetchImage($imgLoc);

if ($cover === false) {
return 0;
Expand Down
Loading

0 comments on commit 3bd4f1c

Please sign in to comment.