ftm.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. class ftm{
  3. public function __construct(){
  4. include "lib/nextpage.php";
  5. $this->nextpage = new nextpage("ftm");
  6. }
  7. public function getfilters($page){
  8. return [];
  9. }
  10. private function get($url, $search, $offset){
  11. $curlproc = curl_init();
  12. curl_setopt($curlproc, CURLOPT_URL, $url);
  13. $payload =
  14. json_encode(
  15. [
  16. "search" => $search,
  17. "offset" => $offset
  18. ]
  19. );
  20. curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
  21. curl_setopt($curlproc, CURLOPT_HTTPHEADER,
  22. ["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/110.0",
  23. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
  24. "Accept-Language: en-US,en;q=0.5",
  25. "Accept-Encoding: gzip",
  26. "Content-Length: " . strlen($payload),
  27. "Content-Type: application/json",
  28. "DNT: 1",
  29. "Connection: keep-alive",
  30. "Origin: https://findthatmeme.com",
  31. "Referer: https://findthatmeme.com/?search=" . urlencode($search),
  32. "Upgrade-Insecure-Requests: 1",
  33. "Sec-Fetch-Dest: document",
  34. "Sec-Fetch-Mode: navigate",
  35. "Sec-Fetch-Site: none",
  36. "Sec-Fetch-User: ?1",
  37. "X-Auth-Key: undefined",
  38. "X-CSRF-Validation-Header: true"]
  39. );
  40. curl_setopt($curlproc, CURLOPT_POST, true);
  41. curl_setopt($curlproc, CURLOPT_POSTFIELDS, $payload);
  42. curl_setopt($curlproc, CURLOPT_RETURNTRANSFER, true);
  43. curl_setopt($curlproc, CURLOPT_SSL_VERIFYHOST, 2);
  44. curl_setopt($curlproc, CURLOPT_SSL_VERIFYPEER, true);
  45. curl_setopt($curlproc, CURLOPT_CONNECTTIMEOUT, 30);
  46. curl_setopt($curlproc, CURLOPT_TIMEOUT, 30);
  47. $data = curl_exec($curlproc);
  48. if(curl_errno($curlproc)){
  49. throw new Exception(curl_error($curlproc));
  50. }
  51. curl_close($curlproc);
  52. return $data;
  53. }
  54. public function image($get){
  55. $search = $get["s"];
  56. $out = [
  57. "status" => "ok",
  58. "npt" => null,
  59. "image" => []
  60. ];
  61. if($get["npt"]){
  62. $count = (int)$this->nextpage->get($get["npt"], "images");
  63. }else{
  64. $count = 0;
  65. }
  66. try{
  67. $json =
  68. json_decode(
  69. $this->get(
  70. "https://findthatmeme.com/api/v1/search",
  71. $search,
  72. $count
  73. ),
  74. true
  75. );
  76. }catch(Exception $error){
  77. throw new Exception("Failed to fetch JSON");
  78. }
  79. if($json === null){
  80. throw new Exception("Failed to decode JSON");
  81. }
  82. foreach($json as $item){
  83. $count++;
  84. if($item["type"] == "VIDEO"){
  85. $thumb = "thumb/" . $item["thumbnail"];
  86. }else{
  87. $thumb = $item["image_path"];
  88. }
  89. $out["image"][] = [
  90. "title" => date("jS \of F Y @ g:ia", strtotime($item["created_at"])),
  91. "source" => [
  92. [
  93. "url" =>
  94. "https://findthatmeme.us-southeast-1.linodeobjects.com/" .
  95. $thumb,
  96. "width" => null,
  97. "height" => null
  98. ]
  99. ],
  100. "url" => $item["source_page_url"]
  101. ];
  102. }
  103. if($count === 50){
  104. $out["npt"] =
  105. $this->nextpage->store(
  106. $count,
  107. "images"
  108. );
  109. }
  110. return $out;
  111. }
  112. }