Goosle/engines/boxoffice/nyaa.php
Arnan de Gans a5740b3dea Version 1.5
- 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
2024-06-19 18:08:00 -06:00

83 lines
No EOL
3.1 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.
------------------------------------------------------------------------------------ */
function nyaa_boxoffice($opts, $amount) {
$api_url = 'https://nyaa.si/';
$results = array();
// If there is a cached result use that instead
if($opts->cache_type !== 'off' && has_cached_results($opts->cache_type, $opts->hash, $api_url, $opts->cache_time)) {
return fetch_cached_results($opts->cache_type, $opts->hash, $api_url);
}
$response = do_curl_request(
$api_url, // (string) Where?
array('Accept: text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7', 'User-Agent: '.$opts->user_agents[0].';'), // (array) User agent + Headers
'get', // (string) post/get
null // (assoc array|null) Post body
);
$xpath = get_xpath($response);
$results = array();
// No response
if(!$xpath) return $results;
// Scrape the results
$limit = $amount + 16;
$scrape = $xpath->query("//tbody/tr[position() <= $limit]");
// No results
if(count($scrape) == 0) return $results;
foreach($scrape as $result) {
$meta = $xpath->evaluate(".//td[@class='text-center']", $result);
$name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result);
if($name->length == 0) continue;
$magnet = $xpath->evaluate(".//a[2]/@href", $meta[0]);
if($magnet->length == 0) $magnet = $xpath->evaluate(".//a/@href", $meta[0]);
if($magnet->length == 0) continue;
$name = sanitize($name[0]->textContent);
$magnet = sanitize($magnet[0]->textContent);
parse_str(parse_url($magnet, PHP_URL_QUERY), $hash_parameters);
$hash = strtolower(str_replace('urn:btih:', '', $hash_parameters['xt']));
$seeders = sanitize($meta[3]->textContent);
$leechers = sanitize($meta[4]->textContent);
$filesize = filesize_to_bytes(str_replace('TiB', 'TB', str_replace('GiB', 'GB', str_replace('MiB', 'MB', str_replace('KiB', 'KB', sanitize($meta[1]->textContent))))));
$category = sanitize($xpath->evaluate(".//td[1]//a/@title", $result)[0]->textContent);
$category = str_replace(' - ', '/', $category);
$results[] = array (
'id' => uniqid(rand(0, 9999)), // Semi random string to separate results on the results page
'name' => $name, // string
'magnet' => $magnet, // string
'seeders' => $seeders, // int
'leechers' => $leechers, // int
'filesize' => $filesize, // int
'category' => $category, // string
);
unset($result, $meta, $name, $magnet, $seeders, $leechers, $filesize, $category);
}
unset($response, $xpath, $scrape, $limit);
$results = array_slice($results, 0, $amount);
// Cache last request if there is something to cache
if($opts->cache_type !== 'off') {
if(count($results) > 0) store_cached_results($opts->cache_type, $opts->hash, $api_url, $results, $opts->cache_time);
}
return $results;
}
?>