coccoc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <?php
  2. class coccoc{
  3. public function __construct(){
  4. include "lib/backend.php";
  5. $this->backend = new backend("coccoc");
  6. include "lib/fuckhtml.php";
  7. $this->fuckhtml = new fuckhtml();
  8. $this->proc = curl_multi_init();
  9. $this->handles = [];
  10. }
  11. private function get($proxy, $url, $cookie = false, $get = []){
  12. $curlproc = curl_init();
  13. if($get !== []){
  14. $get = http_build_query($get);
  15. $url .= "?" . $get;
  16. }
  17. curl_setopt($curlproc, CURLOPT_URL, $url);
  18. // http2 bypass
  19. curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
  20. if($cookie === false){
  21. curl_setopt($curlproc, CURLOPT_HTTPHEADER, [
  22. "User-Agent: " . config::USER_AGENT,
  23. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  24. "Accept-Language: en-CA,en-US;q=0.9,en;q=0.8",
  25. "Accept-Encoding: gzip, deflate, br, zstd",
  26. "DNT: 1",
  27. "Sec-GPC: 1",
  28. "Connection: keep-alive",
  29. "Upgrade-Insecure-Requests: 1",
  30. "Sec-Fetch-Dest: document",
  31. "Sec-Fetch-Mode: navigate",
  32. "Sec-Fetch-Site: none",
  33. "Sec-Fetch-User: ?1",
  34. "Priority: u=0, i"
  35. ]);
  36. }else{
  37. curl_setopt($curlproc, CURLOPT_HTTPHEADER, [
  38. "User-Agent: " . config::USER_AGENT,
  39. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  40. "Accept-Language: en-CA,en-US;q=0.9,en;q=0.8",
  41. "Accept-Encoding: gzip, deflate, br, zstd",
  42. "DNT: 1",
  43. "Sec-GPC: 1",
  44. "Connection: keep-alive",
  45. "Referer: https://coccoc.com/search",
  46. "Cookie: {$cookie}",
  47. "Upgrade-Insecure-Requests: 1",
  48. "Sec-Fetch-Dest: document",
  49. "Sec-Fetch-Mode: navigate",
  50. "Sec-Fetch-Site: same-origin",
  51. "Priority: u=0, i",
  52. "TE: trailers"
  53. ]);
  54. }
  55. $this->backend->assign_proxy($curlproc, $proxy);
  56. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  57. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  58. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  59. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  60. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  61. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  62. $data = curl_exec($curlproc);
  63. if(curl_errno($curlproc)){
  64. throw new Exception(curl_error($curlproc));
  65. }
  66. curl_close($curlproc);
  67. return $data;
  68. }
  69. public function getfilters($pagetype){
  70. return [
  71. "nsfw" => [
  72. "display" => "NSFW",
  73. "option" => [
  74. "yes" => "Yes", // nsfw by default????
  75. "no" => "No" // &safe=1
  76. ]
  77. ],
  78. "time" => [
  79. "display" => "Time posted",
  80. "option" => [
  81. "any" => "Any time",
  82. "1w" => "1 week ago",
  83. "2w" => "2 weeks ago",
  84. "1m" => "1 month ago",
  85. "3m" => "3 months ago",
  86. "6m" => "6 months ago",
  87. "1Y" => "1 year ago"
  88. ]
  89. ],
  90. "filter" => [
  91. "display" => "Remove duplicates",
  92. "option" => [
  93. "no" => "No",
  94. "yes" => "Yes" // &filter=0
  95. ]
  96. ]
  97. ];
  98. }
  99. private function handle_redir($proxy, $html){
  100. $this->fuckhtml->load($html);
  101. $title =
  102. $this->fuckhtml
  103. ->getElementsByTagName("title");
  104. if(
  105. count($title) !== 0 &&
  106. $this->fuckhtml
  107. ->getTextContent(
  108. $title[0]
  109. ) == "Redirecting..."
  110. ){
  111. // get cookie
  112. if(
  113. preg_match(
  114. '/document\.cookie ?= ?"([^;"]+).*"/',
  115. $html,
  116. $cookie
  117. ) === 0
  118. ){
  119. throw new Exception("Failed to grep cookie");
  120. }
  121. // get redirect URL
  122. if(
  123. preg_match(
  124. '/window\.location\.replace\("([^"]+)"\)/',
  125. $html,
  126. $redir
  127. ) === 0
  128. ){
  129. throw new Exception("Failed to grep redirection URL");
  130. }
  131. try{
  132. $html =
  133. $this->get(
  134. $proxy,
  135. $redir[1],
  136. $cookie[1],
  137. []
  138. );
  139. }catch(Exception $error){
  140. throw new Exception("Failed to get redirection page");
  141. }
  142. }
  143. return $html;
  144. }
  145. private function redirect_add_url($url){
  146. // https://coccoc.com/composer/goto?url=0AWtXcuK-mJVvFl8Qhny9LZdMOyEd08nFmTtpg82bmuqtp8p8G_OnTebNhPtNyIXMGQ1TZZ-ADMz0QEiFJhsTLIFkkPDXnJjHo3kqsobmyntiOhFag-2aqTs
  147. if(
  148. preg_match(
  149. '/\/goto\?url=([^&]+)/',
  150. $url,
  151. $slug
  152. ) === 0
  153. ){
  154. // not a coccoc redirect
  155. return $url;
  156. }
  157. $curlproc = curl_init();
  158. curl_setopt($curlproc, CURLOPT_URL, "https://coccoc.com/composer/goto?url=" . urlencode($slug[1]));
  159. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  160. curl_setopt($curlproc, CURLOPT_HTTPHEADER,
  161. ["User-Agent: " . config::USER_AGENT,
  162. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  163. "Accept-Language: en-US,en;q=0.5",
  164. "Accept-Encoding: gzip, deflate, br, zstd",
  165. "DNT: 1",
  166. "Sec-GPC: 1",
  167. "Connection: keep-alive",
  168. "Upgrade-Insecure-Requests: 1",
  169. "Sec-Fetch-Dest: document",
  170. "Sec-Fetch-Mode: navigate",
  171. "Sec-Fetch-Site: none",
  172. "Sec-Fetch-User: ?1",
  173. "Priority: u=0, i"]
  174. );
  175. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  176. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  177. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  178. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  179. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  180. // funny
  181. curl_setopt($curlproc, CURLOPT_HEADER, true);
  182. //$this->backend->assign_proxy($curlproc, $proxy);
  183. curl_multi_add_handle($this->proc, $curlproc);
  184. $this->handles[] = [
  185. "replacement" => $url,
  186. "handle" => $curlproc
  187. ];
  188. return $url;
  189. }
  190. private function resolve_urls(&$scraped_data){
  191. do{
  192. do{
  193. $status = curl_multi_exec($this->proc, $active);
  194. }while($status === CURLM_CALL_MULTI_PERFORM);
  195. if($active){
  196. curl_multi_select($this->proc);
  197. }
  198. }while($active && $status === CURLM_OK);
  199. //
  200. // if we reach this, we're done downloading garbage
  201. //
  202. // parse redirect values & create data shit
  203. $keys = [];
  204. $replacements = [];
  205. for($i=0; $i<count($this->handles); $i++){
  206. $headers =
  207. curl_multi_getcontent(
  208. $this->handles[$i]["handle"]
  209. );
  210. if(
  211. !preg_match(
  212. '/^location: ?([^ ]+)/im',
  213. $headers,
  214. $link
  215. )
  216. ){
  217. // failed to extract redirect location
  218. continue;
  219. }
  220. // theyre too retarded to encode shit properly apparently.
  221. // this is the best i can do, it will still yield errors when searching for "higurashi"
  222. // example: https://coccoc.com/composer/goto?url=0AWtXcuIKWPOkxvarGvy3GJ36XipRirzzqAvltMM5QUfB1RPu49LrNB9qmuAQyvvI0eCTwf-FpjRjxUN8XbruhA0rvCHNNlhVNEozMUqgRcjzsdhyUMCEgwLCXVTQkXnLXqrUw8celcIZdfmZ1geOvioUcg
  223. // redirects to https://vi.wikipedia.org/wiki/Higurashi_no_Naku_Koro_ni#C%E1ch_ch?i
  224. // notice the encoding errors after #
  225. // retards
  226. $link = mb_convert_encoding($link[1], "UTF-8", "ISO-8859-1");
  227. if(
  228. preg_match(
  229. '/^(https?:|)\/\//',
  230. $link
  231. )
  232. ){
  233. $keys[] = $this->handles[$i]["replacement"];
  234. $replacements[] = $link;
  235. }
  236. }
  237. $this->recursive_replace($keys, $replacements, $scraped_data);
  238. curl_multi_close($this->proc);
  239. }
  240. private function recursive_replace(&$keys, &$replacements, &$pointer){
  241. foreach($pointer as $key => &$value){
  242. if($key == "url"){
  243. $search =
  244. array_search(
  245. $value,
  246. $keys
  247. );
  248. if($search !== false){
  249. // replace url
  250. $value = $replacements[$search];
  251. }
  252. }elseif(is_array($value)){
  253. $this->recursive_replace($keys, $replacements, $value);
  254. }
  255. }
  256. }
  257. public function web($get){
  258. if($get["npt"]){
  259. [$query, $proxy] =
  260. $this->backend->get(
  261. $get["npt"],
  262. "web"
  263. );
  264. $query = json_decode($query, true);
  265. }else{
  266. $proxy = $this->backend->get_ip();
  267. $query = [
  268. "query" => $get["s"]
  269. ];
  270. // add filters
  271. if($get["nsfw"] == "no"){
  272. $query["safe"] = 1;
  273. }
  274. if($get["time"] != "any"){
  275. $query["tbs"] = $get["time"];
  276. }
  277. if($get["filter"] == "yes"){
  278. $query["filter"] = 0;
  279. }
  280. }
  281. try{
  282. $html =
  283. $this->get(
  284. $proxy,
  285. "https://coccoc.com/search",
  286. false,
  287. $query
  288. );
  289. }catch(Exception $error){
  290. throw new Exception("Failed to get search page");
  291. }
  292. //$html = file_get_contents("scraper/coccoc.html");
  293. $html = $this->handle_redir($proxy, $html);
  294. $html = explode("window.composerResponse", $html, 2);
  295. if(count($html) !== 2){
  296. throw new Exception("Failed to grep window.composerResponse");
  297. }
  298. $html =
  299. json_decode(
  300. $this->fuckhtml
  301. ->extract_json(
  302. ltrim($html[1], " =")
  303. ),
  304. true
  305. );
  306. if($html === null){
  307. throw new Exception("Failed to decode JSON");
  308. }
  309. if(
  310. isset($html["captcha"]) &&
  311. (int)$html["captcha"] === 1
  312. ){
  313. throw new Exception("Coc Coc returned a Captcha");
  314. }
  315. if(!isset($html["search"]["search_results"])){
  316. throw new Exception("Coc Coc did not return a search_results object");
  317. }
  318. $out = [
  319. "status" => "ok",
  320. "spelling" => [
  321. "type" => "no_correction",
  322. "using" => null,
  323. "correction" => null
  324. ],
  325. "npt" => null,
  326. "answer" => [],
  327. "web" => [],
  328. "image" => [],
  329. "video" => [],
  330. "news" => [],
  331. "related" => []
  332. ];
  333. // word correction
  334. foreach($html["top"] as $element){
  335. if(isset($element["spellChecker"][0]["query"])){
  336. $out["spelling"] = [
  337. "type" => "not_many",
  338. "using" => $html["search"]["query"],
  339. "correction" => $element["spellChecker"][0]["query"]
  340. ];
  341. }
  342. }
  343. foreach($html["search"]["search_results"] as $result){
  344. if(isset($result["type"])){
  345. switch($result["type"]){
  346. //
  347. // Related searches
  348. //
  349. case "related_queries":
  350. $out["related"] = $result["queries"];
  351. continue 2;
  352. //
  353. // Videos
  354. //
  355. case "video_hits":
  356. foreach($result["results"] as $video){
  357. if(
  358. isset($video["image_url"]) &&
  359. !empty($video["image_url"])
  360. ){
  361. $thumb = [
  362. "ratio" => "16:9",
  363. "url" => $video["image_url"]
  364. ];
  365. }else{
  366. $thumb = [
  367. "ratio" => null,
  368. "url" => null
  369. ];
  370. }
  371. $out["video"][] = [
  372. "title" =>
  373. $this->titledots(
  374. $this->fuckhtml
  375. ->getTextContent(
  376. $video["title"]
  377. )
  378. ),
  379. "description" => null,
  380. "author" => [
  381. "name" => $video["uploader"],
  382. "url" => null,
  383. "avatar" => null
  384. ],
  385. "date" => (int)$video["date"],
  386. "duration" => (int)$video["duration"],
  387. "views" => null,
  388. "thumb" => $thumb,
  389. "url" => $video["url"]
  390. ];
  391. }
  392. continue 2;
  393. }
  394. }
  395. if(
  396. !isset($result["title"]) ||
  397. !isset($result["url"])
  398. ){
  399. // should not happen
  400. continue;
  401. }
  402. if(isset($result["rich"]["data"]["image_url"])){
  403. $thumb = [
  404. "url" => $result["rich"]["data"]["image_url"],
  405. "ratio" => "16:9"
  406. ];
  407. }else{
  408. $thumb = [
  409. "url" => null,
  410. "ratio" => null
  411. ];
  412. }
  413. $sublinks = [];
  414. if(isset($result["rich"]["data"]["linked_docs"])){
  415. foreach($result["rich"]["data"]["linked_docs"] as $sub){
  416. $sublinks[] = [
  417. "title" =>
  418. $this->titledots(
  419. $this->fuckhtml
  420. ->getTextContent(
  421. $sub["title"]
  422. )
  423. ),
  424. "description" =>
  425. $this->titledots(
  426. $this->fuckhtml
  427. ->getTextContent(
  428. $sub["content"]
  429. )
  430. ),
  431. "date" => null,
  432. "url" => $this->redirect_add_url($sub["url"])
  433. ];
  434. }
  435. }
  436. // get date
  437. if(isset($result["date"])){
  438. $date = (int)$result["date"];
  439. }else{
  440. $date = null;
  441. }
  442. // probe for metadata
  443. $table = [];
  444. if(isset($result["rich"]["data"]["rating"])){
  445. $table["Rating"] = $result["rich"]["data"]["rating"];
  446. if(isset($result["rich"]["data"]["num_rating"])){
  447. $table["Rating"] .= " (" . number_format($result["rich"]["data"]["num_rating"]) . " ratings)";
  448. }
  449. }
  450. if(isset($result["rich"]["data"]["views"])){
  451. $table["Views"] = number_format($result["rich"]["data"]["views"]);
  452. }
  453. if(isset($result["rich"]["data"]["duration"])){
  454. $table["Duration"] = $this->int2hms($result["rich"]["data"]["duration"]);
  455. }
  456. if(isset($result["rich"]["data"]["channel_name"])){
  457. $table["Author"] = $result["rich"]["data"]["channel_name"];
  458. }
  459. if(isset($result["rich"]["data"]["video_quality"])){
  460. $table["Quality"] = $result["rich"]["data"]["video_quality"];
  461. }
  462. if(isset($result["rich"]["data"]["category"])){
  463. $table["Category"] = $result["rich"]["data"]["category"];
  464. }
  465. $out["web"][] = [
  466. "title" =>
  467. $this->titledots(
  468. $this->fuckhtml
  469. ->getTextContent(
  470. $result["title"]
  471. )
  472. ),
  473. "description" =>
  474. $this->titledots(
  475. $this->fuckhtml
  476. ->getTextContent(
  477. $result["content"]
  478. )
  479. ),
  480. "url" => $this->redirect_add_url($result["url"]),
  481. "date" => $date,
  482. "type" => "web",
  483. "thumb" => $thumb,
  484. "sublink" => $sublinks,
  485. "table" => $table
  486. ];
  487. }
  488. //
  489. // Get wikipedia head
  490. //
  491. if(isset($html["right"])){
  492. foreach($html["right"] as $wiki){
  493. $description = [];
  494. if(isset($wiki["short_intro"])){
  495. $description[] =
  496. [
  497. "type" => "quote",
  498. "value" => $wiki["short_intro"],
  499. ];
  500. }
  501. if(isset($wiki["intro"])){
  502. $description[] =
  503. [
  504. "type" => "text",
  505. "value" => $wiki["intro"],
  506. ];
  507. }
  508. // get table elements
  509. $table = [];
  510. if(isset($wiki["fields"])){
  511. foreach($wiki["fields"] as $element){
  512. $table[$element["title"]] = implode(", ", $element["value"]);
  513. }
  514. }
  515. // get sublinks
  516. $sublinks = [];
  517. if(isset($wiki["website"])){
  518. if(
  519. preg_match(
  520. '/^http/',
  521. $wiki["website"]
  522. ) === 0
  523. ){
  524. $sublinks["Website"] = "https://" . $wiki["website"];
  525. }else{
  526. $sublinks["Website"] = $wiki["website"];
  527. }
  528. }
  529. if(isset($wiki["profiles"])){
  530. foreach($wiki["profiles"] as $sitename => $url){
  531. $sitename = explode("_", $sitename);
  532. $sitename = ucfirst($sitename[count($sitename) - 1]);
  533. $sublinks[$sitename] = $url;
  534. }
  535. }
  536. $out["answer"][] = [
  537. "title" =>
  538. isset($wiki["title"]) ?
  539. $this->titledots(
  540. $wiki["title"]
  541. ) : null,
  542. "description" => $description,
  543. "url" => null,
  544. "thumb" => isset($wiki["image"]["contentUrl"]) ? $wiki["image"]["contentUrl"] : null,
  545. "table" => $table,
  546. "sublink" => $sublinks
  547. ];
  548. }
  549. }
  550. // get next page
  551. if((int)$html["search"]["page"] < (int)$html["search"]["max_page"]){
  552. // https://coccoc.com/composer?_=1754021153532&p=0&q=zbabduiqwhduwqhdnwq&reqid=bwcAs00q&s=direct&apiV=1
  553. // ^json endpoint, but we can just do &page=2 lol
  554. if(!isset($query["page"])){
  555. $query["page"] = 2;
  556. }else{
  557. $query["page"]++;
  558. }
  559. $out["npt"] =
  560. $this->backend
  561. ->store(
  562. json_encode($query),
  563. "web",
  564. $proxy
  565. );
  566. }
  567. $this->resolve_urls($out);
  568. return $out;
  569. }
  570. public function video($get){
  571. //$html = file_get_contents("scraper/coccoc.html");
  572. if($get["npt"]){
  573. [$query, $proxy] =
  574. $this->backend->get(
  575. $get["npt"],
  576. "videos"
  577. );
  578. $query = json_decode($query, true);
  579. }else{
  580. $proxy = $this->backend->get_ip();
  581. $query = [
  582. "query" => $get["s"],
  583. "tbm" => "vid"
  584. ];
  585. // add filters
  586. if($get["nsfw"] == "no"){
  587. $query["safe"] = 1;
  588. }
  589. if($get["time"] != "any"){
  590. $query["tbs"] = $get["time"];
  591. }
  592. if($get["filter"] == "yes"){
  593. $query["filter"] = 0;
  594. }
  595. }
  596. try{
  597. $html =
  598. $this->get(
  599. $proxy,
  600. "https://coccoc.com/search",
  601. false,
  602. $query
  603. );
  604. }catch(Exception $error){
  605. throw new Exception("Failed to get search page");
  606. }
  607. $html = $this->handle_redir($proxy, $html);
  608. $html = explode("window.composerResponse", $html, 2);
  609. if(count($html) !== 2){
  610. throw new Exception("Failed to grep window.composerResponse");
  611. }
  612. $html =
  613. json_decode(
  614. $this->fuckhtml
  615. ->extract_json(
  616. ltrim($html[1], " =")
  617. ),
  618. true
  619. );
  620. if($html === null){
  621. throw new Exception("Failed to decode JSON");
  622. }
  623. $out = [
  624. "status" => "ok",
  625. "npt" => null,
  626. "video" => [],
  627. "author" => [],
  628. "livestream" => [],
  629. "playlist" => [],
  630. "reel" => []
  631. ];
  632. if(!isset($html["search_video"]["search_results"])){
  633. if(isset($html["search_video"]["error"]["title"])){
  634. if($html["search_video"]["error"]["title"] == "Không tìm thấy kết quả nào"){
  635. return $out;
  636. }
  637. throw new Exception("Coc Coc returned an error: " . $html["search_video"]["error"]["title"]);
  638. }
  639. throw new Exception("Coc Coc did not supply a search_results object");
  640. }
  641. foreach($html["search_video"]["search_results"] as $video){
  642. if(isset($video["rich"]["data"]["image_url"])){
  643. $thumb = [
  644. "ratio" => "16:9",
  645. "url" => $video["rich"]["data"]["image_url"]
  646. ];
  647. }else{
  648. $thumb = [
  649. "ratio" => null,
  650. "url" => null
  651. ];
  652. }
  653. $out["video"][] = [
  654. "title" =>
  655. $this->titledots(
  656. $this->fuckhtml
  657. ->getTextContent(
  658. $video["title"]
  659. )
  660. ),
  661. "description" =>
  662. $this->titledots(
  663. $this->fuckhtml
  664. ->getTextContent(
  665. $video["content"]
  666. )
  667. ),
  668. "author" => [
  669. "name" =>
  670. isset($video["rich"]["data"]["channel_name"]) ?
  671. $video["rich"]["data"]["channel_name"] : null,
  672. "url" => null,
  673. "avatar" => null
  674. ],
  675. "date" =>
  676. isset($video["date"]) ?
  677. $video["date"] : null,
  678. "duration" =>
  679. isset($video["rich"]["data"]["duration"]) ?
  680. (int)$video["rich"]["data"]["duration"] : null,
  681. "views" => null,
  682. "thumb" => $thumb,
  683. "url" => $this->redirect_add_url($video["url"])
  684. ];
  685. }
  686. // get next page
  687. if((int)$html["search_video"]["page"] < (int)$html["search_video"]["max_page"]){
  688. if(!isset($query["page"])){
  689. $query["page"] = 2;
  690. }else{
  691. $query["page"]++;
  692. }
  693. $out["npt"] =
  694. $this->backend
  695. ->store(
  696. json_encode($query),
  697. "videos",
  698. $proxy
  699. );
  700. }
  701. $this->resolve_urls($out);
  702. return $out;
  703. }
  704. private function titledots($title){
  705. return trim($title, " .\t\n\r\0\x0B…");
  706. }
  707. private function int2hms($seconds){
  708. $hours = floor($seconds / 3600);
  709. $minutes = floor(($seconds % 3600) / 60);
  710. $seconds = $seconds % 60;
  711. return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
  712. }
  713. }