Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Jul 14, 2020
2 parents dc850a7 + 42d9b70 commit 460559c
Show file tree
Hide file tree
Showing 147 changed files with 24,656 additions and 16,490 deletions.
9 changes: 5 additions & 4 deletions Blacklight/ElasticSearchSiteSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function indexSearch($phrases, int $limit)
'scroll_id' => $scroll_id, //...using our previously obtained _scroll_id
'scroll' => '30s', // and the same timeout window
]
);
);
}

return $searchResult;
Expand Down Expand Up @@ -384,14 +384,15 @@ private function sanitize($phrases): string
} else {
$wordArray = $phrases;
}

$keywords = [];
$tempWords = [];
foreach ($wordArray as $words) {
$tempWords = [];
$words = preg_split('/\s+/', $words);
foreach ($words as $st) {
if (Str::startsWith($st, ['!', '+', '-', '?', '*'])) {
if (Str::startsWith($st, ['!', '+', '-', '?', '*']) && Str::length($st) > 1 && ! preg_match('/(!|\+|\?|-|\*){2,}/', $st)) {
$str = $st;
} elseif (Str::endsWith($st, ['+', '-', '?', '*'])) {
} elseif (Str::endsWith($st, ['+', '-', '?', '*']) && Str::length($st) > 1 && ! preg_match('/(!|\+|\?|-|\*){2,}/', $st)) {
$str = $st;
} else {
$str = Sanitizer::escape($st);
Expand Down
2 changes: 1 addition & 1 deletion Blacklight/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public function updateMovieInfo($imdbId): bool

if (! empty($imdb['language'])) {
$mov['language'] = \is_array($imdb['language']) ? implode(', ', array_unique($imdb['language'])) : $imdb['language'];
} elseif (! empty($omdb['language'])) {
} elseif (! empty($omdb['language']) && ! is_bool($omdb['language'])) {
$mov['language'] = \is_array($imdb['language']) ? implode(', ', array_unique($omdb['language'])) : $omdb['language'];
}

Expand Down
12 changes: 6 additions & 6 deletions Blacklight/NZBImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Settings;
use App\Models\UsenetGroup;
use Blacklight\utility\Utility;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;

/**
Expand Down Expand Up @@ -134,7 +135,7 @@ public function beginImport($filesToProcess, $useNzbName = false, $delete = true
return false;
}

$start = date('Y-m-d H:i:s');
$start = now()->toImmutable()->format('Y-m-d H:i:s');
$nzbsImported = $nzbsSkipped = 0;

// Loop over the file names.
Expand Down Expand Up @@ -222,8 +223,7 @@ public function beginImport($filesToProcess, $useNzbName = false, $delete = true
'Proccessed '.
$nzbsImported.
' NZBs in '.
(strtotime(date('Y-m-d H:i:s')) - strtotime($start)).
' seconds, '.
now()->diffForHumans($start).
$nzbsSkipped.
' NZBs were skipped.'
);
Expand Down Expand Up @@ -261,7 +261,7 @@ protected function scanNZBFile(&$nzbXML, $useNzbName = false): bool
$posterName = (string) $file->attributes()->poster;
}
if ($postDate === false) {
$postDate = date('Y-m-d H:i:s', (string) $file->attributes()->date);
$postDate = Carbon::createFromTimestamp((string) $file->attributes()->date)->format('Y-m-d H:i:s');
}

// Make a fake message array to use to check the blacklist.
Expand Down Expand Up @@ -346,7 +346,7 @@ protected function scanNZBFile(&$nzbXML, $useNzbName = false): bool
[
'subject' => $firstName,
'useFName' => $useNzbName,
'postDate' => empty($postDate) ? date('Y-m-d H:i:s') : $postDate,
'postDate' => empty($postDate) ? now()->format('Y-m-d H:i:s') : $postDate,
'from' => empty($posterName) ? '' : $posterName,
'groups_id' => $groupID,
'groupName' => $groupName,
Expand Down Expand Up @@ -401,7 +401,7 @@ protected function insertNZB($nzbDetails): bool
$relID = Release::insertRelease(
[
'name' => $escapedSubject,
'searchname' => $escapedSearchName,
'searchname' => $escapedSearchName ?? $escapedSubject,
'totalpart' => $nzbDetails['totalFiles'],
'groups_id' => $nzbDetails['groups_id'],
'guid' => $this->relGuid,
Expand Down
20 changes: 12 additions & 8 deletions Blacklight/NameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,11 +1019,11 @@ public function updateRelease($release, $name, $method, $echo, $type, int $nameS
$updateColumns = [
'videos_id' => 0,
'tv_episodes_id' => 0,
'imdbid' => null,
'musicinfo_id' => null,
'consoleinfo_id' => null,
'bookinfo_id' => null,
'anidbid' => null,
'imdbid' => '',
'musicinfo_id' => '',
'consoleinfo_id' => '',
'bookinfo_id' => '',
'anidbid' => '',
'predb_id' => $preId,
'searchname' => $newTitle,
'categories_id' => $determinedCategory['categories_id'],
Expand All @@ -1035,8 +1035,10 @@ public function updateRelease($release, $name, $method, $echo, $type, int $nameS
}
}

$taggedRelease->update($updateColumns);
$taggedRelease->retag($determinedCategory['tags']);
if ($taggedRelease !== null) {
$taggedRelease->update($updateColumns);
$taggedRelease->retag($determinedCategory['tags']);
}
if (config('nntmux.elasticsearch_enabled') === true) {
$this->elasticsearch->updateRelease($release->releases_id);
} else {
Expand All @@ -1060,7 +1062,9 @@ public function updateRelease($release, $name, $method, $echo, $type, int $nameS
'iscategorized' => 1,
]
);
$taggedRelease->retag($determinedCategory['tags']);
if ($taggedRelease !== null) {
$taggedRelease->retag($determinedCategory['tags']);
}
if (config('nntmux.elasticsearch_enabled') === true) {
$this->elasticsearch->updateRelease($release->_releases_id);
} else {
Expand Down
9 changes: 8 additions & 1 deletion Blacklight/Releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Release;
use App\Models\Settings;
use App\Models\UsenetGroup;
use Elasticsearch\Common\Exceptions\Missing404Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -168,9 +169,11 @@ public function showPasswords()
$setting = $show ?? 0;
switch ($setting) {
case 1: // Shows everything.

return '<= '.self::PASSWD_RAR;
case 0:
default:// Hide releases with a password.

return '= '.self::PASSWD_NONE;
}
}
Expand Down Expand Up @@ -460,7 +463,11 @@ public function deleteSingle($identifiers, NZB $nzb, ReleaseImage $releaseImage)
'id' => $identifiers['i'],
];

\Elasticsearch::delete($params);
try {
\Elasticsearch::delete($params);
} catch (Missing404Exception $e) {
//we do nothing here just catch the error, we don't care if release is missing from ES, we are deleting it anyway
}
}
} else {
// Delete from sphinx.
Expand Down
24 changes: 3 additions & 21 deletions Blacklight/Tmux.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Category;
use App\Models\Settings;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;

/**
Expand Down Expand Up @@ -326,28 +327,9 @@ public function rand_bool($loop, $chance = 60): bool
*/
public function relativeTime($_time): string
{
$d = [];
$d[0] = [1, 'sec'];
$d[1] = [60, 'min'];
$d[2] = [3600, 'hr'];
$d[3] = [86400, 'day'];
$d[4] = [31104000, 'yr'];

$w = [];

$return = '';
$now = time();
$secondsLeft = $now - ($_time >= $now ? $_time - 1 : $_time);

for ($i = 4; $i > -1; $i--) {
$w[$i] = (int) ($secondsLeft / $d[$i][0]);
$secondsLeft -= ($w[$i] * $d[$i][0]);
if ($w[$i] !== 0) {
$return .= $w[$i].' '.$d[$i][1].(($w[$i] > 1) ? 's' : '').' ';
}
}
$time = Carbon::createFromTimestamp($_time);

return $return;
return $time->ago();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Blacklight/TmuxOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected function _getHeader(): string
$this->tmpMasks[1],
'Release Added:',
sprintf(
'%s ago',
'%s',
(isset($this->runVar['timers']['newOld']['newestrelease'])
? $this->relativeTime($this->runVar['timers']['newOld']['newestrelease'])
: 0)
Expand All @@ -186,7 +186,7 @@ protected function _getHeader(): string
$this->tmpMasks[1],
'Predb Updated:',
sprintf(
'%s ago',
'%s',
(isset($this->runVar['timers']['newOld']['newestpre'])
? $this->relativeTime($this->runVar['timers']['newOld']['newestpre'])
: 0)
Expand All @@ -199,7 +199,7 @@ protected function _getHeader(): string
$this->runVar['constants']['delaytime']
),
sprintf(
'%s ago',
'%s',
(isset($this->runVar['timers']['newOld']['oldestcollection'])
? $this->relativeTime($this->runVar['timers']['newOld']['oldestcollection'])
: 0)
Expand Down
8 changes: 7 additions & 1 deletion Blacklight/processing/post/ProcessAdditional.php
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,8 @@ protected function _getAudioInfo($fileLocation, $fileExtension): bool
}
} catch (\RuntimeException $e) {
Log::debug($e->getMessage());
} catch (\TypeError $e) {
Log::debug($e->getMessage());
}
}

Expand Down Expand Up @@ -2103,7 +2105,7 @@ protected function _getMediaInfo($fileLocation): bool
// Look for the video file.
if (File::isFile($fileLocation)) {
try {
$xmlArray = $this->mediaInfo->getInfo($fileLocation, false);
$xmlArray = $this->mediaInfo->getInfo($fileLocation, true);

// Check if we got it.

Expand All @@ -2123,6 +2125,10 @@ protected function _getMediaInfo($fileLocation): bool
} catch (\RuntimeException $e) {
Log::debug($e->getMessage());

return false;
} catch (\TypeError $e) {
Log::debug($e->getMessage());

return false;
}
}
Expand Down
8 changes: 6 additions & 2 deletions Blacklight/processing/tv/TVDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,12 @@ protected function formatShowInfo($show): array
$this->colorCli->notice('Fanart image not found on TVDB', true);
}

$imdbid = $this->client->series()->getById($show->id);
preg_match('/tt(?P<imdbid>\d{6,7})$/i', $imdbid->imdbId, $imdb);
try {
$imdbid = $this->client->series()->getById($show->id);
preg_match('/tt(?P<imdbid>\d{6,7})$/i', $imdbid->imdbId, $imdb);
} catch (ResourceNotFoundException $e) {
$this->colorCli->notice('Show ID not found on TVDB', true);
}

return [
'type' => parent::TYPE_TV,
Expand Down
24 changes: 13 additions & 11 deletions Blacklight/processing/tv/TraktTv.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,22 @@ public function getShowInfo($name)

if (\is_array($response)) {
foreach ($response as $show) {
if (! is_bool($show)) {

// Check for exact title match first and then terminate if found
if ($show['show']['title'] === $name) {
$highest = $show;
break;
}
// Check for exact title match first and then terminate if found
if ($show['show']['title'] === $name) {
$highest = $show;
break;
}

// Check each show title for similarity and then find the highest similar value
$matchPercent = $this->checkMatch($show['show']['title'], $name, self::MATCH_PROBABILITY);
// Check each show title for similarity and then find the highest similar value
$matchPercent = $this->checkMatch($show['show']['title'], $name, self::MATCH_PROBABILITY);

// If new match has a higher percentage, set as new matched title
if ($matchPercent > $highestMatch) {
$highestMatch = $matchPercent;
$highest = $show;
// If new match has a higher percentage, set as new matched title
if ($matchPercent > $highestMatch) {
$highestMatch = $matchPercent;
$highest = $show;
}
}
}
if ($highest !== null) {
Expand Down
43 changes: 43 additions & 0 deletions app/Http/Controllers/Api/ApiInformController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Release;
use App\Models\ReleaseInform;
use App\Models\User;
use Blacklight\NameFixer;
use Illuminate\Http\Request;

class ApiInformController extends Controller
{
/**
* http://sitename/api/inform/release?api_token=xxxxx&relo=xxx&relp=xxx.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \Exception
*/
public function release(Request $request)
{
$releaseObName = $request->has('relo') && ! empty($request->input('relo')) ? $request->input('relo') : '';
$releasePrName = $request->has('relp') && ! empty($request->input('relp')) ? $request->input('relp') : '';
$apiToken = $request->has('api_token') && ! empty($request->input('api_token')) ? $request->input('api_token') : '';
$user = User::query()->where('api_token', $request->input('api_token'))->first();
if (! $user) {
return response()->json(['message' => 'Indexer inform error, wrong api key!'], 404);
}

if (! empty($releaseObName) && ! empty($releasePrName) && ! empty($apiToken)) {
ReleaseInform::insertOrIgnore(['relOName' => $releaseObName, 'relPName' => $releasePrName, 'api_token' => $apiToken, 'created_at' => now(), 'updated_at' => now()]);
$release = Release::whereSearchname($releaseObName)->first();
if (! empty($release)) {
(new NameFixer())->updateRelease($release, $releasePrName, 'Release Inform API', true, 'Filenames, ', 1, true);
}

return response()->json(['message' => 'Release Information Added!'], 200);
}

return response()->json(['message' => 'Indexer inform error, wrong data supplied!'], 404);
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/DetailsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function show($guid)
$user = User::find(Auth::id());
$cpapi = $user['cp_api'];
$cpurl = $user['cp_url'];
$releaseRegex = ReleaseRegex::query()->where('releases_id', '=', $data['id'])->first();
$releaseRegex = '';
if (! empty($data)) {
$releaseRegex = ReleaseRegex::query()->where('releases_id', '=', $data['id'])->first();
}

if (! $data) {
return redirect()->back();
Expand Down
10 changes: 10 additions & 0 deletions app/Models/ReleaseInform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ReleaseInform extends Model
{
//
}
6 changes: 3 additions & 3 deletions cli/data/predb_import_daily_batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
foreach ($files as $file) {
if (preg_match("#^https://raw\.githubusercontent\.com/nZEDb/nZEDbPre_Dumps/master/dumps/$dir/$filePattern$#", $file['download_url'])) {
if (preg_match("#^$filePattern$#", $file['name'], $match)) {
$timematch = $progress['last'];
$timeMatch = max($progress['last'], $argv[1]);

// Skip patches the user does not want.
if ($match[1] < $timematch) {
if ($match[1] < $timeMatch) {
echo 'Skipping dump '.$match[2].
', as your minimum unix time argument is '.
$timematch.PHP_EOL;
$timeMatch.PHP_EOL;
$total--;
continue;
}
Expand Down
Loading

0 comments on commit 460559c

Please sign in to comment.