
- NOTICE: config.default.php has changed, re-create your config.php!! - [fix] No longer caches empty results - [fix] No longer make a request if the search query is empty - [fix] Movie highlight/box office cache now works - [fix] Language selector for Qwant, Wikipedia and Duckduckgo - [fix] Season and Episode filter for tv show searches - [fix] Safe search filter now actually works - [fix] Magnet Search category exclusion filter now actually works - [fix] Image size filter works more reliably - [fix] Handling of doublequotes in search queries - [fix] Search sources now show result amounts accurately - [fix] Old cache files are now actually deleted when expired - [fix] Search tabs not properly centered on smaller screens - [new] Box Office page with latest/new downloads from a few supported torrent websites - [new] News page with the latest news from major outlets - [new] Popup with movie info and download links for YTS Movie Highlights - [new] CSS colorschemes configurable in config.php - [new] Easily share magnet links with other Goosle users - [new] Search results from Quant API - [new] Search results from Brave - [new] Image results from Qwant Image API - [new] News results from Hackernews - [new] News results from Yahoo! News - [new] News results from Brave News - [new] News results from Qwant News API - [new] Magnet results from Sukebei.nyaa.si - [new] Special search for IP Lookups via ipify (Search for "ip" or "myip") - [new] Safe search switch for Yahoo! Images - [new] Image size switch for Qwant Images - [new] Merge missing magnet meta data from duplicate results if it doesn't already exist in the matched previous result - [new] Detect meta data for Magnet Search results such as sound and video quality. - [tweak] Cache ttl is now in hours (was minutes) - [tweak] Optimizations in CSS, HTML separators and more - [tweak] Moved icons into CSS so they can be colored using colorschemes - [tweak] Better handling of image results - [tweak] Better handling of empty/incomplete results for all engines - [tweak] Better handling of empty/missing meta data for all magnet engines - [tweak] Better category detection for Limetorrent magnets - [tweak] Raised Magnet search limit to 200 (was 50) - [tweak] Raised Wikipedia search limit to 20 (was 10) - [tweak] Hide magnet results with 0 seeders by default - [tweak] Uniform array formatting for all engines - [tweak] Consistent use of single-quotes and double-qoutes - [tweak] File size string conversion and formatting for all image and magnet engines - [tweak] Update checks are now done weekly(ish) via the Cron job - [tweak] Updated .htaccess caching rules - [removed] CSS for 320px viewport
104 lines
3.4 KiB
PHP
104 lines
3.4 KiB
PHP
<?php
|
|
/* ------------------------------------------------------------------------------------
|
|
* Goosle - The fast, privacy oriented search tool that just works.
|
|
*
|
|
* COPYRIGHT NOTICE
|
|
* Copyright 2023-2024 Arnan de Gans. All Rights Reserved.
|
|
*
|
|
* COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
|
|
* By using this code you agree to indemnify Arnan de Gans from any
|
|
* liability that might arise from its use.
|
|
------------------------------------------------------------------------------------ */
|
|
class QwantRequest extends EngineRequest {
|
|
public function get_request_url() {
|
|
$query = str_replace('%22', '\"', $this->query);
|
|
|
|
// Safe search override
|
|
$safe = '1'; // Moderate results
|
|
if(preg_match('/(safe:)(on|off)/i', $query, $matches)) {
|
|
if($matches[2] == 'on') $safe = '2';
|
|
if($matches[2] == 'off') $safe = '0';
|
|
$query = trim(str_replace($matches[0], '', $query));
|
|
}
|
|
unset($matches);
|
|
|
|
// Set locale
|
|
$language = (preg_match('/[a-z]{2}_[a-z]{2}/i', $this->opts->qwant_language) && strlen($this->opts->qwant_language) == 5) ? strtolower($this->opts->qwant_language) : 'en_gb';
|
|
|
|
// Is there no query left? Bail!
|
|
if(empty($query)) return false;
|
|
|
|
// Based on https://github.com/locness3/qwant-api-docs and variables from qwant website
|
|
$url = 'https://api.qwant.com/v3/search/web?'.http_build_query(array(
|
|
'q' => $query, // Search query
|
|
't' => 'web', // Type of search, web search
|
|
'safesearch' => $safe, // Safe search filter (0 = off, 1 = normal, 2 = strict)
|
|
'locale' => $language, // In which language should the search be done
|
|
'count' => 10, // How many results? (Maximum 10)
|
|
'device' => 'desktop' // What kind of device are we searching from?
|
|
));
|
|
|
|
unset($query, $safe, $language);
|
|
|
|
return $url;
|
|
}
|
|
|
|
public function get_request_headers() {
|
|
return array(
|
|
'Accept' => 'application/json, */*;q=0.8',
|
|
'Accept-Language' => null,
|
|
'Accept-Encoding' => null,
|
|
'Sec-Fetch-Dest' => null,
|
|
'Sec-Fetch-Mode' => null,
|
|
'Sec-Fetch-Site' => null
|
|
);
|
|
}
|
|
|
|
public function parse_results($response) {
|
|
$engine_temp = $engine_result = array();
|
|
$json_response = json_decode($response, true);
|
|
|
|
// No response
|
|
if(empty($json_response)) return $engine_temp;
|
|
|
|
// Figure out results and base rank
|
|
$number_of_results = $rank = $json_response['data']['result']['total'];
|
|
|
|
// No results
|
|
if($number_of_results == 0 || $json_response['status'] == 'error') return $engine_temp;
|
|
|
|
$rank = $json_response['data']['result']['total'];
|
|
|
|
foreach($json_response['data']['result']['items']['mainline'] as $mainline) {
|
|
if($mainline['type'] != 'web') continue;
|
|
|
|
foreach ($mainline['items'] as $result) {
|
|
// Find and process data
|
|
$title = strip_newlines(sanitize($result['title']));
|
|
$url = sanitize($result['url']);
|
|
$description = limit_string_length(strip_newlines(sanitize($result['desc'])));
|
|
|
|
$engine_temp[] = array (
|
|
'title' => $title,
|
|
'url' => $url,
|
|
'description' => $description,
|
|
'engine_rank' => $rank
|
|
);
|
|
$rank -= 1;
|
|
}
|
|
}
|
|
|
|
// Base info
|
|
$number_of_results = count($engine_temp);
|
|
if($number_of_results > 0) {
|
|
$engine_result['source'] = 'Qwant';
|
|
$engine_result['amount'] = $number_of_results;
|
|
$engine_result['search'] = $engine_temp;
|
|
}
|
|
|
|
unset($response, $json_response, $number_of_results, $rank, $engine_temp);
|
|
|
|
return $engine_result;
|
|
}
|
|
}
|
|
?>
|