From 5b4265e45aab67316d3c7848254f14b5438f7d3d Mon Sep 17 00:00:00 2001 From: Jack'lul Date: Fri, 20 Mar 2020 15:43:01 +0100 Subject: [PATCH] Improve saucenao handler --- src/app.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app.php b/src/app.php index e79ca24..9c8bb21 100644 --- a/src/app.php +++ b/src/app.php @@ -1099,15 +1099,23 @@ private function reverseSearchSaucenao($file) $result = json_decode($output, true); + if (empty($output)) { + return ['error' => 'EmptyResult']; + } + $matches = []; if (isset($result['header']['status'])) { if ($result['header']['status'] === 0) { foreach ($result['results'] as $this_result) { - if (isset($this_result['data']['ext_urls'])) { + if (isset($this_result['data']['ext_urls']) && (float)$this_result['header']['similarity'] >= 55) { $matches[] = $this_result['data']['ext_urls'][0]; } } + if (count($matches) === 0) { + return ['error' => 'NoResults']; + } + return $matches; }