123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668 |
- <?php
- class solofield{
-
- public function __construct(){
-
- include "lib/backend.php";
- $this->backend = new backend("solofield");
-
- include "lib/fuckhtml.php";
- $this->fuckhtml = new fuckhtml();
- }
-
- public function getfilters($page){
-
- return [
- "nsfw" => [
- "display" => "NSFW",
- "option" => [
- "yes" => "Yes",
- "no" => "No",
- ]
- ]
- ];
- }
-
- private function get($proxy, $url, $get = []){
-
- $curlproc = curl_init();
-
- if($get !== []){
- $get = http_build_query($get);
- $url .= "?" . $get;
- }
-
- curl_setopt($curlproc, CURLOPT_URL, $url);
-
- curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
- curl_setopt($curlproc, CURLOPT_HTTPHEADER,
- ["User-Agent: " . config::USER_AGENT,
- "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
- "Accept-Language: en-US,en;q=0.5",
- "Accept-Encoding: gzip",
- "Referer: https://solofield.net",
- "DNT: 1",
- "Connection: keep-alive",
- "Cookie: cross-site-cookie=name; lno=35842050",
- "Upgrade-Insecure-Requests: 1",
- "Sec-Fetch-Dest: document",
- "Sec-Fetch-Mode: navigate",
- "Sec-Fetch-Site: same-origin",
- "Sec-Fetch-User: ?1"]
- );
-
- curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
-
- $this->backend->assign_proxy($curlproc, $proxy);
-
- $data = curl_exec($curlproc);
-
- if(curl_errno($curlproc)){
-
- throw new Exception(curl_error($curlproc));
- }
-
- curl_close($curlproc);
- return $data;
- }
-
- public function web($get){
-
- if($get["npt"]){
-
- [$query, $proxy] = $this->backend->get($get["npt"], "web");
-
- try{
-
- $html =
- $this->get(
- $proxy,
- "https://solofield.net/search?" . $query,
- []
- );
- }catch(Exception $error){
-
- throw new Exception("Failed to fetch search page");
- }
- }else{
-
- $proxy = $this->backend->get_ip();
-
- try{
- $html =
- $this->get(
- $proxy,
- "https://solofield.net/search",
- [
- "q" => $get["s"],
- "ie" => "UTF-8",
- "oe" => "UTF-8",
- "hl" => "ja", // changing this doesnt do anything
- "lr" => "lang_ja", // same here
- //"ls" => "", // ??
- "f" => ($get["nsfw"] == "yes" ? "off" : "on")
- ]
- );
- }catch(Exception $error){
-
- throw new Exception("Failed to fetch search page");
- }
- }
-
- $out = [
- "status" => "ok",
- "spelling" => [
- "type" => "no_correction",
- "using" => null,
- "correction" => null
- ],
- "npt" => null,
- "answer" => [],
- "web" => [],
- "image" => [],
- "video" => [],
- "news" => [],
- "related" => []
- ];
-
- // check for errors and load the result div
- if($this->error_and_load($html)){
-
- return $out;
- }
-
- $items =
- $this->fuckhtml
- ->getElementsByClassName(
- "g0",
- "li"
- );
-
- foreach($items as $item){
-
- $this->fuckhtml->load($item);
-
- $title_tag =
- $this->fuckhtml
- ->getElementsByClassName(
- "r",
- "h3"
- );
-
- if(count($title_tag) === 0){
-
- continue;
- }
-
- $this->fuckhtml->load($title_tag[0]);
-
- $link =
- $this->fuckhtml
- ->getTextContent(
- $this->fuckhtml
- ->getElementsByTagName(
- "a"
- )[0]
- ["attributes"]
- ["href"]
- );
-
- $this->fuckhtml->load($item);
- $thumb =
- $this->fuckhtml
- ->getElementsByClassName(
- "webshot",
- "img"
- );
-
- if(count($thumb) !== 0){
-
- $uri =
- $this->fuckhtml
- ->getTextContent(
- $thumb[0]
- ["attributes"]
- ["src"]
- );
-
- if(stripos($uri, "now_printing") === false){
-
- $thumb = [
- "ratio" => "1:1",
- "url" =>
- "https://solofield.net" .
- $this->fuckhtml
- ->getTextContent(
- $thumb[0]
- ["attributes"]
- ["src"]
- )
- ];
- }else{
-
- $thumb = [
- "ratio" => null,
- "url" => null
- ];
- }
- }else{
-
- $thumb = [
- "ratio" => null,
- "url" => null
- ];
- }
-
- $out["web"][] = [
- "title" =>
- $this->fuckhtml
- ->getTextContent(
- $title_tag[0]
- ),
- "description" =>
- $this->fuckhtml
- ->getTextContent(
- $this->fuckhtml
- ->getElementsByClassName(
- "s",
- "div"
- )[0]
- ),
- "url" => $link,
- "date" => null,
- "type" => "web",
- "thumb" => $thumb,
- "sublink" => [],
- "table" => []
- ];
- }
-
- // get next page
- $this->get_npt($html, $proxy, $out, "web");
-
- return $out;
- }
-
-
- public function image($get){
-
- // no pagination
- $html =
- $this->get(
- $this->backend->get_ip(),
- "https://solofield.net/isearch",
- [
- "q" => $get["s"],
- "ie" => "UTF-8",
- "oe" => "UTF-8",
- "hl" => "ja", // changing this doesnt do anything
- //"lr" => "lang_ja", // same here
- "ls" => "", // ??
- "f" => ($get["nsfw"] == "yes" ? "off" : "on")
- ]
- );
-
- $out = [
- "status" => "ok",
- "npt" => null,
- "image" => []
- ];
-
- // check for errors and load the result div
- if($this->error_and_load($html)){
-
- return $out;
- }
-
- $images =
- $this->fuckhtml
- ->getElementsByTagName(
- "li"
- );
-
- foreach($images as $image){
-
- $this->fuckhtml->load($image);
-
- $img =
- $this->fuckhtml
- ->getElementsByTagName(
- "img"
- );
-
- if(count($img) === 0){
-
- // ?? invalid
- continue;
- }
-
- $img = $img[0];
-
- $size =
- explode(
- "x",
- $this->fuckhtml
- ->getTextContent(
- $image
- ),
- 2
- );
-
- $size = [
- (int)trim($size[0]), // width
- (int)trim($size[1]) // height
- ];
-
- $out["image"][] = [
- "title" => null,
- "source" => [
- [
- "url" =>
- "https://solofield.net/" .
- $this->fuckhtml
- ->getTextContent(
- $img["attributes"]["src"]
- ),
- "width" => $size[0],
- "height" => $size[1]
- ]
- ],
- "url" =>
- $this->fuckhtml
- ->getTextContent(
- $this->fuckhtml
- ->getElementsByTagName(
- "a"
- )[0]
- ["attributes"]
- ["href"]
- )
- ];
- }
-
- return $out;
- }
-
-
- public function video($get){
-
- if($get["npt"]){
-
- [$query, $proxy] = $this->backend->get($get["npt"], "videos");
-
- try{
-
- $html =
- $this->get(
- $proxy,
- "https://solofield.net/vsearch?" . $query,
- []
- );
- }catch(Exception $error){
-
- throw new Exception("Failed to fetch search page");
- }
- }else{
-
- $proxy = $this->backend->get_ip();
-
- try{
- $html =
- $this->get(
- $proxy,
- "https://solofield.net/vsearch",
- [
- "q" => $get["s"],
- "ie" => "UTF-8",
- "oe" => "UTF-8",
- "hl" => "ja", // changing this doesnt do anything
- //"lr" => "lang_ja", // same here
- "ls" => "", // ??
- "f" => ($get["nsfw"] == "yes" ? "off" : "on")
- ]
- );
- }catch(Exception $error){
-
- throw new Exception("Failed to fetch search page");
- }
- }
-
- $out = [
- "status" => "ok",
- "npt" => null,
- "video" => [],
- "author" => [],
- "livestream" => [],
- "playlist" => [],
- "reel" => []
- ];
-
- // check for errors and load the result div
- if($this->error_and_load($html)){
-
- return $out;
- }
-
- $items =
- $this->fuckhtml
- ->getElementsByTagName(
- "li"
- );
-
- foreach($items as $item){
-
- $this->fuckhtml->load($item);
-
- $as =
- $this->fuckhtml
- ->getElementsByTagName(
- "a"
- );
-
- if(count($as) === 0){
-
- continue;
- }
-
- $thumb =
- $this->fuckhtml
- ->getElementsByTagName(
- "img"
- );
-
- if(count($thumb) !== 0){
-
- $thumb = [
- "ratio" => "16:9",
- "url" =>
- "https://solofield.net/" .
- $thumb[0]
- ["attributes"]
- ["src"]
- ];
- }else{
-
- $thumb = [
- "ratio" => null,
- "url" => null
- ];
- }
-
- $date =
- $this->fuckhtml
- ->getElementsByAttributeValue(
- "style",
- "font-size: 10px;",
- "span"
- );
-
- if(count($date) !== 0){
-
- $date =
- $this->unfuckdate(
- $this->fuckhtml
- ->getTextContent(
- $date[0]
- )
- );
- }else{
-
- $date = null;
- }
-
- $center_td =
- $this->fuckhtml
- ->getElementsByAttributeValue(
- "align",
- "center",
- "td"
- );
-
- if(count($center_td) === 2){
-
- $duration =
- $this->fuckhtml
- ->getTextContent(
- $this->hms2int(
- $center_td[0]
- )
- );
- }else{
-
- $duration = null;
- }
-
- $out["video"][] = [
- "title" =>
- $this->fuckhtml
- ->getTextContent(
- $as[1]
- ),
- "description" => null,
- "author" => [
- "name" => null,
- "url" => null,
- "avatar" => null
- ],
- "date" => $date,
- "duration" => $duration,
- "views" => null,
- "thumb" => $thumb,
- "url" =>
- $this->fuckhtml
- ->getTextContent(
- $as[0]
- ["attributes"]
- ["href"]
- )
- ];
- }
-
- // get next page
- $this->get_npt($html, $proxy, $out, "videos");
-
- return $out;
- }
-
-
- private function get_npt($html, $proxy, &$out, $type){
-
- // get next page
- $this->fuckhtml->load($html);
-
- $pjs =
- $this->fuckhtml
- ->getElementById(
- "pjs"
- );
-
- if($pjs){
-
- $alnk =
- $this->fuckhtml
- ->getElementsByClassName(
- "alnk",
- "span"
- );
-
- foreach($alnk as $lnk){
-
- if(
- stripos(
- $this->fuckhtml
- ->getTextContent(
- $lnk
- ),
- "Next"
- ) !== false
- ){
-
- $this->fuckhtml->load($lnk);
-
- $out["npt"] =
- $this->backend->store(
- parse_url(
- $this->fuckhtml
- ->getElementsByTagName(
- "a"
- )[0]
- ["attributes"]
- ["href"],
- PHP_URL_QUERY
- ),
- $type,
- $proxy
- );
- }
- }
- }
- }
-
- private function error_and_load($html){
-
- if(strlen($html) === 0){
-
- throw new Exception("Solofield blocked the request IP");
- }
-
- $this->fuckhtml->load($html);
-
- $list =
- $this->fuckhtml
- ->getElementById(
- "list",
- "div"
- );
-
- if($list === false){
-
- $nosearch =
- $this->fuckhtml
- ->getElementById(
- "nosearch",
- "div"
- );
-
- if($nosearch){
-
- return true;
- }
-
- throw new Exception("Failed to grep search list");
- }
-
- $this->fuckhtml->load($list);
- return false;
- }
-
- private function unfuckdate($date){
-
- return
- strtotime(
- rtrim(
- preg_replace(
- '/[^0-9]+/',
- "-",
- explode(
- ":",
- $date,
- 2
- )[1]
- ),
- "-"
- )
- );
- }
-
- private function hms2int($time){
-
- $parts = explode(":", $time, 3);
- $time = 0;
-
- if(count($parts) === 3){
-
- // hours
- $time = $time + ((int)$parts[0] * 3600);
- array_shift($parts);
- }
-
- if(count($parts) === 2){
-
- // minutes
- $time = $time + ((int)$parts[0] * 60);
- array_shift($parts);
- }
-
- // seconds
- $time = $time + (int)$parts[0];
-
- return $time;
- }
- }
|