53
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,53 @@
 | 
				
			||||||
 | 
					# 4Get Search
 | 
				
			||||||
 | 
					**4Get** is a proxy search engine that doesn't suck.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## About 4Get
 | 
				
			||||||
 | 
					https://4g.flossboxin.org.in/about
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Totally unbiased comparison between alternatives
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					|                            | 4Get                    | searx(ng) | FbIN-LibreY | araa      | hearch.co         |
 | 
				
			||||||
 | 
					|----------------------------|-------------------------|-----------|-------------|-----------|-------------------|
 | 
				
			||||||
 | 
					| RAM usage                  | 200-400mb~              | 2GB~      | 200-400mb~  | 2GB~      | idk               |
 | 
				
			||||||
 | 
					| Does it suck               | no (debunked by snopes) | yes       | yes         | a little  | better than searx |
 | 
				
			||||||
 | 
					| Does it work               | ye                      | sometimes | sometimes   | sometimes | yes               |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Features
 | 
				
			||||||
 | 
					1. Rotating proxies on a per-scraper basis
 | 
				
			||||||
 | 
					2. Search filters, which SearxNG lacks for the most part
 | 
				
			||||||
 | 
					3. Bot protection that *actually* filters out the bots (when configured)
 | 
				
			||||||
 | 
					4. Interface doesn't require javascript
 | 
				
			||||||
 | 
					5. Favicon fetcher with caching support & image proxy
 | 
				
			||||||
 | 
					6. Bunch of other shits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tl;dr 4Get is the best way to browse for shit.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Supported websites
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Web        | Images       | Videos     | News       | Music      | Autocompleter |
 | 
				
			||||||
 | 
					|------------|--------------|------------|------------|------------|---------------|
 | 
				
			||||||
 | 
					| DuckDuckGo | DuckDuckGo   | YouTube    | DuckDuckGo | Soundcloud | Brave         |
 | 
				
			||||||
 | 
					| Brave      | Brave        | DuckDuckGo | Brave      |            | DuckDuckGo    |
 | 
				
			||||||
 | 
					| Yandex     | Yandex       | Brave      | Google     |            | Yandex        |
 | 
				
			||||||
 | 
					| Google     | Google       | Yandex     | Startpage  |            | Google        |
 | 
				
			||||||
 | 
					| Startpage  | Startpage    | Google     | Qwant      |            | Startpage     |
 | 
				
			||||||
 | 
					| Qwant      | Qwant        | Startpage  | Mojeek     |            | Kagi          |
 | 
				
			||||||
 | 
					| Ghostery   | Yep          | Qwant      |            |            | Qwant         |
 | 
				
			||||||
 | 
					| Yep        | Solofield    | Solofield  |            |            | Ghostery      |
 | 
				
			||||||
 | 
					| Greppr     | Pinterest    |            |            |            | Yep           |
 | 
				
			||||||
 | 
					| Crowdview  | 500px        |            |            |            | Marginalia    |
 | 
				
			||||||
 | 
					| Mwmbl      | VSCO         |            |            |            | YouTube       |
 | 
				
			||||||
 | 
					| Mojeek     | Imgur        |            |            |            | Soundcloud    |
 | 
				
			||||||
 | 
					| Solofield  | FindThatMeme |            |            |            |               |
 | 
				
			||||||
 | 
					| Marginalia |              |            |            |            |               |
 | 
				
			||||||
 | 
					| wiby       |              |            |            |            |               |
 | 
				
			||||||
 | 
					| Curlie     |              |            |            |            |               |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Installation
 | 
				
			||||||
 | 
					Refer to the <a href="https://git.flossboxin.org.in/FbIN/4Get/src/branch/main/docs/">documentation index</a>. I recommend following the <a href="https://git.flossboxin.org.in/FbIN/4Get/src/branch/main/docs/apache2.md">apache2 guide</a>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Contact
 | 
				
			||||||
 | 
					Shit breaks all the time but I repair it all the time too. Email me here: <b>dev(at)flossboxin(dot)org(dot)in</b> or create an issue.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## License
 | 
				
			||||||
 | 
					AGPL
 | 
				
			||||||
							
								
								
									
										39
									
								
								about.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						$frontend->load(
 | 
				
			||||||
 | 
							"header_nofilters.html",
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"title" => "About",
 | 
				
			||||||
 | 
								"class" => " class=\"about\""
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$left =
 | 
				
			||||||
 | 
						explode(
 | 
				
			||||||
 | 
							"\n",
 | 
				
			||||||
 | 
							file_get_contents("template/about.html")
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$out = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					foreach($left as $line){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$out .= trim($line);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						$frontend->load(
 | 
				
			||||||
 | 
							"search.html",
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"timetaken" => null,
 | 
				
			||||||
 | 
								"class" => "",
 | 
				
			||||||
 | 
								"right-left" => "",
 | 
				
			||||||
 | 
								"right-right" => "",
 | 
				
			||||||
 | 
								"left" => $out
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
							
								
								
									
										27
									
								
								ami4get.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,27 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					header("Access-Control-Allow-Origin: *");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$real_requests = apcu_fetch("real_requests");
 | 
				
			||||||
 | 
					$bot_requests = apcu_fetch("captcha_gen");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo json_encode(
 | 
				
			||||||
 | 
						[
 | 
				
			||||||
 | 
							"status" => "ok",
 | 
				
			||||||
 | 
							"service" => "4get",
 | 
				
			||||||
 | 
							"server" => [
 | 
				
			||||||
 | 
								"name" => config::SERVER_NAME,
 | 
				
			||||||
 | 
								"description" => config::SERVER_LONG_DESCRIPTION,
 | 
				
			||||||
 | 
								"bot_protection" => config::BOT_PROTECTION,
 | 
				
			||||||
 | 
								"real_requests" => $real_requests === false ? 0 : $real_requests,
 | 
				
			||||||
 | 
								"bot_requests" => $bot_requests === false ? 0 : $bot_requests,
 | 
				
			||||||
 | 
								"api_enabled" => config::API_ENABLED,
 | 
				
			||||||
 | 
								"alt_addresses" => config::ALT_ADDRESSES,
 | 
				
			||||||
 | 
								"version" => config::VERSION
 | 
				
			||||||
 | 
							],
 | 
				
			||||||
 | 
							"instances" => config::INSTANCES
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
							
								
								
									
										357
									
								
								api.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,357 @@
 | 
				
			||||||
 | 
					                   44
 | 
				
			||||||
 | 
					                 4444444      44   
 | 
				
			||||||
 | 
					                 44444444   44444       444
 | 
				
			||||||
 | 
					                 44444444  444444    444444444
 | 
				
			||||||
 | 
					                  44444   44444444  444444444
 | 
				
			||||||
 | 
					                         444444444   4444444
 | 
				
			||||||
 | 
					                        4444444444    444444
 | 
				
			||||||
 | 
					                      4444444444444
 | 
				
			||||||
 | 
					                    444444444444444444
 | 
				
			||||||
 | 
					                       444444444444444
 | 
				
			||||||
 | 
					                          44444444
 | 
				
			||||||
 | 
					                          4444
 | 
				
			||||||
 | 
					                           44
 | 
				
			||||||
 | 
					                 
 | 
				
			||||||
 | 
					           + Welcome to the 4Get API documentation +
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Terms of use
 | 
				
			||||||
 | 
					    Do NOT misuse the API. Misuses can include... ::
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					        1. Serp SEO scanning
 | 
				
			||||||
 | 
					        2. Intensive scraping
 | 
				
			||||||
 | 
					        3. Any other activity that isn't triggered by a human
 | 
				
			||||||
 | 
					        4. Illegal activities in Canada
 | 
				
			||||||
 | 
					        5. Constant "test" queries while developping your program
 | 
				
			||||||
 | 
					           (please cache the API responses!)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Examples of good uses of the API ::
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        1. A chatroom bot that presents users with search results
 | 
				
			||||||
 | 
					        2. Personal use
 | 
				
			||||||
 | 
					        3. Any other activity that is initiated by a human
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If you wish to engage in the activities listed under "misuses", feel
 | 
				
			||||||
 | 
					    free to download the source code of the project and running 4get
 | 
				
			||||||
 | 
					    under your own terms. Please respect the terms of use listed here so
 | 
				
			||||||
 | 
					    that this website may be available to all in the far future.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    P.s fuck whoever botted my site for months on end, choke on my dick
 | 
				
			||||||
 | 
					    lol!!!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Get your instance running here ::
 | 
				
			||||||
 | 
					        https://git.flossboxin.org.in/FbIN/4get
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Thanks!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Passes
 | 
				
			||||||
 | 
					    Depending of the instance, you may need to provide a "pass" token
 | 
				
			||||||
 | 
					    in the cookies of your request. These can be obtained from solving
 | 
				
			||||||
 | 
					    a captcha which will allow you to make 100 requests in the next 24
 | 
				
			||||||
 | 
					    hours. In the future, you will be able to ask the serber maintainer
 | 
				
			||||||
 | 
					    for a "pass" which will allow you to bypass the captcha requirement.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The captcha doesn't need javascript to work.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Decode the data
 | 
				
			||||||
 | 
					    All payloads returned by the API are encoded in the JSON format. If
 | 
				
			||||||
 | 
					    you don't know how to tackle the problem, maybe programming is not
 | 
				
			||||||
 | 
					    for you.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    All of the endpoints use the GET method.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Check if an API call was successful
 | 
				
			||||||
 | 
					    All API responses come with an array index named "status". If the
 | 
				
			||||||
 | 
					    status is something else than the string "ok", something went wrong.
 | 
				
			||||||
 | 
					    You can supply the content of the "status" string back to your
 | 
				
			||||||
 | 
					    application to inform the user of what went wrong.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The HTTP code will be 429 if your pass is invalid. It is set to 200
 | 
				
			||||||
 | 
					    otherwise.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Get the next page of results
 | 
				
			||||||
 | 
					    All API responses come with an array index named "npt". To get the
 | 
				
			||||||
 | 
					    next page of results, you must make another API call with &npt.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Example ::
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        + First API call
 | 
				
			||||||
 | 
					            /api/v1/web?s=higurashi
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        + Second API call
 | 
				
			||||||
 | 
					            /api/v1/web?npt=ddg1._rJ2hWmYSjpI2hsXWmYajJx < ... >
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    You shouldn't specify the search term, only the &npt parameter
 | 
				
			||||||
 | 
					    suffices.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The first part of the token before the dot (ddg1) refers to an
 | 
				
			||||||
 | 
					    array position on the serber's memory. The second part is an
 | 
				
			||||||
 | 
					    encryption key used to decode the data at that position. This way,
 | 
				
			||||||
 | 
					    it is impossible to supply invalid pagination data and it is
 | 
				
			||||||
 | 
					    impossible for a 4get operator to peek at the private data of the
 | 
				
			||||||
 | 
					    user after a request has been made.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The tokens will expire as soon as they are used or after a 15
 | 
				
			||||||
 | 
					    minutes inactivity period, whichever comes first.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Beware of null values!
 | 
				
			||||||
 | 
					    Most fields in the API responses can return "null". You don't need
 | 
				
			||||||
 | 
					    to worry about unset values.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ API Parameters
 | 
				
			||||||
 | 
					    To construct a valid request, you can use the 4get web interface
 | 
				
			||||||
 | 
					    to craft a valid request, and replace "/web" with "/api/v1/web".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ "date" and "time" parameters
 | 
				
			||||||
 | 
					    "date" always refer to a calendar date.
 | 
				
			||||||
 | 
					    "time" always refer to the duration of some media.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    They are both integers that uses seconds as its unit. The "date"
 | 
				
			||||||
 | 
					    parameter specifies the number of seconds that passed since January
 | 
				
			||||||
 | 
					    1st 1970. 
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					             ______          __            _       __      
 | 
				
			||||||
 | 
					            / ____/___  ____/ /___  ____  (_)___  / /______
 | 
				
			||||||
 | 
					           / __/ / __ \/ __  / __ \/ __ \/ / __ \/ __/ ___/
 | 
				
			||||||
 | 
					          / /___/ / / / /_/ / /_/ / /_/ / / / / / /_(__  ) 
 | 
				
			||||||
 | 
					         /_____/_/ /_/\__,_/ .___/\____/_/_/ /_/\__/____/  
 | 
				
			||||||
 | 
					                          /_/                              
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /ami4get
 | 
				
			||||||
 | 
					    Tells you basic information about the 4get instance. CORS requests
 | 
				
			||||||
 | 
					    are allowed on this endpoint.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /api/v1/web
 | 
				
			||||||
 | 
					    + &extendedsearch
 | 
				
			||||||
 | 
					        When using the ddg(DuckDuckGo) scraper, you may make use of the
 | 
				
			||||||
 | 
					        &extendedsearch parameter. If you need rich answer data from
 | 
				
			||||||
 | 
					        additional sources like StackOverflow, music lyrics sites, etc.,
 | 
				
			||||||
 | 
					        you need to specify the value of (string)"true".
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        The default value is "false" for API calls.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    + Parse the "spelling"
 | 
				
			||||||
 | 
					        The array index named "spelling" contains 3 indexes ::
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            spelling:
 | 
				
			||||||
 | 
					                type:         "including"
 | 
				
			||||||
 | 
					                using:        "4chan"
 | 
				
			||||||
 | 
					                correction:   '"4cha"'
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        The "type" may be any of these 3 values. When rendering the
 | 
				
			||||||
 | 
					        autocorrect text inside your application, it should look like
 | 
				
			||||||
 | 
					        what follows right after the parameter value ::
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            no_correction    <Empty>
 | 
				
			||||||
 | 
					            including        Including results for %using%. Did you mean
 | 
				
			||||||
 | 
					                             %correction%?
 | 
				
			||||||
 | 
					                            
 | 
				
			||||||
 | 
					            not_many         Not many results for %using%. Did you mean
 | 
				
			||||||
 | 
					                             %correction%?
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        As of right now, the "spelling" is only available on
 | 
				
			||||||
 | 
					        "/api/v1/web".
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    + Parse the "answer"
 | 
				
			||||||
 | 
					        The array index named "answer" may contain a list of multiple
 | 
				
			||||||
 | 
					        answers. The array index "description" contains a linear list of
 | 
				
			||||||
 | 
					        nodes that can help you construct rich formatted data inside of
 | 
				
			||||||
 | 
					        your application. The structure is similar to the one below:
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        answer:
 | 
				
			||||||
 | 
					            0:
 | 
				
			||||||
 | 
					                title: "Higurashi"
 | 
				
			||||||
 | 
					                description:
 | 
				
			||||||
 | 
					                    0:
 | 
				
			||||||
 | 
					                        type:     "text"
 | 
				
			||||||
 | 
					                        value:    "Higurashi is a great show!"
 | 
				
			||||||
 | 
					                    1:
 | 
				
			||||||
 | 
					                        type:     "quote"
 | 
				
			||||||
 | 
					                        value:    "Source: my ass"
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Each "description" node contains an array index named "type".
 | 
				
			||||||
 | 
					        Here is a list of them:
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					              text
 | 
				
			||||||
 | 
					            + title
 | 
				
			||||||
 | 
					              italic
 | 
				
			||||||
 | 
					            + quote
 | 
				
			||||||
 | 
					            + code
 | 
				
			||||||
 | 
					              inline_code
 | 
				
			||||||
 | 
					              link
 | 
				
			||||||
 | 
					            + image
 | 
				
			||||||
 | 
					            + audio
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        Each individual node prepended with a "+" should be prepended by
 | 
				
			||||||
 | 
					        a newline when constructing the rendered description object.
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        There are some nodes that differ from the type-value format.
 | 
				
			||||||
 | 
					        Please parse them accordingly ::
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            + link
 | 
				
			||||||
 | 
					                type:     "link"
 | 
				
			||||||
 | 
					                url:      "https://flossboxin.org.in"
 | 
				
			||||||
 | 
					                value:    "Visit my website!"
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            + image
 | 
				
			||||||
 | 
					                type:    "image"
 | 
				
			||||||
 | 
					                url:     "https://flossboxin.org.in/static/pixels.png"
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            + audio
 | 
				
			||||||
 | 
					                type:    "audio"
 | 
				
			||||||
 | 
					                url:     "https://flossboxin.org.in/static/whatever.mp3"
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        The array index named "table" is an associative array. You can
 | 
				
			||||||
 | 
					        loop over the data using this PHP code, for example ::
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            foreach($table as $website_name => $url){ // ...
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
							The rest of the JSON is pretty self explanatory.
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					+ /api/v1/images
 | 
				
			||||||
 | 
					    All images are contained within "image". The structure looks like
 | 
				
			||||||
 | 
					    below ::
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        image:
 | 
				
			||||||
 | 
					            0:
 | 
				
			||||||
 | 
					                title: "My awesome Higurashi image"
 | 
				
			||||||
 | 
					                source:
 | 
				
			||||||
 | 
					                    0:
 | 
				
			||||||
 | 
					                        url: "https://flossboxin.org.in/static/profile_pix.png"
 | 
				
			||||||
 | 
					                        width: 400
 | 
				
			||||||
 | 
					                        height: 400
 | 
				
			||||||
 | 
					                    1:
 | 
				
			||||||
 | 
					                        url: "https://flossboxin.org.in/static/pixels.png"
 | 
				
			||||||
 | 
					                        width: 640
 | 
				
			||||||
 | 
					                        height: 640
 | 
				
			||||||
 | 
					                    2:
 | 
				
			||||||
 | 
					                        url: "https://tse1.mm.bing.net/th?id=OIP.VBM3BQg
 | 
				
			||||||
 | 
					                        euf0-xScO1bl1UgHaGG"
 | 
				
			||||||
 | 
					                        width: 194
 | 
				
			||||||
 | 
					                        height: 160
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The last image of the "source" array is always the thumbnail, and is
 | 
				
			||||||
 | 
					    a good fallback to use when other sources fail to load. There can be
 | 
				
			||||||
 | 
					    more than 1 source; this is especially true when using the Yandex
 | 
				
			||||||
 | 
					    scraper, but beware of captcha rate limits.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					+ /api/v1/videos
 | 
				
			||||||
 | 
					    The "time" parameter for videos may be set to "_LIVE". For live
 | 
				
			||||||
 | 
					    streams, the amount of people currently watching is passed in
 | 
				
			||||||
 | 
					    "views".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /api/v1/news
 | 
				
			||||||
 | 
					    Just make a request to "/api/v1/news?s=elon+musk". The payload
 | 
				
			||||||
 | 
					    has nothing special about it and is very self explanatory, just like
 | 
				
			||||||
 | 
					    the endpoint above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /api/v1/music
 | 
				
			||||||
 | 
					    Each entry under "song" contains a array index called "stream" that
 | 
				
			||||||
 | 
					    looks like this ::
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					        endpoint: sc
 | 
				
			||||||
 | 
					        url: https://api-v2.soundcloud <...>
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    When the endpoint is something else than "linear", you MUST use
 | 
				
			||||||
 | 
					    the specified endpoint. Otherwise, you are free to handle that
 | 
				
			||||||
 | 
					    json+m3u8 crap yourself. If the endpoint is equal to "linear", the
 | 
				
			||||||
 | 
					    URL should return a valid HTTP audio stream. To access the endpoint,
 | 
				
			||||||
 | 
					    you must add the following prefix in your request, like so:
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					        https://4g.flossboxin.org.in/audio/<endpoint>?s=<url>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /favicon
 | 
				
			||||||
 | 
					    Get the favicon for a website. The only parameter is "s", and must
 | 
				
			||||||
 | 
					    include the protocol for fetching in case the favicon is not cached
 | 
				
			||||||
 | 
					    yet.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Example ::
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        /favicon?s=https://flossboxin.org.in
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    If we had to revert to using Google's favicon cache, it will throw
 | 
				
			||||||
 | 
					    an error in the X-Error header field. If Google's favicon cache
 | 
				
			||||||
 | 
					    also failed to return an image, or if you're too retarded to specify
 | 
				
			||||||
 | 
					    a valid domain name, a default placeholder image will be returned
 | 
				
			||||||
 | 
					    alongside the "404" HTTP error code.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /proxy
 | 
				
			||||||
 | 
					    Get a proxied image. Useful if you don't want to leak your user's IP
 | 
				
			||||||
 | 
					    address. The parameters are "i" for the image link and "s" for the
 | 
				
			||||||
 | 
					    size.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Acceptable "s" parameters:
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        portrait     90x160
 | 
				
			||||||
 | 
					        landscape    160x90
 | 
				
			||||||
 | 
					        square       90x90
 | 
				
			||||||
 | 
					        thumb        236x180
 | 
				
			||||||
 | 
					        cover        207x270
 | 
				
			||||||
 | 
					        original     <Original resolution>
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					    You can also ommit the "s" parameter if you wish to view the
 | 
				
			||||||
 | 
					    original image. When an error occurs, an "X-Error" header field
 | 
				
			||||||
 | 
					    is set.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /audio/linear
 | 
				
			||||||
 | 
					    Get a proxied audio file. Does not support "Range" headers, as it's
 | 
				
			||||||
 | 
					    only used to proxy small files (hence why it's called linear DUH)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The parameter is "s" for the audio link.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /audio/sc
 | 
				
			||||||
 | 
					    Get a proxied audio file for SoundCloud. Does not support downloads
 | 
				
			||||||
 | 
					    trough WGET or CURL, since it returns 30kb~160kb "206 Partial
 | 
				
			||||||
 | 
					    Content" parts, due to technical limitations that comes with
 | 
				
			||||||
 | 
					    converting m3u8 playlists to seekable audio files. If you use this
 | 
				
			||||||
 | 
					    endpoint, you must support these 206 codes and also handle the
 | 
				
			||||||
 | 
					    initial 302 HTTP redirect. I used this method as I didn't want to
 | 
				
			||||||
 | 
					    store information about your request needlessly. This method also
 | 
				
			||||||
 | 
					    allows noJS users to access the files.
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    The parameter is "s" for the SoundCloud JSON m3u8 abomination. It
 | 
				
			||||||
 | 
					    does not support "normal" SoundCloud URLs at this time.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ /audio/spotify
 | 
				
			||||||
 | 
					    Get a proxied Spotify audio file. Accepts a track ID for the "s"
 | 
				
			||||||
 | 
					    parameter. Will only allow you to fetch the 30 second preview since
 | 
				
			||||||
 | 
					    I don't feel like fucking with cookies and accounts every fucking
 | 
				
			||||||
 | 
					    living moment of my life. You must handle the initial 302 redirect
 | 
				
			||||||
 | 
					    to the /audio/linear endpoint.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ Appendix
 | 
				
			||||||
 | 
					    If you have any questions or need clarifications, please send an
 | 
				
			||||||
 | 
					    email my way to will at flossboxin.org.in
 | 
				
			||||||
							
								
								
									
										10
									
								
								api/index.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					http_response_code(404);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo json_encode(
 | 
				
			||||||
 | 
						[
 | 
				
			||||||
 | 
							"status" => "Unknown endpoint"
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
							
								
								
									
										243
									
								
								api/v1/ac.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,243 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "../../data/config.php";
 | 
				
			||||||
 | 
					new autocomplete();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class autocomplete{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("Content-Type: application/json");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->scrapers = [
 | 
				
			||||||
 | 
								"brave" => "https://search.brave.com/api/suggest?q={searchTerms}",
 | 
				
			||||||
 | 
								"ddg" => "https://duckduckgo.com/ac/?q={searchTerms}&type=list",
 | 
				
			||||||
 | 
								"yandex" => "https://suggest.yandex.com/suggest-ff.cgi?part={searchTerms}&uil=en&v=3&sn=5&lr=21276&yu=4861394161661655015",
 | 
				
			||||||
 | 
								"google" => "https://www.google.com/complete/search?client=mobile-gws-lite&q={searchTerms}",
 | 
				
			||||||
 | 
								"qwant" => "https://api.qwant.com/v3/suggest/?q={searchTerms}&client=opensearch",
 | 
				
			||||||
 | 
								"yep" => "https://api.yep.com/ac/?query={searchTerms}",
 | 
				
			||||||
 | 
								"marginalia" => "https://search.marginalia.nu/suggest/?partial={searchTerms}",
 | 
				
			||||||
 | 
								"yt" => "https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&q={searchTerms}",
 | 
				
			||||||
 | 
								"sc" => "",
 | 
				
			||||||
 | 
								"startpage" => "https://www.startpage.com/suggestions?q={searchTerms}&format=opensearch&segment=startpage.defaultffx&lui=english",
 | 
				
			||||||
 | 
								"kagi" => "https://kagi.com/api/autosuggest?q={searchTerms}",
 | 
				
			||||||
 | 
								"ghostery" => "https://ghosterysearch.com/suggest?q={searchTerms}"
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Sanitize input
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if(!isset($_GET["s"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Missing search(s) parameter");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(is_string($_GET["s"]) === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Invalid search(s) parameter");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(strlen($_GET["s"]) > 500){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Search(s) exceeds the 500 char length");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Get $scraper
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if(!isset($_GET["scraper"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($_COOKIE["scraper_ac"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$scraper = $_COOKIE["scraper_ac"];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$scraper = "brave"; // default option
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$scraper = $_GET["scraper"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($scraper == "disabled"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// this shouldnt happen, but let's handle it anyways
 | 
				
			||||||
 | 
								$this->doempty();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// make sure it exists
 | 
				
			||||||
 | 
							if(!isset($this->scrapers[$scraper])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$scraper = "brave"; // default option
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// return results
 | 
				
			||||||
 | 
							switch($scraper){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "google":
 | 
				
			||||||
 | 
								case "yt":
 | 
				
			||||||
 | 
									// handle google cause they want to be a special snowflake :(
 | 
				
			||||||
 | 
									$js = $this->get($this->scrapers[$scraper], $_GET["s"]);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									preg_match(
 | 
				
			||||||
 | 
										'/\((\[.*\])\)/',
 | 
				
			||||||
 | 
										$js,
 | 
				
			||||||
 | 
										$js
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(!isset($js[1])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->doempty();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$js = json_decode($js[1]);
 | 
				
			||||||
 | 
									$json = [];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									foreach($js[1] as $item){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$json[] = htmlspecialchars_decode(strip_tags($item[0]));
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									echo json_encode(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											$_GET["s"],
 | 
				
			||||||
 | 
											$json
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "sc":
 | 
				
			||||||
 | 
									// soundcloud
 | 
				
			||||||
 | 
									chdir("../../");
 | 
				
			||||||
 | 
									include "scraper/sc.php";
 | 
				
			||||||
 | 
									$sc = new sc();
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$token = $sc->get_token("raw_ip::::");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$js = $this->get(
 | 
				
			||||||
 | 
										"https://api-v2.soundcloud.com/search/queries?q={searchTerms}&client_id=" . $token . "&limit=10&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en",
 | 
				
			||||||
 | 
										$_GET["s"]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$js = json_decode($js, true);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(!isset($js["collection"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->doempty();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$json = [];
 | 
				
			||||||
 | 
									foreach($js["collection"] as $item){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$json[] = $item["query"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									echo json_encode(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											$_GET["s"],
 | 
				
			||||||
 | 
											$json
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "marginalia":
 | 
				
			||||||
 | 
									$json = $this->get($this->scrapers[$scraper], $_GET["s"]);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$json = json_decode($json, true);
 | 
				
			||||||
 | 
									if($json === null){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->doempty();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									echo json_encode(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											$_GET["s"],
 | 
				
			||||||
 | 
											$json
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									// if it respects the openSearch protocol
 | 
				
			||||||
 | 
									$json = json_decode($this->get($this->scrapers[$scraper], $_GET["s"]), true);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									echo json_encode(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											$_GET["s"],
 | 
				
			||||||
 | 
											$json[1] // ensure it contains valid key 0
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($url, $query){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$curlproc = curl_init();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url = str_replace("{searchTerms}", urlencode($query), $url);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
									["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0",
 | 
				
			||||||
 | 
									"Accept: application/json, text/javascript, */*; q=0.01",
 | 
				
			||||||
 | 
									"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
									"Accept-Encoding: gzip",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-site"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$data = curl_exec($curlproc);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(curl_errno($curlproc)){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception(curl_error($curlproc));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_close($curlproc);
 | 
				
			||||||
 | 
								return $data;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								do404("Curl error: " . $error->getMessage());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function do404($error){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							echo json_encode(
 | 
				
			||||||
 | 
								["error" => $error],
 | 
				
			||||||
 | 
								JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function doempty(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							echo json_encode(
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									$_GET["s"],
 | 
				
			||||||
 | 
									[]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								api/v1/images.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chdir("../../");
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					if(config::API_ENABLED === false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => "The server administrator disabled the API!"]);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					$null = null;
 | 
				
			||||||
 | 
					new bot_protection($null, $null, $null, "images", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters(
 | 
				
			||||||
 | 
						"images",
 | 
				
			||||||
 | 
						isset($_GET["scraper"]) ? $_GET["scraper"] : null
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						echo json_encode(
 | 
				
			||||||
 | 
							$scraper->image($get),
 | 
				
			||||||
 | 
							JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $e){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => $e->getMessage()]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										10
									
								
								api/v1/index.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					http_response_code(404);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo json_encode(
 | 
				
			||||||
 | 
						[
 | 
				
			||||||
 | 
							"status" => "Unknown endpoint"
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
							
								
								
									
										39
									
								
								api/v1/music.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chdir("../../");
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					if(config::API_ENABLED === false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => "The server administrator disabled the API!"]);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					$null = null;
 | 
				
			||||||
 | 
					new bot_protection($null, $null, $null, "music", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters(
 | 
				
			||||||
 | 
						"music",
 | 
				
			||||||
 | 
						isset($_GET["scraper"]) ? $_GET["scraper"] : null
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						echo json_encode(
 | 
				
			||||||
 | 
							$scraper->music($get),
 | 
				
			||||||
 | 
							JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $e){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => $e->getMessage()]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								api/v1/news.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chdir("../../");
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					if(config::API_ENABLED === false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => "The server administrator disabled the API!"]);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					$null = null;
 | 
				
			||||||
 | 
					new bot_protection($null, $null, $null, "news", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters(
 | 
				
			||||||
 | 
						"news",
 | 
				
			||||||
 | 
						isset($_GET["scraper"]) ? $_GET["scraper"] : null
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						echo json_encode(
 | 
				
			||||||
 | 
							$scraper->news($get),
 | 
				
			||||||
 | 
							JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $e){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => $e->getMessage()]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								api/v1/videos.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chdir("../../");
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					if(config::API_ENABLED === false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => "The server administrator disabled the API!"]);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					$null = null;
 | 
				
			||||||
 | 
					new bot_protection($null, $null, $null, "videos", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters(
 | 
				
			||||||
 | 
						"videos",
 | 
				
			||||||
 | 
						isset($_GET["scraper"]) ? $_GET["scraper"] : null
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						echo json_encode(
 | 
				
			||||||
 | 
							$scraper->video($get),
 | 
				
			||||||
 | 
							JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $e){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => $e->getMessage()]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										52
									
								
								api/v1/web.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,52 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chdir("../../");
 | 
				
			||||||
 | 
					header("Content-Type: application/json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					if(config::API_ENABLED === false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => "The server administrator disabled the API!"]);
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					$null = null;
 | 
				
			||||||
 | 
					new bot_protection($null, $null, $null, "web", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters(
 | 
				
			||||||
 | 
						"web",
 | 
				
			||||||
 | 
						isset($_GET["scraper"]) ? $_GET["scraper"] : null
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(
 | 
				
			||||||
 | 
						isset($_GET["extendedsearch"]) &&
 | 
				
			||||||
 | 
						$_GET["extendedsearch"] == "yes"
 | 
				
			||||||
 | 
					){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$get["extendedsearch"] = "yes";
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$get["extendedsearch"] = "no";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo
 | 
				
			||||||
 | 
							json_encode(
 | 
				
			||||||
 | 
								$scraper->web($get),
 | 
				
			||||||
 | 
								JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_IGNORE
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $e){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo json_encode(["status" => $e->getMessage()]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										20
									
								
								audio/linear.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,20 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!isset($_GET["s"])){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						http_response_code(404);
 | 
				
			||||||
 | 
						header("X-Error: No SOUND(s) provided!");
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "../data/config.php";
 | 
				
			||||||
 | 
					include "../lib/curlproxy.php";
 | 
				
			||||||
 | 
					$proxy = new proxy();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$proxy->stream_linear_audio($_GET["s"]);
 | 
				
			||||||
 | 
					}catch(Exception $error){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						header("X-Error: " . $error->getMessage());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										224
									
								
								audio/sc.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,224 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					new sc_audio();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class sc_audio{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "../data/config.php";
 | 
				
			||||||
 | 
							include "../lib/curlproxy.php";
 | 
				
			||||||
 | 
							$this->proxy = new proxy();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($_GET["u"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
									we're now proxying audio
 | 
				
			||||||
 | 
								*/
 | 
				
			||||||
 | 
								$viewkey = $_GET["u"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($_GET["r"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$this->do404("Ranges(r) are missing");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$ranges = explode(",", $_GET["r"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// sanitize ranges
 | 
				
			||||||
 | 
								foreach($ranges as &$range){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(!is_numeric($range)){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->do404("Invalid range specified");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$range = (int)$range;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// sort ranges (just to make sure)
 | 
				
			||||||
 | 
								sort($ranges);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// convert ranges to pairs
 | 
				
			||||||
 | 
								$last = -1;
 | 
				
			||||||
 | 
								foreach($ranges as &$r){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$tmp = $r;
 | 
				
			||||||
 | 
									$r = [$last + 1, $r];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$last = $tmp;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$browser_headers = getallheaders();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get the requested range from client
 | 
				
			||||||
 | 
								$client_range = 0;
 | 
				
			||||||
 | 
								foreach($browser_headers as $key => $value){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(strtolower($key) == "range"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										preg_match(
 | 
				
			||||||
 | 
											'/bytes=([0-9]+)/',
 | 
				
			||||||
 | 
											$value,
 | 
				
			||||||
 | 
											$client_regex
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(isset($client_regex[1])){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$client_range = (int)$client_regex[1];
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$client_range = 0;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$client_range < 0 ||
 | 
				
			||||||
 | 
									$client_range > $ranges[count($ranges) - 1][1]
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// range is not satisfiable
 | 
				
			||||||
 | 
									http_response_code(416);
 | 
				
			||||||
 | 
									header("Content-Type: text/plain");
 | 
				
			||||||
 | 
									die();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$rng = null;
 | 
				
			||||||
 | 
								for($i=0; $i<count($ranges); $i++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($ranges[$i][0] <= $client_range){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$rng = $ranges[$i];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// proxy data!
 | 
				
			||||||
 | 
								http_response_code(206); // partial content
 | 
				
			||||||
 | 
								header("Accept-Ranges: bytes");
 | 
				
			||||||
 | 
								header("Content-Range: bytes {$rng[0]}-{$rng[1]}/" . ($ranges[count($ranges) - 1][1] + 1));
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$viewkey =
 | 
				
			||||||
 | 
									preg_replace(
 | 
				
			||||||
 | 
										'/\/media\/([0-9]+)\/[0-9]+\/[0-9]+/',
 | 
				
			||||||
 | 
										'/media/$1/' . $rng[0] . '/' . $rng[1],
 | 
				
			||||||
 | 
										$viewkey
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$this->proxy->stream_linear_audio(
 | 
				
			||||||
 | 
										$viewkey
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$this->do404("Could not read stream");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								die();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								redirect user to correct resource
 | 
				
			||||||
 | 
								we need to scrape and store the byte positions in the result URL
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if(!isset($_GET["s"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("The URL(s) parameter is missing");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$viewkey = $_GET["s"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/soundcloud\.com$/',
 | 
				
			||||||
 | 
									parse_url($viewkey, PHP_URL_HOST)
 | 
				
			||||||
 | 
								) === false
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("This endpoint can only be used for soundcloud streams");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json = $this->proxy->get($viewkey)["body"];
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Curl error: " . $error->getMessage());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($json["url"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Could not get URL from JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$viewkey = $json["url"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$m3u8 = $this->proxy->get($viewkey)["body"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$m3u8 = explode("\n", $m3u8);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$lineout = null;
 | 
				
			||||||
 | 
							$streampos_arr = [];
 | 
				
			||||||
 | 
							foreach($m3u8 as $line){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$line = trim($line);
 | 
				
			||||||
 | 
								if($line[0] == "#"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($lineout === null){
 | 
				
			||||||
 | 
									$lineout = $line;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/\/media\/[0-9]+\/([0-9]+)\/([0-9]+)/',
 | 
				
			||||||
 | 
									$line,
 | 
				
			||||||
 | 
									$matches
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($matches[0])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$streampos_arr[] = [
 | 
				
			||||||
 | 
										(int)$matches[1],
 | 
				
			||||||
 | 
										(int)$matches[2]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($lineout === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Could not get stream URL");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$lineout =
 | 
				
			||||||
 | 
								preg_replace(
 | 
				
			||||||
 | 
									'/\/media\/([0-9]+)\/[0-9]+\/[0-9]+/',
 | 
				
			||||||
 | 
									'/media/$1/0/0',
 | 
				
			||||||
 | 
									$lineout
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$streampos = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($streampos_arr as $pos){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$streampos[] = $pos[1];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$streampos = implode(",", $streampos);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("Location: /audio/sc?u=" . urlencode($lineout) . "&r=$streampos");
 | 
				
			||||||
 | 
							header("Accept-Ranges: bytes");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function do404($error){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							http_response_code(404);
 | 
				
			||||||
 | 
							header("Content-Type: text/plain");
 | 
				
			||||||
 | 
							header("X-Error: $error");
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										20
									
								
								audio/seekable.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,20 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!isset($_GET["s"])){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						http_response_code(404);
 | 
				
			||||||
 | 
						header("X-Error: No SOUND(s) provided!");
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "../data/config.php";
 | 
				
			||||||
 | 
					include "../lib/curlproxy.php";
 | 
				
			||||||
 | 
					$proxy = new proxy();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$proxy->stream_linear_audio($_GET["s"]);
 | 
				
			||||||
 | 
					}catch(Exception $error){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						header("X-Error: " . $error->getMessage());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										214
									
								
								audio/spotify.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,214 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "../data/config.php";
 | 
				
			||||||
 | 
					new spotify();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class spotify{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "../lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!isset($_GET["s"]) ||
 | 
				
			||||||
 | 
								!preg_match(
 | 
				
			||||||
 | 
									'/^(track|episode)\.([A-Za-z0-9]{22})$/',
 | 
				
			||||||
 | 
									$_GET["s"],
 | 
				
			||||||
 | 
									$matches
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("The track ID(s) parameter is missing or invalid");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($matches[1] == "episode"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$uri = "show";
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$uri = $matches[1];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$embed =
 | 
				
			||||||
 | 
									$this->get("https://embed.spotify.com/{$uri}/" . $matches[2]);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Failed to fetch embed data");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($embed);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementById(
 | 
				
			||||||
 | 
									"__NEXT_DATA__",
 | 
				
			||||||
 | 
									"script"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Failed to extract JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json =
 | 
				
			||||||
 | 
								json_decode($json["innerHTML"], true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($matches[1]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "track":
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										isset(
 | 
				
			||||||
 | 
											$json
 | 
				
			||||||
 | 
											["props"]
 | 
				
			||||||
 | 
											["pageProps"]
 | 
				
			||||||
 | 
											["state"]
 | 
				
			||||||
 | 
											["data"]
 | 
				
			||||||
 | 
											["entity"]
 | 
				
			||||||
 | 
											["audioPreview"]
 | 
				
			||||||
 | 
											["url"]
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										header("Content-type: audio/mpeg");
 | 
				
			||||||
 | 
										header(
 | 
				
			||||||
 | 
											"Location: /audio/linear?s=" .
 | 
				
			||||||
 | 
											urlencode(
 | 
				
			||||||
 | 
												$json
 | 
				
			||||||
 | 
												["props"]
 | 
				
			||||||
 | 
												["pageProps"]
 | 
				
			||||||
 | 
												["state"]
 | 
				
			||||||
 | 
												["data"]
 | 
				
			||||||
 | 
												["entity"]
 | 
				
			||||||
 | 
												["audioPreview"]
 | 
				
			||||||
 | 
												["url"]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->do404("Could not extract playback URL");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "episode":
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										isset(
 | 
				
			||||||
 | 
											$json
 | 
				
			||||||
 | 
											["props"]
 | 
				
			||||||
 | 
											["pageProps"]
 | 
				
			||||||
 | 
											["state"]
 | 
				
			||||||
 | 
											["data"]
 | 
				
			||||||
 | 
											["entity"]
 | 
				
			||||||
 | 
											["id"]
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										try{
 | 
				
			||||||
 | 
											$json =
 | 
				
			||||||
 | 
												$this->get(
 | 
				
			||||||
 | 
													"https://spclient.wg.spotify.com/soundfinder/v1/unauth/episode/" .
 | 
				
			||||||
 | 
													$json
 | 
				
			||||||
 | 
													["props"]
 | 
				
			||||||
 | 
													["pageProps"]
 | 
				
			||||||
 | 
													["state"]
 | 
				
			||||||
 | 
													["data"]
 | 
				
			||||||
 | 
													["entity"]
 | 
				
			||||||
 | 
													["id"] .
 | 
				
			||||||
 | 
													"/com.widevine.alpha"
 | 
				
			||||||
 | 
												);
 | 
				
			||||||
 | 
										}catch(Exception $error){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$this->do404("Failed to fetch audio resource");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$json = json_decode($json, true);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if($json === null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$this->do404("Failed to decode audio resource JSON");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											isset($json["passthrough"]) &&
 | 
				
			||||||
 | 
											$json["passthrough"] == "ALLOWED" &&
 | 
				
			||||||
 | 
											isset($json["passthroughUrl"])
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											header(
 | 
				
			||||||
 | 
												"Location:" .
 | 
				
			||||||
 | 
												"/audio/linear.php?s=" .
 | 
				
			||||||
 | 
												urlencode(
 | 
				
			||||||
 | 
													str_replace(
 | 
				
			||||||
 | 
														"http://",
 | 
				
			||||||
 | 
														"https://",
 | 
				
			||||||
 | 
														$json["passthroughUrl"]
 | 
				
			||||||
 | 
													)
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$this->do404("Failed to find passthroughUrl");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->do404("Failed to find episode ID");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($url){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$headers = [
 | 
				
			||||||
 | 
								"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",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"Sec-Fetch-User: ?1"
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$data = curl_exec($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(curl_errno($curlproc)){
 | 
				
			||||||
 | 
								throw new Exception(curl_error($curlproc));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curlproc);
 | 
				
			||||||
 | 
							return $data;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function do404($error){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							http_response_code(404);
 | 
				
			||||||
 | 
							header("Content-Type: text/plain");
 | 
				
			||||||
 | 
							header("X-Error: $error");
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										203
									
								
								captcha.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,203 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(
 | 
				
			||||||
 | 
						isset($_GET["v"]) === false ||
 | 
				
			||||||
 | 
						is_array($_GET["v"]) === true ||
 | 
				
			||||||
 | 
						preg_match(
 | 
				
			||||||
 | 
							'/^c[0-9]+\.[A-Za-z0-9_]{20}$/',
 | 
				
			||||||
 | 
							$_GET["v"]
 | 
				
			||||||
 | 
						) === 0
 | 
				
			||||||
 | 
					){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						http_response_code(401);
 | 
				
			||||||
 | 
						header("Content-Type: text/plain");
 | 
				
			||||||
 | 
						echo "Fuck my feathered cloaca";
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//header("Content-Type: image/jpeg");
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(config::BOT_PROTECTION !== 1){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						header("Content-Type: text/plain");
 | 
				
			||||||
 | 
						echo "The IQ test is disabled";
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$grid = apcu_fetch($_GET["v"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if($grid !== false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// captcha already generated
 | 
				
			||||||
 | 
						http_response_code(304); // not modified
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Content-Type: image/jpeg");
 | 
				
			||||||
 | 
					header("Last-Modified: Thu, 01 Oct 1970 00:00:00 GMT");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ** generate captcha data
 | 
				
			||||||
 | 
					// get the positions for the answers
 | 
				
			||||||
 | 
					// will return between 3 and 6 answer positions
 | 
				
			||||||
 | 
					$range = range(0, 15);
 | 
				
			||||||
 | 
					$answer_pos = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					array_splice($range, 0, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$picks = random_int(3, 6);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for($i=0; $i<$picks; $i++){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$answer_pos_tmp =
 | 
				
			||||||
 | 
							array_splice(
 | 
				
			||||||
 | 
								$range,
 | 
				
			||||||
 | 
								random_int(
 | 
				
			||||||
 | 
									0,
 | 
				
			||||||
 | 
									14 - $i
 | 
				
			||||||
 | 
								),
 | 
				
			||||||
 | 
								1
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$answer_pos[] = $answer_pos_tmp[0];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// choose a dataset
 | 
				
			||||||
 | 
					$c = count(config::CAPTCHA_DATASET);
 | 
				
			||||||
 | 
					$choosen = config::CAPTCHA_DATASET[random_int(0, $c - 1)];
 | 
				
			||||||
 | 
					$choices = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for($i=0; $i<$c; $i++){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(config::CAPTCHA_DATASET[$i][0] == $choosen[0]){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							continue;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$choices[] = config::CAPTCHA_DATASET[$i];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// generate grid data
 | 
				
			||||||
 | 
					$grid = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for($i=0; $i<16; $i++){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(in_array($i, $answer_pos)){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$grid[] = $choosen;
 | 
				
			||||||
 | 
						}else{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$grid[] = $choices[random_int(0, count($choices) - 1)];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// store grid data for form validation on captcha_gen.php
 | 
				
			||||||
 | 
					apcu_store(
 | 
				
			||||||
 | 
						$_GET["v"],
 | 
				
			||||||
 | 
						$answer_pos,
 | 
				
			||||||
 | 
						60 // we give user 1 minute to solve
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// generate image
 | 
				
			||||||
 | 
					if(random_int(0,1) === 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$theme = [
 | 
				
			||||||
 | 
							"bg" => "#ebdbb2",
 | 
				
			||||||
 | 
							"fg" => "#1d2021"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$theme = [
 | 
				
			||||||
 | 
							"bg" => "#1d2021",
 | 
				
			||||||
 | 
							"fg" => "#ebdbb2"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$im = new Imagick();
 | 
				
			||||||
 | 
					$im->newImage(400, 427, $theme["bg"]);
 | 
				
			||||||
 | 
					$im->setImageBackgroundColor($theme["bg"]);
 | 
				
			||||||
 | 
					$im->setImageFormat("jpg");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$noise = [
 | 
				
			||||||
 | 
						imagick::NOISE_GAUSSIAN,
 | 
				
			||||||
 | 
						imagick::NOISE_LAPLACIAN
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$distort = [
 | 
				
			||||||
 | 
						imagick::DISTORTION_AFFINE,
 | 
				
			||||||
 | 
						imagick::DISTORTION_SHEPARDS
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$i = 0;
 | 
				
			||||||
 | 
					for($y=0; $y<4; $y++){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						for($x=0; $x<4; $x++){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$tmp = new Imagick("./data/captcha/" . $grid[$i][0] . "/" . random_int(1, $grid[$i][1]) . ".png");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// convert transparency correctly
 | 
				
			||||||
 | 
							$tmp->setImageBackgroundColor("black");
 | 
				
			||||||
 | 
							$tmp->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// randomly mirror
 | 
				
			||||||
 | 
							if(random_int(0,1) === 1){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$tmp->flopImage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// distort $tmp
 | 
				
			||||||
 | 
							$tmp->distortImage(
 | 
				
			||||||
 | 
								$distort[random_int(0,1)],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									0, 0,
 | 
				
			||||||
 | 
									random_int(-15, 15), random_int(-15, 15),
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									100, 0,
 | 
				
			||||||
 | 
									random_int(80, 120), random_int(-15, 15),
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									100, 100,
 | 
				
			||||||
 | 
									random_int(80, 120), random_int(80, 120),
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									0, 100,
 | 
				
			||||||
 | 
									random_int(-15, 15), random_int(80, 120)
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								false
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$tmp->addNoiseImage($noise[random_int(0, 1)]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// append image
 | 
				
			||||||
 | 
							$im->compositeImage($tmp->getImage(), Imagick::COMPOSITE_DEFAULT, $x * 100, ($y * 100) + 27);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$i++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// add text
 | 
				
			||||||
 | 
					$draw = new ImagickDraw();
 | 
				
			||||||
 | 
					$draw->setFontSize(20);
 | 
				
			||||||
 | 
					$draw->setFillColor($theme["fg"]);
 | 
				
			||||||
 | 
					//$draw->setTextAntialias(false);
 | 
				
			||||||
 | 
					$draw->setFont("./data/fonts/captcha.ttf");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$text = "Pick " . $picks . " images of " . str_replace("_", " ", $choosen[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$pos = 200 - ($im->queryFontMetrics($draw, $text)["textWidth"] / 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for($i=0; $i<strlen($text); $i++){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$im->annotateImage(
 | 
				
			||||||
 | 
							$draw,
 | 
				
			||||||
 | 
							$pos,
 | 
				
			||||||
 | 
							20,
 | 
				
			||||||
 | 
							random_int(-15, 15),
 | 
				
			||||||
 | 
							$text[$i]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$pos += $im->queryFontMetrics($draw, $text[$i])["textWidth"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$im->setFormat("jpeg");
 | 
				
			||||||
 | 
					$im->setImageCompressionQuality(90);
 | 
				
			||||||
 | 
					echo $im->getImageBlob();
 | 
				
			||||||
							
								
								
									
										157
									
								
								data/config.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,157 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					class config{
 | 
				
			||||||
 | 
						// Welcome to the 4Get configuration file
 | 
				
			||||||
 | 
						// When updating your instance, please make sure this file isn't missing
 | 
				
			||||||
 | 
						// any parameters.
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// 4Get version. Please keep this updated
 | 
				
			||||||
 | 
						const VERSION = 8;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Will be shown pretty much everywhere.
 | 
				
			||||||
 | 
						const SERVER_NAME = "FbIN 4Get";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Will be shown in <meta> tag on home page
 | 
				
			||||||
 | 
						const SERVER_SHORT_DESCRIPTION = "4Get is a proxy search engine that doesn't suck.";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Will be shown in server list ping (null for no description)
 | 
				
			||||||
 | 
						const SERVER_LONG_DESCRIPTION = FbIN;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Add your own themes in "static/themes". Set to "Dark" for default theme.
 | 
				
			||||||
 | 
						// Eg. To use "static/themes/Cream.css", specify "Cream".
 | 
				
			||||||
 | 
						const DEFAULT_THEME = "Catppuccin Latte";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Enable the API?
 | 
				
			||||||
 | 
						const API_ENABLED = false;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// BOT PROTECTION
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// 0 = disabled, 1 = ask for image captcha, @TODO: 2 = invite only (users needs a pass)
 | 
				
			||||||
 | 
						// VERY useful against a targetted attack
 | 
				
			||||||
 | 
						const BOT_PROTECTION = 0;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// if BOT_PROTECTION is set to 1, specify the available datasets here
 | 
				
			||||||
 | 
						// images should be named from 1.png to X.png, and be 100x100 in size
 | 
				
			||||||
 | 
						// Eg. data/captcha/birds/1.png up to 2263.png
 | 
				
			||||||
 | 
						const CAPTCHA_DATASET = [
 | 
				
			||||||
 | 
							// example:
 | 
				
			||||||
 | 
							//["birds", 2263],
 | 
				
			||||||
 | 
							//["fumo_plushies", 1006],
 | 
				
			||||||
 | 
							//["minecraft", 848]
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// If this regex expression matches on the user agent, it blocks the request
 | 
				
			||||||
 | 
						// Not useful at all against a targetted attack
 | 
				
			||||||
 | 
						const HEADER_REGEX = '/bot|wget|curl|python-requests|scrapy|go-http-client|ruby|yahoo|spider|qwant/i';
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Block clients who present any of the following headers in their request (SPECIFY IN !!lowercase!!)
 | 
				
			||||||
 | 
						// Eg: ["x-forwarded-for", "x-via", "forwarded-for", "via"];
 | 
				
			||||||
 | 
						// Useful for blocking *some* proxies used for botting
 | 
				
			||||||
 | 
						const FILTERED_HEADER_KEYS = [
 | 
				
			||||||
 | 
							//"x-forwarded-for",
 | 
				
			||||||
 | 
							//"x-cluster-client-ip",
 | 
				
			||||||
 | 
							//"x-client-ip",
 | 
				
			||||||
 | 
							//"x-real-ip",
 | 
				
			||||||
 | 
							//"client-ip",
 | 
				
			||||||
 | 
							//"real-ip",
 | 
				
			||||||
 | 
							//"forwarded-for",
 | 
				
			||||||
 | 
							//"forwarded-for-ip",
 | 
				
			||||||
 | 
							//"forwarded",
 | 
				
			||||||
 | 
							//"proxy-connection",
 | 
				
			||||||
 | 
							//"remote-addr",
 | 
				
			||||||
 | 
							//"via"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Block SSL ciphers used by CLI tools used for botting
 | 
				
			||||||
 | 
						// Basically a primitive version of Cloudflare's browser integrity check
 | 
				
			||||||
 | 
						// ** If curl can still access the site (with spoofed headers), please make sure you use the new apache2 config **
 | 
				
			||||||
 | 
						// https://git.flossboxin.org.in/FbIN/4Get/docs/apache2.md
 | 
				
			||||||
 | 
						const DISALLOWED_SSL = [
 | 
				
			||||||
 | 
							// "TLS_AES_256_GCM_SHA384" // used by WGET and CURL
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Maximal number of searches per captcha key/pass issued. Counter gets
 | 
				
			||||||
 | 
						// reset on every APCU cache clear (should happen once a day).
 | 
				
			||||||
 | 
						// Only useful when BOT_PROTECTION is NOT set to 0
 | 
				
			||||||
 | 
						const MAX_SEARCHES = 100;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// List of domains that point to your servers. Include your tor/i2p
 | 
				
			||||||
 | 
						// addresses here! Must be a valid URL. Won't affect links placed on
 | 
				
			||||||
 | 
						// the homepage.
 | 
				
			||||||
 | 
						const ALT_ADDRESSES = [
 | 
				
			||||||
 | 
							//"https://4get.alt-tld",
 | 
				
			||||||
 | 
							//"http://4getwebfrq5zr4sxugk6htxvawqehxtdgjrbcn2oslllcol2vepa23yd.onion"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Known 4Get instances. MUST use the https protocol if your instance uses
 | 
				
			||||||
 | 
						// it. Is used to generate a distributed list of instances.
 | 
				
			||||||
 | 
						// To appear in the list of an instance, contact the host and if everyone added
 | 
				
			||||||
 | 
						// eachother your serber should appear everywhere.
 | 
				
			||||||
 | 
						const INSTANCES = [
 | 
				
			||||||
 | 
							"https://4g.flossboxin.org.in",
 | 
				
			||||||
 | 
							"https://4get.ca",
 | 
				
			||||||
 | 
							"https://4get.nadeko.net",
 | 
				
			||||||
 | 
							"https://4get.silly.computer",
 | 
				
			||||||
 | 
							"https://4get.sijh.net",
 | 
				
			||||||
 | 
							"https://4get.hbubli.cc",
 | 
				
			||||||
 | 
							"https://4get.lunar.icu",
 | 
				
			||||||
 | 
							"https://4get.neco.lol",
 | 
				
			||||||
 | 
							"https://4get.plunked.party/",
 | 
				
			||||||
 | 
							"https://4get.ch",
 | 
				
			||||||
 | 
							"https://4get.edmateo.site",
 | 
				
			||||||
 | 
							"https://4get.sudovanilla.org",
 | 
				
			||||||
 | 
							"https://search.mint.lgbt"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Default user agent to use for scraper requests. Sometimes ignored to get specific webpages
 | 
				
			||||||
 | 
						// Changing this might break things.
 | 
				
			||||||
 | 
						const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Proxy pool assignments for each scraper
 | 
				
			||||||
 | 
						// false = Use server's raw IP
 | 
				
			||||||
 | 
						// string = will load a proxy list from data/proxies
 | 
				
			||||||
 | 
						// Eg. "onion" will load data/proxies/onion.txt
 | 
				
			||||||
 | 
						const PROXY_DDG = false; // duckduckgo
 | 
				
			||||||
 | 
						const PROXY_BRAVE = false;
 | 
				
			||||||
 | 
						const PROXY_FB = false; // facebook
 | 
				
			||||||
 | 
						const PROXY_GOOGLE = false;
 | 
				
			||||||
 | 
						const PROXY_GOOGLE_CSE = false;
 | 
				
			||||||
 | 
						const PROXY_STARTPAGE = false;
 | 
				
			||||||
 | 
						const PROXY_QWANT = false;
 | 
				
			||||||
 | 
						const PROXY_GHOSTERY = false;
 | 
				
			||||||
 | 
						const PROXY_MARGINALIA = false;
 | 
				
			||||||
 | 
						const PROXY_MOJEEK = false;
 | 
				
			||||||
 | 
						const PROXY_SC = false; // soundcloud
 | 
				
			||||||
 | 
						const PROXY_SPOTIFY = false;
 | 
				
			||||||
 | 
						const PROXY_SOLOFIELD = false;
 | 
				
			||||||
 | 
						const PROXY_WIBY = false;
 | 
				
			||||||
 | 
						const PROXY_CURLIE = false;
 | 
				
			||||||
 | 
						const PROXY_YT = false; // youtube
 | 
				
			||||||
 | 
						const PROXY_YEP = false;
 | 
				
			||||||
 | 
						const PROXY_PINTEREST = false;
 | 
				
			||||||
 | 
						const PROXY_FIVEHPX = false;
 | 
				
			||||||
 | 
						const PROXY_VSCO = false;
 | 
				
			||||||
 | 
						const PROXY_SEZNAM = false;
 | 
				
			||||||
 | 
						const PROXY_NAVER = false;
 | 
				
			||||||
 | 
						const PROXY_GREPPR = false;
 | 
				
			||||||
 | 
						const PROXY_CROWDVIEW = false;
 | 
				
			||||||
 | 
						const PROXY_MWMBL = false;
 | 
				
			||||||
 | 
						const PROXY_FTM = false; // findthatmeme
 | 
				
			||||||
 | 
						const PROXY_IMGUR = false;
 | 
				
			||||||
 | 
						const PROXY_YANDEX_W = false; // yandex web
 | 
				
			||||||
 | 
						const PROXY_YANDEX_I = false; // yandex images
 | 
				
			||||||
 | 
						const PROXY_YANDEX_V = false; // yandex videos
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// Scraper-specific parameters
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// GOOGLE CSE
 | 
				
			||||||
 | 
						const GOOGLE_CX_ENDPOINT = "d4e68b99b876541f0";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// MARGINALIA
 | 
				
			||||||
 | 
						// Use "null" to default out to HTML scraping OR specify a string to
 | 
				
			||||||
 | 
						// use the API (Eg: "public"). API has less filters.
 | 
				
			||||||
 | 
						const MARGINALIA_API_KEY = null;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								data/fonts/captcha.ttf
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										3
									
								
								data/proxies/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					!.gitignore
 | 
				
			||||||
 | 
					!onion.txt
 | 
				
			||||||
							
								
								
									
										13
									
								
								data/proxies/onion.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					# Specify proxies by following this format:
 | 
				
			||||||
 | 
					#  <protocol>:<address>:<port>:<username>:<password>
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Examples:
 | 
				
			||||||
 | 
					#  https:1.3.3.7:6969:abcd:efg
 | 
				
			||||||
 | 
					#  socks4:1.2.3.4:8080::
 | 
				
			||||||
 | 
					#  raw_ip::::
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Available protocols:
 | 
				
			||||||
 | 
					#  raw_ip, http, https, socks4, socks5, socks4a, socks5_hostname
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Local tor proxy
 | 
				
			||||||
 | 
					socks5:localhost:9050::
 | 
				
			||||||
							
								
								
									
										195
									
								
								docs/apache2-example.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,195 @@
 | 
				
			||||||
 | 
					# Sample Apache2 configuration
 | 
				
			||||||
 | 
					This is the apache2 configuration file used on the 4g.flossboxin.org.in official instance, in hopes that it's useful to you!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Looking for the apache2 guide? <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/apache2.md">go here.</a>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName www.4g.flossboxin.org.in
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://4g.flossboxin.org.in$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName 4g.flossboxin.org.in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ServerAdmin dev@flossboxin.org.in
 | 
				
			||||||
 | 
						DocumentRoot /var/www/4get
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLOptions +StdEnvVars
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						#ErrorLog ${APACHE_LOG_DIR}/error.log
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						<Directory /var/www/4get>
 | 
				
			||||||
 | 
							Options -MultiViews
 | 
				
			||||||
 | 
							AllowOverride All
 | 
				
			||||||
 | 
							Require all granted
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							RewriteEngine On
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-d
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-f
 | 
				
			||||||
 | 
							RewriteRule ^([^\.]+)$ $1.php [NC,L]
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# deny access to private resources
 | 
				
			||||||
 | 
						<Directory /var/www/4get/data/>
 | 
				
			||||||
 | 
							Order Deny,allow
 | 
				
			||||||
 | 
							Deny from all
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName www.flossboxin.org.in
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://flossboxin.org.in$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName flossboxin.org.in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ServerAdmin dev@flossboxin.org.in
 | 
				
			||||||
 | 
						DocumentRoot /var/www/flossboxin
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLOptions +StdEnvVars	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						#ErrorLog ${APACHE_LOG_DIR}/error.log
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<Directory /var/www/flossboxin>
 | 
				
			||||||
 | 
							Options -MultiViews
 | 
				
			||||||
 | 
							AllowOverride All
 | 
				
			||||||
 | 
							Require all granted
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							RewriteEngine On
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-d
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-f
 | 
				
			||||||
 | 
							RewriteRule ^([^\.]+)$ $1.php [NC,L]
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName www.nyym.co
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/nyym.co/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/nyym.co/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/nyym.co/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://nyym.co$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName nyym.co
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ServerAdmin will@lolcat.ca
 | 
				
			||||||
 | 
						DocumentRoot /var/www/nyym
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLOptions +StdEnvVars	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						#ErrorLog ${APACHE_LOG_DIR}/error.log
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/nyym.co/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/nyym.co/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/nyym.co/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						<Directory /var/www/nyym>
 | 
				
			||||||
 | 
							Options -MultiViews
 | 
				
			||||||
 | 
							AllowOverride All
 | 
				
			||||||
 | 
							Require all granted
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							RewriteEngine On
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-d
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-f
 | 
				
			||||||
 | 
							RewriteRule ^([^\.]+)$ $1.php [NC,L]
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName git.flossboxin.org.in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLOptions +StdEnvVars	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						#ErrorLog ${APACHE_LOG_DIR}/error.log
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ProxyPreserveHost On
 | 
				
			||||||
 | 
						ProxyRequests off
 | 
				
			||||||
 | 
						AllowEncodedSlashes NoDecode
 | 
				
			||||||
 | 
						ProxyPass / http://localhost:3000/ nocanon
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName live.lolcat.ca
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ServerAdmin will@lolcat.ca
 | 
				
			||||||
 | 
						DocumentRoot /var/www/live
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLOptions +StdEnvVars	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						#ErrorLog ${APACHE_LOG_DIR}/error.log
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
							
								
								
									
										216
									
								
								docs/apache2.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,216 @@
 | 
				
			||||||
 | 
					# Install guide for Apache2 webserver
 | 
				
			||||||
 | 
					Welcome to the new and revamped 4get install manual for apache2. Even if you already have services running on an existing installation of apache2, you should still be able to adapt this guide to your needs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For starters, login as `root`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Then, install the following dependencies:
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					apt update
 | 
				
			||||||
 | 
					apt upgrade
 | 
				
			||||||
 | 
					apt install php-mbstring apache2 certbot php-imagick imagemagick php-curl curl php-apcu git libapache2-mod-php
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Enable the required modules:
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					a2enmod ssl
 | 
				
			||||||
 | 
					a2enmod rewrite
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					And enable these optional ones, which might be useful to you later on. The `proxy` module is useful for setting up reverse proxies to services like gitea, and `headers` is useful to tweak global header values:
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					a2enmod proxy
 | 
				
			||||||
 | 
					a2enmod headers
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now, restart apache2:
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					service apache2 restart
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Just for good measure, please check if your webserver is running. Access it through HTTP, not HTTPS. You should see the apache2 default landing page.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 000-default.conf
 | 
				
			||||||
 | 
					Now, edit the following file: `/etc/apache2/sites-available/000-default.conf`, remove everything and carefully add each rule specified here, while making sure to replace my domains with your own:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. The `VirtualHost` here instructs apache2 to redirect all **HTTP** traffic that specify an unknown `Host` header be redirected to a specific domain of your choice. Configuring this is not required but highly recommended.
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:80>
 | 
				
			||||||
 | 
						# no domain = go to 4g.flossboxin.org.in
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://4g.flossboxin.org.in$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. This instruction tells apache2 to redirect all HTTP traffic on `Host` flossboxin.org.in to the HTTPS version of the site. You should add a rule like this for all of your services explicitly.
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:80>
 | 
				
			||||||
 | 
						ServerName flossboxin.org.in
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://flossboxin.org.in$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3. Subdomains won't be matched by the above rule, so I recommend you also add them to be more explicit:
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:80>
 | 
				
			||||||
 | 
						ServerName www.flossboxin.org.in
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://flossboxin.org.in$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					... Etc, for every service you own.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					4. And finally, append this configuration if you wish to host a tor or i2p access point. This configuration should not be binded to SSL(443) as Let's Encrypt does not let you create certificates for onion sites:
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:80>
 | 
				
			||||||
 | 
						# tor site
 | 
				
			||||||
 | 
						ServerName 4getwebfrq5zr4sxugk6htxvawqehxtdgjrbcn2oslllcol2vepa23yd.onion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# compress
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						DocumentRoot /var/www/4get
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Options -MultiViews
 | 
				
			||||||
 | 
						RewriteEngine On
 | 
				
			||||||
 | 
						RewriteCond %{REQUEST_FILENAME} !-d
 | 
				
			||||||
 | 
						RewriteCond %{REQUEST_FILENAME} !-f
 | 
				
			||||||
 | 
						RewriteRule ^([^\.]+)$ $1.php [NC,L]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# deny access to private resources
 | 
				
			||||||
 | 
						<Directory /var/www/4get/data/>
 | 
				
			||||||
 | 
							Order Deny,allow
 | 
				
			||||||
 | 
							Deny from all
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					To make the above snippet work, please refer to our <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/tor.md">tor site guide</a>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## default-ssl.conf
 | 
				
			||||||
 | 
					Now, edit the file `/etc/apache2/sites-available/default-ssl.conf`, remove everything and, again, add each rule while modifying the relevant fields:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					First, append the following redirect rule to point traffic from `www.4g.flossboxin.org.in` to `4g.flossboxin.org.in`:
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName www.4g.flossboxin.org.in
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						RedirectMatch 301 ^(.*)$ https://4g.flossboxin.org.in$1
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This ruleset tells apache2 where 4get is located (`/var/www/4get`), ensures that `4g.flossboxin.org.in/settings` resolves to `4g.flossboxin.org.in/settings.php` internally and that we deny access to `/data/*`, which may contain files you might want to keep private. `StdEnvVArs+` will make it so that PHP can view if the connection uses HTTPS, and which cipher was used. Useful for basic bot protection.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Make sure to replace `4g.flossboxin.org.in` with your own domain under the `SSLCertificate*` directives!
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<VirtualHost *:443>
 | 
				
			||||||
 | 
						ServerName 4g.flossboxin.org.in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ServerAdmin dev@flossboxin.org.in
 | 
				
			||||||
 | 
						DocumentRoot /var/www/4get
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLEngine On
 | 
				
			||||||
 | 
						SSLOptions +StdEnvVars
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						#ErrorLog ${APACHE_LOG_DIR}/error.log
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/json
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE application/x-javascript
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/html
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/plain
 | 
				
			||||||
 | 
						AddOutputFilterByType DEFLATE text/css
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						SSLCertificateFile /etc/letsencrypt/live/4g.flossboxin.org.in/fullchain.pem
 | 
				
			||||||
 | 
						SSLCertificateKeyFile /etc/letsencrypt/live/4g.flossboxin.org.in/privkey.pem
 | 
				
			||||||
 | 
						SSLCertificateChainFile /etc/letsencrypt/live/4g.flossboxin.org.in/chain.pem
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						<Directory /var/www/4get>
 | 
				
			||||||
 | 
							Options -MultiViews
 | 
				
			||||||
 | 
							AllowOverride All
 | 
				
			||||||
 | 
							Require all granted
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							RewriteEngine On
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-d
 | 
				
			||||||
 | 
							RewriteCond %{REQUEST_FILENAME} !-f
 | 
				
			||||||
 | 
							RewriteRule ^([^\.]+)$ $1.php [NC,L]
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# deny access to private resources
 | 
				
			||||||
 | 
						<Directory /var/www/4get/data/>
 | 
				
			||||||
 | 
							Order Deny,allow
 | 
				
			||||||
 | 
							Deny from all
 | 
				
			||||||
 | 
						</Directory>
 | 
				
			||||||
 | 
					</VirtualHost>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					By default, the first rule dictates where traffic should be redirected to in case the client specifies an unknown domain name. Don't forget your webserver's other rules! For a complete real-world example, please <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/apache2-example.md">check out my real-world config file I use on 4g.flossboxin.org.in</a>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## security.conf
 | 
				
			||||||
 | 
					If you enabled the `headers` module, you can head over to `/etc/apache2/conf-enabled/security.conf` and edit:
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					ServerTokens Prod # instead off Full
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					and
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					ServerSignature Off #instead of On
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					This will ensure that the `Server` header apache2 returns is minimal and doesn't leak information like your host system's OS or apache2 version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can also uncomment `Header set X-Content-Type-Options: "nosniff"` and `Header set Content-Security-Policy "frame-ancestors 'self';"` respectively.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## charset.conf
 | 
				
			||||||
 | 
					Head over to `/etc/apache2/conf-enabled/charset.conf` and uncomment `AddDefaultCharset UTF-8`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## other-vhost-access-log.conf
 | 
				
			||||||
 | 
					Since none of our configuration files contains any `CustomLog` directives, all we need to do to disable logging entirely is comment out the `CustomLog` directive located in `/etc/apache2/conf-enabled/other-vhost-access-log.conf`. Only error logs will remain if you configured them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Symlink everything
 | 
				
			||||||
 | 
					Now comes the most important part of the setup. Run
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					Otherwise apache2 will ignore our SSL configuration. Handy, huh?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Setup SSL
 | 
				
			||||||
 | 
					Great, now we've configured the webserver, but we still don't have our security certificate. Let's generate one!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					First, stop `apache2`. 
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					service apache2 stop
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now, run `certbot`, and specify all of your domains by prepending `-d` every time. Make sure the first domain you specify is your main domain, and the same domain you specified in the configuration above! We use ECDSA encryption here as it's better than RSA.
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					certbot certonly --standalone --key-type ecdsa -d 4g.flossboxin.org.in -d www.4g.flossboxin.org.in -d flossboxin.org.in -d www.flossboxin.org.in
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Certbot should ask you a few questions, just play along. At the end of the setup, certbot should tell you about the location of the certificates. Double check to make sure they correspond to the paths we specified in `default-ssl.conf`. Your certificates should now update every 2-3 months automatically.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					After this is complete, create a directory in `/var/www/4get`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now, start `apache2`.
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					service apache2 start
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Congratulations! You now have a... 404 error on your webserver, if everything went well. Now's the time to make sure all of our redirect rules work!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Import the fun junk
 | 
				
			||||||
 | 
					Run these commands:
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					cd /var/www/4get
 | 
				
			||||||
 | 
					git clone https://git.flossboxin.org.in/FbIN/4get
 | 
				
			||||||
 | 
					chmod 777 -R icons/
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					... And try accessing your webserver. You should now have a working 4get instance!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Please make sure to check out how to further <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/configure.md">configure 4get</a> to your liking!
 | 
				
			||||||
							
								
								
									
										58
									
								
								docs/caddy.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,58 @@
 | 
				
			||||||
 | 
					# Install guide for Caddy webserver
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Install dependencies:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`sudo apt install caddy php8.2-dom php8.2-imagick imagemagick php8.2-curl curl php8.2-apcu git`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. Clone this repository where you want to host this from:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`cd /var/www && sudo git clone https://git.konakona.moe/diowo/4get`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3. Set permission on the `icons` directory inside `4get`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`cd /var/www/4get/ && sudo chmod 777 -R icons/`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					4. Add an entry for 4get on your Caddyfile at `/etc/caddy/Caddyfile`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					4get.konakona.moe {
 | 
				
			||||||
 | 
					    root * /var/www/4get
 | 
				
			||||||
 | 
					    file_server
 | 
				
			||||||
 | 
					    encode gzip
 | 
				
			||||||
 | 
					    php_fastcgi unix//var/run/php/php8.2-fpm.sock {
 | 
				
			||||||
 | 
					        index index.php
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    redir /{path}.php{query} 301
 | 
				
			||||||
 | 
					    try_files {path} {path}.php
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Caddy deals with SSL certificates automatically so you don't have to mess with anything. Also if needed, a sample of my Caddyfile can be found [here](https://git.konakona.moe/diowo/misc/src/branch/main/etc/caddy/Caddyfile).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					5. Restart Caddy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`sudo systemctl restart caddy`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Encryption setup
 | 
				
			||||||
 | 
					I'm schizoid (as you should) so I'm gonna setup 4096bit key encryption. To complete this step, you need a domain or subdomain in your possession. Make sure that the DNS shit for your domain has propagated properly before continuing, because certbot is a piece of shit that will error out the ass once you reach 5 attempts under an hour.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Encryption setup on Apache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					certbot --apache --rsa-key-size 4096 -d www.yourdomain.com -d yourdomain.com
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					When it asks to choose a vhost, choose the option with "HTTPS" listed. Don't setup HTTPS for tor, we don't need it (it doesn't even work anyways with let's encrypt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Edit `000-default-le-ssl.conf`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Add this at the end:
 | 
				
			||||||
 | 
					```xml
 | 
				
			||||||
 | 
					<Directory /var/www/html/4get>
 | 
				
			||||||
 | 
						RewriteEngine On
 | 
				
			||||||
 | 
						RewriteCond %{REQUEST_FILENAME}.php -f
 | 
				
			||||||
 | 
						RewriteRule (.*) $1.php [L]
 | 
				
			||||||
 | 
						Options Indexes FollowSymLinks
 | 
				
			||||||
 | 
						AllowOverride All
 | 
				
			||||||
 | 
						Require all granted
 | 
				
			||||||
 | 
					</Directory>
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
							
								
								
									
										63
									
								
								docs/configure.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,63 @@
 | 
				
			||||||
 | 
					# 4Get configuation options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Welcome! This guide assumes that you have a working 4get instance. This will help you configure your instance to the best it can be!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Files location
 | 
				
			||||||
 | 
					1. The main configuration file is located at `data/config.php`
 | 
				
			||||||
 | 
					2. The proxies are located in `data/proxies/*.txt`
 | 
				
			||||||
 | 
					3. The captcha imagesets are located in `data/captcha/your_image_set/*.png`
 | 
				
			||||||
 | 
					4. The captcha font is located in `data/fonts/captcha.ttf`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Cloudflare bypass (TLS check)
 | 
				
			||||||
 | 
					**Note: this only allows you to bypass the browser integrity checks. Captchas & javascript challenges will not be bypassed.**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Configuring this lets you fetch images sitting behind Cloudflare and allows you to scrape the **Yep** & the **Mwmbl** search engines. Please be aware that APT will fight against you and will re-install the openSSL-version of curl constantly when updating.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					First, follow these instructions. Only install the Firefox modules:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					https://github.com/lwthiker/curl-impersonate/blob/main/INSTALL.md#native-build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Once you did this, you should be able to run the following inside your terminal:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					$ curl_ff117 --version
 | 
				
			||||||
 | 
					curl 8.1.1 (x86_64-pc-linux-gnu) libcurl/8.1.1 NSS/3.92 zlib/1.2.13 brotli/1.0.9 zstd/1.5.4 libidn2/2.3.3 nghttp2/1.56.0
 | 
				
			||||||
 | 
					Release-Date: 2023-05-23
 | 
				
			||||||
 | 
					Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss
 | 
				
			||||||
 | 
					Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz NTLM NTLM_WB SSL threadsafe UnixSockets zstd
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					Now, after compiling, you should have a `libcurl-impersonate-ff.so` sitting somewhere. Mine (on my debian install) is located at `/usr/local/lib/libcurl-impersonate-ff.so`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Find the `libcurl.so.4` file used by your current installation of curl. For me, this file is located at `/usr/lib/x86_64-linux-gnu/libcurl.so.4`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now comes the sketchy part: replace `libcurl.so.4` with `libcurl-impersonate-ff.so`. You can do this in the following way:
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					sudo rm /usr/lib/x86_64-linux-gnu/libcurl.so.4
 | 
				
			||||||
 | 
					sudo cp /usr/local/lib/libcurl-impersonate-ff.so /usr/lib/x86_64-linux-gnu/libcurl.so.4
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Make sure to restart your webserver and/or PHP daemon, otherwise it will keep using the old library. You should now be able to bypass Cloudflare's shitty checks!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Robots.txt
 | 
				
			||||||
 | 
					Make sure you configure this right to optimize your search engine presence! Head over to `/robots.txt` and change the `4g.flossboxin.org.in` domain to your own domain.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Proxies
 | 
				
			||||||
 | 
					4get supports rotating proxies for scrapers! Configuring one is really easy.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Head over to the **proxies** folder. Give it any name you want, like `myproxy`, but make sure it has the `txt` extension.
 | 
				
			||||||
 | 
					2. Add your proxies to the file. Examples:
 | 
				
			||||||
 | 
						```conf
 | 
				
			||||||
 | 
						# format -> <protocol>:<address>:<port>:<username>:<password>
 | 
				
			||||||
 | 
						# protocol list:
 | 
				
			||||||
 | 
						# raw_ip, http, https, socks4, socks5, socks4a, socks5_hostname
 | 
				
			||||||
 | 
						socks5:1.1.1.1:juicy:cloaca00
 | 
				
			||||||
 | 
						http:1.3.3.7::
 | 
				
			||||||
 | 
						raw_ip::::
 | 
				
			||||||
 | 
						```
 | 
				
			||||||
 | 
					3. Go to the **main configuration file**. Then, find which website you want to setup a proxy for.
 | 
				
			||||||
 | 
					4. Modify the value `false` with `"myproxy"`, with quotes included and the semicolon at the end.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Done! The scraper you chose should now be using the rotating proxies. When asking for the next page of results, it will use the same proxy to avoid detection!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Important!
 | 
				
			||||||
 | 
					If you ever test out a `socks5` proxy locally on your machine and find out it works but doesn't on your server, try supplying the `socks5_hostname` protocol instead. Hopefully this tip can save you 3 hours of your life!
 | 
				
			||||||
							
								
								
									
										194
									
								
								docs/nginx.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,194 @@
 | 
				
			||||||
 | 
					<h1 align=center>Installation of 4get in NGINX</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div align=right>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> NOTE: As the previous version stated, it is better to follow the <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/apache2.md">Apache2 guide</a> instead of the Nginx one.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> NOTE: This is going to guess that you're using either a <abbr title="(Arch Linux, Artix Linux, Endeavouros, etc...) ">Arch-based system</abbr> or a <abbr title="(Debian, Ubuntu, Devuan, etc...)">Debian-based system</abbr>, although you can still follow it with minor issues.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Login as root.
 | 
				
			||||||
 | 
					2. Upgrade your system:
 | 
				
			||||||
 | 
					   * On Arch-based, run `pacman -Syu`.
 | 
				
			||||||
 | 
					   * On Debian-based, run `apt update`, then `apt upgrade`.
 | 
				
			||||||
 | 
					3. Install the following dependencies:
 | 
				
			||||||
 | 
					   * `git`: So you can clone <a href="https://git.flossboxin.org.in/FbIN/4get">this</a> repository.
 | 
				
			||||||
 | 
					   * `nginx`: So you can run Nginx.
 | 
				
			||||||
 | 
					   * `php-fpm`: This is what allows Nginx to run *(and show)* PHP files.
 | 
				
			||||||
 | 
					   * `php-imagick`, `imagemagick`: Image manipulation.
 | 
				
			||||||
 | 
					   * `php-apcu`: Caching module.
 | 
				
			||||||
 | 
					   * `php-curl`, `curl`:  Transferring data with URLs.
 | 
				
			||||||
 | 
					   * `php-mbstring`: String utils.
 | 
				
			||||||
 | 
					   * `certbot`, `certbot-nginx`: ACME client. Used to create SSL certificates.
 | 
				
			||||||
 | 
					     * In Arch-based distributions:
 | 
				
			||||||
 | 
					       * `pacman -S nginx certbot php-imagick certbot-nginx imagemagick curl php-apcu git`
 | 
				
			||||||
 | 
					     * In Debian-based distributions:
 | 
				
			||||||
 | 
					       * `apt install php-mbstring nginx certbot-nginx certbot php-imagick imagemagick php-curl curl php-apcu git`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div align=right>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> IMPORTANT: `php-curl`, `php-mbstring` might be a Debian-only package, but this needs further fact checking.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> IMPORTANT: If having issues with `php-apcu` or `libsodium`, go to [^1].
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					4. `cd` to `/etc/nginx` and make the `conf.d/` directory if it doesn't exist:
 | 
				
			||||||
 | 
					   * Again, this guesses you're logged in as root.
 | 
				
			||||||
 | 
					   ```sh
 | 
				
			||||||
 | 
					   cd /etc/nginx
 | 
				
			||||||
 | 
					   ls -l conf.d/ # If ls shows conf.d, then it means it exists.
 | 
				
			||||||
 | 
					   # If it does not, run:
 | 
				
			||||||
 | 
					   mkdir conf.d
 | 
				
			||||||
 | 
					   ```
 | 
				
			||||||
 | 
					5. Make a file inside `conf.d/` called `4get.conf` and place the following content:
 | 
				
			||||||
 | 
					   * First run `touch conf.d/4get.conf` then `nano conf.d/4get.conf` to open the nano editor: *(Install it if it is not, or use another editor.)*
 | 
				
			||||||
 | 
					    ```sh
 | 
				
			||||||
 | 
					    server {
 | 
				
			||||||
 | 
					        access_log /dev/null; # Search log file. Do you really need to?
 | 
				
			||||||
 | 
					        error_log /dev/null;  # Error log file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Change this if you have 4get in another folder.
 | 
				
			||||||
 | 
					        root /var/www/4get;
 | 
				
			||||||
 | 
					        # Change 'yourdomain' to your domain.
 | 
				
			||||||
 | 
					        server_name www.yourdomain.com yourdomain.com;
 | 
				
			||||||
 | 
					        # Port to listen to.
 | 
				
			||||||
 | 
					        listen 80;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        location @php {
 | 
				
			||||||
 | 
					            try_files $uri.php $uri/index.php =404;
 | 
				
			||||||
 | 
					            # Change the unix socket address if it's different for you.
 | 
				
			||||||
 | 
					            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
 | 
				
			||||||
 | 
					            fastcgi_index index.php;
 | 
				
			||||||
 | 
					            # Change this to `fastcgi_params` if you use a debian based distribution.
 | 
				
			||||||
 | 
					            include fastcgi.conf;
 | 
				
			||||||
 | 
					            fastcgi_intercept_errors on;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        location / {
 | 
				
			||||||
 | 
					            try_files $uri @php;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        location ~* ^(.*)\.php$ {
 | 
				
			||||||
 | 
					            return 301 $1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ```
 | 
				
			||||||
 | 
					    * The above is a very basic configuration and thus will need tweaking to your personal needs. It should still work as-is, though. A 'real world' example is present in [^2].
 | 
				
			||||||
 | 
					    * After saving the file, check that the `nginx.conf` file inside the main directory includes files inside `conf.d/`:
 | 
				
			||||||
 | 
					      * It should be inside the the http block: *(The following is an example! Don't just Copy and Paste it!)*
 | 
				
			||||||
 | 
					      ```sh
 | 
				
			||||||
 | 
					      http {
 | 
				
			||||||
 | 
					        include       mime.types;
 | 
				
			||||||
 | 
					        include       conf.d/*.conf; 
 | 
				
			||||||
 | 
					        types_hash_max_size 4096;
 | 
				
			||||||
 | 
					        # ...
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      ```
 | 
				
			||||||
 | 
					    * Now, test your configuration with `nginx -t`, if it says that everything is good, restart *(or start)* the Nginx daemon:
 | 
				
			||||||
 | 
					      * This depends on the init manager, most distributions use `systemd`, but it's better practice to include most.
 | 
				
			||||||
 | 
					      ```sh
 | 
				
			||||||
 | 
					      # systemd
 | 
				
			||||||
 | 
					      systemctl stop nginx
 | 
				
			||||||
 | 
					      systemctl start nginxt
 | 
				
			||||||
 | 
					      # or
 | 
				
			||||||
 | 
					      systemctl restart nginx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # openrc
 | 
				
			||||||
 | 
					      rc-service nginx stop
 | 
				
			||||||
 | 
					      rc-service nginx start
 | 
				
			||||||
 | 
					      # or
 | 
				
			||||||
 | 
					      rc-service nginx restart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # runit
 | 
				
			||||||
 | 
					      sv down nginx
 | 
				
			||||||
 | 
					      sv up nginx
 | 
				
			||||||
 | 
					      # or
 | 
				
			||||||
 | 
					      sv restart nginx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # s6
 | 
				
			||||||
 | 
					      s6-rc -d change nginx
 | 
				
			||||||
 | 
					      s6-rc -u change nginx
 | 
				
			||||||
 | 
					      # or
 | 
				
			||||||
 | 
					      s6-svc -r /run/service/nginx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      # dinit
 | 
				
			||||||
 | 
					      dinitctl stop nginx
 | 
				
			||||||
 | 
					      dinitctl start nginx
 | 
				
			||||||
 | 
					      # or
 | 
				
			||||||
 | 
					      dinitctl restart nginx
 | 
				
			||||||
 | 
					      ```
 | 
				
			||||||
 | 
					6. Clone the repository to `/var/www`:
 | 
				
			||||||
 | 
					   * `git clone --depth 1 https://git.flossboxin.org.in/FbIN/4get 4get` - It clones the repository with the depth of one commit *(so it takes less time to download)* and saves the cloned repository as '4get'.
 | 
				
			||||||
 | 
					7. That should be it! There are some extra steps you can take, but it really just depends on you.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h2 align=center>Encryption setup</h2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Generate a certificate for the domain you're using with:
 | 
				
			||||||
 | 
					   * Note that `certbot-nginx` is needed.
 | 
				
			||||||
 | 
					    ```sh
 | 
				
			||||||
 | 
					    certbot --nginx --key-type ecdsa -d www.yourdomain.com -d yourdomain.com
 | 
				
			||||||
 | 
					    ```
 | 
				
			||||||
 | 
					2. After that, certbot will deploy the certificate automatically to your 4get conf file; It should be ready to use from there.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h2 align=center>Tor Setup</h2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div align=right>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> IMPORTANT: Tor onion addresses are very long compared to traditional domains, so, Before doing anything, edit `nginx.conf` and increase <abbr title="This setting in your Nginx configuration controls the internal data structure used to manage multiple server names (hostnames) associated with your web server. Each hostname requires a certain amount of memory within this structure. If the size is insufficient, Nginx will encounter errors."><code>server_names_hash_bucket_size</code></abbr> to your needs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. `cd` to `/etc/nginx` *(if you haven't)* and open your `nginx.conf` file.
 | 
				
			||||||
 | 
					2. Find the line containing `# server_names_hash_bucket_size 64;` inside said file.
 | 
				
			||||||
 | 
					3. Uncomment the line and adjust the value; start with 64, but if you encounter issues, incrementally increase it *(e.g., 128, 256)* until it accommodates your configuration.
 | 
				
			||||||
 | 
					4. Open *(or duplicate the configuration)* and edit it:
 | 
				
			||||||
 | 
					   * Example configuration, again:
 | 
				
			||||||
 | 
					    ```sh
 | 
				
			||||||
 | 
					    server {
 | 
				
			||||||
 | 
					        access_log /dev/null; # Search log file. Do you really need to?
 | 
				
			||||||
 | 
					        error_log /dev/null;  # Error log file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Change this if you have 4get in another folder.
 | 
				
			||||||
 | 
					        root /var/www/4get;
 | 
				
			||||||
 | 
					        # Change 'onionadress.onion' to your onion link.
 | 
				
			||||||
 | 
					        server_name onionadress.onion;
 | 
				
			||||||
 | 
					        # Port to listen to.
 | 
				
			||||||
 | 
					        listen 80;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        location @php {
 | 
				
			||||||
 | 
					            try_files $uri.php $uri/index.php =404;
 | 
				
			||||||
 | 
					            # Change the unix socket address if it's different for you.
 | 
				
			||||||
 | 
					            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
 | 
				
			||||||
 | 
					            fastcgi_index index.php;
 | 
				
			||||||
 | 
					            # Change this to `fastcgi_params` if you use a debian based distribution.
 | 
				
			||||||
 | 
					            include fastcgi.conf;
 | 
				
			||||||
 | 
					            fastcgi_intercept_errors on;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        location / {
 | 
				
			||||||
 | 
					            try_files $uri @php;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        location ~* ^(.*)\.php$ {
 | 
				
			||||||
 | 
					            return 301 $1;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ```
 | 
				
			||||||
 | 
					    A real world example is present in [^2].
 | 
				
			||||||
 | 
					5. Once done, check the configuration with `nginx -t`. If everything's fine and dandy, refer to <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/tor.md">the Tor guide</a> to setup your onion site.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h2 align=center>Other important things</h2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/configure.md">Configuration guide</a>: Things to do after setup.
 | 
				
			||||||
 | 
					2. <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/apache2.md">Apache2 guide</a>: Fallback to this if you couldn't get something to work, or you don't know something.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h2 align=center>Known issues</h2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. https://git.lolcat.ca/lolcat/4get/issues
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[^1]: lolcat/4get#40, If having issues with `libsodium`, or `php-apcu`.
 | 
				
			||||||
 | 
					[^2]: <a href="https://git.nadeko.net/Fijxu/etc-configs/src/branch/selfhost/nginx/conf.d/4get.conf">git.nadeko.net</a> nadeko.net's 4get instance configuration.
 | 
				
			||||||
							
								
								
									
										16
									
								
								docs/tor.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					# Tor setup
 | 
				
			||||||
 | 
					This guide assumes that there is already a configured webserver sitting on port 80 waiting for localhost connections. The <a href="https://git.flossboxin.org.in/FbIN/4get/src/branch/main/docs/apache2.md">apache2 guide</a> guides you through this.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. Login as `root`.
 | 
				
			||||||
 | 
					2. Install `tor`.
 | 
				
			||||||
 | 
					3. Edit `/etc/tor/torrc`
 | 
				
			||||||
 | 
					4. Go to the line that contains `HiddenServiceDir` and `HiddenServicePort`, uncomment those 2 lines and set them like this: 
 | 
				
			||||||
 | 
						```
 | 
				
			||||||
 | 
						HiddenServiceDir /var/lib/tor/4get
 | 
				
			||||||
 | 
						HiddenServicePort 80 127.0.0.1:80
 | 
				
			||||||
 | 
						```
 | 
				
			||||||
 | 
					5. Restart the tor service using `service tor restart`
 | 
				
			||||||
 | 
					6. Wait for a while...
 | 
				
			||||||
 | 
					7. Run `cat /var/lib/tor/4get/hostname`. That is your onion address!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Specify your own tor address
 | 
				
			||||||
							
								
								
									
										39
									
								
								donate.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						$frontend->load(
 | 
				
			||||||
 | 
							"header_nofilters.html",
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"title" => "Donate to the project",
 | 
				
			||||||
 | 
								"class" => " class=\"about\""
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$left =
 | 
				
			||||||
 | 
						explode(
 | 
				
			||||||
 | 
							"\n",
 | 
				
			||||||
 | 
							file_get_contents("template/donate.html")
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$out = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					foreach($left as $line){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$out .= trim($line);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						$frontend->load(
 | 
				
			||||||
 | 
							"search.html",
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"timetaken" => null,
 | 
				
			||||||
 | 
								"class" => "",
 | 
				
			||||||
 | 
								"right-left" => "",
 | 
				
			||||||
 | 
								"right-right" => "",
 | 
				
			||||||
 | 
								"left" => $out
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								favicon.ico
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.7 KiB  | 
							
								
								
									
										363
									
								
								favicon.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,363 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!isset($_GET["s"])){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						header("X-Error: Missing parameter (s)ite");
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					new favicon($_GET["s"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class favicon{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct($url){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("Content-Type: image/png");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(substr_count($url, "/") !== 2){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								header("X-Error: Only provide the protocol and domain");
 | 
				
			||||||
 | 
								$this->defaulticon();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$filename = str_replace(["https://", "http://"], "", $url);
 | 
				
			||||||
 | 
							header("Content-Disposition: inline; filename=\"{$filename}.png\"");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/curlproxy.php";
 | 
				
			||||||
 | 
							$this->proxy = new proxy(false);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->filename = parse_url($url, PHP_URL_HOST);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Check if we have the favicon stored locally
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if(file_exists("icons/" . $filename . ".png")){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								$handle = fopen("icons/" . $filename . ".png", "r");
 | 
				
			||||||
 | 
								echo fread($handle, filesize("icons/" . $filename . ".png"));
 | 
				
			||||||
 | 
								fclose($handle);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Scrape html
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$payload = $this->proxy->get($url, $this->proxy::req_web, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								header("X-Error: Could not fetch HTML (" . $error->getMessage() . ")");
 | 
				
			||||||
 | 
								$this->favicon404();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							//$payload["body"] = '<link rel="manifest" id="MANIFEST_LINK" href="/data/manifest/" crossorigin="use-credentials" />';
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get link tags
 | 
				
			||||||
 | 
							preg_match_all(
 | 
				
			||||||
 | 
								'/< *link +(.*)[\/]?>/Uixs',
 | 
				
			||||||
 | 
								$payload["body"],
 | 
				
			||||||
 | 
								$linktags
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Get relevant tags
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$linktags = $linktags[1];
 | 
				
			||||||
 | 
							$attributes = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							header("Content-Type: text/plain");
 | 
				
			||||||
 | 
							print_r($linktags);
 | 
				
			||||||
 | 
							print_r($payload);
 | 
				
			||||||
 | 
							die();*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<count($linktags); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get attributes
 | 
				
			||||||
 | 
								preg_match_all(
 | 
				
			||||||
 | 
									'/([A-Za-z0-9]+) *= *("[^"]*"|[^" ]+)/s',
 | 
				
			||||||
 | 
									$linktags[$i],
 | 
				
			||||||
 | 
									$tags
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								for($k=0; $k<count($tags[1]); $k++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$attributes[$i][] = [
 | 
				
			||||||
 | 
										"name" => $tags[1][$k],
 | 
				
			||||||
 | 
										"value" => trim($tags[2][$k], "\" \n\r\t\v\x00")
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							unset($payload);
 | 
				
			||||||
 | 
							unset($linktags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$href = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// filter out the tags we want
 | 
				
			||||||
 | 
							foreach($attributes as &$group){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$tmp_href = null;
 | 
				
			||||||
 | 
								$tmp_rel = null;
 | 
				
			||||||
 | 
								$badtype = false;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($group as &$attribute){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									switch($attribute["name"]){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										case "rel":
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$attribute["value"] = strtolower($attribute["value"]);
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(
 | 
				
			||||||
 | 
												(
 | 
				
			||||||
 | 
													$attribute["value"] == "icon" ||
 | 
				
			||||||
 | 
													$attribute["value"] == "manifest" ||
 | 
				
			||||||
 | 
													$attribute["value"] == "shortcut icon" ||
 | 
				
			||||||
 | 
													$attribute["value"] == "apple-touch-icon" ||
 | 
				
			||||||
 | 
													$attribute["value"] == "mask-icon"
 | 
				
			||||||
 | 
												) === false
 | 
				
			||||||
 | 
											){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$tmp_rel = $attribute["value"];
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										case "type":
 | 
				
			||||||
 | 
											$attribute["value"] = explode("/", $attribute["value"], 2);
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(strtolower($attribute["value"][0]) != "image"){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$badtype = true;
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										case "href":
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											// must not contain invalid characters
 | 
				
			||||||
 | 
											// must be bigger than 1
 | 
				
			||||||
 | 
											if(
 | 
				
			||||||
 | 
												filter_var($attribute["value"], FILTER_SANITIZE_URL) == $attribute["value"] &&
 | 
				
			||||||
 | 
												strlen($attribute["value"]) > 0
 | 
				
			||||||
 | 
											){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$tmp_href = $attribute["value"];
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$badtype === false &&
 | 
				
			||||||
 | 
									$tmp_rel !== null &&
 | 
				
			||||||
 | 
									$tmp_href !== null
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$href[$tmp_rel] = $tmp_href;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Priority list
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							header("Content-Type: text/plain");
 | 
				
			||||||
 | 
							print_r($href);
 | 
				
			||||||
 | 
							die();*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($href["icon"])){ $href = $href["icon"]; }
 | 
				
			||||||
 | 
							elseif(isset($href["apple-touch-icon"])){ $href = $href["apple-touch-icon"]; }
 | 
				
			||||||
 | 
							elseif(isset($href["manifest"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// attempt to parse manifest, but fallback to []
 | 
				
			||||||
 | 
								$href = $this->parsemanifest($href["manifest"], $url);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(is_array($href)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($href["mask-icon"])){ $href = $href["mask-icon"]; }
 | 
				
			||||||
 | 
								elseif(isset($href["shortcut icon"])){ $href = $href["shortcut icon"]; }
 | 
				
			||||||
 | 
								else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$href = "/favicon.ico";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$href = $this->proxy->getabsoluteurl($href, $url);
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							header("Content-type: text/plain");
 | 
				
			||||||
 | 
							echo $href;
 | 
				
			||||||
 | 
							die();*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Download the favicon
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							//$href = "https://git.flossboxin.org.in/assets/img/logo.svg";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$payload =
 | 
				
			||||||
 | 
									$this->proxy->get(
 | 
				
			||||||
 | 
										$href,
 | 
				
			||||||
 | 
										$this->proxy::req_image,
 | 
				
			||||||
 | 
										true,
 | 
				
			||||||
 | 
										$url
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								header("X-Error: Could not fetch the favicon (" . $error->getMessage() . ")");
 | 
				
			||||||
 | 
								$this->favicon404();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Parse the file format
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							$image = null;
 | 
				
			||||||
 | 
							$format = $this->proxy->getimageformat($payload, $image);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Convert the image
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
									@todo: fix issues with avif+transparency
 | 
				
			||||||
 | 
									maybe using GD as fallback?
 | 
				
			||||||
 | 
								*/
 | 
				
			||||||
 | 
								if($format !== false){
 | 
				
			||||||
 | 
									$image->setFormat($format);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image->setBackgroundColor(new ImagickPixel("transparent"));
 | 
				
			||||||
 | 
								$image->readImageBlob($payload["body"]);
 | 
				
			||||||
 | 
								$image->resizeImage(16, 16, imagick::FILTER_LANCZOS, 1);
 | 
				
			||||||
 | 
								$image->setFormat("png");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image = $image->getImageBlob();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// save favicon
 | 
				
			||||||
 | 
								$handle = fopen("icons/" . $this->filename . ".png", "w");
 | 
				
			||||||
 | 
								fwrite($handle, $image, strlen($image));
 | 
				
			||||||
 | 
								fclose($handle);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								echo $image;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(ImagickException $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								header("X-Error: Could not convert the favicon: (" . $error->getMessage() . ")");
 | 
				
			||||||
 | 
								$this->favicon404();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function parsemanifest($href, $url){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								// check if base64-encoded JSON manifest
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/^data:application\/json;base64,([A-Za-z0-9=]*)$/',
 | 
				
			||||||
 | 
									$href,
 | 
				
			||||||
 | 
									$json
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json = base64_decode($json[1]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($json === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// could not decode the manifest regex
 | 
				
			||||||
 | 
									return [];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$json =
 | 
				
			||||||
 | 
										$this->proxy->get(
 | 
				
			||||||
 | 
											$this->proxy->getabsoluteurl($href, $url),
 | 
				
			||||||
 | 
											$this->proxy::req_web,
 | 
				
			||||||
 | 
											false,
 | 
				
			||||||
 | 
											$url
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$json = $json["body"];
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// could not fetch the manifest
 | 
				
			||||||
 | 
									return [];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// manifest did not return valid json
 | 
				
			||||||
 | 
								return [];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($json["start_url"]) &&
 | 
				
			||||||
 | 
								$this->proxy->validateurl($json["start_url"])
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url = $json["start_url"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($json["icons"][0]["src"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// manifest does not contain a path to the favicon
 | 
				
			||||||
 | 
								return [];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// horay, return the favicon path
 | 
				
			||||||
 | 
							return $json["icons"][0]["src"];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function favicon404(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// fallback to google favicons
 | 
				
			||||||
 | 
							// ... probably blocked by cuckflare
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image =
 | 
				
			||||||
 | 
									$this->proxy->get(
 | 
				
			||||||
 | 
										"https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://{$this->filename}&size=16",
 | 
				
			||||||
 | 
										$this->proxy::req_image
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->defaulticon();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// write favicon from google
 | 
				
			||||||
 | 
							$handle = fopen("icons/" . $this->filename . ".png", "w");
 | 
				
			||||||
 | 
							fwrite($handle, $image["body"], strlen($image["body"]));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							echo $image["body"];
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function defaulticon(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// give 404 and fuck off
 | 
				
			||||||
 | 
							http_response_code(404);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$handle = fopen("lib/favicon404.png", "r");
 | 
				
			||||||
 | 
							echo fread($handle, filesize("lib/favicon404.png"));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								icons/vb.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 22 KiB  | 
							
								
								
									
										77
									
								
								images.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,77 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Initialize random shit
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters("images");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					new bot_protection($frontend, $get, $filters, "images", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$payload = [
 | 
				
			||||||
 | 
						"timetaken" => microtime(true),
 | 
				
			||||||
 | 
						"images" => "",
 | 
				
			||||||
 | 
						"nextpage" => ""
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						$results = $scraper->image($get);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $error){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$frontend->drawscrapererror($error->getMessage(), $get, "images", $payload["timetaken"]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(count($results["image"]) === 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["images"] =
 | 
				
			||||||
 | 
							'<div class="infobox">' .
 | 
				
			||||||
 | 
								"<h1>Nobody here but us chickens!</h1>" .
 | 
				
			||||||
 | 
								'Have you tried:' .
 | 
				
			||||||
 | 
								'<ul>' .
 | 
				
			||||||
 | 
									'<li>Using a different scraper</li>' .
 | 
				
			||||||
 | 
									'<li>Using fewer keywords</li>' .
 | 
				
			||||||
 | 
									'<li>Defining broader filters (Is NSFW turned off?)</li>' .
 | 
				
			||||||
 | 
								'</ul>' .
 | 
				
			||||||
 | 
							'</div>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					foreach($results["image"] as $image){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["images"] .=
 | 
				
			||||||
 | 
							'<div class="image-wrapper" title="' . htmlspecialchars($image["title"]) .'" data-json="' . htmlspecialchars(json_encode($image["source"])) . '">' .
 | 
				
			||||||
 | 
								'<div class="image">' .
 | 
				
			||||||
 | 
									'<a href="' . htmlspecialchars($image["source"][0]["url"]) . '" rel="noreferrer nofollow" class="thumb">' .
 | 
				
			||||||
 | 
										'<img src="' . $frontend->htmlimage($image["source"][count($image["source"]) - 1]["url"], "thumb") . '" alt="thumbnail">';
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($image["source"][0]["width"] !== null){
 | 
				
			||||||
 | 
										$payload["images"] .= '<div class="duration">' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '</div>';
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								$payload["images"] .=
 | 
				
			||||||
 | 
									'</a>' .
 | 
				
			||||||
 | 
									'<a href="' . htmlspecialchars($image["url"]) . '" rel="noreferrer nofollow">' .
 | 
				
			||||||
 | 
										'<div class="title">' . htmlspecialchars(parse_url($image["url"], PHP_URL_HOST)) . '</div>' .
 | 
				
			||||||
 | 
										'<div class="description">' . $frontend->highlighttext($get["s"], $image["title"]) . '</div>' .
 | 
				
			||||||
 | 
									'</a>' .
 | 
				
			||||||
 | 
								'</div>' .
 | 
				
			||||||
 | 
							'</div>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if($results["npt"] !== null){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["nextpage"] =
 | 
				
			||||||
 | 
							'<a href="' . $frontend->htmlnextpage($get, $results["npt"], "images") . '" class="nextpage img">Next page ></a>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo $frontend->load("images.html", $payload);
 | 
				
			||||||
							
								
								
									
										15
									
								
								index.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,15 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$images = glob("");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo $frontend->load(
 | 
				
			||||||
 | 
						"home.html",
 | 
				
			||||||
 | 
						[
 | 
				
			||||||
 | 
							"server_short_description" => htmlspecialchars(config::SERVER_SHORT_DESCRIPTION),
 | 
				
			||||||
 | 
							"banner" => $images[rand(0, count($images) - 1)]
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
							
								
								
									
										55
									
								
								instances.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,55 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$params = "";
 | 
				
			||||||
 | 
					$first = true;
 | 
				
			||||||
 | 
					foreach($_GET as $key => $value){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(
 | 
				
			||||||
 | 
							!is_string($value) ||
 | 
				
			||||||
 | 
							$key == "target"
 | 
				
			||||||
 | 
						){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							continue;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($first === true){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$first = false;
 | 
				
			||||||
 | 
							$params = "?";
 | 
				
			||||||
 | 
						}else{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$params .= "&";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$params .= urlencode($key) . "=" . urlencode($value);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(
 | 
				
			||||||
 | 
						!isset($_GET["target"]) ||
 | 
				
			||||||
 | 
						!is_string($_GET["target"])
 | 
				
			||||||
 | 
					){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$target = "";
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$target = "/" . urlencode($_GET["target"]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$instances = "";
 | 
				
			||||||
 | 
					foreach(config::INSTANCES as $instance){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$instances .= '<tr><td class="expand"><a href="' . htmlspecialchars($instance) . $target . $params . '" target="_BLANK" rel="noreferer">' . htmlspecialchars($instance) . '</a></td></tr>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						$frontend->load(
 | 
				
			||||||
 | 
							"instances.html",
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"instances_html" => $instances
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
							
								
								
									
										178
									
								
								lib/backend.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,178 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					class backend{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct($scraper){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->scraper = $scraper;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Proxy stuff
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						public function get_ip(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$pool = constant("config::PROXY_" . strtoupper($this->scraper));
 | 
				
			||||||
 | 
							if($pool === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// we don't want a proxy, fuck off!
 | 
				
			||||||
 | 
								return 'raw_ip::::';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// indent
 | 
				
			||||||
 | 
							$proxy_index_raw = apcu_inc("p." . $this->scraper);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$proxylist = file_get_contents("data/proxies/" . $pool . ".txt");
 | 
				
			||||||
 | 
							$proxylist = explode("\n", $proxylist);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// ignore empty or commented lines
 | 
				
			||||||
 | 
							$proxylist = array_filter($proxylist, function($entry){
 | 
				
			||||||
 | 
								$entry = ltrim($entry);
 | 
				
			||||||
 | 
								return strlen($entry) > 0 && substr($entry, 0, 1) != "#";
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$proxylist = array_values($proxylist);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $proxylist[$proxy_index_raw % count($proxylist)];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// this function is also called directly on nextpage
 | 
				
			||||||
 | 
						public function assign_proxy(&$curlproc, string $ip){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// parse proxy line
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								$type,
 | 
				
			||||||
 | 
								$address,
 | 
				
			||||||
 | 
								$port,
 | 
				
			||||||
 | 
								$username,
 | 
				
			||||||
 | 
								$password
 | 
				
			||||||
 | 
							] = explode(":", $ip, 5);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($type){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "raw_ip":
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "http":
 | 
				
			||||||
 | 
								case "https":
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXY, $type . "://" . $address . ":" . $port);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "socks4":
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXY, $address . ":" . $port);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "socks5":
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXY, $address . ":" . $port);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "socks4a":
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXY, $address . ":" . $port);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "socks5_hostname":
 | 
				
			||||||
 | 
								case "socks5h":
 | 
				
			||||||
 | 
								case "socks5a":
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_PROXY, $address . ":" . $port);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($username != ""){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_PROXYUSERPWD, $username . ":" . $password);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Next page stuff
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						public function store(string $payload, string $page, string $proxy){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$key = sodium_crypto_secretbox_keygen();
 | 
				
			||||||
 | 
							$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$requestid = apcu_inc("requestid");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							apcu_store(
 | 
				
			||||||
 | 
								$page[0] . "." . // first letter of page name
 | 
				
			||||||
 | 
								$this->scraper . // scraper name
 | 
				
			||||||
 | 
								$requestid,
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									$nonce,
 | 
				
			||||||
 | 
									$proxy,
 | 
				
			||||||
 | 
									// compress and encrypt
 | 
				
			||||||
 | 
									sodium_crypto_secretbox(
 | 
				
			||||||
 | 
										gzdeflate($payload),
 | 
				
			||||||
 | 
										$nonce,
 | 
				
			||||||
 | 
										$key
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								900 // cache information for 15 minutes
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return 
 | 
				
			||||||
 | 
								$this->scraper . $requestid . "." .
 | 
				
			||||||
 | 
								rtrim(strtr(base64_encode($key), '+/', '-_'), '=');
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function get(string $npt, string $page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$page = $page[0];
 | 
				
			||||||
 | 
							$explode = explode(".", $npt, 2);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($explode) !== 2){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Malformed nextPageToken!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$apcu = $page . "." . $explode[0];
 | 
				
			||||||
 | 
							$key = $explode[1];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$payload = apcu_fetch($apcu);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($payload === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("The next page token is invalid or has expired!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$key =
 | 
				
			||||||
 | 
								base64_decode(
 | 
				
			||||||
 | 
									str_pad(
 | 
				
			||||||
 | 
										strtr($key, '-_', '+/'),
 | 
				
			||||||
 | 
										strlen($key) % 4,
 | 
				
			||||||
 | 
										'=',
 | 
				
			||||||
 | 
										STR_PAD_RIGHT
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// decrypt and decompress data
 | 
				
			||||||
 | 
							$payload[2] =
 | 
				
			||||||
 | 
								gzinflate(
 | 
				
			||||||
 | 
									sodium_crypto_secretbox_open(
 | 
				
			||||||
 | 
										$payload[2], // data
 | 
				
			||||||
 | 
										$payload[0], // nonce
 | 
				
			||||||
 | 
										$key
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($payload[2] === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("The next page token is invalid or has expired!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// remove the key after using successfully
 | 
				
			||||||
 | 
							apcu_delete($apcu);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								$payload[2], // data
 | 
				
			||||||
 | 
								$payload[1] // proxy
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										144
									
								
								lib/bingcache-todo-fix.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,144 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// https://www.bing.com/search?q=url%3Ahttps%3A%2F%2Fflossboxin.org.in
 | 
				
			||||||
 | 
					// https://cc.bingj.com/cache.aspx?q=url%3ahttps%3a%2f%2f4g.flossboxin.org.in&d=4769685974291356&mkt=en-DE&setlang=en-GB&w=tEsWuE7HW3Z5AIPQMVkDH4WaotS4LrK-
 | 
				
			||||||
 | 
					// <div class="b_attribution" u="0N|5119|4769685974291356|tEsWuE7HW3Z5AIPQMVkDH4WaotS4LrK-" tabindex="0">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					new bingcache();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class bingcache{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!isset($_GET["s"]) ||
 | 
				
			||||||
 | 
								$this->validate_url($_GET["s"]) === false
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var_dump($this->validate_url($_GET["s"]));
 | 
				
			||||||
 | 
								$this->do404("Please provide a valid URL.");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$url = $_GET["s"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curlproc,
 | 
				
			||||||
 | 
								CURLOPT_URL,
 | 
				
			||||||
 | 
								"https://www.bing.com/search?q=url%3A" .
 | 
				
			||||||
 | 
								urlencode($url)
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curlproc,
 | 
				
			||||||
 | 
								CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
								["User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0",
 | 
				
			||||||
 | 
								"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",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"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, 5);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$data = curl_exec($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(curl_errno($curlproc)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Failed to connect to bing servers. Please try again later.");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							preg_match(
 | 
				
			||||||
 | 
								'/<div class="b_attribution" u="(.*)" tabindex="0">/',
 | 
				
			||||||
 | 
								$data,
 | 
				
			||||||
 | 
								$keys
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							print_r($keys);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($keys) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->do404("Bing has not archived this URL.");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$keys = explode("|", $keys[1]);
 | 
				
			||||||
 | 
							$count = count($keys);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//header("Location: https://cc.bingj.com/cache.aspx?d=" . $keys[$count - 2] . "&w=" . $keys[$count - 1]);
 | 
				
			||||||
 | 
							echo("Location: https://cc.bingj.com/cache.aspx?d=" . $keys[$count - 2] . "&w=" . $keys[$count - 1]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function do404($text){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
							include "lib/frontend.php";
 | 
				
			||||||
 | 
							$frontend = new frontend();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							echo
 | 
				
			||||||
 | 
								$frontend->load(
 | 
				
			||||||
 | 
									"error.html",
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"title" => "Shit",
 | 
				
			||||||
 | 
										"text" => $text
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function validate_url($url){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$url_parts = parse_url($url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check if required parts are there
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!isset($url_parts["scheme"]) ||
 | 
				
			||||||
 | 
								!(
 | 
				
			||||||
 | 
									$url_parts["scheme"] == "http" ||
 | 
				
			||||||
 | 
									$url_parts["scheme"] == "https"
 | 
				
			||||||
 | 
								) ||
 | 
				
			||||||
 | 
								!isset($url_parts["host"])
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								// if its not an RFC-valid URL
 | 
				
			||||||
 | 
								!filter_var($url, FILTER_VALIDATE_URL)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$ip = 
 | 
				
			||||||
 | 
								str_replace(
 | 
				
			||||||
 | 
									["[", "]"], // handle ipv6
 | 
				
			||||||
 | 
									"",
 | 
				
			||||||
 | 
									$url_parts["host"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// if its not an IP
 | 
				
			||||||
 | 
							if(!filter_var($ip, FILTER_VALIDATE_IP)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// resolve domain's IP
 | 
				
			||||||
 | 
								$ip = gethostbyname($url_parts["host"] . ".");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check if its localhost
 | 
				
			||||||
 | 
							return filter_var(
 | 
				
			||||||
 | 
								$ip,
 | 
				
			||||||
 | 
								FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										281
									
								
								lib/bot_protection.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,281 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class bot_protection{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct($frontend, $get, $filters, $page, $output){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check if we want captcha
 | 
				
			||||||
 | 
							if(config::BOT_PROTECTION !== 1){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								apcu_inc("real_requests");
 | 
				
			||||||
 | 
								if($output === true){
 | 
				
			||||||
 | 
									$frontend->loadheader(
 | 
				
			||||||
 | 
										$get,
 | 
				
			||||||
 | 
										$filters,
 | 
				
			||||||
 | 
										$page
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Validate cookie, if it exists
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if(isset($_COOKIE["pass"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									// check if key is not malformed
 | 
				
			||||||
 | 
									preg_match(
 | 
				
			||||||
 | 
										'/^k[0-9]+\.[A-Za-z0-9_]{20}$/',
 | 
				
			||||||
 | 
										$_COOKIE["pass"]
 | 
				
			||||||
 | 
									) &&
 | 
				
			||||||
 | 
									// does key exist
 | 
				
			||||||
 | 
									apcu_exists($_COOKIE["pass"])
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
									// exists, increment counter
 | 
				
			||||||
 | 
									$inc = apcu_inc($_COOKIE["pass"]);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// we start counting from 1
 | 
				
			||||||
 | 
									// when it has been incremented to 102, it has reached
 | 
				
			||||||
 | 
									// 100 reqs
 | 
				
			||||||
 | 
									if($inc >= config::MAX_SEARCHES + 2){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// reached limit, delete and give captcha
 | 
				
			||||||
 | 
										apcu_delete($_COOKIE["pass"]);
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// the cookie is OK! dont die() and give results
 | 
				
			||||||
 | 
										apcu_inc("real_requests");
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if($output === true){
 | 
				
			||||||
 | 
											$frontend->loadheader(
 | 
				
			||||||
 | 
												$get,
 | 
				
			||||||
 | 
												$filters,
 | 
				
			||||||
 | 
												$page
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($output === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								http_response_code(401); // forbidden
 | 
				
			||||||
 | 
								echo json_encode([
 | 
				
			||||||
 | 
									"status" => "The \"pass\" token in your cookies is missing or has expired!!"
 | 
				
			||||||
 | 
								]);
 | 
				
			||||||
 | 
								die();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Validate form data
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							$lines =
 | 
				
			||||||
 | 
								explode(
 | 
				
			||||||
 | 
									"\r\n",
 | 
				
			||||||
 | 
									file_get_contents("php://input")
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$invalid = false;
 | 
				
			||||||
 | 
							$answers = [];
 | 
				
			||||||
 | 
							$key = false;
 | 
				
			||||||
 | 
							$error = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							foreach($lines as $line){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$line = explode("=", $line, 2);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($line) !== 2){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$invalid = true;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/^c\[([0-9]+)\]$/',
 | 
				
			||||||
 | 
									$line[0],
 | 
				
			||||||
 | 
									$regex
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$line[1] != "on" ||
 | 
				
			||||||
 | 
									!isset($regex[0][1])
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// check if its the v key
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$line[0] == "v" &&
 | 
				
			||||||
 | 
										preg_match(
 | 
				
			||||||
 | 
											'/^c[0-9]+\.[A-Za-z0-9_]{20}$/',
 | 
				
			||||||
 | 
											$line[1]
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$key = apcu_fetch($line[1]);
 | 
				
			||||||
 | 
										apcu_delete($line[1]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$regex = (int)$regex[1];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$regex >= 16 ||
 | 
				
			||||||
 | 
									$regex <= -1
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$invalid = true;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$answers[] = $regex;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!$invalid &&
 | 
				
			||||||
 | 
								$key !== false // has captcha been gen'd?
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								$check = count($key);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// validate answer
 | 
				
			||||||
 | 
								for($i=0; $i<count($answers); $i++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(in_array($answers[$i], $key)){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$check--;
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$check = -1;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($check === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// we passed the captcha
 | 
				
			||||||
 | 
									// set cookie
 | 
				
			||||||
 | 
									$inc = apcu_inc("cookie");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$key = "k" . $inc . "." . $this->randomchars();
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									apcu_inc($key, 1, $stupid, 86400);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									apcu_inc("real_requests");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									setcookie(
 | 
				
			||||||
 | 
										"pass",
 | 
				
			||||||
 | 
										$key,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"expires" => time() + 86400, // expires in 24 hours
 | 
				
			||||||
 | 
											"samesite" => "Lax",
 | 
				
			||||||
 | 
											"path" => "/"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$frontend->loadheader(
 | 
				
			||||||
 | 
										$get,
 | 
				
			||||||
 | 
										$filters,
 | 
				
			||||||
 | 
										$page
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$error = "<div class=\"quote\">You were <a href=\"https://www.youtube.com/watch?v=e1d7fkQx2rk\" target=\"_BLANK\" rel=\"noreferrer nofollow\">kicked out of Mensa.</a> Please try again.</div>";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$key = "c" . apcu_inc("captcha_gen", 1) . "." . $this->randomchars();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$payload = [
 | 
				
			||||||
 | 
								"timetaken" => microtime(true),
 | 
				
			||||||
 | 
								"class" => "",
 | 
				
			||||||
 | 
								"right-left" => "",
 | 
				
			||||||
 | 
								"right-right" => "",
 | 
				
			||||||
 | 
								"left" =>
 | 
				
			||||||
 | 
									'<div class="infobox">' .
 | 
				
			||||||
 | 
										'<h1>IQ test</h1>' .
 | 
				
			||||||
 | 
										'IQ test has been enabled due to bot abuse on the network.<br>' .
 | 
				
			||||||
 | 
										'Solving this IQ test will let you make 100 searches today. I will add an invite system to bypass this soon...' .
 | 
				
			||||||
 | 
										$error .
 | 
				
			||||||
 | 
										'<form method="POST" enctype="text/plain" autocomplete="off">' .
 | 
				
			||||||
 | 
											'<div class="captcha-wrapper">' .
 | 
				
			||||||
 | 
												'<div class="captcha">' .
 | 
				
			||||||
 | 
													'<img src="captcha?v=' . $key . '" alt="Captcha image">' .
 | 
				
			||||||
 | 
													'<div class="captcha-controls">' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[0]" id="c0">' .
 | 
				
			||||||
 | 
														'<label for="c0"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[1]" id="c1">' .
 | 
				
			||||||
 | 
														'<label for="c1"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[2]" id="c2">' .
 | 
				
			||||||
 | 
														'<label for="c2"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[3]" id="c3">' .
 | 
				
			||||||
 | 
														'<label for="c3"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[4]" id="c4">' .
 | 
				
			||||||
 | 
														'<label for="c4"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[5]" id="c5">' .
 | 
				
			||||||
 | 
														'<label for="c5"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[6]" id="c6">' .
 | 
				
			||||||
 | 
														'<label for="c6"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[7]" id="c7">' .
 | 
				
			||||||
 | 
														'<label for="c7"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[8]" id="c8">' .
 | 
				
			||||||
 | 
														'<label for="c8"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[9]" id="c9">' .
 | 
				
			||||||
 | 
														'<label for="c9"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[10]" id="c10">' .
 | 
				
			||||||
 | 
														'<label for="c10"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[11]" id="c11">' .
 | 
				
			||||||
 | 
														'<label for="c11"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[12]" id="c12">' .
 | 
				
			||||||
 | 
														'<label for="c12"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[13]" id="c13">' .
 | 
				
			||||||
 | 
														'<label for="c13"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[14]" id="c14">' .
 | 
				
			||||||
 | 
														'<label for="c14"></label>' .
 | 
				
			||||||
 | 
														'<input type="checkbox" name="c[15]" id="c15">' .
 | 
				
			||||||
 | 
														'<label for="c15"></label>' .
 | 
				
			||||||
 | 
													'</div>' .
 | 
				
			||||||
 | 
												'</div>' .
 | 
				
			||||||
 | 
											'</div>' .
 | 
				
			||||||
 | 
											'<input type="hidden" name="v" value="' . $key . '">' .
 | 
				
			||||||
 | 
											'<input type="submit" value="Check IQ" class="captcha-submit">' .
 | 
				
			||||||
 | 
										'</form>' .
 | 
				
			||||||
 | 
									'</div>'
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$frontend->loadheader(
 | 
				
			||||||
 | 
								$get,
 | 
				
			||||||
 | 
								$filters,
 | 
				
			||||||
 | 
								$page
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							echo $frontend->load("search.html", $payload);
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function randomchars(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$chars =
 | 
				
			||||||
 | 
								array_merge(
 | 
				
			||||||
 | 
									range("A", "Z"),
 | 
				
			||||||
 | 
									range("a", "z"),
 | 
				
			||||||
 | 
									range(0, 9)
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$chars[] = "_";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$c = count($chars) - 1;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$key = "";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<20; $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$key .= $chars[random_int(0, $c)];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $key;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										660
									
								
								lib/curlproxy.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,660 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class proxy{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public const req_web = 0;
 | 
				
			||||||
 | 
						public const req_image = 1;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct($cache = true){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->cache = $cache;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function do404(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							http_response_code(404);
 | 
				
			||||||
 | 
							header("Content-Type: image/png");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$handle = fopen("lib/img404.png", "r");
 | 
				
			||||||
 | 
							echo fread($handle, filesize("lib/img404.png"));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getabsoluteurl($path, $relative){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($this->validateurl($path)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $path;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(substr($path, 0, 2) == "//"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return "https:" . $path;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$url = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$relative = parse_url($relative);
 | 
				
			||||||
 | 
							$url = $relative["scheme"] . "://";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($relative["user"]) &&
 | 
				
			||||||
 | 
								isset($relative["pass"])
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url .= $relative["user"] . ":" . $relative["pass"] . "@";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$url .= $relative["host"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($relative["path"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$relative["path"] = explode(
 | 
				
			||||||
 | 
									"/",
 | 
				
			||||||
 | 
									$relative["path"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								unset($relative["path"][count($relative["path"]) - 1]);
 | 
				
			||||||
 | 
								$relative["path"] = implode("/", $relative["path"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url .= $relative["path"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								strlen($path) !== 0 &&
 | 
				
			||||||
 | 
								$path[0] !== "/"
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url .= "/";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$url .= $path;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $url;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function validateurl($url){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$url_parts = parse_url($url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check if required parts are there
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!isset($url_parts["scheme"]) ||
 | 
				
			||||||
 | 
								!(
 | 
				
			||||||
 | 
									$url_parts["scheme"] == "http" ||
 | 
				
			||||||
 | 
									$url_parts["scheme"] == "https"
 | 
				
			||||||
 | 
								) ||
 | 
				
			||||||
 | 
								!isset($url_parts["host"])
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$ip = 
 | 
				
			||||||
 | 
								str_replace(
 | 
				
			||||||
 | 
									["[", "]"], // handle ipv6
 | 
				
			||||||
 | 
									"",
 | 
				
			||||||
 | 
									$url_parts["host"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// if its not an IP
 | 
				
			||||||
 | 
							if(!filter_var($ip, FILTER_VALIDATE_IP)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// resolve domain's IP
 | 
				
			||||||
 | 
								$ip = gethostbyname($url_parts["host"] . ".");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check if its localhost
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								filter_var(
 | 
				
			||||||
 | 
									$ip,
 | 
				
			||||||
 | 
									FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
 | 
				
			||||||
 | 
								) === false
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function get($url, $reqtype = self::req_web, $acceptallcodes = false, $referer = null, $redirectcount = 0){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($redirectcount === 5){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Too many redirects");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($url == "https://i.imgur.com/removed.png"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Encountered imgur 404");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// sanitize URL
 | 
				
			||||||
 | 
							if($this->validateurl($url) === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Invalid URL");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->clientcache();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curl = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_HEADER, 1);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($reqtype){
 | 
				
			||||||
 | 
								case self::req_web:
 | 
				
			||||||
 | 
									curl_setopt(
 | 
				
			||||||
 | 
										$curl,
 | 
				
			||||||
 | 
										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, deflate",
 | 
				
			||||||
 | 
											"DNT: 1",
 | 
				
			||||||
 | 
											"Connection: keep-alive",
 | 
				
			||||||
 | 
											"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
											"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
											"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
											"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
											"Sec-Fetch-User: ?1"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case self::req_image:
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($referer === null){
 | 
				
			||||||
 | 
										$referer = explode("/", $url, 4);
 | 
				
			||||||
 | 
										array_pop($referer);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$referer = implode("/", $referer);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									curl_setopt(
 | 
				
			||||||
 | 
										$curl,
 | 
				
			||||||
 | 
										CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
											"Accept: image/avif,image/webp,*/*",
 | 
				
			||||||
 | 
											"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
											"Accept-Encoding: gzip, deflate",
 | 
				
			||||||
 | 
											"DNT: 1",
 | 
				
			||||||
 | 
											"Connection: keep-alive",
 | 
				
			||||||
 | 
											"Referer: {$referer}"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_TIMEOUT, 30);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// limit size of payloads
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_BUFFERSIZE, 1024);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_NOPROGRESS, false);
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curl,
 | 
				
			||||||
 | 
								CURLOPT_PROGRESSFUNCTION,
 | 
				
			||||||
 | 
								function($downloadsize, $downloaded, $uploadsize, $uploaded
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// if $downloaded exceeds 100MB, fuck off
 | 
				
			||||||
 | 
								return ($downloaded > 100000000) ? 1 : 0;
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$body = curl_exec($curl);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(curl_errno($curl)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception(curl_error($curl));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curl);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$headers = [];
 | 
				
			||||||
 | 
							$http = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							while(true){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$header = explode("\n", $body, 2);
 | 
				
			||||||
 | 
								$body = $header[1];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($http === null){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// http/1.1 200 ok
 | 
				
			||||||
 | 
									$header = explode("/", $header[0], 2);
 | 
				
			||||||
 | 
									$header = explode(" ", $header[1], 3);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$http = [
 | 
				
			||||||
 | 
										"version" => (float)$header[0],
 | 
				
			||||||
 | 
										"code" => (int)$header[1]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(trim($header[0]) == ""){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// reached end of headers
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$header = explode(":", $header[0], 2);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// malformed headers
 | 
				
			||||||
 | 
								if(count($header) !== 2){ continue; }
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$headers[strtolower(trim($header[0]))] = trim($header[1]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check http code
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$http["code"] >= 300 &&
 | 
				
			||||||
 | 
								$http["code"] <= 309
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// redirect
 | 
				
			||||||
 | 
								if(!isset($headers["location"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Broken redirect");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$redirectcount++;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $this->get($this->getabsoluteurl($headers["location"], $url), $reqtype, $acceptallcodes, $referer, $redirectcount);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$acceptallcodes === false &&
 | 
				
			||||||
 | 
									$http["code"] > 300
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Remote server returned an error code! ({$http["code"]})");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check if data is okay
 | 
				
			||||||
 | 
							switch($reqtype){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case self::req_image:
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$format = false;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($headers["content-type"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(stripos($headers["content-type"], "text/html") !== false){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											throw new Exception("Server returned html");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											preg_match(
 | 
				
			||||||
 | 
												'/image\/([^ ]+)/i',
 | 
				
			||||||
 | 
												$headers["content-type"],
 | 
				
			||||||
 | 
												$match
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$format = strtolower($match[1]);
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(substr(strtolower($format), 0, 2) == "x-"){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$format = substr($format, 2);
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return [
 | 
				
			||||||
 | 
										"http" => $http,
 | 
				
			||||||
 | 
										"format" => $format,
 | 
				
			||||||
 | 
										"headers" => $headers,
 | 
				
			||||||
 | 
										"body" => $body
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return [
 | 
				
			||||||
 | 
										"http" => $http,
 | 
				
			||||||
 | 
										"headers" => $headers,
 | 
				
			||||||
 | 
										"body" => $body
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function stream_linear_image($url, $referer = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->stream($url, $referer, "image");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function stream_linear_audio($url, $referer = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->stream($url, $referer, "audio");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function stream($url, $referer, $format){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->clientcache();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->url = $url;
 | 
				
			||||||
 | 
							$this->format = $format;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// sanitize URL
 | 
				
			||||||
 | 
							if($this->validateurl($url) === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Invalid URL");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curl = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// set headers
 | 
				
			||||||
 | 
							if($referer === null){
 | 
				
			||||||
 | 
								$referer = explode("/", $url, 4);
 | 
				
			||||||
 | 
								array_pop($referer);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$referer = implode("/", $referer);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($format){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "image":
 | 
				
			||||||
 | 
									curl_setopt(
 | 
				
			||||||
 | 
										$curl,
 | 
				
			||||||
 | 
										CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
											"Accept: image/avif,image/webp,*/*",
 | 
				
			||||||
 | 
											"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
											"Accept-Encoding: gzip, deflate, br",
 | 
				
			||||||
 | 
											"DNT: 1",
 | 
				
			||||||
 | 
											"Connection: keep-alive",
 | 
				
			||||||
 | 
											"Referer: {$referer}"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "audio":
 | 
				
			||||||
 | 
									curl_setopt(
 | 
				
			||||||
 | 
										$curl,
 | 
				
			||||||
 | 
										CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
											"Accept: audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5",
 | 
				
			||||||
 | 
											"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
											"Accept-Encoding: gzip, deflate, br",
 | 
				
			||||||
 | 
											"DNT: 1",
 | 
				
			||||||
 | 
											"Connection: keep-alive",
 | 
				
			||||||
 | 
											"Referer: {$referer}"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// follow redirects
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_AUTOREFERER, 5);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// set url
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// timeout + disable ssl
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
 | 
				
			||||||
 | 
							curl_setopt($curl, CURLOPT_TIMEOUT, 30);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curl,
 | 
				
			||||||
 | 
								CURLOPT_WRITEFUNCTION,
 | 
				
			||||||
 | 
								function($c, $data){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(curl_getinfo($c, CURLINFO_HTTP_CODE) !== 200){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										throw new Exception("Serber returned a non-200 code");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									echo $data;
 | 
				
			||||||
 | 
									return strlen($data);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->empty_header = false;
 | 
				
			||||||
 | 
							$this->cont = false;
 | 
				
			||||||
 | 
							$this->headers_tmp = [];
 | 
				
			||||||
 | 
							$this->headers = [];
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curl,
 | 
				
			||||||
 | 
								CURLOPT_HEADERFUNCTION,
 | 
				
			||||||
 | 
								function($c, $header){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$head = trim($header);
 | 
				
			||||||
 | 
									$len = strlen($head);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($len === 0){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->empty_header = true;
 | 
				
			||||||
 | 
										$this->headers_tmp = [];
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->empty_header = false;
 | 
				
			||||||
 | 
										$this->headers_tmp[] = $head;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									foreach($this->headers_tmp as $h){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// parse headers
 | 
				
			||||||
 | 
										$h = explode(":", $h, 2);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(count($h) !== 2){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(curl_getinfo($c, CURLINFO_HTTP_CODE) !== 200){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												// not HTTP 200, probably a redirect
 | 
				
			||||||
 | 
												$this->cont = false;
 | 
				
			||||||
 | 
											}else{
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$this->cont = true;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											// is HTTP 200, just ignore that line
 | 
				
			||||||
 | 
											continue;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$this->headers[strtolower(trim($h[0]))] = trim($h[1]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$this->cont &&
 | 
				
			||||||
 | 
										$this->empty_header
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// get content type
 | 
				
			||||||
 | 
										if(isset($this->headers["content-type"])){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$octet_check = stripos($this->headers["content-type"], "octet-stream");
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(
 | 
				
			||||||
 | 
												stripos($this->headers["content-type"], $this->format) === false &&
 | 
				
			||||||
 | 
												$octet_check === false
 | 
				
			||||||
 | 
											){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												throw new Exception("Resource reported invalid Content-Type");
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											throw new Exception("Resource is not an {$this->format} (no Content-Type)");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$filetype = explode("/", $this->headers["content-type"]);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(!isset($filetype[1])){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											throw new Exception("Malformed Content-Type header");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if($octet_check !== false){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$filetype[1] = "jpeg";
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										header("Content-Type: {$this->format}/{$filetype[1]}");
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// give payload size
 | 
				
			||||||
 | 
										if(isset($this->headers["content-length"])){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											header("Content-Length: {$this->headers["content-length"]}");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// give filename
 | 
				
			||||||
 | 
										$this->getfilenameheader($this->headers, $this->url, $filetype[1]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return strlen($header);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_exec($curl);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(curl_errno($curl)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception(curl_error($curl));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curl);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilenameheader($headers, $url, $filetype = "jpg"){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get filename from content-disposition header
 | 
				
			||||||
 | 
							if(isset($headers["content-disposition"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/filename=([^;]+)/',
 | 
				
			||||||
 | 
									$headers["content-disposition"],
 | 
				
			||||||
 | 
									$filename
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($filename[1])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									header("Content-Disposition: filename=\"" . trim($filename[1], "\"'") . "." . $filetype . "\"");
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get filename from URL
 | 
				
			||||||
 | 
							$filename = parse_url($url, PHP_URL_PATH);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($filename === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// everything failed! rename file to domain name
 | 
				
			||||||
 | 
								header("Content-Disposition: filename=\"" . parse_url($url, PHP_URL_HOST) . "." . $filetype . "\"");
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// remove extension from filename
 | 
				
			||||||
 | 
							$filename =
 | 
				
			||||||
 | 
								explode(
 | 
				
			||||||
 | 
									".",
 | 
				
			||||||
 | 
									basename($filename)
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($filename) > 1){
 | 
				
			||||||
 | 
								array_pop($filename);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$filename = implode(".", $filename);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("Content-Disposition: inline; filename=\"" . $filename . "." . $filetype . "\"");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getimageformat($payload, &$imagick){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$finfo = new finfo(FILEINFO_MIME_TYPE);
 | 
				
			||||||
 | 
							$format = $finfo->buffer($payload["body"]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($format === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($payload["format"] === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									header("X-Error: Could not parse format");
 | 
				
			||||||
 | 
									$this->favicon404();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$format = $payload["format"];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$format_tmp = explode("/", $format, 2);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($format_tmp[0] == "image"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$format_tmp = strtolower($format_tmp[1]);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(substr($format_tmp, 0, 2) == "x-"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$format_tmp = substr($format_tmp, 2);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$format = $format_tmp;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($format){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "tiff": $format = "gif"; break;
 | 
				
			||||||
 | 
								case "vnd.microsoft.icon": $format = "ico"; break;
 | 
				
			||||||
 | 
								case "icon": $format = "ico"; break;
 | 
				
			||||||
 | 
								case "svg+xml": $format = "svg"; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$imagick = new Imagick();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!in_array(
 | 
				
			||||||
 | 
									$format,
 | 
				
			||||||
 | 
									array_map("strtolower", $imagick->queryFormats())
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// format could not be found, but imagemagick can
 | 
				
			||||||
 | 
								// sometimes detect it? shit's fucked
 | 
				
			||||||
 | 
								$format = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $format;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function clientcache(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($this->cache === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("Last-Modified: Thu, 01 Oct 1970 00:00:00 GMT");
 | 
				
			||||||
 | 
							$headers = getallheaders();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($headers["If-Modified-Since"]) ||
 | 
				
			||||||
 | 
								isset($headers["If-Unmodified-Since"])
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								http_response_code(304); // 304: Not Modified
 | 
				
			||||||
 | 
								die();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								lib/favicon404.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 744 B  | 
							
								
								
									
										1342
									
								
								lib/frontend.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										610
									
								
								lib/fuckhtml.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,610 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					class fuckhtml{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct($html = null, $isfile = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($html !== null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->load($html, $isfile);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function load($html, $isfile = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(is_array($html)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($html["innerHTML"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("(load) Supplied array doesn't contain an innerHTML index");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								$html = $html["innerHTML"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($isfile){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$handle = fopen($html, "r");
 | 
				
			||||||
 | 
								$fetch = fread($handle, filesize($html));
 | 
				
			||||||
 | 
								fclose($handle);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->html = $fetch;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->html = $html;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->strlen = strlen($this->html);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getloadedhtml(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $this->html;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getElementsByTagName(string $tagname){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Scrape start of the tag. Example
 | 
				
			||||||
 | 
								<div class="mydiv"> ...
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($tagname == "*"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$tagname = '[A-Za-z0-9._-]+';
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$tagname = preg_quote(strtolower($tagname));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							preg_match_all(
 | 
				
			||||||
 | 
								'/<\s*(' . $tagname . ')(\s(?:[^>\'"]*|"[^"]*"|\'[^\']*\')+)?\s*>/i',
 | 
				
			||||||
 | 
								/* '/<\s*(' . $tagname . ')(\s[\S\s]*?)?>/i', */
 | 
				
			||||||
 | 
								$this->html,
 | 
				
			||||||
 | 
								$starting_tags,
 | 
				
			||||||
 | 
								PREG_OFFSET_CAPTURE
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<count($starting_tags[0]); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
									Parse attributes
 | 
				
			||||||
 | 
								*/
 | 
				
			||||||
 | 
								$attributes = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								preg_match_all(
 | 
				
			||||||
 | 
									'/([^\/\s\\=]+)(?:\s*=\s*("[^"]*"|\'[^\']*\'|[^\s]*))?/i',
 | 
				
			||||||
 | 
									$starting_tags[2][$i][0],
 | 
				
			||||||
 | 
									$regex_attributes
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								for($k=0; $k<count($regex_attributes[0]); $k++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(trim($regex_attributes[2][$k]) == ""){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$attributes[$regex_attributes[1][$k]] =
 | 
				
			||||||
 | 
											"true";
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$attributes[strtolower($regex_attributes[1][$k])] =
 | 
				
			||||||
 | 
										trim($regex_attributes[2][$k], "'\" \n\r\t\v\x00");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out[] = [
 | 
				
			||||||
 | 
									"tagName" => strtolower($starting_tags[1][$i][0]),
 | 
				
			||||||
 | 
									"startPos" => $starting_tags[0][$i][1],
 | 
				
			||||||
 | 
									"endPos" => 0,
 | 
				
			||||||
 | 
									"startTag" => $starting_tags[0][$i][0],
 | 
				
			||||||
 | 
									"attributes" => $attributes,
 | 
				
			||||||
 | 
									"innerHTML" => null
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Get innerHTML
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							// get closing tag positions
 | 
				
			||||||
 | 
							preg_match_all(
 | 
				
			||||||
 | 
								'/<\s*\/\s*(' . $tagname . ')\s*>/i',
 | 
				
			||||||
 | 
								$this->html,
 | 
				
			||||||
 | 
								$regex_closing_tags,
 | 
				
			||||||
 | 
								PREG_OFFSET_CAPTURE
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// merge opening and closing tags together
 | 
				
			||||||
 | 
							for($i=0; $i<count($regex_closing_tags[1]); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out[] = [
 | 
				
			||||||
 | 
									"tagName" => strtolower($regex_closing_tags[1][$i][0]),
 | 
				
			||||||
 | 
									"endTag" => $regex_closing_tags[0][$i][0],
 | 
				
			||||||
 | 
									"startPos" => $regex_closing_tags[0][$i][1]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							usort(
 | 
				
			||||||
 | 
								$out,
 | 
				
			||||||
 | 
								function($a, $b){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return $a["startPos"] > $b["startPos"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// compute the indent level for each element
 | 
				
			||||||
 | 
							$level = [];
 | 
				
			||||||
 | 
							$count = count($out);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<$count; $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($level[$out[$i]["tagName"]])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$level[$out[$i]["tagName"]] = 0;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($out[$i]["startTag"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// encountered starting tag
 | 
				
			||||||
 | 
									$level[$out[$i]["tagName"]]++;
 | 
				
			||||||
 | 
									$out[$i]["level"] = $level[$out[$i]["tagName"]];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// encountered closing tag
 | 
				
			||||||
 | 
									$out[$i]["level"] = $level[$out[$i]["tagName"]];
 | 
				
			||||||
 | 
									$level[$out[$i]["tagName"]]--;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// if the indent level is the same for a div,
 | 
				
			||||||
 | 
							// we encountered _THE_ closing tag
 | 
				
			||||||
 | 
							for($i=0; $i<$count; $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($out[$i]["startTag"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								for($k=$i; $k<$count; $k++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										isset($out[$k]["endTag"]) &&
 | 
				
			||||||
 | 
										$out[$i]["tagName"] == $out[$k]["tagName"] &&
 | 
				
			||||||
 | 
										$out[$i]["level"]
 | 
				
			||||||
 | 
										=== $out[$k]["level"]
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$startlen = strlen($out[$i]["startTag"]);
 | 
				
			||||||
 | 
										$endlen = strlen($out[$k]["endTag"]);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$out[$i]["endPos"] = $out[$k]["startPos"] + $endlen;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$out[$i]["innerHTML"] =
 | 
				
			||||||
 | 
											substr(
 | 
				
			||||||
 | 
												$this->html,
 | 
				
			||||||
 | 
												$out[$i]["startPos"] + $startlen,
 | 
				
			||||||
 | 
												$out[$k]["startPos"] - ($out[$i]["startPos"] + $startlen)
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$out[$i]["outerHTML"] =
 | 
				
			||||||
 | 
											substr(
 | 
				
			||||||
 | 
												$this->html,
 | 
				
			||||||
 | 
												$out[$i]["startPos"],
 | 
				
			||||||
 | 
												$out[$k]["startPos"] - $out[$i]["startPos"] + $endlen
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// filter out ending divs
 | 
				
			||||||
 | 
							for($i=0; $i<$count; $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($out[$i]["endTag"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									unset($out[$i]);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								unset($out[$i]["startTag"]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return array_values($out);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getElementsByAttributeName(string $name, $collection = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($collection === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$collection = $this->getElementsByTagName("*");
 | 
				
			||||||
 | 
							}elseif(is_string($collection)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$collection = $this->getElementsByTagName($collection);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$return = [];
 | 
				
			||||||
 | 
							foreach($collection as $elem){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($elem["attributes"] as $attrib_name => $attrib_value){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($attrib_name == $name){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$return[] = $elem;
 | 
				
			||||||
 | 
										continue 2;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getElementsByFuzzyAttributeValue(string $name, string $value, $collection = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$elems = $this->getElementsByAttributeName($name, $collection);
 | 
				
			||||||
 | 
							$value =
 | 
				
			||||||
 | 
								explode(
 | 
				
			||||||
 | 
									" ",
 | 
				
			||||||
 | 
									trim(
 | 
				
			||||||
 | 
										preg_replace(
 | 
				
			||||||
 | 
											'/ +/',
 | 
				
			||||||
 | 
											" ",
 | 
				
			||||||
 | 
											$value
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$return = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($elems as $elem){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($elem["attributes"] as $attrib_name => $attrib_value){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$attrib_value = explode(" ", $attrib_value);
 | 
				
			||||||
 | 
									$ac = count($attrib_value);
 | 
				
			||||||
 | 
									$nc = count($value);
 | 
				
			||||||
 | 
									$cr = 0;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									for($i=0; $i<$nc; $i++){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										for($k=0; $k<$ac; $k++){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if($value[$i] == $attrib_value[$k]){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$cr++;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($cr === $nc){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$return[] = $elem;
 | 
				
			||||||
 | 
										continue 2;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getElementsByAttributeValue(string $name, string $value, $collection = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$elems = $this->getElementsByAttributeName($name, $collection);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$return = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($elems as $elem){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($elem["attributes"] as $attrib_name => $attrib_value){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($attrib_value == $value){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$return[] = $elem;
 | 
				
			||||||
 | 
										continue 2;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getElementById(string $idname, $collection = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$id = $this->getElementsByAttributeValue("id", $idname, $collection);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($id) !== 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $id[0];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getElementsByClassName(string $classname, $collection = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $this->getElementsByFuzzyAttributeValue("class", $classname, $collection);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getTextContent($html, $whitespace = false, $trim = true){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(is_array($html)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($html["innerHTML"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("(getTextContent) Supplied array doesn't contain an innerHTML index");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$html = $html["innerHTML"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$html = preg_split('/\n|<\/?br>/i', $html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = "";
 | 
				
			||||||
 | 
							for($i=0; $i<count($html); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$tmp =
 | 
				
			||||||
 | 
									html_entity_decode(
 | 
				
			||||||
 | 
										strip_tags(
 | 
				
			||||||
 | 
											$html[$i]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										ENT_QUOTES | ENT_XML1, "UTF-8"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($trim){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$tmp = trim($tmp);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out .= $tmp;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($whitespace === true){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out .= "\n";
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out .= " ";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($trim){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return trim($out);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function parseJsObject(string $json){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$bracket = false;
 | 
				
			||||||
 | 
							$is_close_bracket = false;
 | 
				
			||||||
 | 
							$escape = false;
 | 
				
			||||||
 | 
							$lastchar = false;
 | 
				
			||||||
 | 
							$json_out = null;
 | 
				
			||||||
 | 
							$last_char = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$keyword_check = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<strlen($json); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($json[$i]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "\"":
 | 
				
			||||||
 | 
									case "'":
 | 
				
			||||||
 | 
										if($escape === true){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if($json[$i] == $bracket){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$bracket = false;
 | 
				
			||||||
 | 
											$is_close_bracket = true;
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if($bracket === false){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$bracket = $json[$i];
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									default:
 | 
				
			||||||
 | 
										$is_close_bracket = false;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$json[$i] == "\\" &&
 | 
				
			||||||
 | 
									!(
 | 
				
			||||||
 | 
										$lastchar !== false &&
 | 
				
			||||||
 | 
										$lastchar . $json[$i] == "\\\\"
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$escape = true;
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$escape = false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$bracket === false &&
 | 
				
			||||||
 | 
									$is_close_bracket === false
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// do keyword check
 | 
				
			||||||
 | 
									$keyword_check .= $json[$i];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(in_array($json[$i], [":", "{"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$keyword_check = substr($keyword_check, 0, -1);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											preg_match(
 | 
				
			||||||
 | 
												'/function|array|return/i',
 | 
				
			||||||
 | 
												$keyword_check
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$json_out =
 | 
				
			||||||
 | 
												preg_replace(
 | 
				
			||||||
 | 
													'/[{"]*' . preg_quote($keyword_check, "/") . '$/',
 | 
				
			||||||
 | 
													"",
 | 
				
			||||||
 | 
													$json_out
 | 
				
			||||||
 | 
												);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$keyword_check = null;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// here we know we're not iterating over a quoted string
 | 
				
			||||||
 | 
									switch($json[$i]){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										case "[":
 | 
				
			||||||
 | 
										case "{":
 | 
				
			||||||
 | 
											$json_out .= $json[$i];
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										case "]":
 | 
				
			||||||
 | 
										case "}":
 | 
				
			||||||
 | 
										case ",":
 | 
				
			||||||
 | 
										case ":":
 | 
				
			||||||
 | 
											if(!in_array($last_char, ["[", "{", "}", "]", "\""])){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$json_out .= "\"";
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$json_out .= $json[$i];
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										default:
 | 
				
			||||||
 | 
											if(in_array($last_char, ["{", "[", ",", ":"])){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$json_out .= "\"";
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$json_out .= $json[$i];
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$json_out .= $json[$i];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$last_char = $json[$i];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return json_decode($json_out, true);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function parseJsString($string){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
								preg_replace_callback(
 | 
				
			||||||
 | 
									'/\\\u[A-Fa-f0-9]{4}|\\\x[A-Fa-f0-9]{2}|\\\n|\\\r/',
 | 
				
			||||||
 | 
									function($match){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										switch($match[0][1]){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											case "u":
 | 
				
			||||||
 | 
												return json_decode('"' . $match[0] . '"');
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											case "x":
 | 
				
			||||||
 | 
												return mb_convert_encoding(
 | 
				
			||||||
 | 
													stripcslashes($match[0]),
 | 
				
			||||||
 | 
													"utf-8",
 | 
				
			||||||
 | 
													"windows-1252"
 | 
				
			||||||
 | 
												);
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											default:
 | 
				
			||||||
 | 
												return " ";
 | 
				
			||||||
 | 
												break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									$string
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function extract_json($json){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$len = strlen($json);
 | 
				
			||||||
 | 
							$array_level = 0;
 | 
				
			||||||
 | 
							$object_level = 0;
 | 
				
			||||||
 | 
							$in_quote = null;
 | 
				
			||||||
 | 
							$start = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<$len; $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($json[$i]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "[":
 | 
				
			||||||
 | 
										if($in_quote === null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$array_level++;
 | 
				
			||||||
 | 
											if($start === null){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$start = $i;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "]":
 | 
				
			||||||
 | 
										if($in_quote === null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$array_level--;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "{":
 | 
				
			||||||
 | 
										if($in_quote === null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$object_level++;
 | 
				
			||||||
 | 
											if($start === null){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$start = $i;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "}":
 | 
				
			||||||
 | 
										if($in_quote === null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$object_level--;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "\"":
 | 
				
			||||||
 | 
									case "'":
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											$i !== 0 &&
 | 
				
			||||||
 | 
											$json[$i - 1] !== "\\"
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											// found a non-escaped quote
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if($in_quote === null){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												// open quote
 | 
				
			||||||
 | 
												$in_quote = $json[$i];
 | 
				
			||||||
 | 
											}elseif($in_quote === $json[$i]){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												// close quote
 | 
				
			||||||
 | 
												$in_quote = null;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									$start !== null &&
 | 
				
			||||||
 | 
									$array_level === 0 &&
 | 
				
			||||||
 | 
									$object_level === 0
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return substr($json, $start, $i - $start + 1);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								lib/img404.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 216 B  | 
							
								
								
									
										132
									
								
								lib/type-todo.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,132 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function type($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							$bang = $get["bang"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(empty($search)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!empty($bang)){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// !youtube
 | 
				
			||||||
 | 
									$conn = pg_connect("host=localhost dbname=4get user=postgres password=postgres");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									pg_prepare($conn, "bang_get", "SELECT bang,name FROM bangs WHERE bang LIKE $1 ORDER BY bang ASC LIMIT 8");
 | 
				
			||||||
 | 
									$q = pg_execute($conn, "bang_get", ["$bang%"]);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$results = [];
 | 
				
			||||||
 | 
									while($row = pg_fetch_array($q, null, PGSQL_ASSOC)){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$results[] = [
 | 
				
			||||||
 | 
											"s" => "!" . $row["bang"],
 | 
				
			||||||
 | 
											"n" => $row["name"]
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return $results;
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// everything is empty
 | 
				
			||||||
 | 
									// lets just return a bang list
 | 
				
			||||||
 | 
									return [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!w",
 | 
				
			||||||
 | 
											"n" => "Wikipedia",
 | 
				
			||||||
 | 
											"u" => "https://en.wikipedia.org/wiki/Special:Search?search={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!4ch",
 | 
				
			||||||
 | 
											"n" => "4chan Board",
 | 
				
			||||||
 | 
											"u" => "https://find.4chan.org/?q={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!a",
 | 
				
			||||||
 | 
											"n" => "Amazon",
 | 
				
			||||||
 | 
											"u" => "https://www.amazon.com/s?k={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!e",
 | 
				
			||||||
 | 
											"n" => "eBay",
 | 
				
			||||||
 | 
											"u" => "https://www.ebay.com/sch/items/?_nkw={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!so",
 | 
				
			||||||
 | 
											"n" => "Stack Overflow",
 | 
				
			||||||
 | 
											"u" => "http://stackoverflow.com/search?q={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!gh",
 | 
				
			||||||
 | 
											"n" => "GitHub",
 | 
				
			||||||
 | 
											"u" => "https://github.com/search?utf8=%E2%9C%93&q={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!tw",
 | 
				
			||||||
 | 
											"n" => "Twitter",
 | 
				
			||||||
 | 
											"u" => "https://twitter.com/search?q={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"s" => "!r",
 | 
				
			||||||
 | 
											"n" => "Reddit",
 | 
				
			||||||
 | 
											"u" => "https://www.reddit.com/search?q={%q%}"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// now we know search isnt empty
 | 
				
			||||||
 | 
							if(!empty($bang)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// check if the bang exists
 | 
				
			||||||
 | 
								$conn = pg_connect("host=localhost dbname=4get user=postgres password=postgres");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								pg_prepare($conn, "bang_get_single", "SELECT bang,name FROM bangs WHERE bang = $1 LIMIT 1");
 | 
				
			||||||
 | 
								$q = pg_execute($conn, "bang_get_single", [$bang]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$row = pg_fetch_array($q, null, PGSQL_ASSOC);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($row["bang"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$bang = "!$bang ";
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$bang = "";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$res = $this->get(
 | 
				
			||||||
 | 
									"https://duckduckgo.com/ac/",
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"q" => strtolower($search)
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									ddg::req_xhr
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$res = json_decode($res, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $e){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to get /ac/");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$arr = [];
 | 
				
			||||||
 | 
							for($i=0; $i<count($res); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($i === 8){break;}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(empty($bang)){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$arr[] = [
 | 
				
			||||||
 | 
										"s" => $res[$i]["phrase"]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$arr[] = [
 | 
				
			||||||
 | 
										"s" => $bang . $res[$i]["phrase"],
 | 
				
			||||||
 | 
										"n" => $row["name"]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $arr;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
							
								
								
									
										661
									
								
								license.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,661 @@
 | 
				
			||||||
 | 
					                    GNU AFFERO GENERAL PUBLIC LICENSE
 | 
				
			||||||
 | 
					                       Version 3, 19 November 2007
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 | 
				
			||||||
 | 
					 Everyone is permitted to copy and distribute verbatim copies
 | 
				
			||||||
 | 
					 of this license document, but changing it is not allowed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            Preamble
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The GNU Affero General Public License is a free, copyleft license for
 | 
				
			||||||
 | 
					software and other kinds of works, specifically designed to ensure
 | 
				
			||||||
 | 
					cooperation with the community in the case of network server software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The licenses for most software and other practical works are designed
 | 
				
			||||||
 | 
					to take away your freedom to share and change the works.  By contrast,
 | 
				
			||||||
 | 
					our General Public Licenses are intended to guarantee your freedom to
 | 
				
			||||||
 | 
					share and change all versions of a program--to make sure it remains free
 | 
				
			||||||
 | 
					software for all its users.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  When we speak of free software, we are referring to freedom, not
 | 
				
			||||||
 | 
					price.  Our General Public Licenses are designed to make sure that you
 | 
				
			||||||
 | 
					have the freedom to distribute copies of free software (and charge for
 | 
				
			||||||
 | 
					them if you wish), that you receive source code or can get it if you
 | 
				
			||||||
 | 
					want it, that you can change the software or use pieces of it in new
 | 
				
			||||||
 | 
					free programs, and that you know you can do these things.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Developers that use our General Public Licenses protect your rights
 | 
				
			||||||
 | 
					with two steps: (1) assert copyright on the software, and (2) offer
 | 
				
			||||||
 | 
					you this License which gives you legal permission to copy, distribute
 | 
				
			||||||
 | 
					and/or modify the software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A secondary benefit of defending all users' freedom is that
 | 
				
			||||||
 | 
					improvements made in alternate versions of the program, if they
 | 
				
			||||||
 | 
					receive widespread use, become available for other developers to
 | 
				
			||||||
 | 
					incorporate.  Many developers of free software are heartened and
 | 
				
			||||||
 | 
					encouraged by the resulting cooperation.  However, in the case of
 | 
				
			||||||
 | 
					software used on network servers, this result may fail to come about.
 | 
				
			||||||
 | 
					The GNU General Public License permits making a modified version and
 | 
				
			||||||
 | 
					letting the public access it on a server without ever releasing its
 | 
				
			||||||
 | 
					source code to the public.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The GNU Affero General Public License is designed specifically to
 | 
				
			||||||
 | 
					ensure that, in such cases, the modified source code becomes available
 | 
				
			||||||
 | 
					to the community.  It requires the operator of a network server to
 | 
				
			||||||
 | 
					provide the source code of the modified version running there to the
 | 
				
			||||||
 | 
					users of that server.  Therefore, public use of a modified version, on
 | 
				
			||||||
 | 
					a publicly accessible server, gives the public access to the source
 | 
				
			||||||
 | 
					code of the modified version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  An older license, called the Affero General Public License and
 | 
				
			||||||
 | 
					published by Affero, was designed to accomplish similar goals.  This is
 | 
				
			||||||
 | 
					a different license, not a version of the Affero GPL, but Affero has
 | 
				
			||||||
 | 
					released a new version of the Affero GPL which permits relicensing under
 | 
				
			||||||
 | 
					this license.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The precise terms and conditions for copying, distribution and
 | 
				
			||||||
 | 
					modification follow.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                       TERMS AND CONDITIONS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  0. Definitions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "This License" refers to version 3 of the GNU Affero General Public License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "Copyright" also means copyright-like laws that apply to other kinds of
 | 
				
			||||||
 | 
					works, such as semiconductor masks.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "The Program" refers to any copyrightable work licensed under this
 | 
				
			||||||
 | 
					License.  Each licensee is addressed as "you".  "Licensees" and
 | 
				
			||||||
 | 
					"recipients" may be individuals or organizations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  To "modify" a work means to copy from or adapt all or part of the work
 | 
				
			||||||
 | 
					in a fashion requiring copyright permission, other than the making of an
 | 
				
			||||||
 | 
					exact copy.  The resulting work is called a "modified version" of the
 | 
				
			||||||
 | 
					earlier work or a work "based on" the earlier work.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A "covered work" means either the unmodified Program or a work based
 | 
				
			||||||
 | 
					on the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  To "propagate" a work means to do anything with it that, without
 | 
				
			||||||
 | 
					permission, would make you directly or secondarily liable for
 | 
				
			||||||
 | 
					infringement under applicable copyright law, except executing it on a
 | 
				
			||||||
 | 
					computer or modifying a private copy.  Propagation includes copying,
 | 
				
			||||||
 | 
					distribution (with or without modification), making available to the
 | 
				
			||||||
 | 
					public, and in some countries other activities as well.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  To "convey" a work means any kind of propagation that enables other
 | 
				
			||||||
 | 
					parties to make or receive copies.  Mere interaction with a user through
 | 
				
			||||||
 | 
					a computer network, with no transfer of a copy, is not conveying.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  An interactive user interface displays "Appropriate Legal Notices"
 | 
				
			||||||
 | 
					to the extent that it includes a convenient and prominently visible
 | 
				
			||||||
 | 
					feature that (1) displays an appropriate copyright notice, and (2)
 | 
				
			||||||
 | 
					tells the user that there is no warranty for the work (except to the
 | 
				
			||||||
 | 
					extent that warranties are provided), that licensees may convey the
 | 
				
			||||||
 | 
					work under this License, and how to view a copy of this License.  If
 | 
				
			||||||
 | 
					the interface presents a list of user commands or options, such as a
 | 
				
			||||||
 | 
					menu, a prominent item in the list meets this criterion.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  1. Source Code.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The "source code" for a work means the preferred form of the work
 | 
				
			||||||
 | 
					for making modifications to it.  "Object code" means any non-source
 | 
				
			||||||
 | 
					form of a work.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A "Standard Interface" means an interface that either is an official
 | 
				
			||||||
 | 
					standard defined by a recognized standards body, or, in the case of
 | 
				
			||||||
 | 
					interfaces specified for a particular programming language, one that
 | 
				
			||||||
 | 
					is widely used among developers working in that language.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The "System Libraries" of an executable work include anything, other
 | 
				
			||||||
 | 
					than the work as a whole, that (a) is included in the normal form of
 | 
				
			||||||
 | 
					packaging a Major Component, but which is not part of that Major
 | 
				
			||||||
 | 
					Component, and (b) serves only to enable use of the work with that
 | 
				
			||||||
 | 
					Major Component, or to implement a Standard Interface for which an
 | 
				
			||||||
 | 
					implementation is available to the public in source code form.  A
 | 
				
			||||||
 | 
					"Major Component", in this context, means a major essential component
 | 
				
			||||||
 | 
					(kernel, window system, and so on) of the specific operating system
 | 
				
			||||||
 | 
					(if any) on which the executable work runs, or a compiler used to
 | 
				
			||||||
 | 
					produce the work, or an object code interpreter used to run it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The "Corresponding Source" for a work in object code form means all
 | 
				
			||||||
 | 
					the source code needed to generate, install, and (for an executable
 | 
				
			||||||
 | 
					work) run the object code and to modify the work, including scripts to
 | 
				
			||||||
 | 
					control those activities.  However, it does not include the work's
 | 
				
			||||||
 | 
					System Libraries, or general-purpose tools or generally available free
 | 
				
			||||||
 | 
					programs which are used unmodified in performing those activities but
 | 
				
			||||||
 | 
					which are not part of the work.  For example, Corresponding Source
 | 
				
			||||||
 | 
					includes interface definition files associated with source files for
 | 
				
			||||||
 | 
					the work, and the source code for shared libraries and dynamically
 | 
				
			||||||
 | 
					linked subprograms that the work is specifically designed to require,
 | 
				
			||||||
 | 
					such as by intimate data communication or control flow between those
 | 
				
			||||||
 | 
					subprograms and other parts of the work.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The Corresponding Source need not include anything that users
 | 
				
			||||||
 | 
					can regenerate automatically from other parts of the Corresponding
 | 
				
			||||||
 | 
					Source.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The Corresponding Source for a work in source code form is that
 | 
				
			||||||
 | 
					same work.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  2. Basic Permissions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  All rights granted under this License are granted for the term of
 | 
				
			||||||
 | 
					copyright on the Program, and are irrevocable provided the stated
 | 
				
			||||||
 | 
					conditions are met.  This License explicitly affirms your unlimited
 | 
				
			||||||
 | 
					permission to run the unmodified Program.  The output from running a
 | 
				
			||||||
 | 
					covered work is covered by this License only if the output, given its
 | 
				
			||||||
 | 
					content, constitutes a covered work.  This License acknowledges your
 | 
				
			||||||
 | 
					rights of fair use or other equivalent, as provided by copyright law.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may make, run and propagate covered works that you do not
 | 
				
			||||||
 | 
					convey, without conditions so long as your license otherwise remains
 | 
				
			||||||
 | 
					in force.  You may convey covered works to others for the sole purpose
 | 
				
			||||||
 | 
					of having them make modifications exclusively for you, or provide you
 | 
				
			||||||
 | 
					with facilities for running those works, provided that you comply with
 | 
				
			||||||
 | 
					the terms of this License in conveying all material for which you do
 | 
				
			||||||
 | 
					not control copyright.  Those thus making or running the covered works
 | 
				
			||||||
 | 
					for you must do so exclusively on your behalf, under your direction
 | 
				
			||||||
 | 
					and control, on terms that prohibit them from making any copies of
 | 
				
			||||||
 | 
					your copyrighted material outside their relationship with you.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Conveying under any other circumstances is permitted solely under
 | 
				
			||||||
 | 
					the conditions stated below.  Sublicensing is not allowed; section 10
 | 
				
			||||||
 | 
					makes it unnecessary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  No covered work shall be deemed part of an effective technological
 | 
				
			||||||
 | 
					measure under any applicable law fulfilling obligations under article
 | 
				
			||||||
 | 
					11 of the WIPO copyright treaty adopted on 20 December 1996, or
 | 
				
			||||||
 | 
					similar laws prohibiting or restricting circumvention of such
 | 
				
			||||||
 | 
					measures.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  When you convey a covered work, you waive any legal power to forbid
 | 
				
			||||||
 | 
					circumvention of technological measures to the extent such circumvention
 | 
				
			||||||
 | 
					is effected by exercising rights under this License with respect to
 | 
				
			||||||
 | 
					the covered work, and you disclaim any intention to limit operation or
 | 
				
			||||||
 | 
					modification of the work as a means of enforcing, against the work's
 | 
				
			||||||
 | 
					users, your or third parties' legal rights to forbid circumvention of
 | 
				
			||||||
 | 
					technological measures.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  4. Conveying Verbatim Copies.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may convey verbatim copies of the Program's source code as you
 | 
				
			||||||
 | 
					receive it, in any medium, provided that you conspicuously and
 | 
				
			||||||
 | 
					appropriately publish on each copy an appropriate copyright notice;
 | 
				
			||||||
 | 
					keep intact all notices stating that this License and any
 | 
				
			||||||
 | 
					non-permissive terms added in accord with section 7 apply to the code;
 | 
				
			||||||
 | 
					keep intact all notices of the absence of any warranty; and give all
 | 
				
			||||||
 | 
					recipients a copy of this License along with the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may charge any price or no price for each copy that you convey,
 | 
				
			||||||
 | 
					and you may offer support or warranty protection for a fee.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  5. Conveying Modified Source Versions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may convey a work based on the Program, or the modifications to
 | 
				
			||||||
 | 
					produce it from the Program, in the form of source code under the
 | 
				
			||||||
 | 
					terms of section 4, provided that you also meet all of these conditions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    a) The work must carry prominent notices stating that you modified
 | 
				
			||||||
 | 
					    it, and giving a relevant date.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    b) The work must carry prominent notices stating that it is
 | 
				
			||||||
 | 
					    released under this License and any conditions added under section
 | 
				
			||||||
 | 
					    7.  This requirement modifies the requirement in section 4 to
 | 
				
			||||||
 | 
					    "keep intact all notices".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    c) You must license the entire work, as a whole, under this
 | 
				
			||||||
 | 
					    License to anyone who comes into possession of a copy.  This
 | 
				
			||||||
 | 
					    License will therefore apply, along with any applicable section 7
 | 
				
			||||||
 | 
					    additional terms, to the whole of the work, and all its parts,
 | 
				
			||||||
 | 
					    regardless of how they are packaged.  This License gives no
 | 
				
			||||||
 | 
					    permission to license the work in any other way, but it does not
 | 
				
			||||||
 | 
					    invalidate such permission if you have separately received it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    d) If the work has interactive user interfaces, each must display
 | 
				
			||||||
 | 
					    Appropriate Legal Notices; however, if the Program has interactive
 | 
				
			||||||
 | 
					    interfaces that do not display Appropriate Legal Notices, your
 | 
				
			||||||
 | 
					    work need not make them do so.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A compilation of a covered work with other separate and independent
 | 
				
			||||||
 | 
					works, which are not by their nature extensions of the covered work,
 | 
				
			||||||
 | 
					and which are not combined with it such as to form a larger program,
 | 
				
			||||||
 | 
					in or on a volume of a storage or distribution medium, is called an
 | 
				
			||||||
 | 
					"aggregate" if the compilation and its resulting copyright are not
 | 
				
			||||||
 | 
					used to limit the access or legal rights of the compilation's users
 | 
				
			||||||
 | 
					beyond what the individual works permit.  Inclusion of a covered work
 | 
				
			||||||
 | 
					in an aggregate does not cause this License to apply to the other
 | 
				
			||||||
 | 
					parts of the aggregate.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  6. Conveying Non-Source Forms.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may convey a covered work in object code form under the terms
 | 
				
			||||||
 | 
					of sections 4 and 5, provided that you also convey the
 | 
				
			||||||
 | 
					machine-readable Corresponding Source under the terms of this License,
 | 
				
			||||||
 | 
					in one of these ways:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    a) Convey the object code in, or embodied in, a physical product
 | 
				
			||||||
 | 
					    (including a physical distribution medium), accompanied by the
 | 
				
			||||||
 | 
					    Corresponding Source fixed on a durable physical medium
 | 
				
			||||||
 | 
					    customarily used for software interchange.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    b) Convey the object code in, or embodied in, a physical product
 | 
				
			||||||
 | 
					    (including a physical distribution medium), accompanied by a
 | 
				
			||||||
 | 
					    written offer, valid for at least three years and valid for as
 | 
				
			||||||
 | 
					    long as you offer spare parts or customer support for that product
 | 
				
			||||||
 | 
					    model, to give anyone who possesses the object code either (1) a
 | 
				
			||||||
 | 
					    copy of the Corresponding Source for all the software in the
 | 
				
			||||||
 | 
					    product that is covered by this License, on a durable physical
 | 
				
			||||||
 | 
					    medium customarily used for software interchange, for a price no
 | 
				
			||||||
 | 
					    more than your reasonable cost of physically performing this
 | 
				
			||||||
 | 
					    conveying of source, or (2) access to copy the
 | 
				
			||||||
 | 
					    Corresponding Source from a network server at no charge.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    c) Convey individual copies of the object code with a copy of the
 | 
				
			||||||
 | 
					    written offer to provide the Corresponding Source.  This
 | 
				
			||||||
 | 
					    alternative is allowed only occasionally and noncommercially, and
 | 
				
			||||||
 | 
					    only if you received the object code with such an offer, in accord
 | 
				
			||||||
 | 
					    with subsection 6b.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    d) Convey the object code by offering access from a designated
 | 
				
			||||||
 | 
					    place (gratis or for a charge), and offer equivalent access to the
 | 
				
			||||||
 | 
					    Corresponding Source in the same way through the same place at no
 | 
				
			||||||
 | 
					    further charge.  You need not require recipients to copy the
 | 
				
			||||||
 | 
					    Corresponding Source along with the object code.  If the place to
 | 
				
			||||||
 | 
					    copy the object code is a network server, the Corresponding Source
 | 
				
			||||||
 | 
					    may be on a different server (operated by you or a third party)
 | 
				
			||||||
 | 
					    that supports equivalent copying facilities, provided you maintain
 | 
				
			||||||
 | 
					    clear directions next to the object code saying where to find the
 | 
				
			||||||
 | 
					    Corresponding Source.  Regardless of what server hosts the
 | 
				
			||||||
 | 
					    Corresponding Source, you remain obligated to ensure that it is
 | 
				
			||||||
 | 
					    available for as long as needed to satisfy these requirements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    e) Convey the object code using peer-to-peer transmission, provided
 | 
				
			||||||
 | 
					    you inform other peers where the object code and Corresponding
 | 
				
			||||||
 | 
					    Source of the work are being offered to the general public at no
 | 
				
			||||||
 | 
					    charge under subsection 6d.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A separable portion of the object code, whose source code is excluded
 | 
				
			||||||
 | 
					from the Corresponding Source as a System Library, need not be
 | 
				
			||||||
 | 
					included in conveying the object code work.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A "User Product" is either (1) a "consumer product", which means any
 | 
				
			||||||
 | 
					tangible personal property which is normally used for personal, family,
 | 
				
			||||||
 | 
					or household purposes, or (2) anything designed or sold for incorporation
 | 
				
			||||||
 | 
					into a dwelling.  In determining whether a product is a consumer product,
 | 
				
			||||||
 | 
					doubtful cases shall be resolved in favor of coverage.  For a particular
 | 
				
			||||||
 | 
					product received by a particular user, "normally used" refers to a
 | 
				
			||||||
 | 
					typical or common use of that class of product, regardless of the status
 | 
				
			||||||
 | 
					of the particular user or of the way in which the particular user
 | 
				
			||||||
 | 
					actually uses, or expects or is expected to use, the product.  A product
 | 
				
			||||||
 | 
					is a consumer product regardless of whether the product has substantial
 | 
				
			||||||
 | 
					commercial, industrial or non-consumer uses, unless such uses represent
 | 
				
			||||||
 | 
					the only significant mode of use of the product.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "Installation Information" for a User Product means any methods,
 | 
				
			||||||
 | 
					procedures, authorization keys, or other information required to install
 | 
				
			||||||
 | 
					and execute modified versions of a covered work in that User Product from
 | 
				
			||||||
 | 
					a modified version of its Corresponding Source.  The information must
 | 
				
			||||||
 | 
					suffice to ensure that the continued functioning of the modified object
 | 
				
			||||||
 | 
					code is in no case prevented or interfered with solely because
 | 
				
			||||||
 | 
					modification has been made.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If you convey an object code work under this section in, or with, or
 | 
				
			||||||
 | 
					specifically for use in, a User Product, and the conveying occurs as
 | 
				
			||||||
 | 
					part of a transaction in which the right of possession and use of the
 | 
				
			||||||
 | 
					User Product is transferred to the recipient in perpetuity or for a
 | 
				
			||||||
 | 
					fixed term (regardless of how the transaction is characterized), the
 | 
				
			||||||
 | 
					Corresponding Source conveyed under this section must be accompanied
 | 
				
			||||||
 | 
					by the Installation Information.  But this requirement does not apply
 | 
				
			||||||
 | 
					if neither you nor any third party retains the ability to install
 | 
				
			||||||
 | 
					modified object code on the User Product (for example, the work has
 | 
				
			||||||
 | 
					been installed in ROM).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The requirement to provide Installation Information does not include a
 | 
				
			||||||
 | 
					requirement to continue to provide support service, warranty, or updates
 | 
				
			||||||
 | 
					for a work that has been modified or installed by the recipient, or for
 | 
				
			||||||
 | 
					the User Product in which it has been modified or installed.  Access to a
 | 
				
			||||||
 | 
					network may be denied when the modification itself materially and
 | 
				
			||||||
 | 
					adversely affects the operation of the network or violates the rules and
 | 
				
			||||||
 | 
					protocols for communication across the network.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Corresponding Source conveyed, and Installation Information provided,
 | 
				
			||||||
 | 
					in accord with this section must be in a format that is publicly
 | 
				
			||||||
 | 
					documented (and with an implementation available to the public in
 | 
				
			||||||
 | 
					source code form), and must require no special password or key for
 | 
				
			||||||
 | 
					unpacking, reading or copying.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  7. Additional Terms.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  "Additional permissions" are terms that supplement the terms of this
 | 
				
			||||||
 | 
					License by making exceptions from one or more of its conditions.
 | 
				
			||||||
 | 
					Additional permissions that are applicable to the entire Program shall
 | 
				
			||||||
 | 
					be treated as though they were included in this License, to the extent
 | 
				
			||||||
 | 
					that they are valid under applicable law.  If additional permissions
 | 
				
			||||||
 | 
					apply only to part of the Program, that part may be used separately
 | 
				
			||||||
 | 
					under those permissions, but the entire Program remains governed by
 | 
				
			||||||
 | 
					this License without regard to the additional permissions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  When you convey a copy of a covered work, you may at your option
 | 
				
			||||||
 | 
					remove any additional permissions from that copy, or from any part of
 | 
				
			||||||
 | 
					it.  (Additional permissions may be written to require their own
 | 
				
			||||||
 | 
					removal in certain cases when you modify the work.)  You may place
 | 
				
			||||||
 | 
					additional permissions on material, added by you to a covered work,
 | 
				
			||||||
 | 
					for which you have or can give appropriate copyright permission.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Notwithstanding any other provision of this License, for material you
 | 
				
			||||||
 | 
					add to a covered work, you may (if authorized by the copyright holders of
 | 
				
			||||||
 | 
					that material) supplement the terms of this License with terms:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    a) Disclaiming warranty or limiting liability differently from the
 | 
				
			||||||
 | 
					    terms of sections 15 and 16 of this License; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    b) Requiring preservation of specified reasonable legal notices or
 | 
				
			||||||
 | 
					    author attributions in that material or in the Appropriate Legal
 | 
				
			||||||
 | 
					    Notices displayed by works containing it; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    c) Prohibiting misrepresentation of the origin of that material, or
 | 
				
			||||||
 | 
					    requiring that modified versions of such material be marked in
 | 
				
			||||||
 | 
					    reasonable ways as different from the original version; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    d) Limiting the use for publicity purposes of names of licensors or
 | 
				
			||||||
 | 
					    authors of the material; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    e) Declining to grant rights under trademark law for use of some
 | 
				
			||||||
 | 
					    trade names, trademarks, or service marks; or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    f) Requiring indemnification of licensors and authors of that
 | 
				
			||||||
 | 
					    material by anyone who conveys the material (or modified versions of
 | 
				
			||||||
 | 
					    it) with contractual assumptions of liability to the recipient, for
 | 
				
			||||||
 | 
					    any liability that these contractual assumptions directly impose on
 | 
				
			||||||
 | 
					    those licensors and authors.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  All other non-permissive additional terms are considered "further
 | 
				
			||||||
 | 
					restrictions" within the meaning of section 10.  If the Program as you
 | 
				
			||||||
 | 
					received it, or any part of it, contains a notice stating that it is
 | 
				
			||||||
 | 
					governed by this License along with a term that is a further
 | 
				
			||||||
 | 
					restriction, you may remove that term.  If a license document contains
 | 
				
			||||||
 | 
					a further restriction but permits relicensing or conveying under this
 | 
				
			||||||
 | 
					License, you may add to a covered work material governed by the terms
 | 
				
			||||||
 | 
					of that license document, provided that the further restriction does
 | 
				
			||||||
 | 
					not survive such relicensing or conveying.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If you add terms to a covered work in accord with this section, you
 | 
				
			||||||
 | 
					must place, in the relevant source files, a statement of the
 | 
				
			||||||
 | 
					additional terms that apply to those files, or a notice indicating
 | 
				
			||||||
 | 
					where to find the applicable terms.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Additional terms, permissive or non-permissive, may be stated in the
 | 
				
			||||||
 | 
					form of a separately written license, or stated as exceptions;
 | 
				
			||||||
 | 
					the above requirements apply either way.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  8. Termination.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may not propagate or modify a covered work except as expressly
 | 
				
			||||||
 | 
					provided under this License.  Any attempt otherwise to propagate or
 | 
				
			||||||
 | 
					modify it is void, and will automatically terminate your rights under
 | 
				
			||||||
 | 
					this License (including any patent licenses granted under the third
 | 
				
			||||||
 | 
					paragraph of section 11).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  However, if you cease all violation of this License, then your
 | 
				
			||||||
 | 
					license from a particular copyright holder is reinstated (a)
 | 
				
			||||||
 | 
					provisionally, unless and until the copyright holder explicitly and
 | 
				
			||||||
 | 
					finally terminates your license, and (b) permanently, if the copyright
 | 
				
			||||||
 | 
					holder fails to notify you of the violation by some reasonable means
 | 
				
			||||||
 | 
					prior to 60 days after the cessation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Moreover, your license from a particular copyright holder is
 | 
				
			||||||
 | 
					reinstated permanently if the copyright holder notifies you of the
 | 
				
			||||||
 | 
					violation by some reasonable means, this is the first time you have
 | 
				
			||||||
 | 
					received notice of violation of this License (for any work) from that
 | 
				
			||||||
 | 
					copyright holder, and you cure the violation prior to 30 days after
 | 
				
			||||||
 | 
					your receipt of the notice.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Termination of your rights under this section does not terminate the
 | 
				
			||||||
 | 
					licenses of parties who have received copies or rights from you under
 | 
				
			||||||
 | 
					this License.  If your rights have been terminated and not permanently
 | 
				
			||||||
 | 
					reinstated, you do not qualify to receive new licenses for the same
 | 
				
			||||||
 | 
					material under section 10.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  9. Acceptance Not Required for Having Copies.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You are not required to accept this License in order to receive or
 | 
				
			||||||
 | 
					run a copy of the Program.  Ancillary propagation of a covered work
 | 
				
			||||||
 | 
					occurring solely as a consequence of using peer-to-peer transmission
 | 
				
			||||||
 | 
					to receive a copy likewise does not require acceptance.  However,
 | 
				
			||||||
 | 
					nothing other than this License grants you permission to propagate or
 | 
				
			||||||
 | 
					modify any covered work.  These actions infringe copyright if you do
 | 
				
			||||||
 | 
					not accept this License.  Therefore, by modifying or propagating a
 | 
				
			||||||
 | 
					covered work, you indicate your acceptance of this License to do so.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  10. Automatic Licensing of Downstream Recipients.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Each time you convey a covered work, the recipient automatically
 | 
				
			||||||
 | 
					receives a license from the original licensors, to run, modify and
 | 
				
			||||||
 | 
					propagate that work, subject to this License.  You are not responsible
 | 
				
			||||||
 | 
					for enforcing compliance by third parties with this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  An "entity transaction" is a transaction transferring control of an
 | 
				
			||||||
 | 
					organization, or substantially all assets of one, or subdividing an
 | 
				
			||||||
 | 
					organization, or merging organizations.  If propagation of a covered
 | 
				
			||||||
 | 
					work results from an entity transaction, each party to that
 | 
				
			||||||
 | 
					transaction who receives a copy of the work also receives whatever
 | 
				
			||||||
 | 
					licenses to the work the party's predecessor in interest had or could
 | 
				
			||||||
 | 
					give under the previous paragraph, plus a right to possession of the
 | 
				
			||||||
 | 
					Corresponding Source of the work from the predecessor in interest, if
 | 
				
			||||||
 | 
					the predecessor has it or can get it with reasonable efforts.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You may not impose any further restrictions on the exercise of the
 | 
				
			||||||
 | 
					rights granted or affirmed under this License.  For example, you may
 | 
				
			||||||
 | 
					not impose a license fee, royalty, or other charge for exercise of
 | 
				
			||||||
 | 
					rights granted under this License, and you may not initiate litigation
 | 
				
			||||||
 | 
					(including a cross-claim or counterclaim in a lawsuit) alleging that
 | 
				
			||||||
 | 
					any patent claim is infringed by making, using, selling, offering for
 | 
				
			||||||
 | 
					sale, or importing the Program or any portion of it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  11. Patents.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A "contributor" is a copyright holder who authorizes use under this
 | 
				
			||||||
 | 
					License of the Program or a work on which the Program is based.  The
 | 
				
			||||||
 | 
					work thus licensed is called the contributor's "contributor version".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A contributor's "essential patent claims" are all patent claims
 | 
				
			||||||
 | 
					owned or controlled by the contributor, whether already acquired or
 | 
				
			||||||
 | 
					hereafter acquired, that would be infringed by some manner, permitted
 | 
				
			||||||
 | 
					by this License, of making, using, or selling its contributor version,
 | 
				
			||||||
 | 
					but do not include claims that would be infringed only as a
 | 
				
			||||||
 | 
					consequence of further modification of the contributor version.  For
 | 
				
			||||||
 | 
					purposes of this definition, "control" includes the right to grant
 | 
				
			||||||
 | 
					patent sublicenses in a manner consistent with the requirements of
 | 
				
			||||||
 | 
					this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Each contributor grants you a non-exclusive, worldwide, royalty-free
 | 
				
			||||||
 | 
					patent license under the contributor's essential patent claims, to
 | 
				
			||||||
 | 
					make, use, sell, offer for sale, import and otherwise run, modify and
 | 
				
			||||||
 | 
					propagate the contents of its contributor version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  In the following three paragraphs, a "patent license" is any express
 | 
				
			||||||
 | 
					agreement or commitment, however denominated, not to enforce a patent
 | 
				
			||||||
 | 
					(such as an express permission to practice a patent or covenant not to
 | 
				
			||||||
 | 
					sue for patent infringement).  To "grant" such a patent license to a
 | 
				
			||||||
 | 
					party means to make such an agreement or commitment not to enforce a
 | 
				
			||||||
 | 
					patent against the party.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If you convey a covered work, knowingly relying on a patent license,
 | 
				
			||||||
 | 
					and the Corresponding Source of the work is not available for anyone
 | 
				
			||||||
 | 
					to copy, free of charge and under the terms of this License, through a
 | 
				
			||||||
 | 
					publicly available network server or other readily accessible means,
 | 
				
			||||||
 | 
					then you must either (1) cause the Corresponding Source to be so
 | 
				
			||||||
 | 
					available, or (2) arrange to deprive yourself of the benefit of the
 | 
				
			||||||
 | 
					patent license for this particular work, or (3) arrange, in a manner
 | 
				
			||||||
 | 
					consistent with the requirements of this License, to extend the patent
 | 
				
			||||||
 | 
					license to downstream recipients.  "Knowingly relying" means you have
 | 
				
			||||||
 | 
					actual knowledge that, but for the patent license, your conveying the
 | 
				
			||||||
 | 
					covered work in a country, or your recipient's use of the covered work
 | 
				
			||||||
 | 
					in a country, would infringe one or more identifiable patents in that
 | 
				
			||||||
 | 
					country that you have reason to believe are valid.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If, pursuant to or in connection with a single transaction or
 | 
				
			||||||
 | 
					arrangement, you convey, or propagate by procuring conveyance of, a
 | 
				
			||||||
 | 
					covered work, and grant a patent license to some of the parties
 | 
				
			||||||
 | 
					receiving the covered work authorizing them to use, propagate, modify
 | 
				
			||||||
 | 
					or convey a specific copy of the covered work, then the patent license
 | 
				
			||||||
 | 
					you grant is automatically extended to all recipients of the covered
 | 
				
			||||||
 | 
					work and works based on it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  A patent license is "discriminatory" if it does not include within
 | 
				
			||||||
 | 
					the scope of its coverage, prohibits the exercise of, or is
 | 
				
			||||||
 | 
					conditioned on the non-exercise of one or more of the rights that are
 | 
				
			||||||
 | 
					specifically granted under this License.  You may not convey a covered
 | 
				
			||||||
 | 
					work if you are a party to an arrangement with a third party that is
 | 
				
			||||||
 | 
					in the business of distributing software, under which you make payment
 | 
				
			||||||
 | 
					to the third party based on the extent of your activity of conveying
 | 
				
			||||||
 | 
					the work, and under which the third party grants, to any of the
 | 
				
			||||||
 | 
					parties who would receive the covered work from you, a discriminatory
 | 
				
			||||||
 | 
					patent license (a) in connection with copies of the covered work
 | 
				
			||||||
 | 
					conveyed by you (or copies made from those copies), or (b) primarily
 | 
				
			||||||
 | 
					for and in connection with specific products or compilations that
 | 
				
			||||||
 | 
					contain the covered work, unless you entered into that arrangement,
 | 
				
			||||||
 | 
					or that patent license was granted, prior to 28 March 2007.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Nothing in this License shall be construed as excluding or limiting
 | 
				
			||||||
 | 
					any implied license or other defenses to infringement that may
 | 
				
			||||||
 | 
					otherwise be available to you under applicable patent law.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  12. No Surrender of Others' Freedom.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If conditions are imposed on you (whether by court order, agreement or
 | 
				
			||||||
 | 
					otherwise) that contradict the conditions of this License, they do not
 | 
				
			||||||
 | 
					excuse you from the conditions of this License.  If you cannot convey a
 | 
				
			||||||
 | 
					covered work so as to satisfy simultaneously your obligations under this
 | 
				
			||||||
 | 
					License and any other pertinent obligations, then as a consequence you may
 | 
				
			||||||
 | 
					not convey it at all.  For example, if you agree to terms that obligate you
 | 
				
			||||||
 | 
					to collect a royalty for further conveying from those to whom you convey
 | 
				
			||||||
 | 
					the Program, the only way you could satisfy both those terms and this
 | 
				
			||||||
 | 
					License would be to refrain entirely from conveying the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  13. Remote Network Interaction; Use with the GNU General Public License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Notwithstanding any other provision of this License, if you modify the
 | 
				
			||||||
 | 
					Program, your modified version must prominently offer all users
 | 
				
			||||||
 | 
					interacting with it remotely through a computer network (if your version
 | 
				
			||||||
 | 
					supports such interaction) an opportunity to receive the Corresponding
 | 
				
			||||||
 | 
					Source of your version by providing access to the Corresponding Source
 | 
				
			||||||
 | 
					from a network server at no charge, through some standard or customary
 | 
				
			||||||
 | 
					means of facilitating copying of software.  This Corresponding Source
 | 
				
			||||||
 | 
					shall include the Corresponding Source for any work covered by version 3
 | 
				
			||||||
 | 
					of the GNU General Public License that is incorporated pursuant to the
 | 
				
			||||||
 | 
					following paragraph.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Notwithstanding any other provision of this License, you have
 | 
				
			||||||
 | 
					permission to link or combine any covered work with a work licensed
 | 
				
			||||||
 | 
					under version 3 of the GNU General Public License into a single
 | 
				
			||||||
 | 
					combined work, and to convey the resulting work.  The terms of this
 | 
				
			||||||
 | 
					License will continue to apply to the part which is the covered work,
 | 
				
			||||||
 | 
					but the work with which it is combined will remain governed by version
 | 
				
			||||||
 | 
					3 of the GNU General Public License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  14. Revised Versions of this License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The Free Software Foundation may publish revised and/or new versions of
 | 
				
			||||||
 | 
					the GNU Affero General Public License from time to time.  Such new versions
 | 
				
			||||||
 | 
					will be similar in spirit to the present version, but may differ in detail to
 | 
				
			||||||
 | 
					address new problems or concerns.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Each version is given a distinguishing version number.  If the
 | 
				
			||||||
 | 
					Program specifies that a certain numbered version of the GNU Affero General
 | 
				
			||||||
 | 
					Public License "or any later version" applies to it, you have the
 | 
				
			||||||
 | 
					option of following the terms and conditions either of that numbered
 | 
				
			||||||
 | 
					version or of any later version published by the Free Software
 | 
				
			||||||
 | 
					Foundation.  If the Program does not specify a version number of the
 | 
				
			||||||
 | 
					GNU Affero General Public License, you may choose any version ever published
 | 
				
			||||||
 | 
					by the Free Software Foundation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If the Program specifies that a proxy can decide which future
 | 
				
			||||||
 | 
					versions of the GNU Affero General Public License can be used, that proxy's
 | 
				
			||||||
 | 
					public statement of acceptance of a version permanently authorizes you
 | 
				
			||||||
 | 
					to choose that version for the Program.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Later license versions may give you additional or different
 | 
				
			||||||
 | 
					permissions.  However, no additional obligations are imposed on any
 | 
				
			||||||
 | 
					author or copyright holder as a result of your choosing to follow a
 | 
				
			||||||
 | 
					later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  15. Disclaimer of Warranty.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
 | 
				
			||||||
 | 
					APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
 | 
				
			||||||
 | 
					HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
 | 
				
			||||||
 | 
					OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
 | 
				
			||||||
 | 
					THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 | 
				
			||||||
 | 
					PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
 | 
				
			||||||
 | 
					IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
 | 
				
			||||||
 | 
					ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  16. Limitation of Liability.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
 | 
				
			||||||
 | 
					WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
 | 
				
			||||||
 | 
					THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
 | 
				
			||||||
 | 
					GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
 | 
				
			||||||
 | 
					USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
 | 
				
			||||||
 | 
					DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
 | 
				
			||||||
 | 
					PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
 | 
				
			||||||
 | 
					EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
 | 
				
			||||||
 | 
					SUCH DAMAGES.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  17. Interpretation of Sections 15 and 16.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If the disclaimer of warranty and limitation of liability provided
 | 
				
			||||||
 | 
					above cannot be given local legal effect according to their terms,
 | 
				
			||||||
 | 
					reviewing courts shall apply local law that most closely approximates
 | 
				
			||||||
 | 
					an absolute waiver of all civil liability in connection with the
 | 
				
			||||||
 | 
					Program, unless a warranty or assumption of liability accompanies a
 | 
				
			||||||
 | 
					copy of the Program in return for a fee.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                     END OF TERMS AND CONDITIONS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            How to Apply These Terms to Your New Programs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If you develop a new program, and you want it to be of the greatest
 | 
				
			||||||
 | 
					possible use to the public, the best way to achieve this is to make it
 | 
				
			||||||
 | 
					free software which everyone can redistribute and change under these terms.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  To do so, attach the following notices to the program.  It is safest
 | 
				
			||||||
 | 
					to attach them to the start of each source file to most effectively
 | 
				
			||||||
 | 
					state the exclusion of warranty; and each file should have at least
 | 
				
			||||||
 | 
					the "copyright" line and a pointer to where the full notice is found.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <one line to give the program's name and a brief idea of what it does.>
 | 
				
			||||||
 | 
					    Copyright (C) <year>  <name of author>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					    it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					    the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					    (at your option) any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					    GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Also add information on how to contact you by electronic and paper mail.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  If your software can interact with users remotely through a computer
 | 
				
			||||||
 | 
					network, you should also make sure that it provides a way for users to
 | 
				
			||||||
 | 
					get its source.  For example, if your program is a web application, its
 | 
				
			||||||
 | 
					interface could display a "Source" link that leads users to an archive
 | 
				
			||||||
 | 
					of the code.  There are many ways you could offer source, and different
 | 
				
			||||||
 | 
					solutions will be better for different programs; see section 13 for the
 | 
				
			||||||
 | 
					specific requirements.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You should also get your employer (if you work as a programmer) or school,
 | 
				
			||||||
 | 
					if any, to sign a "copyright disclaimer" for the program, if necessary.
 | 
				
			||||||
 | 
					For more information on this, and how to apply and follow the GNU AGPL, see
 | 
				
			||||||
 | 
					<https://www.gnu.org/licenses/>.
 | 
				
			||||||
							
								
								
									
										222
									
								
								music.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,222 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Initialize random shit
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters("music");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					new bot_protection($frontend, $get, $filters, "music", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$payload = [
 | 
				
			||||||
 | 
						"timetaken" => microtime(true),
 | 
				
			||||||
 | 
						"class" => "",
 | 
				
			||||||
 | 
						"right-left" => "",
 | 
				
			||||||
 | 
						"right-right" => "",
 | 
				
			||||||
 | 
						"left" => ""
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						$results = $scraper->music($get);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $error){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$frontend->drawscrapererror($error->getMessage(), $get, "music", $payload["timetaken"]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$categories = [
 | 
				
			||||||
 | 
						"song" => "",
 | 
				
			||||||
 | 
						"author" => "",
 | 
				
			||||||
 | 
						"playlist" => "",
 | 
				
			||||||
 | 
						"album" => "",
 | 
				
			||||||
 | 
						"podcast" => "",
 | 
				
			||||||
 | 
						"user" => ""
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Set the main container
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					$main = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(count($results["song"]) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$main = "song";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}elseif(count($results["album"]) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$main = "album";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}elseif(count($results["playlist"]) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$main = "playlist";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}elseif(count($results["podcast"]) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$main = "podcast";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}elseif(count($results["author"]) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$main = "author";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					}elseif(count($results["user"]) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$main = "user";
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// No results found!
 | 
				
			||||||
 | 
						echo
 | 
				
			||||||
 | 
							$frontend->drawerror(
 | 
				
			||||||
 | 
								"Nobody here but us chickens!",
 | 
				
			||||||
 | 
								'Have you tried:' .
 | 
				
			||||||
 | 
									'<ul>' .
 | 
				
			||||||
 | 
										'<li>Using a different scraper</li>' .
 | 
				
			||||||
 | 
										'<li>Using fewer keywords</li>' .
 | 
				
			||||||
 | 
										'<li>Defining broader filters (Is NSFW turned off?)</li>' .
 | 
				
			||||||
 | 
									'</ul>' .
 | 
				
			||||||
 | 
								'</div>'
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Generate list of songs
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					foreach($categories as $name => $data){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						foreach($results[$name] as $item){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$greentext = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($item["date"]) &&
 | 
				
			||||||
 | 
								$item["date"] !== null
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$greentext[] = date("jS M y @ g:ia", $item["date"]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($item["views"]) &&
 | 
				
			||||||
 | 
								$item["views"] !== null
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$views = number_format($item["views"]) . " views";
 | 
				
			||||||
 | 
								$greentext[] = $views;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($item["followers"]) &&
 | 
				
			||||||
 | 
								$item["followers"] !== null
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$greentext[] = number_format($item["followers"]) . " followers";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($item["author"]["name"]) &&
 | 
				
			||||||
 | 
								$item["author"]["name"] !== null
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$greentext[] = $item["author"]["name"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$greentext = implode(" • ", $greentext);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($item["duration"]) &&
 | 
				
			||||||
 | 
								$item["duration"] !== null
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$duration = $frontend->s_to_timestamp($item["duration"]);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$duration = null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$tabindex = $name == $main ? true : false;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$customhtml = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								(
 | 
				
			||||||
 | 
									$name == "song" ||
 | 
				
			||||||
 | 
									$name == "podcast"
 | 
				
			||||||
 | 
								) &&
 | 
				
			||||||
 | 
								$item["stream"]["endpoint"] !== null
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$customhtml =
 | 
				
			||||||
 | 
									'<audio src="/audio/' . $item["stream"]["endpoint"] . '?s=' . urlencode($item["stream"]["url"]) . '" controls autostart="false" preload="none">';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$categories[$name] .= $frontend->drawtextresult($item, $greentext, $duration, $get["s"], $tabindex, $customhtml);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$payload["left"] = $categories[$main];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// dont re-draw the category
 | 
				
			||||||
 | 
					unset($categories[$main]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Populate right handside
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$i = 1;
 | 
				
			||||||
 | 
					foreach($categories as $name => $value){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($value == ""){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							continue;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($i % 2 === 1){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$write = "right-left";
 | 
				
			||||||
 | 
						}else{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$write = "right-right";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload[$write] .=
 | 
				
			||||||
 | 
							'<div class="answer-wrapper">' .
 | 
				
			||||||
 | 
							'<input id="answer' . $i . '" class="spoiler" type="checkbox">' .
 | 
				
			||||||
 | 
							'<div class="answer">' .
 | 
				
			||||||
 | 
								'<div class="answer-title">' .
 | 
				
			||||||
 | 
									'<a class="answer-title" href="?s=' . urlencode($get["s"]);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload[$write] .=
 | 
				
			||||||
 | 
							'&type=' . $name . '"><h2>' . ucfirst($name) . 's</h2></a>';
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload[$write] .=
 | 
				
			||||||
 | 
								'</div>' .
 | 
				
			||||||
 | 
								$categories[$name] .
 | 
				
			||||||
 | 
							'</div>' .
 | 
				
			||||||
 | 
							'<label class="spoiler-button" for="answer' . $i . '"></label></div>';
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$i++;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if($i !== 1){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["class"] = " has-answer";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if($results["npt"] !== null){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["left"] .=
 | 
				
			||||||
 | 
							'<a href="' . $frontend->htmlnextpage($get, $results["npt"], "music") . '" class="nextpage">Next page ></a>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo $frontend->load("search.html", $payload);
 | 
				
			||||||
							
								
								
									
										86
									
								
								news.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,86 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Initialize random shit
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[$scraper, $filters] = $frontend->getscraperfilters("news");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$get = $frontend->parsegetfilters($_GET, $filters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Captcha
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					include "lib/bot_protection.php";
 | 
				
			||||||
 | 
					new bot_protection($frontend, $get, $filters, "news", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$payload = [
 | 
				
			||||||
 | 
						"timetaken" => microtime(true),
 | 
				
			||||||
 | 
						"class" => "",
 | 
				
			||||||
 | 
						"right-left" => "",
 | 
				
			||||||
 | 
						"right-right" => "",
 | 
				
			||||||
 | 
						"left" => ""
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						$results = $scraper->news($get);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $error){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$frontend->drawscrapererror($error->getMessage(), $get, "news", $payload["timetaken"]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Populate links
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					if(count($results["news"]) === 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["left"] =
 | 
				
			||||||
 | 
							'<div class="infobox">' .
 | 
				
			||||||
 | 
								"<h1>Nobody here but us chickens!</h1>" .
 | 
				
			||||||
 | 
								'Have you tried:' .
 | 
				
			||||||
 | 
								'<ul>' .
 | 
				
			||||||
 | 
									'<li>Using a different scraper</li>' .
 | 
				
			||||||
 | 
									'<li>Using fewer keywords</li>' .
 | 
				
			||||||
 | 
									'<li>Defining broader filters (Is NSFW turned off?)</li>' .
 | 
				
			||||||
 | 
								'</ul>' .
 | 
				
			||||||
 | 
							'</div>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					foreach($results["news"] as $news){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$greentext = [];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($news["date"] !== null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$greentext[] = date("jS M y @ g:ia", $news["date"]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($news["author"] !== null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$greentext[] = htmlspecialchars($news["author"]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(count($greentext) !== 0){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$greentext = implode(" • ", $greentext);
 | 
				
			||||||
 | 
						}else{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$greentext = null;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$n = null;
 | 
				
			||||||
 | 
						$payload["left"] .= $frontend->drawtextresult($news, $greentext, $n, $get["s"]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if($results["npt"] !== null){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$payload["left"] .=
 | 
				
			||||||
 | 
							'<a href="' . $frontend->htmlnextpage($get, $results["npt"], "news") . '" class="nextpage">Next page ></a>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo $frontend->load("search.html", $payload);
 | 
				
			||||||
							
								
								
									
										42
									
								
								opensearch.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,42 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Content-Type: application/xml");
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$domain =
 | 
				
			||||||
 | 
						htmlspecialchars(
 | 
				
			||||||
 | 
							(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "https" : "http") .
 | 
				
			||||||
 | 
							'://' . $_SERVER["HTTP_HOST"]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(
 | 
				
			||||||
 | 
						preg_match(
 | 
				
			||||||
 | 
							'/\.onion$/',
 | 
				
			||||||
 | 
							$domain
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$onion = true;
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$onion = false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						'<?xml version="1.0" encoding="UTF-8"?>' .
 | 
				
			||||||
 | 
						'<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' .
 | 
				
			||||||
 | 
							'<ShortName>' . htmlspecialchars(config::SERVER_NAME) . ($onion ? " (onion)" : "") . '</ShortName>' .
 | 
				
			||||||
 | 
							'<InputEncoding>UTF-8</InputEncoding>' .
 | 
				
			||||||
 | 
							'<Image width="16" height="16">' . $domain . '/favicon.ico</Image>' .
 | 
				
			||||||
 | 
							'<Url type="text/html" method="GET" template="' . $domain . '/web?s={searchTerms}"/>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(
 | 
				
			||||||
 | 
						isset($_GET["ac"]) &&
 | 
				
			||||||
 | 
						is_string($_GET["ac"]) &&
 | 
				
			||||||
 | 
						$_GET["ac"] != "disabled"
 | 
				
			||||||
 | 
					){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo '<Url rel="suggestions" type="application/x-suggestions+json" template="' . $domain . '/api/v1/ac?s={searchTerms}&scraper=' . htmlspecialchars($_GET["ac"]) . '"/>';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo '</OpenSearchDescription>';
 | 
				
			||||||
							
								
								
									
										36
									
								
								oracles/base.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,36 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					abstract class oracle {
 | 
				
			||||||
 | 
						// some info to spit out alongside the result, so the user knows
 | 
				
			||||||
 | 
						//  what exactly is giving out the answer. prevents confusion
 | 
				
			||||||
 | 
						//   about what oracle is answering them for ambiguous queries.
 | 
				
			||||||
 | 
						public $info = [
 | 
				
			||||||
 | 
							"name" => "some oracle"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						// this function should take in a query string search from $_GET,
 | 
				
			||||||
 | 
						//  and return a bool determining whether or not it is a question
 | 
				
			||||||
 | 
						//   intended for the oracle.
 | 
				
			||||||
 | 
						public function check_query($q) {
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// produce the correct answer for the query using the oracle.
 | 
				
			||||||
 | 
						//  note: if it becomes apparent /during generation/ that the
 | 
				
			||||||
 | 
						//   query is not in fact for the oracle, returning an empty
 | 
				
			||||||
 | 
						//    string will kill the oracle pane.
 | 
				
			||||||
 | 
						// answer format: ["ans1 title" => "ans1", ...]
 | 
				
			||||||
 | 
						public function generate_response($q) {
 | 
				
			||||||
 | 
							return "";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					// backwards compatibility
 | 
				
			||||||
 | 
					if (!function_exists('str_starts_with')) {
 | 
				
			||||||
 | 
						function str_starts_with($haystack, $needle) {
 | 
				
			||||||
 | 
							return strncmp($haystack, $needle, strlen($needle)) === 0;;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					if (!function_exists('str_contains')) {
 | 
				
			||||||
 | 
						function str_contains($haystack, $needle) {
 | 
				
			||||||
 | 
							return strpos((string)$haystack, (string)$needle) !== false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
							
								
								
									
										165
									
								
								oracles/calc.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,165 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					include_once("oracles/base.php");
 | 
				
			||||||
 | 
					class calculator extends oracle {
 | 
				
			||||||
 | 
						public $info = [
 | 
				
			||||||
 | 
							"name" => "calculator"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						public function check_query($q) {
 | 
				
			||||||
 | 
							// straight numerics should go to that oracle
 | 
				
			||||||
 | 
							if (is_numeric($q)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// all chars should be number-y or operator-y
 | 
				
			||||||
 | 
							$char_whitelist = str_split("1234567890.+-/*^%() ");
 | 
				
			||||||
 | 
							foreach (str_split($q) as $char) {
 | 
				
			||||||
 | 
								if (!in_array($char, $char_whitelist)) {
 | 
				
			||||||
 | 
									return false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// a custom parser and calculator because FUCK YUO, libraries are
 | 
				
			||||||
 | 
						//  gay.
 | 
				
			||||||
 | 
						public function generate_response($q)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$nums = str_split("1234567890.");
 | 
				
			||||||
 | 
							$ops = str_split("+-/*^%;");
 | 
				
			||||||
 | 
							$grouping = str_split("()");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$q = str_replace(" ", "", $q);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// backstop for the parser so it catches the last
 | 
				
			||||||
 | 
							//  numeric token
 | 
				
			||||||
 | 
							$q .= ";"; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// the following comments refer to this example input:
 | 
				
			||||||
 | 
							//  21+9*(3+2^9)+1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// 2-length lists of the following patterns:
 | 
				
			||||||
 | 
							//  ["n" (umeric), <some number>]
 | 
				
			||||||
 | 
							//  ["o" (perator), "<some operator>"]
 | 
				
			||||||
 | 
							//  ["g" (roup explicit), <"(" or ")">]
 | 
				
			||||||
 | 
							// e.g. [["n", 21], ["o", "+"], ["n", 9], ["o", *],
 | 
				
			||||||
 | 
							//       ["g", "("], ["n", 3], ["o", "+"], ["n", 2],
 | 
				
			||||||
 | 
							//       ["o", "^"], ["n", 9], ["g", ")"], ["o", "+"],
 | 
				
			||||||
 | 
							//       ["n", "1"]]
 | 
				
			||||||
 | 
							$tokens = array();
 | 
				
			||||||
 | 
							$dragline = 0;
 | 
				
			||||||
 | 
							foreach(str_split($q) as $i=>$char) {
 | 
				
			||||||
 | 
								if (in_array($char, $nums)) {
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								elseif (in_array($char, $ops) || in_array($char, $grouping)) {
 | 
				
			||||||
 | 
									// hitting a non-numeric implies everything since the
 | 
				
			||||||
 | 
									//  last hit has been part of a number
 | 
				
			||||||
 | 
									$capture = substr($q, $dragline, $i - $dragline);
 | 
				
			||||||
 | 
									// prevent the int cast from creating imaginary
 | 
				
			||||||
 | 
									//  ["n", 0] tokens
 | 
				
			||||||
 | 
									if ($capture != "") {
 | 
				
			||||||
 | 
										if (substr_count($capture, ".") > 1) {
 | 
				
			||||||
 | 
											return "";
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										array_push($tokens, ["n", (float)$capture]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									// reset to one past the current (non-numeric) char
 | 
				
			||||||
 | 
									$dragline = $i + 1; 
 | 
				
			||||||
 | 
									// the `;' backstop is not a real token and this should
 | 
				
			||||||
 | 
									//  never be present in the token list
 | 
				
			||||||
 | 
									if ($char != ";") {
 | 
				
			||||||
 | 
										array_push($tokens, [
 | 
				
			||||||
 | 
											($char == "(" || $char == ")") ? "g" : "o",
 | 
				
			||||||
 | 
											$char
 | 
				
			||||||
 | 
										]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else {
 | 
				
			||||||
 | 
									return "";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// two operators back to back should fail
 | 
				
			||||||
 | 
							for ($i = 1; $i < count($tokens); $i++) {
 | 
				
			||||||
 | 
								if ($tokens[$i][0] == "o" && $tokens[$i-1][0] == "o") {
 | 
				
			||||||
 | 
									return "";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// no implicit multiplication
 | 
				
			||||||
 | 
							for ($i = 0; $i < count($tokens) - 1; $i++) {
 | 
				
			||||||
 | 
								if ($tokens[$i][0] == "n" && $tokens[$i+1] == ["g", "("]) {
 | 
				
			||||||
 | 
									return "";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//strategy:
 | 
				
			||||||
 | 
							// traverse to group open (if there is one)
 | 
				
			||||||
 | 
							//  - return to start with the internals
 | 
				
			||||||
 | 
							// traverse to ^, attack token previous and after
 | 
				
			||||||
 | 
							// same but for *, then / then + then -
 | 
				
			||||||
 | 
							// poppers all teh way down
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								return [
 | 
				
			||||||
 | 
									substr($q, 0, strlen($q)-1)." = " => $this->executeBlock($tokens)[0][1]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}   
 | 
				
			||||||
 | 
							catch (\Throwable $e) {
 | 
				
			||||||
 | 
								if (get_class($e) == "DivisionByZeroError") {
 | 
				
			||||||
 | 
									return [
 | 
				
			||||||
 | 
										$q." = " => "Division by Zero Error!!"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return "";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						public function executeBlock($tokens) {
 | 
				
			||||||
 | 
							if (count($tokens) >= 2 && $tokens[0][0] == "o" && $tokens[0][1] == "-" && $tokens[1][0] == "n") {
 | 
				
			||||||
 | 
								array_splice($tokens, 0, 2, [["n", -1 * (float)$tokens[1][1]]]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (count($tokens) > 0 && $tokens[0][0] == "o" || $tokens[count($tokens)-1][0] == "o") {
 | 
				
			||||||
 | 
								throw new Exception("Error Processing Request", 1);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							while (in_array(["g", "("], $tokens)) {
 | 
				
			||||||
 | 
								$first_open = array_search(["g", "("], $tokens);
 | 
				
			||||||
 | 
								$enclosedality = 1;
 | 
				
			||||||
 | 
								for ($i = $first_open+1; $i < count($tokens); $i++) {
 | 
				
			||||||
 | 
									if ($tokens[$i][0] == "g") {
 | 
				
			||||||
 | 
										$enclosedality += ($tokens[$i][1] == "(") ? 1 : -1;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if ($enclosedality == 0) {
 | 
				
			||||||
 | 
										array_splice($tokens, 
 | 
				
			||||||
 | 
											$first_open, 
 | 
				
			||||||
 | 
											$i+1 - $first_open, 
 | 
				
			||||||
 | 
											$this->executeBlock(
 | 
				
			||||||
 | 
												array_slice($tokens, $first_open+1, $i-1 - $first_open)
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$operators_in_pemdas_order = [
 | 
				
			||||||
 | 
								"^" => (fn($x, $y) => $x ** $y),
 | 
				
			||||||
 | 
								"*" => (fn($x, $y) => $x * $y),
 | 
				
			||||||
 | 
								"/" => (fn($x, $y) => $x / $y), 
 | 
				
			||||||
 | 
								"%" => (fn($x, $y) => $x % $y),
 | 
				
			||||||
 | 
								"+" => (fn($x, $y) => $x + $y), 
 | 
				
			||||||
 | 
								"-" => (fn($x, $y) => $x - $y)
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							foreach ($operators_in_pemdas_order as $op=>$func) {
 | 
				
			||||||
 | 
								while (in_array(["o", $op], $tokens)) {
 | 
				
			||||||
 | 
									for ($i = 0; $i < count($tokens); $i++) {
 | 
				
			||||||
 | 
										if ($tokens[$i] == ["o", $op]) {
 | 
				
			||||||
 | 
											array_splice(
 | 
				
			||||||
 | 
												$tokens,
 | 
				
			||||||
 | 
												$i-1,
 | 
				
			||||||
 | 
												3,
 | 
				
			||||||
 | 
												[["n", (string)($func((float)$tokens[$i-1][1], (float)$tokens[$i+1][1]))]]
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return $tokens;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
							
								
								
									
										40
									
								
								oracles/encoder.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,40 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					include_once("oracles/base.php");
 | 
				
			||||||
 | 
					class encoder extends oracle {
 | 
				
			||||||
 | 
						public $info = [
 | 
				
			||||||
 | 
							"name" => "text encoder/hasher"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						private $special_types = [
 | 
				
			||||||
 | 
							"rot13",
 | 
				
			||||||
 | 
							"base64"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						public function check_query($q) {
 | 
				
			||||||
 | 
							$types = array_merge($this->special_types, hash_algos());
 | 
				
			||||||
 | 
							foreach ($types as $type) {
 | 
				
			||||||
 | 
								$type .= " ";
 | 
				
			||||||
 | 
								if (str_starts_with($q, $type)) {
 | 
				
			||||||
 | 
									return true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						public function generate_response($q)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$type = explode(" ", $q)[0];
 | 
				
			||||||
 | 
							$victim = substr($q, strlen($type)+1);
 | 
				
			||||||
 | 
							if (in_array($type, hash_algos())) {
 | 
				
			||||||
 | 
								return [$type." hash" => hash($type, $victim)];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							switch ($type) {
 | 
				
			||||||
 | 
								case "rot13":
 | 
				
			||||||
 | 
									return ["rot13 encoded" => str_rot13($victim)];
 | 
				
			||||||
 | 
								case "base64":
 | 
				
			||||||
 | 
									return [
 | 
				
			||||||
 | 
										"base64 encoded" => base64_encode($victim),
 | 
				
			||||||
 | 
										"base64 decoded" => base64_decode($victim)
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return "";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
							
								
								
									
										54
									
								
								oracles/numerics.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,54 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					include_once("oracles/base.php");
 | 
				
			||||||
 | 
					class numerics extends oracle {
 | 
				
			||||||
 | 
						public $info = [
 | 
				
			||||||
 | 
							"name" => "numeric base conversion"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						public function check_query($q) {
 | 
				
			||||||
 | 
							if (str_contains($q, " ")) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$q = strtolower($q);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$profiles = [
 | 
				
			||||||
 | 
								["0x", str_split("0123456789abcdef")],
 | 
				
			||||||
 | 
								["", str_split("1234567890")],
 | 
				
			||||||
 | 
								["b", str_split("10")]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							foreach ($profiles as $profile) {
 | 
				
			||||||
 | 
								$good = true;
 | 
				
			||||||
 | 
								$good &= str_starts_with($q, $profile[0]);
 | 
				
			||||||
 | 
								$nq = substr($q, strlen($profile[0]));
 | 
				
			||||||
 | 
								foreach (str_split($nq) as $c) {
 | 
				
			||||||
 | 
									$good &= in_array($c, $profile[1]);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if ($good) {
 | 
				
			||||||
 | 
									return true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						public function generate_response($q) {
 | 
				
			||||||
 | 
							$n = 0;
 | 
				
			||||||
 | 
							if (str_starts_with($q, "0x")) {
 | 
				
			||||||
 | 
								$nq = substr($q, strlen("0x"));
 | 
				
			||||||
 | 
								$n = hexdec($nq);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							elseif (str_starts_with($q, "b")) {
 | 
				
			||||||
 | 
								$nq = substr($q, strlen("b"));
 | 
				
			||||||
 | 
								$n = bindec($nq);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else {
 | 
				
			||||||
 | 
								$n = (int)$q;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"decimal (base 10)" => (string)$n,
 | 
				
			||||||
 | 
								"hexadecimal (base 16)" => "0x".(string)dechex($n),
 | 
				
			||||||
 | 
								"binary (base 2)" => "b".(string)decbin($n),
 | 
				
			||||||
 | 
								"" => "binary inputs should be prefixed with 'b', hex with '0x'."
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
							
								
								
									
										45
									
								
								oracles/time.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,45 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					include_once("oracles/base.php");
 | 
				
			||||||
 | 
					class time extends oracle {
 | 
				
			||||||
 | 
						public $info = [
 | 
				
			||||||
 | 
							"name" => "what time is it?"
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
						public function check_query($q) {
 | 
				
			||||||
 | 
							$prompts = [
 | 
				
			||||||
 | 
								"what", "time", "is", "it",
 | 
				
			||||||
 | 
								"right", "now", "the", "current",
 | 
				
			||||||
 | 
								"get", "date"
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							$q = str_replace(",", "", $q);
 | 
				
			||||||
 | 
							$q = str_replace("?", "", $q);
 | 
				
			||||||
 | 
							$q = str_replace("what's", "what is", $q);
 | 
				
			||||||
 | 
							$oq = $q;
 | 
				
			||||||
 | 
							$q = explode(" ", $q);
 | 
				
			||||||
 | 
							$count = 0;
 | 
				
			||||||
 | 
							foreach ($q as $word) {
 | 
				
			||||||
 | 
								if (in_array($word, $prompts)) {
 | 
				
			||||||
 | 
									$count++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// remove one from total count if a timezone is specified
 | 
				
			||||||
 | 
							return ($count/(count($q) + (str_contains($oq, "tz:") ? -1 : 0))) > 3/4;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						public function generate_response($q) {
 | 
				
			||||||
 | 
							$timezone = timezone_name_from_abbr("UTC");
 | 
				
			||||||
 | 
							foreach (explode(" ", $q) as $word) {
 | 
				
			||||||
 | 
								if (str_starts_with($word, "tz:")) {
 | 
				
			||||||
 | 
									$decltz = timezone_name_from_abbr(substr($word, 3, 3));
 | 
				
			||||||
 | 
									if ($decltz) {
 | 
				
			||||||
 | 
										$timezone = $decltz;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							date_default_timezone_set($timezone);
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"The time in ".$timezone => date("H:i:s"),
 | 
				
			||||||
 | 
								" " => date("l, F jS"),
 | 
				
			||||||
 | 
								"" => "include the string \"tz:XXX\" to use timezone XXX"
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
							
								
								
									
										156
									
								
								proxy.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,156 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					include "lib/curlproxy.php";
 | 
				
			||||||
 | 
					$proxy = new proxy();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!isset($_GET["i"])){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						header("X-Error: No URL(i) provided!");
 | 
				
			||||||
 | 
						$proxy->do404();
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// original size request, stream file to browser
 | 
				
			||||||
 | 
						if(
 | 
				
			||||||
 | 
							!isset($_GET["s"]) ||
 | 
				
			||||||
 | 
							$_GET["s"] == "original"
 | 
				
			||||||
 | 
						){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$proxy->stream_linear_image($_GET["i"]);
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// bing request, ask bing to resize and stream to browser
 | 
				
			||||||
 | 
						$image = parse_url($_GET["i"]);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(
 | 
				
			||||||
 | 
							isset($image["host"]) &&
 | 
				
			||||||
 | 
							preg_match(
 | 
				
			||||||
 | 
								'/^[A-z0-9.]*bing\.(net|com)$/i',
 | 
				
			||||||
 | 
								$image["host"]
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!isset($image["query"]) ||
 | 
				
			||||||
 | 
								!isset($image["path"]) ||
 | 
				
			||||||
 | 
								$image["path"] != "/th"
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								header("X-Error: Invalid bing image path");
 | 
				
			||||||
 | 
								$proxy->do404();
 | 
				
			||||||
 | 
								die();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							parse_str($image["query"], $str);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($str["id"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								header("X-Error: Missing bing ID");
 | 
				
			||||||
 | 
								$proxy->do404();
 | 
				
			||||||
 | 
								die();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							switch($_GET["s"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "portrait": $req = "&w=50&h=90&p=0&qlt=90"; break;
 | 
				
			||||||
 | 
								case "landscape": $req = "&w=160&h=90&p=0&qlt=90"; break;
 | 
				
			||||||
 | 
								case "square": $req = "&w=90&h=90&p=0&qlt=90"; break;
 | 
				
			||||||
 | 
								case "thumb": $req = "&w=236&h=180&p=0&qlt=90"; break;
 | 
				
			||||||
 | 
								case "cover": $req = "&w=207&h=270&p=0&qlt=90"; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$proxy->stream_linear_image("https://" . $image["host"] . "/th?id=" . urlencode($str["id"]) . $req, "https://www.bing.com");
 | 
				
			||||||
 | 
							die();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// resize image ourselves
 | 
				
			||||||
 | 
						$payload = $proxy->get($_GET["i"], $proxy::req_image, true);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// get image format & set imagick
 | 
				
			||||||
 | 
						$image = null;
 | 
				
			||||||
 | 
						$format = $proxy->getimageformat($payload, $image);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						try{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($format !== false){
 | 
				
			||||||
 | 
								$image->setFormat($format);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$image->readImageBlob($payload["body"]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$image_width = $image->getImageWidth();
 | 
				
			||||||
 | 
							$image_height = $image->getImageHeight();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($_GET["s"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "portrait":
 | 
				
			||||||
 | 
									$width = 50;
 | 
				
			||||||
 | 
									$height = 90;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "landscape":
 | 
				
			||||||
 | 
									$width = 160;
 | 
				
			||||||
 | 
									$height = 90;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "square":
 | 
				
			||||||
 | 
									$width = 90;
 | 
				
			||||||
 | 
									$height = 90;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "thumb":
 | 
				
			||||||
 | 
									$width = 236;
 | 
				
			||||||
 | 
									$height = 180;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "cover":
 | 
				
			||||||
 | 
									$width = 207;
 | 
				
			||||||
 | 
									$height = 270;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$ratio = $image_width / $image_height;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($image_width > $width){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image_width = $width;
 | 
				
			||||||
 | 
								$image_height = round($image_width / $ratio);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if($image_height > $height){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$ratio = $image_width / $image_height;
 | 
				
			||||||
 | 
								$image_height = $height;
 | 
				
			||||||
 | 
								$image_width = $image_height * $ratio;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$image->setImageBackgroundColor("#504945");
 | 
				
			||||||
 | 
							$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$image->stripImage();
 | 
				
			||||||
 | 
							$image->setFormat("jpeg");
 | 
				
			||||||
 | 
							$image->setImageCompressionQuality(90);
 | 
				
			||||||
 | 
							$image->setImageCompression(Imagick::COMPRESSION_JPEG2000);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$image->resizeImage($image_width, $image_height, Imagick::FILTER_LANCZOS, 1);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$proxy->getfilenameheader($payload["headers"], $_GET["i"]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("Content-Type: image/jpeg");
 | 
				
			||||||
 | 
							echo $image->getImageBlob();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						}catch(ImagickException $error){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							header("X-Error: Could not convert the image: (" . $error->getMessage() . ")");
 | 
				
			||||||
 | 
							$proxy->do404();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}catch(Exception $error){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						header("X-Error: " . $error->getMessage());
 | 
				
			||||||
 | 
						$proxy->do404();
 | 
				
			||||||
 | 
						die();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										28
									
								
								robots.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,28 @@
 | 
				
			||||||
 | 
					# When the robots.txt is sus
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ⠀⠀⠀⡯⡯⡾⠝⠘⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢊⠘⡮⣣⠪⠢⡑⡌
 | 
				
			||||||
 | 
					# ⠀⠀⠀⠟⠝⠈⠀⠀⠀⠡⠀⠠⢈⠠⢐⢠⢂⢔⣐⢄⡂⢔⠀⡁⢉⠸⢨⢑⠕⡌
 | 
				
			||||||
 | 
					# ⠀⠀⡀⠁⠀⠀⠀⡀⢂⠡⠈⡔⣕⢮⣳⢯⣿⣻⣟⣯⣯⢷⣫⣆⡂⠀⠀⢐⠑⡌
 | 
				
			||||||
 | 
					# ⢀⠠⠐⠈⠀⢀⢂⠢⡂⠕⡁⣝⢮⣳⢽⡽⣾⣻⣿⣯⡯⣟⣞⢾⢜⢆⠀⡀⠀⠪
 | 
				
			||||||
 | 
					# ⣬⠂⠀⠀⢀⢂⢪⠨⢂⠥⣺⡪⣗⢗⣽⢽⡯⣿⣽⣷⢿⡽⡾⡽⣝⢎⠀⠀⠀⢡
 | 
				
			||||||
 | 
					# ⣿⠀⠀⠀⢂⠢⢂⢥⢱⡹⣪⢞⡵⣻⡪⡯⡯⣟⡾⣿⣻⡽⣯⡻⣪⠧⠑⠀⠁⢐
 | 
				
			||||||
 | 
					# ⣿⠀⠀⠀⠢⢑⠠⠑⠕⡝⡎⡗⡝⡎⣞⢽⡹⣕⢯⢻⠹⡹⢚⠝⡷⡽⡨⠀⠀⢔
 | 
				
			||||||
 | 
					# ⣿⡯⠀⢈⠈⢄⠂⠂⠐⠀⠌⠠⢑⠱⡱⡱⡑⢔⠁⠀⡀⠐⠐⠐⡡⡹⣪⠀⠀⢘
 | 
				
			||||||
 | 
					# ⣿⣽⠀⡀⡊⠀⠐⠨⠈⡁⠂⢈⠠⡱⡽⣷⡑⠁⠠⠑⠀⢉⢇⣤⢘⣪⢽⠀⢌⢎
 | 
				
			||||||
 | 
					# ⣿⢾⠀⢌⠌⠀⡁⠢⠂⠐⡀⠀⢀⢳⢽⣽⡺⣨⢄⣑⢉⢃⢭⡲⣕⡭⣹⠠⢐⢗
 | 
				
			||||||
 | 
					# ⣿⡗⠀⠢⠡⡱⡸⣔⢵⢱⢸⠈⠀⡪⣳⣳⢹⢜⡵⣱⢱⡱⣳⡹⣵⣻⢔⢅⢬⡷
 | 
				
			||||||
 | 
					# ⣷⡇⡂⠡⡑⢕⢕⠕⡑⠡⢂⢊⢐⢕⡝⡮⡧⡳⣝⢴⡐⣁⠃⡫⡒⣕⢏⡮⣷⡟
 | 
				
			||||||
 | 
					# ⣷⣻⣅⠑⢌⠢⠁⢐⠠⠑⡐⠐⠌⡪⠮⡫⠪⡪⡪⣺⢸⠰⠡⠠⠐⢱⠨⡪⡪⡰
 | 
				
			||||||
 | 
					# ⣯⢷⣟⣇⡂⡂⡌⡀⠀⠁⡂⠅⠂⠀⡑⡄⢇⠇⢝⡨⡠⡁⢐⠠⢀⢪⡐⡜⡪⡊
 | 
				
			||||||
 | 
					# ⣿⢽⡾⢹⡄⠕⡅⢇⠂⠑⣴⡬⣬⣬⣆⢮⣦⣷⣵⣷⡗⢃⢮⠱⡸⢰⢱⢸⢨⢌
 | 
				
			||||||
 | 
					# ⣯⢯⣟⠸⣳⡅⠜⠔⡌⡐⠈⠻⠟⣿⢿⣿⣿⠿⡻⣃⠢⣱⡳⡱⡩⢢⠣⡃⠢⠁
 | 
				
			||||||
 | 
					# ⡯⣟⣞⡇⡿⣽⡪⡘⡰⠨⢐⢀⠢⢢⢄⢤⣰⠼⡾⢕⢕⡵⣝⠎⢌⢪⠪⡘⡌⠀
 | 
				
			||||||
 | 
					# ⡯⣳⠯⠚⢊⠡⡂⢂⠨⠊⠔⡑⠬⡸⣘⢬⢪⣪⡺⡼⣕⢯⢞⢕⢝⠎⢻⢼⣀⠀
 | 
				
			||||||
 | 
					# ⠁⡂⠔⡁⡢⠣⢀⠢⠀⠅⠱⡐⡱⡘⡔⡕⡕⣲⡹⣎⡮⡏⡑⢜⢼⡱⢩⣗⣯⣟
 | 
				
			||||||
 | 
					# ⢀⢂⢑⠀⡂⡃⠅⠊⢄⢑⠠⠑⢕⢕⢝⢮⢺⢕⢟⢮⢊⢢⢱⢄⠃⣇⣞⢞⣞⢾
 | 
				
			||||||
 | 
					# ⢀⠢⡑⡀⢂⢊⠠⠁⡂⡐⠀⠅⡈⠪⠪⠪⠣⠫⠑⡁⢔⠕⣜⣜⢦⡰⡎⡯⡾⡽
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					User-agent: *
 | 
				
			||||||
 | 
					Disallow:
 | 
				
			||||||
 | 
					Host: 4g.flossboxin.org.in
 | 
				
			||||||
 | 
					Sitemap: https://4g.flossboxin.org.in/sitemap
 | 
				
			||||||
							
								
								
									
										1860
									
								
								scraper/brave.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										145
									
								
								scraper/crowdview.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,145 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class crowdview{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("crowdview");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return [];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						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",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"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){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$json = $this->get(
 | 
				
			||||||
 | 
									$proxy,
 | 
				
			||||||
 | 
									"https://crowdview-next-js.onrender.com/api/search-v3",
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"query" => $search
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === NULL){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json["results"] as $item){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description = explode("<b>", $item["snippet"], 2);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" => $this->sanitize($item["title"]),
 | 
				
			||||||
 | 
									"description" => $this->sanitize($description[1]),
 | 
				
			||||||
 | 
									"url" => $item["link"],
 | 
				
			||||||
 | 
									"date" => strtotime($description[0]),
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => [],
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function sanitize($html){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
								trim(
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getTextContent(
 | 
				
			||||||
 | 
										html_entity_decode(
 | 
				
			||||||
 | 
											$html
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
									". "
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										309
									
								
								scraper/curlie.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,309 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class curlie{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("curlie");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($page != "web"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return [];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"lang" => [
 | 
				
			||||||
 | 
									"display" => "Language",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "Any language",
 | 
				
			||||||
 | 
										"en" => "English",
 | 
				
			||||||
 | 
										"de" => "German",
 | 
				
			||||||
 | 
										"fr" => "French",
 | 
				
			||||||
 | 
										"ja" => "Japanese",
 | 
				
			||||||
 | 
										"it" => "Italian",
 | 
				
			||||||
 | 
										"es" => "Spanish",
 | 
				
			||||||
 | 
										"ru" => "Russian",
 | 
				
			||||||
 | 
										"nl" => "Dutch",
 | 
				
			||||||
 | 
										"pl" => "Polish",
 | 
				
			||||||
 | 
										"tr" => "Turkish",
 | 
				
			||||||
 | 
										"da" => "Danish",
 | 
				
			||||||
 | 
										"sv" => "Swedish",
 | 
				
			||||||
 | 
										"no" => "Norwegian",
 | 
				
			||||||
 | 
										"is" => "Icelandic",
 | 
				
			||||||
 | 
										"fo" => "Faroese",
 | 
				
			||||||
 | 
										"fi" => "Finnish",
 | 
				
			||||||
 | 
										"et" => "Estonian",
 | 
				
			||||||
 | 
										"lt" => "Lithuanian",
 | 
				
			||||||
 | 
										"lv" => "Latvian",
 | 
				
			||||||
 | 
										"cy" => "Welsh",
 | 
				
			||||||
 | 
										"ga" => "Irish",
 | 
				
			||||||
 | 
										"gd" => "Scottish Gaelic",
 | 
				
			||||||
 | 
										"br" => "Breton",
 | 
				
			||||||
 | 
										"fy" => "Frisian",
 | 
				
			||||||
 | 
										"frr" => "North Frisian",
 | 
				
			||||||
 | 
										"gem" => "Saterland Frisian",
 | 
				
			||||||
 | 
										"lb" => "Luxembourgish",
 | 
				
			||||||
 | 
										"rm" => "Romansh",
 | 
				
			||||||
 | 
										"pt" => "Portuguese",
 | 
				
			||||||
 | 
										"ca" => "Catalan",
 | 
				
			||||||
 | 
										"gl" => "Galician",
 | 
				
			||||||
 | 
										"eu" => "Basque",
 | 
				
			||||||
 | 
										"ast" => "Asturian",
 | 
				
			||||||
 | 
										"an" => "Aragonese",
 | 
				
			||||||
 | 
										"fur" => "Friulan",
 | 
				
			||||||
 | 
										"sc" => "Sardinian",
 | 
				
			||||||
 | 
										"scn" => "Sicilian",
 | 
				
			||||||
 | 
										"oc" => "Occitan",
 | 
				
			||||||
 | 
										"be" => "Belarusian",
 | 
				
			||||||
 | 
										"cs" => "Czech",
 | 
				
			||||||
 | 
										"hu" => "Hungarian",
 | 
				
			||||||
 | 
										"sk" => "Slovak",
 | 
				
			||||||
 | 
										"uk" => "Ukrainian",
 | 
				
			||||||
 | 
										"csb" => "Kashubian",
 | 
				
			||||||
 | 
										"tt" => "Tatar",
 | 
				
			||||||
 | 
										"ba" => "Bashkir",
 | 
				
			||||||
 | 
										"os" => "Ossetian",
 | 
				
			||||||
 | 
										"sl" => "Slovene",
 | 
				
			||||||
 | 
										"sr" => "Serbian",
 | 
				
			||||||
 | 
										"hr" => "Croatian",
 | 
				
			||||||
 | 
										"bs" => "Bosnian",
 | 
				
			||||||
 | 
										"bg" => "Bulgarian",
 | 
				
			||||||
 | 
										"sq" => "Albanian",
 | 
				
			||||||
 | 
										"ro" => "Romanian",
 | 
				
			||||||
 | 
										"mk" => "Macedonian",
 | 
				
			||||||
 | 
										"el" => "Greek",
 | 
				
			||||||
 | 
										"iw" => "Hebrew",
 | 
				
			||||||
 | 
										"fa" => "Persian",
 | 
				
			||||||
 | 
										"ar" => "Arabic",
 | 
				
			||||||
 | 
										"ku" => "Kurdish",
 | 
				
			||||||
 | 
										"az" => "Azerbaijani",
 | 
				
			||||||
 | 
										"hy" => "Armenian",
 | 
				
			||||||
 | 
										"af" => "Afrikaans",
 | 
				
			||||||
 | 
										"sw" => "Kiswahili",
 | 
				
			||||||
 | 
										"uz" => "Uzbek",
 | 
				
			||||||
 | 
										"kk" => "Kazakh",
 | 
				
			||||||
 | 
										"ky" => "Kyrgyz",
 | 
				
			||||||
 | 
										"tg" => "Tajik",
 | 
				
			||||||
 | 
										"tk" => "Turkmen",
 | 
				
			||||||
 | 
										"ug" => "Uyghurche",
 | 
				
			||||||
 | 
										"hi" => "Hindi",
 | 
				
			||||||
 | 
										"si" => "Sinhalese",
 | 
				
			||||||
 | 
										"gu" => "Gujarati",
 | 
				
			||||||
 | 
										"ur" => "Urdu",
 | 
				
			||||||
 | 
										"mr" => "Marathi",
 | 
				
			||||||
 | 
										"pa" => "Punjabi",
 | 
				
			||||||
 | 
										"bn" => "Bengali",
 | 
				
			||||||
 | 
										"ta" => "Tamil",
 | 
				
			||||||
 | 
										"te" => "Telugu",
 | 
				
			||||||
 | 
										"kn" => "Kannada",
 | 
				
			||||||
 | 
										"zh_CN" => "Chinese Simplified",
 | 
				
			||||||
 | 
										"zh_TW" => "Chinese Traditional",
 | 
				
			||||||
 | 
										"ko" => "Korean",
 | 
				
			||||||
 | 
										"cfr" => "Taiwanese",
 | 
				
			||||||
 | 
										"th" => "Thai",
 | 
				
			||||||
 | 
										"vi" => "Vietnamese",
 | 
				
			||||||
 | 
										"in" => "Indonesian",
 | 
				
			||||||
 | 
										"ms" => "Malay",
 | 
				
			||||||
 | 
										"tl" => "Tagalog",
 | 
				
			||||||
 | 
										"eo" => "Esperanto",
 | 
				
			||||||
 | 
										"ia" => "Interlingua",
 | 
				
			||||||
 | 
										"la" => "Latin"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						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",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"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://curlie.org/" . $query,
 | 
				
			||||||
 | 
										[]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch search page");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$query = [
 | 
				
			||||||
 | 
									"q" => $get["s"],
 | 
				
			||||||
 | 
									"start" => 0,
 | 
				
			||||||
 | 
									"stime" => 92452189 // ?
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($get["lang"] !== "any"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$query["lang"] = $get["lang"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$html = $this->get(
 | 
				
			||||||
 | 
										$proxy,
 | 
				
			||||||
 | 
										"https://curlie.org/search",
 | 
				
			||||||
 | 
										$query
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch search page");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$nextpage =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"next-page",
 | 
				
			||||||
 | 
									"a"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($nextpage) !== 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										$nextpage[0]["attributes"]["href"],
 | 
				
			||||||
 | 
										"web",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage = null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => $nextpage,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$items =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"site-item",
 | 
				
			||||||
 | 
									"div"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($items as $item){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($item);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$a =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByAttributeValue(
 | 
				
			||||||
 | 
										"target",
 | 
				
			||||||
 | 
										"_blank",
 | 
				
			||||||
 | 
										"a"
 | 
				
			||||||
 | 
									)[0];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName("site-descr");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($description) !== 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description =
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$description[0]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description = null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$a
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"description" => $description,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$a["attributes"]["href"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => [],
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1967
									
								
								scraper/ddg.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										820
									
								
								scraper/facebook.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,820 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class facebook{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						const get = 0;
 | 
				
			||||||
 | 
						const post = 1;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/nextpage.php";
 | 
				
			||||||
 | 
							$this->nextpage = new nextpage("fb");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							include "lib/proxy_pool.php";
 | 
				
			||||||
 | 
							$this->proxy = new proxy_pool("facebook");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"sort" => [
 | 
				
			||||||
 | 
									"display" => "Sort by",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"relevance" => "Relevance",
 | 
				
			||||||
 | 
										"most_recent" => "Most recent"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"newer" => [
 | 
				
			||||||
 | 
									"display" => "Newer than",
 | 
				
			||||||
 | 
									"option" => "_DATE"
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"older" => [
 | 
				
			||||||
 | 
									"display" => "Older than",
 | 
				
			||||||
 | 
									"option" => "_DATE"
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"live" => [
 | 
				
			||||||
 | 
									"display" => "Livestream",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"no" => "No",
 | 
				
			||||||
 | 
										"yes" => "Yes"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($url, $get = [], $reqtype = self::get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get !== []){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$get = http_build_query($get);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($reqtype === self::get){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$headers = [
 | 
				
			||||||
 | 
										"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0",
 | 
				
			||||||
 | 
										"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",
 | 
				
			||||||
 | 
										"DNT: 1",
 | 
				
			||||||
 | 
										"Connection: keep-alive",
 | 
				
			||||||
 | 
										"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
										"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
										"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
										"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
										"Sec-Fetch-User: ?1"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$url .= "?" . $get;
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$headers = [
 | 
				
			||||||
 | 
										"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0",
 | 
				
			||||||
 | 
										"Accept: */*",
 | 
				
			||||||
 | 
										"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
										"Accept-Encoding: gzip, deflate, br",
 | 
				
			||||||
 | 
										"Content-Type: application/x-www-form-urlencoded",
 | 
				
			||||||
 | 
										"X-FB-Friendly-Name: SearchCometResultsPaginatedResultsQuery",
 | 
				
			||||||
 | 
										//"X-FB-LSD: AVptQC4a16c",
 | 
				
			||||||
 | 
										//"X-ASBD-ID: 129477",
 | 
				
			||||||
 | 
										"Content-Length: " . strlen($get),
 | 
				
			||||||
 | 
										"Origin: https://www.facebook.com",
 | 
				
			||||||
 | 
										"DNT: 1",
 | 
				
			||||||
 | 
										"Connection: keep-alive",
 | 
				
			||||||
 | 
										"Referer: https://www.facebook.com/watch/",
 | 
				
			||||||
 | 
										"Cookie: datr=__GMZCgwVF5BbyvAtfJojQwg; oo=v1%7C3%3A1691641171; wd=955x995",
 | 
				
			||||||
 | 
										"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
										"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
										"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
										"TE: trailers"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_POST, true);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_POSTFIELDS, $get);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTPHEADER, $headers);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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->proxy->assign_proxy($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$data = curl_exec($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(curl_errno($curlproc)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception(curl_error($curlproc));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curlproc);
 | 
				
			||||||
 | 
							return $data;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function video($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							$npt = $get["npt"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"author" => [],
 | 
				
			||||||
 | 
								"livestream" => [],
 | 
				
			||||||
 | 
								"playlist" => [],
 | 
				
			||||||
 | 
								"reel" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage =
 | 
				
			||||||
 | 
									json_decode(
 | 
				
			||||||
 | 
										$this->nextpage->get(
 | 
				
			||||||
 | 
											$npt,
 | 
				
			||||||
 | 
											"videos"
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										true
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// parse next page
 | 
				
			||||||
 | 
								$this->video_nextpage($nextpage);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $this->out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// generate filter data
 | 
				
			||||||
 | 
							// {
 | 
				
			||||||
 | 
							//    "rp_creation_time:0":"{\"name\":\"creation_time\",\"args\":\"{\\\"start_year\\\":\\\"2023\\\",\\\"start_month\\\":\\\"2023-08\\\",\\\"end_year\\\":\\\"2023\\\",\\\"end_month\\\":\\\"2023-08\\\",\\\"start_day\\\":\\\"2023-08-10\\\",\\\"end_day\\\":\\\"2023-08-10\\\"}\"}",
 | 
				
			||||||
 | 
							//    "videos_sort_by:0":"{\"name\":\"videos_sort_by\",\"args\":\"Most Recent\"}",
 | 
				
			||||||
 | 
							//    "videos_live:0":"{\"name\":\"videos_live\",\"args\":\"\"}"
 | 
				
			||||||
 | 
							// }
 | 
				
			||||||
 | 
							$filter = [];
 | 
				
			||||||
 | 
							$sort = $get["sort"];
 | 
				
			||||||
 | 
							$live = $get["live"];
 | 
				
			||||||
 | 
							$older = $get["older"];
 | 
				
			||||||
 | 
							$newer = $get["newer"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$older !== false ||
 | 
				
			||||||
 | 
								$newer !== false
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($older === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$older = time();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($newer === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$newer = 0;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$filter["rp_creation_time:0"] =
 | 
				
			||||||
 | 
									json_encode(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"name" => "creation_time",
 | 
				
			||||||
 | 
											"args" =>
 | 
				
			||||||
 | 
												json_encode(
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"start_year" => date("Y", $newer),
 | 
				
			||||||
 | 
														"start_month" => date("Y-m", $newer),
 | 
				
			||||||
 | 
														"end_year" => date("Y", $older),
 | 
				
			||||||
 | 
														"end_month" => date("Y-m", $older),
 | 
				
			||||||
 | 
														"start_day" => date("Y-m-d", $newer),
 | 
				
			||||||
 | 
														"end_day" => date("Y-m-d", $older)
 | 
				
			||||||
 | 
													]
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($sort != "relevance"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$filter["videos_sort_by:0"] =
 | 
				
			||||||
 | 
									json_encode(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"name" => "videos_sort_by",
 | 
				
			||||||
 | 
											"args" => "Most Recent"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($live != "no"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$filter["videos_live:0"] = json_encode(
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"name" => "videos_live",
 | 
				
			||||||
 | 
										"args" => ""
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$req = [
 | 
				
			||||||
 | 
								"q" => $search
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($filter) !== 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$req["filters"] =
 | 
				
			||||||
 | 
									base64_encode(
 | 
				
			||||||
 | 
										json_encode(
 | 
				
			||||||
 | 
											$filter
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							$html =
 | 
				
			||||||
 | 
								$this->get(
 | 
				
			||||||
 | 
									"https://www.facebook.com/watch/search/",
 | 
				
			||||||
 | 
									$req
 | 
				
			||||||
 | 
								);*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$handle = fopen("scraper/facebook.html", "r");
 | 
				
			||||||
 | 
							$html = fread($handle, filesize("scraper/facebook.html"));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							preg_match_all(
 | 
				
			||||||
 | 
								'/({"__bbox":.*,"sequence_number":0}})\]\]/',
 | 
				
			||||||
 | 
								$html,
 | 
				
			||||||
 | 
								$json
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($json[1][1])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Could not grep JSON body");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json[1][1], true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach(
 | 
				
			||||||
 | 
								$json
 | 
				
			||||||
 | 
								["__bbox"]
 | 
				
			||||||
 | 
								["result"]
 | 
				
			||||||
 | 
								["data"]
 | 
				
			||||||
 | 
								["serpResponse"]
 | 
				
			||||||
 | 
								["results"]
 | 
				
			||||||
 | 
								["edges"]
 | 
				
			||||||
 | 
								as $result
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->parse_edge($result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get nextpage data
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$json
 | 
				
			||||||
 | 
								["__bbox"]
 | 
				
			||||||
 | 
								["result"]
 | 
				
			||||||
 | 
								["data"]
 | 
				
			||||||
 | 
								["serpResponse"]
 | 
				
			||||||
 | 
								["results"]
 | 
				
			||||||
 | 
								["page_info"]
 | 
				
			||||||
 | 
								["has_next_page"]
 | 
				
			||||||
 | 
								== 1
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/handleWithCustomApplyEach\(ScheduledApplyEach,({.*})\);}\);}\);<\/script>/',
 | 
				
			||||||
 | 
									$html,
 | 
				
			||||||
 | 
									$nextpagedata
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// [POST] https://www.facebook.com/api/graphql/
 | 
				
			||||||
 | 
								// FORM data, not JSON!
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage = [
 | 
				
			||||||
 | 
									"av" => "0",
 | 
				
			||||||
 | 
									"__user" => null,
 | 
				
			||||||
 | 
									"__a" => null,
 | 
				
			||||||
 | 
									"__req" => "2",
 | 
				
			||||||
 | 
									"__hs" => null,
 | 
				
			||||||
 | 
									"dpr" => "1",
 | 
				
			||||||
 | 
									"__ccg" => null,
 | 
				
			||||||
 | 
									"__rev" => null,
 | 
				
			||||||
 | 
									// another client side token
 | 
				
			||||||
 | 
									"__s" => $this->randomstring(6) . ":" . $this->randomstring(6) . ":" . $this->randomstring(6),
 | 
				
			||||||
 | 
									"__hsi" => null,
 | 
				
			||||||
 | 
									// tracking fingerprint (probably generated using webgl)
 | 
				
			||||||
 | 
									"__dyn" => "7xeUmwlE7ibwKBWo2vwAxu13w8CewSwMwNw9G2S0im3y4o0B-q1ew65xO2O1Vw8G1Qw5Mx61vw9m1YwBgao6C0Mo5W3S7Udo5q4U2zxe2Gew9O222SUbEaU2eU5O0GpovU19pobodEGdw46wbS1LwTwNwLw8O1pwr86C16w",
 | 
				
			||||||
 | 
									"__csr" => $this->randomstring(null),
 | 
				
			||||||
 | 
									"__comet_req" => null,
 | 
				
			||||||
 | 
									"lsd" => null,
 | 
				
			||||||
 | 
									"jazoest" => null,
 | 
				
			||||||
 | 
									"__spin_r" => null,
 | 
				
			||||||
 | 
									"__spin_b" => null,
 | 
				
			||||||
 | 
									"__spin_t" => null,
 | 
				
			||||||
 | 
									"fb_api_caller_class" => "RelayModern",
 | 
				
			||||||
 | 
									"fb_api_req_friendly_name" => "SearchCometResultsPaginatedResultsQuery",
 | 
				
			||||||
 | 
									"variables" => [ // this is json
 | 
				
			||||||
 | 
										"UFI2CommentsProvider_commentsKey" => "SearchCometResultsInitialResultsQuery",
 | 
				
			||||||
 | 
										"allow_streaming" => false,
 | 
				
			||||||
 | 
										"args" => [
 | 
				
			||||||
 | 
											"callsite" => "comet:watch_search",
 | 
				
			||||||
 | 
											"config" => [
 | 
				
			||||||
 | 
												"exact_match" => false,
 | 
				
			||||||
 | 
												"high_confidence_config" => null,
 | 
				
			||||||
 | 
												"intercept_config" => null,
 | 
				
			||||||
 | 
												"sts_disambiguation" => null,
 | 
				
			||||||
 | 
												"watch_config" => null
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"context" => [
 | 
				
			||||||
 | 
												"bsid" => null,
 | 
				
			||||||
 | 
												"tsid" => null
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"experience" => [
 | 
				
			||||||
 | 
												"encoded_server_defined_params" => null,
 | 
				
			||||||
 | 
												"fbid" => null,
 | 
				
			||||||
 | 
												"type" => "WATCH_TAB_GLOBAL"
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"filters" => [],
 | 
				
			||||||
 | 
											"text" => $search
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"count" => 5,
 | 
				
			||||||
 | 
										"cursor" =>
 | 
				
			||||||
 | 
											$json
 | 
				
			||||||
 | 
											["__bbox"]
 | 
				
			||||||
 | 
											["result"]
 | 
				
			||||||
 | 
											["data"]
 | 
				
			||||||
 | 
											["serpResponse"]
 | 
				
			||||||
 | 
											["results"]
 | 
				
			||||||
 | 
											["page_info"]
 | 
				
			||||||
 | 
											["end_cursor"],
 | 
				
			||||||
 | 
										"displayCommentsContextEnableComment" => false,
 | 
				
			||||||
 | 
										"displayCommentsContextIsAdPreview" => false,
 | 
				
			||||||
 | 
										"displayCommentsContextIsAggregatedShare" => false,
 | 
				
			||||||
 | 
										"displayCommentsContextIsStorySet" => false,
 | 
				
			||||||
 | 
										"displayCommentsFeedbackContext" => null,
 | 
				
			||||||
 | 
										"feedLocation" => "SEARCH",
 | 
				
			||||||
 | 
										"feedbackSource" => 23,
 | 
				
			||||||
 | 
										"fetch_filters" => true,
 | 
				
			||||||
 | 
										"focusCommentID" => null,
 | 
				
			||||||
 | 
										"locale" => null,
 | 
				
			||||||
 | 
										"privacySelectorRenderLocation" => "COMET_STREAM",
 | 
				
			||||||
 | 
										"renderLocation" => "search_results_page",
 | 
				
			||||||
 | 
										"scale" => 1,
 | 
				
			||||||
 | 
										"stream_initial_count" => 0,
 | 
				
			||||||
 | 
										"useDefaultActor" => false,
 | 
				
			||||||
 | 
										"__relay_internal__pv__IsWorkUserrelayprovider" => false,
 | 
				
			||||||
 | 
										"__relay_internal__pv__IsMergQAPollsrelayprovider" => false,
 | 
				
			||||||
 | 
										"__relay_internal__pv__StoriesArmadilloReplyEnabledrelayprovider" => false,
 | 
				
			||||||
 | 
										"__relay_internal__pv__StoriesRingrelayprovider" => false
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"server_timestamps" => "true",
 | 
				
			||||||
 | 
									"doc_id" => "6761275837251607" // is actually dynamic
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// append filters to nextpage
 | 
				
			||||||
 | 
								foreach($filter as $key => $value){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$nextpage["variables"]["args"]["filters"][] =
 | 
				
			||||||
 | 
										$value;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpagedata = json_decode($nextpagedata[1], true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get bsid
 | 
				
			||||||
 | 
								foreach($nextpagedata["require"] as $key){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									foreach($key as $innerkey){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(is_array($innerkey)){
 | 
				
			||||||
 | 
											foreach($innerkey as $inner_innerkey){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												if(is_array($inner_innerkey)){
 | 
				
			||||||
 | 
													foreach($inner_innerkey as $inner_inner_innerkey){
 | 
				
			||||||
 | 
															
 | 
				
			||||||
 | 
														if(
 | 
				
			||||||
 | 
															isset(
 | 
				
			||||||
 | 
																$inner_inner_innerkey
 | 
				
			||||||
 | 
																["variables"]
 | 
				
			||||||
 | 
																["args"]
 | 
				
			||||||
 | 
																["context"]
 | 
				
			||||||
 | 
																["bsid"]
 | 
				
			||||||
 | 
															)
 | 
				
			||||||
 | 
														){
 | 
				
			||||||
 | 
															
 | 
				
			||||||
 | 
															$nextpage
 | 
				
			||||||
 | 
															["variables"]
 | 
				
			||||||
 | 
															["args"]
 | 
				
			||||||
 | 
															["context"]
 | 
				
			||||||
 | 
															["bsid"] =
 | 
				
			||||||
 | 
																$inner_inner_innerkey
 | 
				
			||||||
 | 
																["variables"]
 | 
				
			||||||
 | 
																["args"]
 | 
				
			||||||
 | 
																["context"]
 | 
				
			||||||
 | 
																["bsid"];
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($nextpagedata["define"] as $key){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["haste_session"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__hs"] = $key[2]["haste_session"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["connectionClass"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__ccg"] = $key[2]["connectionClass"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["__spin_r"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__spin_r"] = (string)$key[2]["__spin_r"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["hsi"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__hsi"] = (string)$key[2]["hsi"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										isset($key[2]["token"]) &&
 | 
				
			||||||
 | 
										!empty($key[2]["token"])
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["lsd"] = $key[2]["token"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["__spin_r"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__spin_r"] = (string)$key[2]["__spin_r"];
 | 
				
			||||||
 | 
										$nextpage["__rev"] = $nextpage["__spin_r"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["__spin_b"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__spin_b"] = $key[2]["__spin_b"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(isset($key[2]["__spin_t"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$nextpage["__spin_t"] = (string)$key[2]["__spin_t"];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/{"u":"\\\\\/ajax\\\\\/qm\\\\\/\?__a=([0-9]+)&__user=([0-9]+)&__comet_req=([0-9]+)&jazoest=([0-9]+)"/',
 | 
				
			||||||
 | 
									$html,
 | 
				
			||||||
 | 
									$ajaxparams
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($ajaxparams) !== 5){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Could not grep the AJAX parameters");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage["__a"] = $ajaxparams[1];
 | 
				
			||||||
 | 
								$nextpage["__user"] = $ajaxparams[2];
 | 
				
			||||||
 | 
								$nextpage["__comet_req"] = $ajaxparams[3];
 | 
				
			||||||
 | 
								$nextpage["jazoest"] = $ajaxparams[4];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
								$handle = fopen("scraper/facebook-nextpage.json", "r");
 | 
				
			||||||
 | 
								$json = fread($handle, filesize("scraper/facebook-nextpage.json"));
 | 
				
			||||||
 | 
								fclose($handle);*/
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage["variables"] = json_encode($nextpage["variables"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->video_nextpage($nextpage);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $this->out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function video_nextpage($nextpage, $getcursor = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json =
 | 
				
			||||||
 | 
								$this->get(
 | 
				
			||||||
 | 
									"https://www.facebook.com/api/graphql/",
 | 
				
			||||||
 | 
									$nextpage,
 | 
				
			||||||
 | 
									self::post
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode next page JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach(
 | 
				
			||||||
 | 
								$json
 | 
				
			||||||
 | 
								["data"]
 | 
				
			||||||
 | 
								["serpResponse"]
 | 
				
			||||||
 | 
								["results"]
 | 
				
			||||||
 | 
								["edges"]
 | 
				
			||||||
 | 
								as $result
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->parse_edge($result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$json
 | 
				
			||||||
 | 
								["data"]
 | 
				
			||||||
 | 
								["serpResponse"]
 | 
				
			||||||
 | 
								["results"]
 | 
				
			||||||
 | 
								["page_info"]
 | 
				
			||||||
 | 
								["has_next_page"] == 1
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage["variables"] = json_decode($nextpage["variables"], true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage["variables"]["cursor"] =
 | 
				
			||||||
 | 
									$json
 | 
				
			||||||
 | 
									["data"]
 | 
				
			||||||
 | 
									["serpResponse"]
 | 
				
			||||||
 | 
									["results"]
 | 
				
			||||||
 | 
									["page_info"]
 | 
				
			||||||
 | 
									["end_cursor"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage["variables"] = json_encode($nextpage["variables"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//change this for second call. after, it's static.
 | 
				
			||||||
 | 
								// TODO: csr also updates to longer string
 | 
				
			||||||
 | 
								$nextpage["__dyn"] = "7xeUmwlEnwn8K2WnFw9-2i5U4e0yoW3q322aew9G2S0zU20xi3y4o0B-q1ew65xOfxO1Vw8G11xmfz81s8hwGwQw9m1YwBgao6C2O0B85W3S7Udo5qfK0EUjwGzE2swwwJK2W2K0zK5o4q0GpovU19pobodEGdw46wbS1LwTwNwLw8O1pwr86C16w";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// TODO: change this on third and 6th call
 | 
				
			||||||
 | 
								//$nextpage["__s"] = $this->randomstring(6) . ":" . explode(":", $nextpage["__s"], 2)[1];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->out["npt"] = $this->nextpage->store(json_encode($nextpage), "videos");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function parse_edge($edge){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$append = "video";		
 | 
				
			||||||
 | 
							$edge =
 | 
				
			||||||
 | 
								$edge
 | 
				
			||||||
 | 
								["relay_rendering_strategy"]
 | 
				
			||||||
 | 
								["view_model"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								strtolower(
 | 
				
			||||||
 | 
									$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["video_broadcast_status"]
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
								== "live"
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// handle livestream
 | 
				
			||||||
 | 
								$duration = "_LIVE";
 | 
				
			||||||
 | 
								$append = "livestream";
 | 
				
			||||||
 | 
								$timetext = null;
 | 
				
			||||||
 | 
								$views =
 | 
				
			||||||
 | 
									(int)$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["relative_time_string"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url_prefix = "https://www.facebook.com/watch/live/?v=";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}elseif(
 | 
				
			||||||
 | 
								stripos(
 | 
				
			||||||
 | 
									$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["video_broadcast_status"],
 | 
				
			||||||
 | 
									"vod"
 | 
				
			||||||
 | 
								) !== false
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// handle VOD format
 | 
				
			||||||
 | 
								$timetext = null;
 | 
				
			||||||
 | 
								$views =
 | 
				
			||||||
 | 
									(int)$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["relative_time_string"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$duration =
 | 
				
			||||||
 | 
									$this->hms2int(
 | 
				
			||||||
 | 
										$edge
 | 
				
			||||||
 | 
										["video_thumbnail_model"]
 | 
				
			||||||
 | 
										["video_duration_text"]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url_prefix = "https://www.facebook.com/watch/live/?v=";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// handle normal format
 | 
				
			||||||
 | 
								$timetext =
 | 
				
			||||||
 | 
									explode(
 | 
				
			||||||
 | 
										" · ",
 | 
				
			||||||
 | 
										$edge
 | 
				
			||||||
 | 
										["video_metadata_model"]
 | 
				
			||||||
 | 
										["relative_time_string"],
 | 
				
			||||||
 | 
										2
 | 
				
			||||||
 | 
									); 
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($timetext) === 2){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$views = $this->truncatedcount2int($timetext[1]);
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$views = null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$timetext = strtotime($timetext[0]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$duration =
 | 
				
			||||||
 | 
									$this->hms2int(
 | 
				
			||||||
 | 
										$edge
 | 
				
			||||||
 | 
										["video_thumbnail_model"]
 | 
				
			||||||
 | 
										["video_duration_text"]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url_prefix = "https://www.facebook.com/watch/?v=";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset(
 | 
				
			||||||
 | 
									$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["video_owner_profile"]
 | 
				
			||||||
 | 
									["uri_token"]
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$profileurl =
 | 
				
			||||||
 | 
									"https://www.facebook.com/watch/" .
 | 
				
			||||||
 | 
									$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["video_owner_profile"]
 | 
				
			||||||
 | 
									["uri_token"];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$profileurl =
 | 
				
			||||||
 | 
									$edge
 | 
				
			||||||
 | 
									["video_metadata_model"]
 | 
				
			||||||
 | 
									["video_owner_profile"]
 | 
				
			||||||
 | 
									["url"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->out[$append][] = [
 | 
				
			||||||
 | 
								"title" =>
 | 
				
			||||||
 | 
									$this->limitstrlen(
 | 
				
			||||||
 | 
										str_replace(
 | 
				
			||||||
 | 
											"\n",
 | 
				
			||||||
 | 
											" ",
 | 
				
			||||||
 | 
											$edge
 | 
				
			||||||
 | 
											["video_metadata_model"]
 | 
				
			||||||
 | 
											["title"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										100
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
								"description" =>
 | 
				
			||||||
 | 
									empty(
 | 
				
			||||||
 | 
										$edge
 | 
				
			||||||
 | 
										["video_metadata_model"]
 | 
				
			||||||
 | 
										["save_description"]
 | 
				
			||||||
 | 
									) ?
 | 
				
			||||||
 | 
									null :
 | 
				
			||||||
 | 
									str_replace(
 | 
				
			||||||
 | 
										"\n",
 | 
				
			||||||
 | 
										" ",
 | 
				
			||||||
 | 
										$this->limitstrlen(
 | 
				
			||||||
 | 
											$edge
 | 
				
			||||||
 | 
											["video_metadata_model"]
 | 
				
			||||||
 | 
											["save_description"]
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
								"author" => [
 | 
				
			||||||
 | 
									"name" =>
 | 
				
			||||||
 | 
										$edge
 | 
				
			||||||
 | 
										["video_metadata_model"]
 | 
				
			||||||
 | 
										["video_owner_profile"]
 | 
				
			||||||
 | 
										["name"],
 | 
				
			||||||
 | 
									"url" => $profileurl,
 | 
				
			||||||
 | 
									"avatar" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"date" => $timetext,
 | 
				
			||||||
 | 
								"duration" => $duration,
 | 
				
			||||||
 | 
								"views" => $views,
 | 
				
			||||||
 | 
								"thumb" =>
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"url" =>
 | 
				
			||||||
 | 
											$edge
 | 
				
			||||||
 | 
											["video_thumbnail_model"]
 | 
				
			||||||
 | 
											["thumbnail_image"]
 | 
				
			||||||
 | 
											["uri"],
 | 
				
			||||||
 | 
										"ratio" => "16:9"
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
								"url" =>
 | 
				
			||||||
 | 
									$url_prefix .
 | 
				
			||||||
 | 
									$edge
 | 
				
			||||||
 | 
									["video_click_model"]
 | 
				
			||||||
 | 
									["click_metadata_model"]
 | 
				
			||||||
 | 
									["video_id"]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function randomstring($len){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($len === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-";
 | 
				
			||||||
 | 
								$len = rand(141, 145);
 | 
				
			||||||
 | 
								$c = 61;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
								$str = "abcdefghijklmnopqrstuvwxyz123456789";
 | 
				
			||||||
 | 
								$c = 34;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = null;
 | 
				
			||||||
 | 
							for($i=0; $i<$len; $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out .= $str[rand(0, $c)];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function limitstrlen($text, $len = 300){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return explode("\n", wordwrap($text, $len, "\n"))[0];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						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;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function truncatedcount2int($number){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// decimal should always be 1 number long
 | 
				
			||||||
 | 
							$number = explode(" ", $number, 2);
 | 
				
			||||||
 | 
							$number = $number[0];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$unit = strtolower($number[strlen($number) - 1]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$tmp = explode(".", $number, 2);
 | 
				
			||||||
 | 
							$number = (int)$number;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($tmp) === 2){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$decimal = (int)$tmp[1];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$decimal = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($unit){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "k":
 | 
				
			||||||
 | 
									$exponant = 1000;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "m":
 | 
				
			||||||
 | 
									$exponant = 1000000;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "b";
 | 
				
			||||||
 | 
									$exponant = 1000000000;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									$exponant = 1;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return ($number * $exponant) + ($decimal * ($exponant / 10));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										262
									
								
								scraper/fivehpx.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,262 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class fivehpx{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("fivehpx");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"sort" => [
 | 
				
			||||||
 | 
									"display" => "Sort",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"relevance" => "Relevance",
 | 
				
			||||||
 | 
										"pulse" => "Pulse",
 | 
				
			||||||
 | 
										"newest" => "Newest"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $post_data = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($post_data === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Sec-GPC: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
									"Sec-Fetch-User: ?1",
 | 
				
			||||||
 | 
									"Priority: u=0, i",
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
									["User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
									"Accept: */*",
 | 
				
			||||||
 | 
									"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
									"Accept-Encoding: gzip",
 | 
				
			||||||
 | 
									"Referer: https://500px.com/",
 | 
				
			||||||
 | 
									"content-type: application/json",
 | 
				
			||||||
 | 
									//"x-csrf-token: undefined",
 | 
				
			||||||
 | 
									"x-500px-source: Search",
 | 
				
			||||||
 | 
									"Content-Length: " . strlen($post_data),
 | 
				
			||||||
 | 
									"Origin: https://500px.com",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Sec-GPC: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									// "Cookie: _pin_unauth, _fbp, _sharedID, _sharedID_cst",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-site",
 | 
				
			||||||
 | 
									"Priority: u=4",
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
								// set post data
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_POST, true);
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_POSTFIELDS, $post_data);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// http2 bypass
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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 image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$pagination, $proxy] =
 | 
				
			||||||
 | 
									$this->backend->get(
 | 
				
			||||||
 | 
										$get["npt"], "images"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$pagination = json_decode($pagination, true);
 | 
				
			||||||
 | 
								$search = $pagination["search"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								$pagination = [
 | 
				
			||||||
 | 
									"sort" => strtoupper($get["sort"]),
 | 
				
			||||||
 | 
									"search" => $search,
 | 
				
			||||||
 | 
									"filters" => [],
 | 
				
			||||||
 | 
									"nlp" => false,
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$proxy,
 | 
				
			||||||
 | 
										"https://api.500px.com/graphql",
 | 
				
			||||||
 | 
										[],
 | 
				
			||||||
 | 
										json_encode([
 | 
				
			||||||
 | 
											"operationName" => "PhotoSearchPaginationContainerQuery",
 | 
				
			||||||
 | 
											"variables" => $pagination,
 | 
				
			||||||
 | 
											"query" =>
 | 
				
			||||||
 | 
												'query PhotoSearchPaginationContainerQuery(' .
 | 
				
			||||||
 | 
												(isset($pagination["cursor"]) ? '$cursor: String, ' : "") .
 | 
				
			||||||
 | 
												'$sort: PhotoSort, $search: String!, $filters: [PhotoSearchFilter!], $nlp: Boolean) {  ...PhotoSearchPaginationContainer_query_1vzAZD} fragment PhotoSearchPaginationContainer_query_1vzAZD on Query { photoSearch(sort: $sort, first: 100, ' .
 | 
				
			||||||
 | 
												(isset($pagination["cursor"]) ? 'after: $cursor, ' : "") .
 | 
				
			||||||
 | 
												'search: $search, filters: $filters, nlp: $nlp) { edges { node { id legacyId canonicalPath name description width height images(sizes: [33, 36]) { size url id } } } totalCount pageInfo { endCursor hasNextPage } }}'
 | 
				
			||||||
 | 
										])
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch graphQL object");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode graphQL object");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json["errors"][0]["message"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("500px returned an API error: " . $json["errors"][0]["message"]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($json["data"]["photoSearch"]["edges"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("No edges returned by API");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json["data"]["photoSearch"]["edges"] as $image){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image = $image["node"];
 | 
				
			||||||
 | 
								$title =
 | 
				
			||||||
 | 
									trim(
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$image["name"]
 | 
				
			||||||
 | 
										) . ": " .
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$image["description"]
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
										, " :"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$small = $this->image_ratio(600, $image["width"], $image["height"]);
 | 
				
			||||||
 | 
								$large = $this->image_ratio(2048, $image["width"], $image["height"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["image"][] = [
 | 
				
			||||||
 | 
									"title" => $title,
 | 
				
			||||||
 | 
									"source" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $image["images"][1]["url"],
 | 
				
			||||||
 | 
											"width" => $large[0],
 | 
				
			||||||
 | 
											"height" => $large[1]
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $image["images"][0]["url"],
 | 
				
			||||||
 | 
											"width" => $small[0],
 | 
				
			||||||
 | 
											"height" => $small[1]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"url" => "https://500px.com" . $image["canonicalPath"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get NPT token
 | 
				
			||||||
 | 
							if($json["data"]["photoSearch"]["pageInfo"]["hasNextPage"] === true){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode([
 | 
				
			||||||
 | 
											"cursor" => $json["data"]["photoSearch"]["pageInfo"]["endCursor"],
 | 
				
			||||||
 | 
											"search" => $search,
 | 
				
			||||||
 | 
											"sort" => $pagination["sort"],
 | 
				
			||||||
 | 
											"filters" => [],
 | 
				
			||||||
 | 
											"nlp" => false
 | 
				
			||||||
 | 
										]),
 | 
				
			||||||
 | 
										"images",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function image_ratio($longest_edge, $width, $height){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$ratio = [
 | 
				
			||||||
 | 
								$longest_edge / $width,
 | 
				
			||||||
 | 
								$longest_edge / $height
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($ratio[0] < $ratio[1]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$ratio = $ratio[0];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$ratio = $ratio[1];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								floor($width * $ratio),
 | 
				
			||||||
 | 
								floor($height * $ratio)
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										161
									
								
								scraper/ftm.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,161 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ftm{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("ftm");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $search, $offset){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$payload =
 | 
				
			||||||
 | 
								json_encode(
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"search" => $search,
 | 
				
			||||||
 | 
										"offset" => $offset
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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",
 | 
				
			||||||
 | 
								"Content-Length: " . strlen($payload),
 | 
				
			||||||
 | 
								"Content-Type: application/json",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Origin: https://findthatmeme.com",
 | 
				
			||||||
 | 
								"Referer: https://findthatmeme.com/?search=" . urlencode($search),
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"Sec-Fetch-User: ?1",
 | 
				
			||||||
 | 
								"X-Auth-Key: undefined",
 | 
				
			||||||
 | 
								"X-CSRF-Validation-Header: true"]
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_POST, true);
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_POSTFIELDS, $payload);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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 image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$data, $proxy] = $this->backend->get($get["npt"], "images");
 | 
				
			||||||
 | 
								$data = json_decode($data, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$count = $data["count"];
 | 
				
			||||||
 | 
								$search = $data["search"];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$count = 0;
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									json_decode(
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://findthatmeme.com/api/v1/search",
 | 
				
			||||||
 | 
											$search,
 | 
				
			||||||
 | 
											$count
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										true
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json as $item){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$count++;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($item["type"] == "VIDEO"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumb = "thumb/" . $item["thumbnail"];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumb = $item["image_path"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["image"][] = [
 | 
				
			||||||
 | 
									"title" => date("jS \of F Y @ g:ia", strtotime($item["created_at"])),
 | 
				
			||||||
 | 
									"source" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" =>
 | 
				
			||||||
 | 
												"https://s3.thehackerblog.com/findthatmeme/" .
 | 
				
			||||||
 | 
												$thumb,
 | 
				
			||||||
 | 
											"width" => null,
 | 
				
			||||||
 | 
											"height" => null
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"url" => $item["source_page_url"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out["npt"] =
 | 
				
			||||||
 | 
								$this->backend->store(
 | 
				
			||||||
 | 
									json_encode([
 | 
				
			||||||
 | 
										"count" => $count,
 | 
				
			||||||
 | 
										"search" => $search
 | 
				
			||||||
 | 
									]),
 | 
				
			||||||
 | 
									"images",
 | 
				
			||||||
 | 
									$proxy
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										320
									
								
								scraper/ghostery.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,320 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ghostery{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("ghostery");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($page != "web"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return [];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"country" => [
 | 
				
			||||||
 | 
									"display" => "Country",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "All regions",
 | 
				
			||||||
 | 
										"AR" => "Argentina",
 | 
				
			||||||
 | 
										"AU" => "Australia",
 | 
				
			||||||
 | 
										"AT" => "Austria",
 | 
				
			||||||
 | 
										"BE" => "Belgium",
 | 
				
			||||||
 | 
										"BR" => "Brazil",
 | 
				
			||||||
 | 
										"CA" => "Canada",
 | 
				
			||||||
 | 
										"CL" => "Chile",
 | 
				
			||||||
 | 
										"DK" => "Denmark",
 | 
				
			||||||
 | 
										"FI" => "Finland",
 | 
				
			||||||
 | 
										"FR" => "France",
 | 
				
			||||||
 | 
										"DE" => "Germany",
 | 
				
			||||||
 | 
										"HK" => "Hong Kong",
 | 
				
			||||||
 | 
										"IN" => "India",
 | 
				
			||||||
 | 
										"ID" => "Indonesia",
 | 
				
			||||||
 | 
										"IT" => "Italy",
 | 
				
			||||||
 | 
										"JP" => "Japan",
 | 
				
			||||||
 | 
										"KR" => "Korea",
 | 
				
			||||||
 | 
										"MY" => "Malaysia",
 | 
				
			||||||
 | 
										"MX" => "Mexico",
 | 
				
			||||||
 | 
										"NL" => "Netherlands",
 | 
				
			||||||
 | 
										"NZ" => "New Zealand",
 | 
				
			||||||
 | 
										"NO" => "Norway",
 | 
				
			||||||
 | 
										"CN" => "People's Republic of China",
 | 
				
			||||||
 | 
										"PL" => "Poland",
 | 
				
			||||||
 | 
										"PT" => "Portugal",
 | 
				
			||||||
 | 
										"PH" => "Republic of the Philippines",
 | 
				
			||||||
 | 
										"RU" => "Russia",
 | 
				
			||||||
 | 
										"SA" => "Saudi Arabia",
 | 
				
			||||||
 | 
										"ZA" => "South Africa",
 | 
				
			||||||
 | 
										"ES" => "Spain",
 | 
				
			||||||
 | 
										"SE" => "Sweden",
 | 
				
			||||||
 | 
										"CH" => "Switzerland",
 | 
				
			||||||
 | 
										"TW" => "Taiwan",
 | 
				
			||||||
 | 
										"TR" => "Turkey",
 | 
				
			||||||
 | 
										"GB" => "United Kingdom",
 | 
				
			||||||
 | 
										"US" => "United States"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $country){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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://ghosterysearch.com",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Sec-GPC: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Cookie: ctry=" . ($country == "any" ? "--" : $country) . "; noads=true",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
								"Sec-Fetch-User: ?1",
 | 
				
			||||||
 | 
								"Priority: u=0, i"]
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// http2 bypass
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								parse_str($query, $query);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// country
 | 
				
			||||||
 | 
								$country = $query["c"];
 | 
				
			||||||
 | 
								unset($query["c"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$query = http_build_query($query);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$html =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://ghosterysearch.com/search?" . $query,
 | 
				
			||||||
 | 
											[],
 | 
				
			||||||
 | 
											$country
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch search page");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$html =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://ghosterysearch.com/search",
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"q" => $get["s"]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											$get["country"]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}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" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$results_wrapper =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"results",
 | 
				
			||||||
 | 
									"section"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($results_wrapper) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to grep result section");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($results_wrapper[0]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get search results
 | 
				
			||||||
 | 
							$results =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"result",
 | 
				
			||||||
 | 
									"li"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($results) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($results as $result){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($result);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$a =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"url",
 | 
				
			||||||
 | 
										"a"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($a) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$a = $a[0];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										$this->titledots(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getElementsByTagName(
 | 
				
			||||||
 | 
													"h2"
 | 
				
			||||||
 | 
												)[0]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"description" =>
 | 
				
			||||||
 | 
										$this->titledots(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getElementsByTagName(
 | 
				
			||||||
 | 
													"p"
 | 
				
			||||||
 | 
												)[0]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$a
 | 
				
			||||||
 | 
											["attributes"]
 | 
				
			||||||
 | 
											["href"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => [],
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get pagination token
 | 
				
			||||||
 | 
							$pagination_wrapper =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"pagination",
 | 
				
			||||||
 | 
									"div"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($pagination_wrapper) !== 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// found next page!
 | 
				
			||||||
 | 
								$this->fuckhtml->load($pagination_wrapper[0]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$a =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByTagName(
 | 
				
			||||||
 | 
										"a"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($a) !== 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$q =
 | 
				
			||||||
 | 
										parse_url(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$a[count($a) - 1]
 | 
				
			||||||
 | 
												["attributes"]
 | 
				
			||||||
 | 
												["href"]
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
											PHP_URL_QUERY
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["npt"] =
 | 
				
			||||||
 | 
										$this->backend
 | 
				
			||||||
 | 
										->store(
 | 
				
			||||||
 | 
											$q . "&c=" . $get["country"],
 | 
				
			||||||
 | 
											"web",
 | 
				
			||||||
 | 
											$proxy
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function titledots($title){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return trim($title, " .\t\n\r\0\x0B…");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3448
									
								
								scraper/google.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										1054
									
								
								scraper/google_cse.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										435
									
								
								scraper/greppr.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,435 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class greppr{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("greppr");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $cookie = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($cookie === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
									"Sec-Fetch-User: ?1"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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",
 | 
				
			||||||
 | 
									"Cookie: PHPSESSID=" . $cookie,
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
									"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);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$headers = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curlproc,
 | 
				
			||||||
 | 
								CURLOPT_HEADERFUNCTION,
 | 
				
			||||||
 | 
								function($curlproc, $header) use (&$headers){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$len = strlen($header);
 | 
				
			||||||
 | 
									$header = explode(':', $header, 2);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(count($header) < 2){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// ignore invalid headers
 | 
				
			||||||
 | 
										return $len;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$headers[strtolower(trim($header[0]))] = trim($header[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									return $len;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
							$data = curl_exec($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(curl_errno($curlproc)){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception(curl_error($curlproc));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curlproc);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"headers" => $headers,
 | 
				
			||||||
 | 
								"data" => $data
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function web($get, $first_attempt = true){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$q, $proxy] = $this->backend->get($get["npt"], "web");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$q = json_decode($q, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get token
 | 
				
			||||||
 | 
							// token[0] = static token that changes once a day
 | 
				
			||||||
 | 
							// token[1] = dynamic token that changes on every request
 | 
				
			||||||
 | 
							// token[1] = PHPSESSID cookie
 | 
				
			||||||
 | 
							$tokens = apcu_fetch("greppr_token");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$tokens === false ||
 | 
				
			||||||
 | 
								$first_attempt === false // force token fetch
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// we haven't gotten the token yet, get it
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$response =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://greppr.org",
 | 
				
			||||||
 | 
											[]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch search tokens");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$tokens = $this->parse_token($response);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($tokens === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to grep search tokens");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($get["npt"]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$params = [
 | 
				
			||||||
 | 
										$tokens[0] => $q["q"],
 | 
				
			||||||
 | 
										"s" => $q["s"],
 | 
				
			||||||
 | 
										"l" => 30,
 | 
				
			||||||
 | 
										"n" => $tokens[1]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$params = [
 | 
				
			||||||
 | 
										$tokens[0] => $search,
 | 
				
			||||||
 | 
										"n" => $tokens[1]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$searchresults = $this->get(
 | 
				
			||||||
 | 
									$proxy,
 | 
				
			||||||
 | 
									"https://greppr.org/search",
 | 
				
			||||||
 | 
									$params,
 | 
				
			||||||
 | 
									$tokens[2]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch search page");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(strlen($searchresults["data"]) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// redirected to main page, which means we got old token
 | 
				
			||||||
 | 
								// generate a new one
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// ... unless we just tried to do that
 | 
				
			||||||
 | 
								if($first_attempt === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to get a new search token");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $this->web($get, false);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// refresh the token with new data (this also triggers fuckhtml load)
 | 
				
			||||||
 | 
							$this->parse_token($searchresults, $tokens[2]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// response object
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get results for later
 | 
				
			||||||
 | 
							$results =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"result",
 | 
				
			||||||
 | 
									"div"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check for next page
 | 
				
			||||||
 | 
							$next_elem =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"pagination",
 | 
				
			||||||
 | 
									"ul"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($next_elem) !== 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($next_elem[0]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$as =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"page-link",
 | 
				
			||||||
 | 
										"a"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$break = false;
 | 
				
			||||||
 | 
								foreach($as as $a){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($break === true){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										parse_str(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$a["attributes"]["href"]
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
											$values
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$values = array_values($values);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$out["npt"] =
 | 
				
			||||||
 | 
											$this->backend->store(
 | 
				
			||||||
 | 
												json_encode(
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"q" => $values[0],
 | 
				
			||||||
 | 
														"s" => $values[1]
 | 
				
			||||||
 | 
													]
 | 
				
			||||||
 | 
												),
 | 
				
			||||||
 | 
												"web",
 | 
				
			||||||
 | 
												$proxy
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($a["attributes"]["href"] == "#"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$break = true;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// scrape results
 | 
				
			||||||
 | 
							foreach($results as $result){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($result);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$a =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByTagName(
 | 
				
			||||||
 | 
										"a"
 | 
				
			||||||
 | 
									)[0];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"highlightedDesc",
 | 
				
			||||||
 | 
										"p"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($description) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description = null;
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description =
 | 
				
			||||||
 | 
										$this->limitstrlen(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$description[0]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$date =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByTagName(
 | 
				
			||||||
 | 
										"p"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$date =
 | 
				
			||||||
 | 
									strtotime(
 | 
				
			||||||
 | 
										explode(
 | 
				
			||||||
 | 
											":",
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$date[count($date) - 1]["innerHTML"]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										)[1]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$a["innerHTML"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"description" => $description,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$a["attributes"]["href"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"date" => $date,
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => [],
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function parse_token($response, $cookie = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($response["data"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$scripts =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByTagName("script");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$found = false;
 | 
				
			||||||
 | 
							foreach($scripts as $script){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/window\.location ?= ?\'\/search\?([^=]+).*&n=([0-9]+)/',
 | 
				
			||||||
 | 
									$script["innerHTML"],
 | 
				
			||||||
 | 
									$tokens
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($tokens[1])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$found = true;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($found === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$tokens = [
 | 
				
			||||||
 | 
								$tokens[1],
 | 
				
			||||||
 | 
								$tokens[2]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($cookie !== false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// we already specified a cookie, so use the one we have already
 | 
				
			||||||
 | 
								$tokens[] = $cookie;
 | 
				
			||||||
 | 
								apcu_store("greppr_token", $tokens);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $tokens;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($response["headers"]["set-cookie"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// server didn't send a cookie
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get cookie
 | 
				
			||||||
 | 
							preg_match(
 | 
				
			||||||
 | 
								'/PHPSESSID=([^;]+)/',
 | 
				
			||||||
 | 
								$response["headers"]["set-cookie"],
 | 
				
			||||||
 | 
								$cookie
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($cookie[1])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// server sent an unexpected cookie
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$tokens[] = $cookie[1];
 | 
				
			||||||
 | 
							apcu_store("greppr_token", $tokens);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $tokens;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function limitstrlen($text){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return explode("\n", wordwrap($text, 300, "\n"))[0];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										258
									
								
								scraper/imgur.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,258 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class imgur{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("imgur");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"sort" => [ // /score/
 | 
				
			||||||
 | 
									"display" => "Sort by",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"score" => "Highest scoring",
 | 
				
			||||||
 | 
										"relevance" => "Most relevant",
 | 
				
			||||||
 | 
										"time" => "Newest first"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"time" => [ // /score/day/
 | 
				
			||||||
 | 
									"display" => "Time posted",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"all" => "All time",
 | 
				
			||||||
 | 
										"day" => "Today",
 | 
				
			||||||
 | 
										"week" => "This week",
 | 
				
			||||||
 | 
										"month" => "This month",
 | 
				
			||||||
 | 
										"year" => "This year"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"format" => [ // q_type
 | 
				
			||||||
 | 
									"display" => "Format",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "Any format",
 | 
				
			||||||
 | 
										"jpg" => "JPG",
 | 
				
			||||||
 | 
										"png" => "PNG",
 | 
				
			||||||
 | 
										"gif" => "GIF",
 | 
				
			||||||
 | 
										"anigif" => "Animated GIF",
 | 
				
			||||||
 | 
										"album" => "Albums"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"size" => [ // q_size_px
 | 
				
			||||||
 | 
									"display" => "Size",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "Any size",
 | 
				
			||||||
 | 
										"small" => "Small (500px or less)",
 | 
				
			||||||
 | 
										"med" => "Medium (500px to 2000px)",
 | 
				
			||||||
 | 
										"big" => "Big (2000px to 5000px)",
 | 
				
			||||||
 | 
										"lrg" => "Large (5000px to 10000px)",
 | 
				
			||||||
 | 
										"huge" => "Huge (10000px and above)"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = []){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get !== []){
 | 
				
			||||||
 | 
								$get = http_build_query($get);
 | 
				
			||||||
 | 
								$url .= "?scrolled&" . $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",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Referer: https://imgur.com/search/",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
								"TE: trailers",
 | 
				
			||||||
 | 
								"X-Requested-With: XMLHttpRequest"]
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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 image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$filter, $proxy] =
 | 
				
			||||||
 | 
									$this->backend->get(
 | 
				
			||||||
 | 
										$get["npt"],
 | 
				
			||||||
 | 
										"images"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$filter = json_decode($filter, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $filter["s"];
 | 
				
			||||||
 | 
								unset($filter["s"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$sort = $filter["sort"];
 | 
				
			||||||
 | 
								unset($filter["sort"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$time = $filter["time"];
 | 
				
			||||||
 | 
								unset($filter["time"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$format = $filter["format"];
 | 
				
			||||||
 | 
								unset($filter["format"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$size = $filter["size"];
 | 
				
			||||||
 | 
								unset($filter["size"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$page = $filter["page"];
 | 
				
			||||||
 | 
								unset($filter["page"]);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								$sort = $get["sort"];
 | 
				
			||||||
 | 
								$time = $get["time"];
 | 
				
			||||||
 | 
								$format = $get["format"];
 | 
				
			||||||
 | 
								$size = $get["size"];
 | 
				
			||||||
 | 
								$page = 0;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$filter = [
 | 
				
			||||||
 | 
									"q" => $search
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($format != "any"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$filter["q_type"] = $format;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($size != "any"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$filter["q_size_px"] = $size;
 | 
				
			||||||
 | 
									$filter["q_size_is_mpx"] = "off";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$html =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$proxy,
 | 
				
			||||||
 | 
										"https://imgur.com/search/$sort/$time/page/$page",
 | 
				
			||||||
 | 
										$filter
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch HTML");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$posts =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"post",
 | 
				
			||||||
 | 
									"div"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($posts as $post){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($post);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByTagName("img")[0];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image_url = "https:" . substr($this->fuckhtml->getTextContent($image["attributes"]["src"]), 0, -5);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["image"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$image["attributes"]["alt"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"source" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $image_url . ".jpg",
 | 
				
			||||||
 | 
											"width" => null,
 | 
				
			||||||
 | 
											"height" => null
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $image_url . "m.jpg",
 | 
				
			||||||
 | 
											"width" => null,
 | 
				
			||||||
 | 
											"height" => null
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										"https://imgur.com" .
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getElementsByClassName(
 | 
				
			||||||
 | 
												"image-list-link",
 | 
				
			||||||
 | 
												"a"
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
											[0]
 | 
				
			||||||
 | 
											["attributes"]
 | 
				
			||||||
 | 
											["href"]
 | 
				
			||||||
 | 
										)
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($out["image"][0])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// store nextpage
 | 
				
			||||||
 | 
								$filter["s"] = $search;
 | 
				
			||||||
 | 
								$filter["sort"] = $sort;
 | 
				
			||||||
 | 
								$filter["time"] = $time;
 | 
				
			||||||
 | 
								$filter["format"] = $format;
 | 
				
			||||||
 | 
								$filter["size"] = $size;
 | 
				
			||||||
 | 
								$filter["page"] = $page + 1;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode($filter),
 | 
				
			||||||
 | 
										"images",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										476
									
								
								scraper/marginalia.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,476 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class marginalia{
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("marginalia");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(config::MARGINALIA_API_KEY === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$base = [
 | 
				
			||||||
 | 
									"adtech" => [
 | 
				
			||||||
 | 
										"display" => "Reduce adtech",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"no" => "No",
 | 
				
			||||||
 | 
											"yes" => "Yes"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"recent" => [
 | 
				
			||||||
 | 
										"display" => "Recent results",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"no" => "No",
 | 
				
			||||||
 | 
											"yes" => "Yes"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"intitle" => [
 | 
				
			||||||
 | 
										"display" => "Search in title",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"no" => "No",
 | 
				
			||||||
 | 
											"yes" => "Yes"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$base = [];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return array_merge(
 | 
				
			||||||
 | 
								$base,
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"format" => [
 | 
				
			||||||
 | 
										"display" => "Format",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"any" => "Any format",
 | 
				
			||||||
 | 
											"html5" => "html5",
 | 
				
			||||||
 | 
											"xhtml" => "xhtml",
 | 
				
			||||||
 | 
											"html123" => "html123"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"file" => [
 | 
				
			||||||
 | 
										"display" => "Filetype",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"any" => "Any filetype",
 | 
				
			||||||
 | 
											"nomedia" => "Deny media",
 | 
				
			||||||
 | 
											"media" => "Contains media",
 | 
				
			||||||
 | 
											"audio" => "Contains audio",
 | 
				
			||||||
 | 
											"video" => "Contains video",
 | 
				
			||||||
 | 
											"archive" => "Contains archive",
 | 
				
			||||||
 | 
											"document" => "Contains document"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"javascript" => [
 | 
				
			||||||
 | 
										"display" => "Javascript",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"any" => "Allow JS",
 | 
				
			||||||
 | 
											"deny" => "Deny JS",
 | 
				
			||||||
 | 
											"require" => "Require JS"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"trackers" => [
 | 
				
			||||||
 | 
										"display" => "Trackers",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"any" => "Allow trackers",
 | 
				
			||||||
 | 
											"deny" => "Deny trackers",
 | 
				
			||||||
 | 
											"require" => "Require trackers"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"cookies" => [
 | 
				
			||||||
 | 
										"display" => "Cookies",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"any" => "Allow cookies",
 | 
				
			||||||
 | 
											"deny" => "Deny cookies",
 | 
				
			||||||
 | 
											"require" => "Require cookies"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"affiliate" => [
 | 
				
			||||||
 | 
										"display" => "Affiliate links in body",
 | 
				
			||||||
 | 
										"option" => [
 | 
				
			||||||
 | 
											"any" => "Allow affiliate links",
 | 
				
			||||||
 | 
											"deny" => "Deny affiliate links",
 | 
				
			||||||
 | 
											"require" => "Require affiliate links"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = []){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$headers = [
 | 
				
			||||||
 | 
								"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",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"Sec-Fetch-User: ?1"
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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, $headers);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = [$get["s"]];
 | 
				
			||||||
 | 
							if(strlen($get["s"]) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$format = $get["format"];
 | 
				
			||||||
 | 
							$file = $get["file"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach(
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"javascript" => $get["javascript"],
 | 
				
			||||||
 | 
									"trackers" => $get["trackers"],
 | 
				
			||||||
 | 
									"cookies" => $get["cookies"],
 | 
				
			||||||
 | 
									"affiliate" => $get["affiliate"]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
								as $key => $value
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($value == "any"){ continue; }
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($key){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "javascript": $str = "js:true"; break;
 | 
				
			||||||
 | 
									case "trackers": $str = "special:tracking"; break;
 | 
				
			||||||
 | 
									case "cookies": $str = "special:cookies"; break;
 | 
				
			||||||
 | 
									case "affiliate": $str = "special:affiliate"; break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($value == "deny"){
 | 
				
			||||||
 | 
									$str = "-" . $str;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search[] = $str;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($format != "any"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search[] = "format:$format";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($file){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "any": break;
 | 
				
			||||||
 | 
								case "nomedia": $search[] = "-special:media"; break;
 | 
				
			||||||
 | 
								case "media": $search[] = "special:media"; break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									$search[] = "file:$file";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = implode(" ", $search);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// API scraper
 | 
				
			||||||
 | 
							if(config::MARGINALIA_API_KEY !== null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$json =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$this->backend->get_ip(), // no nextpage
 | 
				
			||||||
 | 
											"https://api.marginalia-search.com/" . config::MARGINALIA_API_KEY . "/search/" . urlencode($search),
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"count" => 20
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to get JSON");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($json == "Slow down"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("The API key used is rate limited. Please try again in a few minutes.");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json = json_decode($json, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($json["results"] as $result){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["web"][] = [
 | 
				
			||||||
 | 
										"title" => $result["title"],
 | 
				
			||||||
 | 
										"description" => str_replace("\n", " ", $result["description"]),
 | 
				
			||||||
 | 
										"url" => $result["url"],
 | 
				
			||||||
 | 
										"date" => null,
 | 
				
			||||||
 | 
										"type" => "web",
 | 
				
			||||||
 | 
										"thumb" => [
 | 
				
			||||||
 | 
											"url" => null,
 | 
				
			||||||
 | 
											"ratio" => null
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"sublink" => [],
 | 
				
			||||||
 | 
										"table" => []
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// HTML parser
 | 
				
			||||||
 | 
							$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$params, $proxy] =
 | 
				
			||||||
 | 
									$this->backend->get(
 | 
				
			||||||
 | 
										$get["npt"],
 | 
				
			||||||
 | 
										"web"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$html =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://old-search.marginalia.nu/search?" . $params
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to get HTML");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								$params = [
 | 
				
			||||||
 | 
									"query" => $search
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach(["adtech", "recent", "intitle"] as $v){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($get[$v] == "yes"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										switch($v){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											case "adtech": $params["adtech"] = "reduce"; break;
 | 
				
			||||||
 | 
											case "recent": $params["recent"] = "recent"; break;
 | 
				
			||||||
 | 
											case "adtech": $params["searchTitle"] = "title"; break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$html =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://old-search.marginalia.nu/search",
 | 
				
			||||||
 | 
											$params
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to get HTML");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$sections =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"card search-result",
 | 
				
			||||||
 | 
									"section"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($sections as $section){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($section);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$title =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"title",
 | 
				
			||||||
 | 
										"a"
 | 
				
			||||||
 | 
									)[0];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"description",
 | 
				
			||||||
 | 
										"p"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($description) !== 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description =
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$description[0]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description = null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$sublinks = [];
 | 
				
			||||||
 | 
								$sublink_html =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName("additional-results");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(count($sublink_html) !== 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$this->fuckhtml->load($sublink_html[0]);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$links =
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getElementsByTagName("a");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									foreach($links as $link){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$sublinks[] = [
 | 
				
			||||||
 | 
											"title" =>
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getTextContent(
 | 
				
			||||||
 | 
													$link
 | 
				
			||||||
 | 
												),
 | 
				
			||||||
 | 
											"date" => null,
 | 
				
			||||||
 | 
											"description" => null,
 | 
				
			||||||
 | 
											"url" =>
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getTextContent(
 | 
				
			||||||
 | 
													$link["attributes"]["href"]
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$title
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"description" => $description,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$title["attributes"]["href"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => $sublinks,
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get next page
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$pagination =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByAttributeValue(
 | 
				
			||||||
 | 
									"aria-label",
 | 
				
			||||||
 | 
									"pagination",
 | 
				
			||||||
 | 
									"nav"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($pagination) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// no pagination
 | 
				
			||||||
 | 
								return $out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($pagination[0]);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$pages =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"page-link",
 | 
				
			||||||
 | 
									"a"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$found_current_page = false;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($pages as $page){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									stripos(
 | 
				
			||||||
 | 
										$page["attributes"]["class"],
 | 
				
			||||||
 | 
										"active"
 | 
				
			||||||
 | 
									) !== false
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$found_current_page = true;
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($found_current_page){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// we found current page index, and we iterated over
 | 
				
			||||||
 | 
									// the next page <a>
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["npt"] =
 | 
				
			||||||
 | 
										$this->backend->store(
 | 
				
			||||||
 | 
											parse_url(
 | 
				
			||||||
 | 
												$page["attributes"]["href"],
 | 
				
			||||||
 | 
												PHP_URL_QUERY
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
											"web",
 | 
				
			||||||
 | 
											$proxy
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
							
								
								
									
										1174
									
								
								scraper/mojeek.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										236
									
								
								scraper/mwmbl.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,236 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class mwmbl{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("mwmbl");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = []){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get !== []){
 | 
				
			||||||
 | 
								$get = http_build_query($get);
 | 
				
			||||||
 | 
								$url .= "?" . $get;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// use http2
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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://beta.mwmbl.org/",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Sec-GPC: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
								"Priority: u=0, i",
 | 
				
			||||||
 | 
								"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){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$html = $this->get(
 | 
				
			||||||
 | 
									$this->backend->get_ip(), // no next page!
 | 
				
			||||||
 | 
									"https://beta.mwmbl.org/",
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"q" => $search
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch HTML. If you're getting a timeout, make sure you have curl-impersonate setup.");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$results =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByClassName(
 | 
				
			||||||
 | 
									"result",
 | 
				
			||||||
 | 
									"li"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($results as $result){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$this->fuckhtml->load($result);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$p =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByTagName("p");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$sublinks = [];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$mores =
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"result-link-more",
 | 
				
			||||||
 | 
										"div"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($mores as $more){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$this->fuckhtml->load($more);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$as =
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getElementsByClassName(
 | 
				
			||||||
 | 
											"more",
 | 
				
			||||||
 | 
											"a"
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(count($as) === 0){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// ?? invalid
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$sublinks[] = [
 | 
				
			||||||
 | 
										"title" =>
 | 
				
			||||||
 | 
											$this->titledots(
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getTextContent(
 | 
				
			||||||
 | 
													$this->fuckhtml
 | 
				
			||||||
 | 
													->getElementsByClassName(
 | 
				
			||||||
 | 
														"more-title",
 | 
				
			||||||
 | 
														"span"
 | 
				
			||||||
 | 
													)[0]
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
										"description" =>
 | 
				
			||||||
 | 
											$this->titledots(
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getTextContent(
 | 
				
			||||||
 | 
													$this->fuckhtml
 | 
				
			||||||
 | 
													->getElementsByClassName(
 | 
				
			||||||
 | 
														"more-extract",
 | 
				
			||||||
 | 
														"span"
 | 
				
			||||||
 | 
													)[0]
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
										"url" =>
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$as[0]
 | 
				
			||||||
 | 
												["attributes"]
 | 
				
			||||||
 | 
												["href"]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// reset
 | 
				
			||||||
 | 
								$this->fuckhtml->load($result);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										$this->titledots(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getElementsByClassName(
 | 
				
			||||||
 | 
													"title",
 | 
				
			||||||
 | 
													$p
 | 
				
			||||||
 | 
												)[0]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"description" =>
 | 
				
			||||||
 | 
										$this->titledots(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getTextContent(
 | 
				
			||||||
 | 
												$this->fuckhtml
 | 
				
			||||||
 | 
												->getElementsByClassName(
 | 
				
			||||||
 | 
													"extract",
 | 
				
			||||||
 | 
													$p
 | 
				
			||||||
 | 
												)[0]
 | 
				
			||||||
 | 
											)
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										$this->fuckhtml
 | 
				
			||||||
 | 
										->getTextContent(
 | 
				
			||||||
 | 
											$this->fuckhtml
 | 
				
			||||||
 | 
											->getElementsByTagName("a")
 | 
				
			||||||
 | 
											[0]
 | 
				
			||||||
 | 
											["attributes"]
 | 
				
			||||||
 | 
											["href"]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => $sublinks,
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function titledots($title){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return rtrim($title, "…");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										439
									
								
								scraper/pinterest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,439 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class pinterest{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("pinterest");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], &$cookies, $header_data_post = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($header_data_post === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// handling GET
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
								// extract cookies
 | 
				
			||||||
 | 
								$cookies_tmp = [];
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_HEADERFUNCTION, function($curlproc, $header) use (&$cookies_tmp){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$length = strlen($header);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$header = explode(":", $header, 2);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(trim(strtolower($header[0])) == "set-cookie"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$cookie_tmp = explode("=", trim($header[1]), 2);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$cookies_tmp[trim($cookie_tmp[0])] =
 | 
				
			||||||
 | 
											explode(";", $cookie_tmp[1], 2)[0];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return $length;
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
									["User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
									"Accept: application/json, text/javascript, */*, q=0.01",
 | 
				
			||||||
 | 
									"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
									"Accept-Encoding: gzip",
 | 
				
			||||||
 | 
									"Referer: https://ca.pinterest.com/",
 | 
				
			||||||
 | 
									"X-Requested-With: XMLHttpRequest",
 | 
				
			||||||
 | 
									"X-APP-VERSION: 78f8764",
 | 
				
			||||||
 | 
									"X-Pinterest-AppState: active",
 | 
				
			||||||
 | 
									"X-Pinterest-Source-Url: /",
 | 
				
			||||||
 | 
									"X-Pinterest-PWS-Handler: www/index.js",
 | 
				
			||||||
 | 
									"screen-dpr: 1",
 | 
				
			||||||
 | 
									"is-preload-enabled: 1",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Sec-GPC: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Alt-Used: ca.pinterest.com",
 | 
				
			||||||
 | 
									"Priority: u=0",
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($get !== []){
 | 
				
			||||||
 | 
									$get = http_build_query($get);
 | 
				
			||||||
 | 
									$url .= "?" . $get;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// handling POST (pagination)
 | 
				
			||||||
 | 
								$get = http_build_query($get);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
									["User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
									"Accept: application/json, text/javascript, */*, q=0.01",
 | 
				
			||||||
 | 
									"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
									"Accept-Encoding: gzip",
 | 
				
			||||||
 | 
									"Content-Type: application/x-www-form-urlencoded",
 | 
				
			||||||
 | 
									"Content-Length: " . strlen($get),
 | 
				
			||||||
 | 
									"Referer: https://ca.pinterest.com/",
 | 
				
			||||||
 | 
									"X-Requested-With: XMLHttpRequest",
 | 
				
			||||||
 | 
									"X-APP-VERSION: 78f8764",
 | 
				
			||||||
 | 
									"X-CSRFToken: " . $cookies["csrf"],
 | 
				
			||||||
 | 
									"X-Pinterest-AppState: active",
 | 
				
			||||||
 | 
									"X-Pinterest-Source-Url: /search/pins/?rs=ac&len=2&q=" . urlencode($header_data_post) . "&eq=" . urlencode($header_data_post),
 | 
				
			||||||
 | 
									"X-Pinterest-PWS-Handler: www/search/[scope].js",
 | 
				
			||||||
 | 
									"screen-dpr: 1",
 | 
				
			||||||
 | 
									"is-preload-enabled: 1",
 | 
				
			||||||
 | 
									"Origin: https://ca.pinterest.com",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Sec-GPC: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Alt-Used: ca.pinterest.com",
 | 
				
			||||||
 | 
									"Cookie: " . $cookies["cookie"],
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_POST, true);
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_POSTFIELDS, $get);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// http2 bypass
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($header_data_post === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($cookies_tmp["csrftoken"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to grep CSRF token");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$cookies = "";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($cookies_tmp as $cookie_name => $cookie_value){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$cookies .= $cookie_name . "=" . $cookie_value . "; ";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$cookies = [
 | 
				
			||||||
 | 
									"csrf" => $cookies_tmp["csrftoken"],
 | 
				
			||||||
 | 
									"cookie" => rtrim($cookies, " ;")
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_close($curlproc);
 | 
				
			||||||
 | 
							return $data;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$data, $proxy] =
 | 
				
			||||||
 | 
									$this->backend->get(
 | 
				
			||||||
 | 
										$get["npt"], "images"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$data = json_decode($data, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $data["q"];
 | 
				
			||||||
 | 
								$cookies = $data["cookies"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$json =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://ca.pinterest.com/resource/BaseSearchResource/get/",
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"source_url" => "/search/pins/?q=" . urlencode($search) . "&rs=typed",
 | 
				
			||||||
 | 
												"data" => json_encode(
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"options" => [
 | 
				
			||||||
 | 
															"applied_unified_filters" => null,
 | 
				
			||||||
 | 
															"appliedProductFilters" => "---",
 | 
				
			||||||
 | 
															"article" => null,
 | 
				
			||||||
 | 
															"auto_correction_disabled" => false,
 | 
				
			||||||
 | 
															"corpus" => null,
 | 
				
			||||||
 | 
															"customized_rerank_type" => null,
 | 
				
			||||||
 | 
															"domains" => null,
 | 
				
			||||||
 | 
															"dynamicPageSizeExpGroup" => null,
 | 
				
			||||||
 | 
															"filters" => null,
 | 
				
			||||||
 | 
															"journey_depth" => null,
 | 
				
			||||||
 | 
															"page_size" => null,
 | 
				
			||||||
 | 
															"price_max" => null,
 | 
				
			||||||
 | 
															"price_min" => null,
 | 
				
			||||||
 | 
															"query_pin_sigs" => null,
 | 
				
			||||||
 | 
															"query" => $data["q"],
 | 
				
			||||||
 | 
															"redux_normalize_feed" => true,
 | 
				
			||||||
 | 
															"request_params" => null,
 | 
				
			||||||
 | 
															"rs" => "typed",
 | 
				
			||||||
 | 
															"scope" => "pins",
 | 
				
			||||||
 | 
															"selected_one_bar_modules" => null,
 | 
				
			||||||
 | 
															"source_id" => null,
 | 
				
			||||||
 | 
															"source_module_id" => null,
 | 
				
			||||||
 | 
															"source_url" => "/search/pins/?q=" . urlencode($search) . "&rs=typed",
 | 
				
			||||||
 | 
															"top_pin_id" => null,
 | 
				
			||||||
 | 
															"top_pin_ids" => null,
 | 
				
			||||||
 | 
															"bookmarks" => [
 | 
				
			||||||
 | 
																$data["bookmark"]
 | 
				
			||||||
 | 
															]
 | 
				
			||||||
 | 
														],
 | 
				
			||||||
 | 
														"context" => []
 | 
				
			||||||
 | 
													],
 | 
				
			||||||
 | 
													JSON_UNESCAPED_SLASHES
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											$cookies,
 | 
				
			||||||
 | 
											$search
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
								// https://ca.pinterest.com/resource/BaseSearchResource/get/?source_url=%2Fsearch%2Fpins%2F%3Feq%3Dhigurashi%26etslf%3D5966%26len%3D2%26q%3Dhigurashi%2520when%2520they%2520cry%26rs%3Dac&data=%7B%22options%22%3A%7B%22applied_unified_filters%22%3Anull%2C%22appliedProductFilters%22%3A%22---%22%2C%22article%22%3Anull%2C%22auto_correction_disabled%22%3Afalse%2C%22corpus%22%3Anull%2C%22customized_rerank_type%22%3Anull%2C%22domains%22%3Anull%2C%22dynamicPageSizeExpGroup%22%3Anull%2C%22filters%22%3Anull%2C%22journey_depth%22%3Anull%2C%22page_size%22%3Anull%2C%22price_max%22%3Anull%2C%22price_min%22%3Anull%2C%22query_pin_sigs%22%3Anull%2C%22query%22%3A%22higurashi%20when%20they%20cry%22%2C%22redux_normalize_feed%22%3Atrue%2C%22request_params%22%3Anull%2C%22rs%22%3A%22ac%22%2C%22scope%22%3A%22pins%22%2C%22selected_one_bar_modules%22%3Anull%2C%22source_id%22%3Anull%2C%22source_module_id%22%3Anull%2C%22source_url%22%3A%22%2Fsearch%2Fpins%2F%3Feq%3Dhigurashi%26etslf%3D5966%26len%3D2%26q%3Dhigurashi%2520when%2520they%2520cry%26rs%3Dac%22%2C%22top_pin_id%22%3Anull%2C%22top_pin_ids%22%3Anull%7D%2C%22context%22%3A%7B%7D%7D&_=1736116313987
 | 
				
			||||||
 | 
								// source_url=%2Fsearch%2Fpins%2F%3Feq%3Dhigurashi%26etslf%3D5966%26len%3D2%26q%3Dhigurashi%2520when%2520they%2520cry%26rs%3Dac
 | 
				
			||||||
 | 
								// &data=%7B%22options%22%3A%7B%22applied_unified_filters%22%3Anull%2C%22appliedProductFilters%22%3A%22---%22%2C%22article%22%3Anull%2C%22auto_correction_disabled%22%3Afalse%2C%22corpus%22%3Anull%2C%22customized_rerank_type%22%3Anull%2C%22domains%22%3Anull%2C%22dynamicPageSizeExpGroup%22%3Anull%2C%22filters%22%3Anull%2C%22journey_depth%22%3Anull%2C%22page_size%22%3Anull%2C%22price_max%22%3Anull%2C%22price_min%22%3Anull%2C%22query_pin_sigs%22%3Anull%2C%22query%22%3A%22higurashi%20when%20they%20cry%22%2C%22redux_normalize_feed%22%3Atrue%2C%22request_params%22%3Anull%2C%22rs%22%3A%22ac%22%2C%22scope%22%3A%22pins%22%2C%22selected_one_bar_modules%22%3Anull%2C%22source_id%22%3Anull%2C%22source_module_id%22%3Anull%2C%22source_url%22%3A%22%2Fsearch%2Fpins%2F%3Feq%3Dhigurashi%26etslf%3D5966%26len%3D2%26q%3Dhigurashi%2520when%2520they%2520cry%26rs%3Dac%22%2C%22top_pin_id%22%3Anull%2C%22top_pin_ids%22%3Anull%7D%2C%22context%22%3A%7B%7D%7D
 | 
				
			||||||
 | 
								// &_=1736116313987
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$source_url = "/search/pins/?q=" . urlencode($search) . "&rs=" . urlencode($search);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$filter = [
 | 
				
			||||||
 | 
									"source_url" => $source_url,
 | 
				
			||||||
 | 
									"rs" => "typed",
 | 
				
			||||||
 | 
									"data" =>
 | 
				
			||||||
 | 
										json_encode(
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"options" => [
 | 
				
			||||||
 | 
													"applied_unified_filters" => null,
 | 
				
			||||||
 | 
													"appliedProductFilters" => "---",
 | 
				
			||||||
 | 
													"article" => null,
 | 
				
			||||||
 | 
													"corpus" => null,
 | 
				
			||||||
 | 
													"customized_rerank_type" => null,
 | 
				
			||||||
 | 
													"domains" => null,
 | 
				
			||||||
 | 
													"dynamicPageSizeExpGroup" => null,
 | 
				
			||||||
 | 
													"filters" => null,
 | 
				
			||||||
 | 
													"journey_depth" => null,
 | 
				
			||||||
 | 
													"page_size" => null,
 | 
				
			||||||
 | 
													"price_max" => null,
 | 
				
			||||||
 | 
													"price_min" => null,
 | 
				
			||||||
 | 
													"query_pin_sigs" => null,
 | 
				
			||||||
 | 
													"query" => $search,
 | 
				
			||||||
 | 
													"redux_normalize_feed" => true,
 | 
				
			||||||
 | 
													"request_params" => null,
 | 
				
			||||||
 | 
													"rs" => "ac",
 | 
				
			||||||
 | 
													"scope" => "pins", // pins, boards, videos, 
 | 
				
			||||||
 | 
													"selected_one_bar_modules" => null,
 | 
				
			||||||
 | 
													"source_id" => null,
 | 
				
			||||||
 | 
													"source_module_id" => null,
 | 
				
			||||||
 | 
													"source_url" => $source_url,
 | 
				
			||||||
 | 
													"top_pin_id" => null,
 | 
				
			||||||
 | 
													"top_pin_ids" => null
 | 
				
			||||||
 | 
												],
 | 
				
			||||||
 | 
												"context" => []
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
									"_" => substr(str_replace(".", "", (string)microtime(true)), 0, -1)
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								$cookies = [];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$json =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://ca.pinterest.com/resource/BaseSearchResource/get/",
 | 
				
			||||||
 | 
											$filter,
 | 
				
			||||||
 | 
											$cookies,
 | 
				
			||||||
 | 
											null
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								!isset(
 | 
				
			||||||
 | 
									$json["resource_response"]
 | 
				
			||||||
 | 
									["status"]
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Unknown API failure");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json["resource_response"]["status"] != "success"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$status = "Got non-OK response: " . $json["resource_response"]["status"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									isset(
 | 
				
			||||||
 | 
										$json["resource_response"]["message"]
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$status .= " - " . $json["resource_response"]["message"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception($status);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset(
 | 
				
			||||||
 | 
									$json["resource_response"]["sensitivity"]
 | 
				
			||||||
 | 
									["notices"][0]["description"]["text"]
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception(
 | 
				
			||||||
 | 
									"Pinterest returned a notice: " .
 | 
				
			||||||
 | 
									$json["resource_response"]["sensitivity"]["notices"][0]["description"]["text"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get NPT
 | 
				
			||||||
 | 
							if(isset($json["resource_response"]["bookmark"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode([
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"bookmark" => $json["resource_response"]["bookmark"],
 | 
				
			||||||
 | 
											"cookies" => $cookies
 | 
				
			||||||
 | 
										]),
 | 
				
			||||||
 | 
										"images",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach(
 | 
				
			||||||
 | 
								$json
 | 
				
			||||||
 | 
								["resource_response"]
 | 
				
			||||||
 | 
								["data"]
 | 
				
			||||||
 | 
								["results"]
 | 
				
			||||||
 | 
								as $item
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($item["type"]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "pin":
 | 
				
			||||||
 | 
									case "board":
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										/*
 | 
				
			||||||
 | 
											Handle image object
 | 
				
			||||||
 | 
										*/
 | 
				
			||||||
 | 
										$images = array_values($item["images"]);
 | 
				
			||||||
 | 
										$image = &$images[count($images) - 1]; // original
 | 
				
			||||||
 | 
										$thumb = &$images[1]; // 236x
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$title = [];
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											isset($item["grid_title"]) &&
 | 
				
			||||||
 | 
											trim($item["grid_title"]) != ""
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$title[] = $item["grid_title"];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											isset($item["description"]) &&
 | 
				
			||||||
 | 
											trim($item["description"]) != ""
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$title[] = $item["description"];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$title = implode(": ", $title);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											$title == "" &&
 | 
				
			||||||
 | 
											isset($item["board"]["name"]) &&
 | 
				
			||||||
 | 
											trim($item["board"]["name"]) != ""
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$title = $item["board"]["name"];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if($title == ""){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$title = null;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$out["image"][] = [
 | 
				
			||||||
 | 
											"title" => $title,
 | 
				
			||||||
 | 
											"source" => [
 | 
				
			||||||
 | 
												[
 | 
				
			||||||
 | 
													"url" => $image["url"],
 | 
				
			||||||
 | 
													"width" => (int)$image["width"],
 | 
				
			||||||
 | 
													"height" => (int)$image["height"]
 | 
				
			||||||
 | 
												],
 | 
				
			||||||
 | 
												[
 | 
				
			||||||
 | 
													"url" => $thumb["url"],
 | 
				
			||||||
 | 
													"width" => (int)$thumb["width"],
 | 
				
			||||||
 | 
													"height" => (int)$thumb["height"]
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"url" =>
 | 
				
			||||||
 | 
												$item["link"] === null ?
 | 
				
			||||||
 | 
												"https://ca.pinterest.com/pin/" . $item["id"] :
 | 
				
			||||||
 | 
												$item["link"]
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										937
									
								
								scraper/qwant.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,937 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class qwant{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("qwant");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$base = [
 | 
				
			||||||
 | 
								"nsfw" => [
 | 
				
			||||||
 | 
									"display" => "NSFW",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"yes" => "Yes",
 | 
				
			||||||
 | 
										"maybe" => "Maybe",
 | 
				
			||||||
 | 
										"no" => "No"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"country" => [
 | 
				
			||||||
 | 
									"display" => "Country",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"en_US" => "United States",
 | 
				
			||||||
 | 
										"fr_FR" => "France",
 | 
				
			||||||
 | 
										"en_GB" => "Great Britain",
 | 
				
			||||||
 | 
										"de_DE" => "Germany",
 | 
				
			||||||
 | 
										"it_IT" => "Italy",
 | 
				
			||||||
 | 
										"es_AR" => "Argentina",
 | 
				
			||||||
 | 
										"en_AU" => "Australia",
 | 
				
			||||||
 | 
										"es_ES" => "Spain (es)",
 | 
				
			||||||
 | 
										"ca_ES" => "Spain (ca)",
 | 
				
			||||||
 | 
										"cs_CZ" => "Czech Republic",
 | 
				
			||||||
 | 
										"ro_RO" => "Romania",
 | 
				
			||||||
 | 
										"el_GR" => "Greece",
 | 
				
			||||||
 | 
										"zh_CN" => "China",
 | 
				
			||||||
 | 
										"zh_HK" => "Hong Kong",
 | 
				
			||||||
 | 
										"en_NZ" => "New Zealand",
 | 
				
			||||||
 | 
										"fr_FR" => "France",
 | 
				
			||||||
 | 
										"th_TH" => "Thailand",
 | 
				
			||||||
 | 
										"ko_KR" => "South Korea",
 | 
				
			||||||
 | 
										"sv_SE" => "Sweden",
 | 
				
			||||||
 | 
										"nb_NO" => "Norway",
 | 
				
			||||||
 | 
										"da_DK" => "Denmark",
 | 
				
			||||||
 | 
										"hu_HU" => "Hungary",
 | 
				
			||||||
 | 
										"et_EE" => "Estonia",
 | 
				
			||||||
 | 
										"es_MX" => "Mexico",
 | 
				
			||||||
 | 
										"es_CL" => "Chile",
 | 
				
			||||||
 | 
										"en_CA" => "Canada (en)",
 | 
				
			||||||
 | 
										"fr_CA" => "Canada (fr)",
 | 
				
			||||||
 | 
										"en_MY" => "Malaysia",
 | 
				
			||||||
 | 
										"bg_BG" => "Bulgaria",
 | 
				
			||||||
 | 
										"fi_FI" => "Finland",
 | 
				
			||||||
 | 
										"pl_PL" => "Poland",
 | 
				
			||||||
 | 
										"nl_NL" => "Netherlands",
 | 
				
			||||||
 | 
										"pt_PT" => "Portugal",
 | 
				
			||||||
 | 
										"de_CH" => "Switzerland (de)",
 | 
				
			||||||
 | 
										"fr_CH" => "Switzerland (fr)",
 | 
				
			||||||
 | 
										"it_CH" => "Switzerland (it)",
 | 
				
			||||||
 | 
										"de_AT" => "Austria",
 | 
				
			||||||
 | 
										"fr_BE" => "Belgium (fr)",
 | 
				
			||||||
 | 
										"nl_BE" => "Belgium (nl)",
 | 
				
			||||||
 | 
										"en_IE" => "Ireland",
 | 
				
			||||||
 | 
										"he_IL" => "Israel"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($page){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "web":
 | 
				
			||||||
 | 
									$base = array_merge(
 | 
				
			||||||
 | 
										$base,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"time" => [
 | 
				
			||||||
 | 
												"display" => "Time posted",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any time",
 | 
				
			||||||
 | 
													"day" => "Past 24 hours",
 | 
				
			||||||
 | 
													"week" => "Past week",
 | 
				
			||||||
 | 
													"month" => "Past month"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"extendedsearch" => [
 | 
				
			||||||
 | 
												// no display, wont show in interface
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"yes" => "Yes",
 | 
				
			||||||
 | 
													"no" => "No"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "images":
 | 
				
			||||||
 | 
									$base = array_merge(
 | 
				
			||||||
 | 
										$base,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"time" => [
 | 
				
			||||||
 | 
												"display" => "Time posted",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any time",
 | 
				
			||||||
 | 
													"day" => "Past 24 hours",
 | 
				
			||||||
 | 
													"week" => "Past week",
 | 
				
			||||||
 | 
													"month" => "Past month"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"size" => [
 | 
				
			||||||
 | 
												"display" => "Size",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any size",
 | 
				
			||||||
 | 
													"large" => "Large",
 | 
				
			||||||
 | 
													"medium" => "Medium",
 | 
				
			||||||
 | 
													"small" => "Small"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"color" => [
 | 
				
			||||||
 | 
												"display" => "Color",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any color",
 | 
				
			||||||
 | 
													"coloronly" => "Color only",
 | 
				
			||||||
 | 
													"monochrome" => "Monochrome",
 | 
				
			||||||
 | 
													"black" => "Black",
 | 
				
			||||||
 | 
													"brown" => "Brown",
 | 
				
			||||||
 | 
													"gray" => "Gray",
 | 
				
			||||||
 | 
													"white" => "White",
 | 
				
			||||||
 | 
													"yellow" => "Yellow",
 | 
				
			||||||
 | 
													"orange" => "Orange",
 | 
				
			||||||
 | 
													"red" => "Red",
 | 
				
			||||||
 | 
													"pink" => "Pink",
 | 
				
			||||||
 | 
													"purple" => "Purple",
 | 
				
			||||||
 | 
													"blue" => "Blue",
 | 
				
			||||||
 | 
													"teal" => "Teal",
 | 
				
			||||||
 | 
													"green" => "Green"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"imagetype" => [
 | 
				
			||||||
 | 
												"display" => "Type",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any type",
 | 
				
			||||||
 | 
													"animatedgif" => "Animated GIF",
 | 
				
			||||||
 | 
													"photo" => "Photograph",
 | 
				
			||||||
 | 
													"transparent" => "Transparent"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"license" => [
 | 
				
			||||||
 | 
												"display" => "License",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any license",
 | 
				
			||||||
 | 
													"share" => "Non-commercial reproduction and sharing",
 | 
				
			||||||
 | 
													"sharecommercially" => "Reproduction and sharing",
 | 
				
			||||||
 | 
													"modify" => "Non-commercial reproduction, sharing and modification",
 | 
				
			||||||
 | 
													"modifycommercially" => "Reproduction, sharing and modification",
 | 
				
			||||||
 | 
													"public" => "Public domain"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "videos":
 | 
				
			||||||
 | 
									$base = array_merge(
 | 
				
			||||||
 | 
										$base,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"order" => [
 | 
				
			||||||
 | 
												"display" => "Order by",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"relevance" => "Relevance",
 | 
				
			||||||
 | 
													"views" => "Views",
 | 
				
			||||||
 | 
													"date" => "Most recent",
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"source" => [
 | 
				
			||||||
 | 
												"display" => "Source",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any source",
 | 
				
			||||||
 | 
													"youtube" => "YouTube",
 | 
				
			||||||
 | 
													"dailymotion" => "Dailymotion",
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "news":
 | 
				
			||||||
 | 
									$base = array_merge(
 | 
				
			||||||
 | 
										$base,
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"time" => [
 | 
				
			||||||
 | 
												"display" => "Time posted",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"any" => "Any time",
 | 
				
			||||||
 | 
													"hour" => "Less than 1 hour ago",
 | 
				
			||||||
 | 
													"day" => "Past 24 hours",
 | 
				
			||||||
 | 
													"week" => "Past week",
 | 
				
			||||||
 | 
													"month" => "Past month"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"order" => [
 | 
				
			||||||
 | 
												"display" => "Order by",
 | 
				
			||||||
 | 
												"option" => [
 | 
				
			||||||
 | 
													"relevance" => "Relevance",
 | 
				
			||||||
 | 
													"date" => "Most recent"
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $base;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = []){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$headers = [
 | 
				
			||||||
 | 
								"User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
								"Accept: application/json, text/plain, */*",
 | 
				
			||||||
 | 
								"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
								"Accept-Encoding: gzip",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Origin: https://www.qwant.com",
 | 
				
			||||||
 | 
								"Referer: https://www.qwant.com/",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: same-site",
 | 
				
			||||||
 | 
								"TE: trailers"
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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, $headers);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Bypass HTTP/2 check
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get next page data
 | 
				
			||||||
 | 
								[$params, $proxy] = $this->backend->get($get["npt"], "web");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params = json_decode($params, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get _GET data instead
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(strlen($search) > 2048){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is too long!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params = [
 | 
				
			||||||
 | 
									"q" => $search,
 | 
				
			||||||
 | 
									"freshness" => $get["time"],
 | 
				
			||||||
 | 
									"count" => 10,
 | 
				
			||||||
 | 
									"locale" => $get["country"],
 | 
				
			||||||
 | 
									"offset" => 0,
 | 
				
			||||||
 | 
									"device" => "desktop",
 | 
				
			||||||
 | 
									"tgp" => 3,
 | 
				
			||||||
 | 
									"safesearch" => 0,
 | 
				
			||||||
 | 
									"displayed" => "true"
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($get["nsfw"]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "yes": $params["safesearch"] = 0; break;
 | 
				
			||||||
 | 
									case "maybe": $params["safesearch"] = 1; break;
 | 
				
			||||||
 | 
									case "no": $params["safesearch"] = 2; break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							$handle = fopen("scraper/qwant_web.json", "r");
 | 
				
			||||||
 | 
							$json = fread($handle, filesize("scraper/qwant_web.json"));
 | 
				
			||||||
 | 
							fclose($handle);*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$proxy,
 | 
				
			||||||
 | 
										"https://fdn.qwant.com/v3/search/web",
 | 
				
			||||||
 | 
										$params
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Could not fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === NULL){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json["data"]["message"][0])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Server returned an error:\n" . $json["data"]["message"][0]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$json["status"] != "success" &&
 | 
				
			||||||
 | 
								$json["data"]["error_code"] === 5
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// no results
 | 
				
			||||||
 | 
								return $out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_errors($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($json["data"]["result"]["items"]["mainline"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Server did not return a result object");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// data is OK, parse
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get instant answer
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								$get["extendedsearch"] == "yes" &&
 | 
				
			||||||
 | 
								isset($json["data"]["result"]["items"]["sidebar"][0]["endpoint"])
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$answer =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://api.qwant.com/v3" .
 | 
				
			||||||
 | 
											$json["data"]["result"]["items"]["sidebar"][0]["endpoint"],
 | 
				
			||||||
 | 
											[]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$answer = json_decode($answer, true);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$answer === null ||
 | 
				
			||||||
 | 
										$answer["status"] != "success" ||
 | 
				
			||||||
 | 
										$answer["data"]["result"] === null
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										throw new Exception();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// parse answer
 | 
				
			||||||
 | 
									$out["answer"][] = [
 | 
				
			||||||
 | 
										"title" => $answer["data"]["result"]["title"],
 | 
				
			||||||
 | 
										"description" => [
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"type" => "text",
 | 
				
			||||||
 | 
												"value" => $this->trimdots($answer["data"]["result"]["description"])
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"url" => $answer["data"]["result"]["url"],
 | 
				
			||||||
 | 
										"thumb" =>
 | 
				
			||||||
 | 
											$answer["data"]["result"]["thumbnail"]["landscape"] == null ?
 | 
				
			||||||
 | 
											null :
 | 
				
			||||||
 | 
											$this->unshitimage(
 | 
				
			||||||
 | 
												$answer["data"]["result"]["thumbnail"]["landscape"],
 | 
				
			||||||
 | 
												false
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
										"table" => [],
 | 
				
			||||||
 | 
										"sublink" => []
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// do nothing in case of failure
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get word correction
 | 
				
			||||||
 | 
							if(isset($json["data"]["query"]["queryContext"]["alteredQuery"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["spelling"] = [
 | 
				
			||||||
 | 
									"type" => "including",
 | 
				
			||||||
 | 
									"using" => $json["data"]["query"]["queryContext"]["alteredQuery"],
 | 
				
			||||||
 | 
									"correction" => $json["data"]["query"]["queryContext"]["alterationOverrideQuery"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// check for next page
 | 
				
			||||||
 | 
							if($json["data"]["result"]["lastPage"] === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params["offset"] = $params["offset"] + 10;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode($params),
 | 
				
			||||||
 | 
										"web",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// parse results
 | 
				
			||||||
 | 
							foreach($json["data"]["result"]["items"]["mainline"] as $item){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($item["type"]){ // ignores ads
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "web":
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$first_iteration = true;
 | 
				
			||||||
 | 
										foreach($item["items"] as $result){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(isset($result["thumbnailUrl"])){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$thumb = [
 | 
				
			||||||
 | 
													"url" => $this->unshitimage($result["thumbnailUrl"]),
 | 
				
			||||||
 | 
													"ratio" => "16:9"
 | 
				
			||||||
 | 
												];
 | 
				
			||||||
 | 
											}else{
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												$thumb = [
 | 
				
			||||||
 | 
													"url" => null,
 | 
				
			||||||
 | 
													"ratio" => null
 | 
				
			||||||
 | 
												];
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$sublinks = [];
 | 
				
			||||||
 | 
											if(isset($result["links"])){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												foreach($result["links"] as $link){
 | 
				
			||||||
 | 
													
 | 
				
			||||||
 | 
													$sublinks[] = [
 | 
				
			||||||
 | 
														"title" => $this->trimdots($link["title"]),
 | 
				
			||||||
 | 
														"date" => null,
 | 
				
			||||||
 | 
														"description" => isset($link["desc"]) ? $this->trimdots($link["desc"]) : null,
 | 
				
			||||||
 | 
														"url" => $link["url"]
 | 
				
			||||||
 | 
													];
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											// detect gibberish results
 | 
				
			||||||
 | 
											if(
 | 
				
			||||||
 | 
												$first_iteration &&
 | 
				
			||||||
 | 
												!isset($result["urlPingSuffix"])
 | 
				
			||||||
 | 
											){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												throw new Exception("Qwant returned gibberish results");
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$out["web"][] = [
 | 
				
			||||||
 | 
												"title" => $this->trimdots($result["title"]),
 | 
				
			||||||
 | 
												"description" => $this->trimdots($result["desc"]),
 | 
				
			||||||
 | 
												"url" => $result["url"],
 | 
				
			||||||
 | 
												"date" => null,
 | 
				
			||||||
 | 
												"type" => "web",
 | 
				
			||||||
 | 
												"thumb" => $thumb,
 | 
				
			||||||
 | 
												"sublink" => $sublinks,
 | 
				
			||||||
 | 
												"table" => []
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$first_iteration = false;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "images":
 | 
				
			||||||
 | 
										foreach($item["items"] as $image){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$out["image"][] = [
 | 
				
			||||||
 | 
												"title" => $image["title"],
 | 
				
			||||||
 | 
												"source" => [
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"url" => $image["media"],
 | 
				
			||||||
 | 
														"width" => (int)$image["width"],
 | 
				
			||||||
 | 
														"height" => (int)$image["height"]
 | 
				
			||||||
 | 
													],
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"url" => $this->unshitimage($image["thumbnail"]),
 | 
				
			||||||
 | 
														"width" => $image["thumb_width"],
 | 
				
			||||||
 | 
														"height" => $image["thumb_height"]
 | 
				
			||||||
 | 
													]
 | 
				
			||||||
 | 
												],
 | 
				
			||||||
 | 
												"url" => $image["url"]
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "videos":
 | 
				
			||||||
 | 
										foreach($item["items"] as $video){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$out["video"][] = [
 | 
				
			||||||
 | 
												"title" => $video["title"],
 | 
				
			||||||
 | 
												"description" => null,
 | 
				
			||||||
 | 
												"date" => (int)$video["date"],
 | 
				
			||||||
 | 
												"duration" => $video["duration"] === null ? null : $video["duration"] / 1000,
 | 
				
			||||||
 | 
												"views" => null,
 | 
				
			||||||
 | 
												"thumb" =>
 | 
				
			||||||
 | 
													$video["thumbnail"] === null ?
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"url" => null,
 | 
				
			||||||
 | 
														"ratio" => null,
 | 
				
			||||||
 | 
													] :
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"url" => $this->unshitimage($video["thumbnail"]),
 | 
				
			||||||
 | 
														"ratio" => "16:9",
 | 
				
			||||||
 | 
													],
 | 
				
			||||||
 | 
												"url" => $video["url"]
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "related_searches":
 | 
				
			||||||
 | 
										foreach($item["items"] as $related){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$out["related"][] = $related["text"];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$params, $proxy] =
 | 
				
			||||||
 | 
									$this->backend->get(
 | 
				
			||||||
 | 
										$get["npt"],
 | 
				
			||||||
 | 
										"images"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params = json_decode($params, true);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params = [
 | 
				
			||||||
 | 
									"t" => "images",
 | 
				
			||||||
 | 
									"q" => $search,
 | 
				
			||||||
 | 
									"count" => 125,
 | 
				
			||||||
 | 
									"locale" => $get["country"],
 | 
				
			||||||
 | 
									"offset" => 0, // increment by 125
 | 
				
			||||||
 | 
									"device" => "desktop",
 | 
				
			||||||
 | 
									"tgp" => 3
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($get["time"] != "any"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$params["freshness"] = $get["time"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach(["size", "color", "imagetype", "license"] as $p){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if($get[$p] != "any"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$params[$p] = $get[$p];
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($get["nsfw"]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "yes": $params["safesearch"] = 0; break;
 | 
				
			||||||
 | 
									case "maybe": $params["safesearch"] = 1; break;
 | 
				
			||||||
 | 
									case "no": $params["safesearch"] = 2; break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$json = $this->get(
 | 
				
			||||||
 | 
									$proxy,
 | 
				
			||||||
 | 
									"https://api.qwant.com/v3/search/images",
 | 
				
			||||||
 | 
									$params,
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}catch(Exception $err){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to get JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							$handle = fopen("scraper/yandex.json", "r");
 | 
				
			||||||
 | 
							$json = fread($handle, filesize("scraper/yandex.json"));
 | 
				
			||||||
 | 
							fclose($handle);*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_errors($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json["data"]["result"]["items"]["mainline"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Qwant returned gibberish results");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json["data"]["result"]["lastPage"] === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params["offset"] = $params["offset"] + 125;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] = $this->backend->store(
 | 
				
			||||||
 | 
									json_encode($params),
 | 
				
			||||||
 | 
									"images",
 | 
				
			||||||
 | 
									$proxy
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json["data"]["result"]["items"] as $image){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["image"][] = [
 | 
				
			||||||
 | 
									"title" => $this->trimdots($image["title"]),
 | 
				
			||||||
 | 
									"source" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $image["media"],
 | 
				
			||||||
 | 
											"width" => $image["width"],
 | 
				
			||||||
 | 
											"height" => $image["height"]
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $this->unshitimage($image["thumbnail"]),
 | 
				
			||||||
 | 
											"width" => $image["thumb_width"],
 | 
				
			||||||
 | 
											"height" => $image["thumb_height"]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"url" => $image["url"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function video($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$params = [
 | 
				
			||||||
 | 
								"t" => "videos",
 | 
				
			||||||
 | 
								"q" => $search,
 | 
				
			||||||
 | 
								"count" => 50,
 | 
				
			||||||
 | 
								"locale" => $get["country"],
 | 
				
			||||||
 | 
								"offset" => 0, // dont implement pagination
 | 
				
			||||||
 | 
								"device" => "desktop",
 | 
				
			||||||
 | 
								"tgp" => 3
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($get["nsfw"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "yes": $params["safesearch"] = 0; break;
 | 
				
			||||||
 | 
								case "maybe": $params["safesearch"] = 1; break;
 | 
				
			||||||
 | 
								case "no": $params["safesearch"] = 2; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$this->backend->get_ip(),
 | 
				
			||||||
 | 
										"https://api.qwant.com/v3/search/videos",
 | 
				
			||||||
 | 
										$params
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Could not fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							$handle = fopen("scraper/yandex-video.json", "r");
 | 
				
			||||||
 | 
							$json = fread($handle, filesize("scraper/yandex-video.json"));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Could not parse JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_errors($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json["data"]["result"]["items"]["mainline"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Qwant returned gibberish results");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"author" => [],
 | 
				
			||||||
 | 
								"livestream" => [],
 | 
				
			||||||
 | 
								"playlist" => [],
 | 
				
			||||||
 | 
								"reel" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json["data"]["result"]["items"] as $video){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(empty($video["thumbnail"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumb = [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumb = [
 | 
				
			||||||
 | 
										"url" => $this->unshitimage($video["thumbnail"], false),
 | 
				
			||||||
 | 
										"ratio" => "16:9"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$duration = (int)$video["duration"];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["video"][] = [
 | 
				
			||||||
 | 
									"title" => $video["title"],
 | 
				
			||||||
 | 
									"description" => $this->limitstrlen($video["desc"]),
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" => $video["channel"],
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"avatar" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"date" => (int)$video["date"],
 | 
				
			||||||
 | 
									"duration" => $duration === 0 ? null : $duration,
 | 
				
			||||||
 | 
									"views" => null,
 | 
				
			||||||
 | 
									"thumb" => $thumb,
 | 
				
			||||||
 | 
									"url" => preg_replace("/\?syndication=.+/", "", $video["url"])
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function news($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$params = [
 | 
				
			||||||
 | 
								"t" => "news",
 | 
				
			||||||
 | 
								"q" => $search,
 | 
				
			||||||
 | 
								"count" => 50,
 | 
				
			||||||
 | 
								"locale" => $get["country"],
 | 
				
			||||||
 | 
								"offset" => 0, // dont implement pagination
 | 
				
			||||||
 | 
								"device" => "desktop",
 | 
				
			||||||
 | 
								"tgp" => 3
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($get["nsfw"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "yes": $params["safesearch"] = 0; break;
 | 
				
			||||||
 | 
								case "maybe": $params["safesearch"] = 1; break;
 | 
				
			||||||
 | 
								case "no": $params["safesearch"] = 2; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$this->backend->get_ip(),
 | 
				
			||||||
 | 
										"https://api.qwant.com/v3/search/news",
 | 
				
			||||||
 | 
										$params
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Could not fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							$handle = fopen("scraper/yandex-video.json", "r");
 | 
				
			||||||
 | 
							$json = fread($handle, filesize("scraper/yandex-video.json"));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Could not parse JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_errors($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json["data"]["result"]["items"]["mainline"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Qwant returned gibberish results");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"news" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json["data"]["result"]["items"] as $news){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(empty($news["media"][0]["pict_big"]["url"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumb = [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumb = [
 | 
				
			||||||
 | 
										"url" => $this->unshitimage($news["media"][0]["pict_big"]["url"], false),
 | 
				
			||||||
 | 
										"ratio" => "16:9"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["news"][] = [
 | 
				
			||||||
 | 
									"title" => $news["title"],
 | 
				
			||||||
 | 
									"author" => $news["press_name"],
 | 
				
			||||||
 | 
									"description" => $this->trimdots($news["desc"]),
 | 
				
			||||||
 | 
									"date" => (int)$news["date"],
 | 
				
			||||||
 | 
									"thumb" => $thumb,
 | 
				
			||||||
 | 
									"url" => $news["url"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function detect_errors($json){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								isset($json["status"]) &&
 | 
				
			||||||
 | 
								$json["status"] == "error"
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($json["data"]["error_data"]["captchaUrl"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Qwant returned a captcha");
 | 
				
			||||||
 | 
								}elseif(isset($json["data"]["error_data"]["error_code"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception(
 | 
				
			||||||
 | 
										"Qwant returned an API error: " .
 | 
				
			||||||
 | 
										$json["data"]["error_data"]["error_code"]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Qwant returned an API error");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function limitstrlen($text){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return explode("\n", wordwrap($text, 300, "\n"))[0];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function trimdots($text){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return trim($text, ". ");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function unshitimage($url, $is_bing = true){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// https://s1.qwant.com/thumbr/0x0/8/d/f6de4deb2c2b12f55d8bdcaae576f9f62fd58a05ec0feeac117b354d1bf5c2/th.jpg?u=https%3A%2F%2Fwww.bing.com%2Fth%3Fid%3DOIP.vvDWsagzxjoKKP_rOqhwrQAAAA%26w%3D160%26h%3D160%26c%3D7%26pid%3D5.1&q=0&b=1&p=0&a=0
 | 
				
			||||||
 | 
							parse_str(parse_url($url)["query"], $parts);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($is_bing){
 | 
				
			||||||
 | 
								$parse = parse_url($parts["u"]);
 | 
				
			||||||
 | 
								parse_str($parse["query"], $parts);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return "https://" . $parse["host"] . "/th?id=" . urlencode($parts["id"]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $parts["u"];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										512
									
								
								scraper/sc.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,512 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class sc{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("sc");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"type" => [
 | 
				
			||||||
 | 
									"display" => "Type",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "Any type",
 | 
				
			||||||
 | 
										"track" => "Tracks",
 | 
				
			||||||
 | 
										"author" => "People",
 | 
				
			||||||
 | 
										"album" => "Albums",
 | 
				
			||||||
 | 
										"playlist" => "Playlists",
 | 
				
			||||||
 | 
										"goplus" => "Go+ Tracks"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $web_req = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// use http2
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($web_req === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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://soundcloud.com/",
 | 
				
			||||||
 | 
									"Origin: https://soundcloud.com",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-site",
 | 
				
			||||||
 | 
									"Priority: u=1"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: cross-site",
 | 
				
			||||||
 | 
									"Priority: u=1",
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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 music($get, $last_attempt = false){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$params, $proxy] = $this->backend->get($get["npt"], "music");
 | 
				
			||||||
 | 
								$params = json_decode($params, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$url = $params["url"];
 | 
				
			||||||
 | 
								unset($params["url"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// normal search:
 | 
				
			||||||
 | 
								// https://api-v2.soundcloud.com/search?q=freddie%20dredd&variant_ids=&facet=model&user_id=351062-302234-707916-795081&client_id=iMxZgT5mfGstBj8GWJbYMvpzelS8ne0E&limit=20&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// soundcloud go+ search:
 | 
				
			||||||
 | 
								// https://api-v2.soundcloud.com/search/tracks?q=freddie%20dredd&variant_ids=&filter.content_tier=SUB_HIGH_TIER&facet=genre&user_id=630591-269800-703400-765403&client_id=iMxZgT5mfGstBj8GWJbYMvpzelS8ne0E&limit=20&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// tracks search:
 | 
				
			||||||
 | 
								// https://api-v2.soundcloud.com/search/tracks?q=freddie%20dredd&variant_ids=&facet=genre&user_id=630591-269800-703400-765403&client_id=iMxZgT5mfGstBj8GWJbYMvpzelS8ne0E&limit=20&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// users search:
 | 
				
			||||||
 | 
								// https://api-v2.soundcloud.com/search/users?q=freddie%20dredd&variant_ids=&facet=place&user_id=630591-269800-703400-765403&client_id=iMxZgT5mfGstBj8GWJbYMvpzelS8ne0E&limit=20&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// albums search:
 | 
				
			||||||
 | 
								// https://api-v2.soundcloud.com/search/albums?q=freddie%20dredd&variant_ids=&facet=genre&user_id=630591-269800-703400-765403&client_id=iMxZgT5mfGstBj8GWJbYMvpzelS8ne0E&limit=20&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// playlists search:
 | 
				
			||||||
 | 
								// https://api-v2.soundcloud.com/search/playlists_without_albums?q=freddie%20dredd&variant_ids=&facet=genre&user_id=630591-269800-703400-765403&client_id=iMxZgT5mfGstBj8GWJbYMvpzelS8ne0E&limit=20&offset=0&linked_partitioning=1&app_version=1693487844&app_locale=en
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$type = $get["type"];
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								$token = $this->get_token($proxy);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($type){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "any":
 | 
				
			||||||
 | 
										$url = "https://api-v2.soundcloud.com/search";
 | 
				
			||||||
 | 
										$params = [
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"variant_ids" => "",
 | 
				
			||||||
 | 
											"facet" => "model",
 | 
				
			||||||
 | 
											"client_id" => $token,
 | 
				
			||||||
 | 
											"limit" => 20,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"linked_partitioning" => 1,
 | 
				
			||||||
 | 
											"app_version" => 1713542117,
 | 
				
			||||||
 | 
											"app_locale" => "en"
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "track":
 | 
				
			||||||
 | 
										$url = "https://api-v2.soundcloud.com/search/tracks";
 | 
				
			||||||
 | 
										$params = [
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"variant_ids" => "",
 | 
				
			||||||
 | 
											"facet_genre" => "",
 | 
				
			||||||
 | 
											"client_id" => $token,
 | 
				
			||||||
 | 
											"limit" => 20,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"linked_partitioning" => 1,
 | 
				
			||||||
 | 
											"app_version" => 1713542117,
 | 
				
			||||||
 | 
											"app_locale" => "en"
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "author":
 | 
				
			||||||
 | 
										$url = "https://api-v2.soundcloud.com/search/users";
 | 
				
			||||||
 | 
										$params = [
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"variant_ids" => "",
 | 
				
			||||||
 | 
											"facet" => "place",
 | 
				
			||||||
 | 
											"client_id" => $token,
 | 
				
			||||||
 | 
											"limit" => 20,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"linked_partitioning" => 1,
 | 
				
			||||||
 | 
											"app_version" => 1713542117,
 | 
				
			||||||
 | 
											"app_locale" => "en"
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "album":
 | 
				
			||||||
 | 
										$url = "https://api-v2.soundcloud.com/search/albums";
 | 
				
			||||||
 | 
										$params = [
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"variant_ids" => "",
 | 
				
			||||||
 | 
											"facet" => "genre",
 | 
				
			||||||
 | 
											"client_id" => $token,
 | 
				
			||||||
 | 
											"limit" => 20,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"linked_partitioning" => 1,
 | 
				
			||||||
 | 
											"app_version" => 1713542117,
 | 
				
			||||||
 | 
											"app_locale" => "en"
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "playlist":
 | 
				
			||||||
 | 
										$url = "https://api-v2.soundcloud.com/search/playlists_without_albums";
 | 
				
			||||||
 | 
										$params = [
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"variant_ids" => "",
 | 
				
			||||||
 | 
											"facet" => "genre",
 | 
				
			||||||
 | 
											"client_id" => $token,
 | 
				
			||||||
 | 
											"limit" => 20,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"linked_partitioning" => 1,
 | 
				
			||||||
 | 
											"app_version" => 1713542117,
 | 
				
			||||||
 | 
											"app_locale" => "en"
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "goplus":
 | 
				
			||||||
 | 
										$url = "https://api-v2.soundcloud.com/search/tracks";
 | 
				
			||||||
 | 
										$params = [
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"variant_ids" => "",
 | 
				
			||||||
 | 
											"filter.content_tier" => "SUB_HIGH_TIER",
 | 
				
			||||||
 | 
											"facet" => "genre",
 | 
				
			||||||
 | 
											"client_id" => $token,
 | 
				
			||||||
 | 
											"limit" => 20,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"linked_partitioning" => 1,
 | 
				
			||||||
 | 
											"app_version" => 1713542117,
 | 
				
			||||||
 | 
											"app_locale" => "en"
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json = $this->get($proxy, $url, $params);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							$handle = fopen("scraper/soundcloud.json", "r");
 | 
				
			||||||
 | 
							$json = fread($handle, filesize("scraper/soundcloud.json"));
 | 
				
			||||||
 | 
							fclose($handle);
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($last_attempt === true){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Fetched an invalid token (please report!!)");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// token might've expired, get a new one and re-try search
 | 
				
			||||||
 | 
								$this->get_token($proxy);
 | 
				
			||||||
 | 
								return $this->music($get, true);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"song" => [],
 | 
				
			||||||
 | 
								"playlist" => [],
 | 
				
			||||||
 | 
								"album" => [],
 | 
				
			||||||
 | 
								"podcast" => [],
 | 
				
			||||||
 | 
								"author" => [],
 | 
				
			||||||
 | 
								"user" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Get next page
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							if(isset($json["next_href"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$params["query_urn"] = $json["query_urn"];
 | 
				
			||||||
 | 
								$params["offset"] = $params["offset"] + 20;
 | 
				
			||||||
 | 
								$params["url"] = $url; // we will remove this later
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode($params),
 | 
				
			||||||
 | 
										"music",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
								Scrape items
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							foreach($json["collection"] as $item){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($item["kind"]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "user":
 | 
				
			||||||
 | 
										// parse author
 | 
				
			||||||
 | 
										$out["author"][] = [
 | 
				
			||||||
 | 
											"title" => $item["username"],
 | 
				
			||||||
 | 
											"followers" => $item["followers_count"],
 | 
				
			||||||
 | 
											"description" => trim($item["track_count"] . " songs. " . $this->limitstrlen($item["description"])),
 | 
				
			||||||
 | 
											"thumb" => [
 | 
				
			||||||
 | 
												"url" => $item["avatar_url"],
 | 
				
			||||||
 | 
												"ratio" => "1:1"
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"url" => $item["permalink_url"]
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "playlist":
 | 
				
			||||||
 | 
										// parse playlist
 | 
				
			||||||
 | 
										$description = [];
 | 
				
			||||||
 | 
										$count = 0;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										foreach($item["tracks"] as $song){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$count++;
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(!isset($song["title"])){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												continue;
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$description[] = $song["title"];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(count($description) !== 0){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$description = trim($count . " songs. " . implode(", ", $description));
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$description = "";
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(
 | 
				
			||||||
 | 
											isset($item["artwork_url"]) &&
 | 
				
			||||||
 | 
											!empty($item["artwork_url"])
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$thumb = [
 | 
				
			||||||
 | 
												"ratio" => "1:1",
 | 
				
			||||||
 | 
												"url" => $item["artwork_url"]
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
										}elseif(
 | 
				
			||||||
 | 
											isset($item["tracks"][0]["artwork_url"]) &&
 | 
				
			||||||
 | 
											!empty($item["tracks"][0]["artwork_url"])
 | 
				
			||||||
 | 
										){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$thumb = [
 | 
				
			||||||
 | 
												"ratio" => "1:1",
 | 
				
			||||||
 | 
												"url" => $item["tracks"][0]["artwork_url"]
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$thumb = [
 | 
				
			||||||
 | 
												"ratio" => null,
 | 
				
			||||||
 | 
												"url" => null
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$out["playlist"][] = [
 | 
				
			||||||
 | 
											"title" => $item["title"],
 | 
				
			||||||
 | 
											"description" => $this->limitstrlen($description),
 | 
				
			||||||
 | 
											"author" => [
 | 
				
			||||||
 | 
												"name" => $item["user"]["username"],
 | 
				
			||||||
 | 
												"url" => $item["user"]["permalink_url"],
 | 
				
			||||||
 | 
												"avatar" => $item["user"]["avatar_url"]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"thumb" => $thumb,
 | 
				
			||||||
 | 
											"date" => strtotime($item["created_at"]),
 | 
				
			||||||
 | 
											"duration" => $item["duration"] / 1000,
 | 
				
			||||||
 | 
											"url" => $item["permalink_url"]
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "track":
 | 
				
			||||||
 | 
										if(stripos($item["monetization_model"], "TIER") === false){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$stream = [
 | 
				
			||||||
 | 
												"endpoint" => "sc",
 | 
				
			||||||
 | 
												"url" =>
 | 
				
			||||||
 | 
													$item["media"]["transcodings"][0]["url"] .
 | 
				
			||||||
 | 
													"?client_id=" . $token .
 | 
				
			||||||
 | 
													"&track_authorization=" .
 | 
				
			||||||
 | 
													$item["track_authorization"]
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
										}else{
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$stream = [
 | 
				
			||||||
 | 
												"endpoint" => null,
 | 
				
			||||||
 | 
												"url" => null
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// parse track
 | 
				
			||||||
 | 
										$out["song"][] = [
 | 
				
			||||||
 | 
											"title" => $item["title"],
 | 
				
			||||||
 | 
											"description" => $item["description"] == "" ? null : $this->limitstrlen($item["description"]),
 | 
				
			||||||
 | 
											"url" => $item["permalink_url"],
 | 
				
			||||||
 | 
											"views" => $item["playback_count"],
 | 
				
			||||||
 | 
											"author" => [
 | 
				
			||||||
 | 
												"name" => $item["user"]["username"],
 | 
				
			||||||
 | 
												"url" => $item["user"]["permalink_url"],
 | 
				
			||||||
 | 
												"avatar" => $item["user"]["avatar_url"]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"thumb" => [
 | 
				
			||||||
 | 
												"ratio" => "1:1",
 | 
				
			||||||
 | 
												"url" => $item["artwork_url"]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											"date" => strtotime($item["created_at"]),
 | 
				
			||||||
 | 
											"duration" => (int)$item["full_duration"] / 1000,
 | 
				
			||||||
 | 
											"stream" => $stream
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function get_token($proxy){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$token = apcu_fetch("sc_token");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($token !== false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $token;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// search through all javascript components on the main page
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$html =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$proxy,
 | 
				
			||||||
 | 
										"https://soundcloud.com",
 | 
				
			||||||
 | 
										[],
 | 
				
			||||||
 | 
										true
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch front page");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$scripts =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementsByTagName(
 | 
				
			||||||
 | 
									"script"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($scripts as $script){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									!isset($script["attributes"]["src"]) ||
 | 
				
			||||||
 | 
									strpos($script["attributes"]["src"], "sndcdn.com") === false
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									$js =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											$script["attributes"]["src"],
 | 
				
			||||||
 | 
											[]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch search token");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/client_id=([^"]+)/',
 | 
				
			||||||
 | 
									$js,
 | 
				
			||||||
 | 
									$token
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($token[1])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									apcu_store("sc_token", $token[1]);
 | 
				
			||||||
 | 
									return $token[1];
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							throw new Exception("Did not find a Soundcloud token in the Javascript blobs");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function limitstrlen($text){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
								explode(
 | 
				
			||||||
 | 
									"\n",
 | 
				
			||||||
 | 
									wordwrap(
 | 
				
			||||||
 | 
										str_replace(
 | 
				
			||||||
 | 
											["\n\r", "\r\n", "\n", "\r"],
 | 
				
			||||||
 | 
											" ",
 | 
				
			||||||
 | 
											$text
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										300,
 | 
				
			||||||
 | 
										"\n"
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
									2
 | 
				
			||||||
 | 
								)[0];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										668
									
								
								scraper/solofield.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,668 @@
 | 
				
			||||||
 | 
					<?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;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										726
									
								
								scraper/spotify.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,726 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class spotify{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						private const req_web = 0;
 | 
				
			||||||
 | 
						private const req_api = 1;
 | 
				
			||||||
 | 
						private const req_clientid = 2;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("spotify");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"category" => [
 | 
				
			||||||
 | 
									"display" => "Category",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "All (no pagination)",
 | 
				
			||||||
 | 
										"audiobooks" => "Audiobooks",
 | 
				
			||||||
 | 
										"tracks" => "Songs",
 | 
				
			||||||
 | 
										"artists" => "Artists",
 | 
				
			||||||
 | 
										"playlists" => "Playlists",
 | 
				
			||||||
 | 
										"albums" => "Albums",
 | 
				
			||||||
 | 
										"podcastAndEpisodes" => "Podcasts & Shows (no pagination)",
 | 
				
			||||||
 | 
										"episodes" => "Episodes",
 | 
				
			||||||
 | 
										"users" => "Profiles"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $reqtype = self::req_web, $bearer = null, $token = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($reqtype){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case self::req_api:
 | 
				
			||||||
 | 
									$headers = [
 | 
				
			||||||
 | 
										"User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
										"Accept: application/json",
 | 
				
			||||||
 | 
										"Accept-Language: en",
 | 
				
			||||||
 | 
										"app-platform: WebPlayer",
 | 
				
			||||||
 | 
										"authorization: Bearer {$bearer}",
 | 
				
			||||||
 | 
										"client-token: {$token}",
 | 
				
			||||||
 | 
										"content-type: application/json;charset=UTF-8",
 | 
				
			||||||
 | 
										"Origin: https://open.spotify.com",
 | 
				
			||||||
 | 
										"Referer: https://open.spotify.com/",
 | 
				
			||||||
 | 
										"DNT: 1",
 | 
				
			||||||
 | 
										"Connection: keep-alive",
 | 
				
			||||||
 | 
										"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
										"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
										"Sec-Fetch-Site: same-site",
 | 
				
			||||||
 | 
										"spotify-app-version: 1.2.27.93.g7aee53d4",
 | 
				
			||||||
 | 
										"TE: trailers"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case self::req_web:
 | 
				
			||||||
 | 
									$headers = [
 | 
				
			||||||
 | 
										"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",
 | 
				
			||||||
 | 
										"DNT: 1",
 | 
				
			||||||
 | 
										"Sec-GPC: 1",
 | 
				
			||||||
 | 
										"Connection: keep-alive",
 | 
				
			||||||
 | 
										"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
										"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
										"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
										"Sec-Fetch-Site: cross-site"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case self::req_clientid:			
 | 
				
			||||||
 | 
									$get = json_encode($get);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_POST, true);
 | 
				
			||||||
 | 
									curl_setopt($curlproc, CURLOPT_POSTFIELDS, $get);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
									$headers = [
 | 
				
			||||||
 | 
										"User-Agent:" . config::USER_AGENT,
 | 
				
			||||||
 | 
										"Accept: application/json",
 | 
				
			||||||
 | 
										"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
										"Accept-Encoding: gzip, deflate, br",
 | 
				
			||||||
 | 
										"Referer: https://open.spotify.com/",
 | 
				
			||||||
 | 
										"content-type: application/json",
 | 
				
			||||||
 | 
										"Content-Length: " . strlen($get),
 | 
				
			||||||
 | 
										"Origin: https://open.spotify.com",
 | 
				
			||||||
 | 
										"DNT: 1",
 | 
				
			||||||
 | 
										"Sec-GPC: 1",
 | 
				
			||||||
 | 
										"Connection: keep-alive",
 | 
				
			||||||
 | 
										"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
										"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
										"Sec-Fetch-Site: same-site",
 | 
				
			||||||
 | 
										"TE: trailers"
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($reqtype !== self::req_clientid){
 | 
				
			||||||
 | 
								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, $headers);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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 music($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							$ip = $this->backend->get_ip();
 | 
				
			||||||
 | 
							$category = $get["category"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							audiobooks first and second page decoded
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchAudiobooks&variables={"searchTerm":"freddie+dredd","offset":0,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"8758e540afdba5afa3c5246817f6bd31d86a15b3f5666c363dd017030f35d785"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchAudiobooks&variables={"searchTerm":"freddie+dredd","offset":30,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"8758e540afdba5afa3c5246817f6bd31d86a15b3f5666c363dd017030f35d785"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							songs
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchTracks&variables={"searchTerm":"asmr","offset":0,"limit":100,"numberOfTopResults":20,"includeAudiobooks":false}&extensions={"persistedQuery":{"version":1,"sha256Hash":"16c02d6304f5f721fc2eb39dacf2361a4543815112506a9c05c9e0bc9733a679"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchTracks&variables={"searchTerm":"asmr","offset":100,"limit":100,"numberOfTopResults":20,"includeAudiobooks":false}&extensions={"persistedQuery":{"version":1,"sha256Hash":"16c02d6304f5f721fc2eb39dacf2361a4543815112506a9c05c9e0bc9733a679"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							artists
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchArtists&variables={"searchTerm":"asmr","offset":0,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"b8840daafdda9a9ceadb7c5774731f63f9eca100445d2d94665f2dc58b45e2b9"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchArtists&variables={"searchTerm":"asmr","offset":30,"limit":23,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"b8840daafdda9a9ceadb7c5774731f63f9eca100445d2d94665f2dc58b45e2b9"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchArtists&variables={"searchTerm":"asmr","offset":53,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"b8840daafdda9a9ceadb7c5774731f63f9eca100445d2d94665f2dc58b45e2b9"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							playlists
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchPlaylists&variables={"searchTerm":"asmr","offset":0,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"19b4143a0500ccec189ca0f4a0316bc2c615ecb51ce993ba4d7d08afd1d87aa4"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchPlaylists&variables={"searchTerm":"asmr","offset":30,"limit":3,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"19b4143a0500ccec189ca0f4a0316bc2c615ecb51ce993ba4d7d08afd1d87aa4"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							albums
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchAlbums&variables={"searchTerm":"asmr","offset":33,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"e93b13cda461482da2940467eb2beed9368e9bb2fff37df3fb6633fc61271a27"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchAlbums&variables={"searchTerm":"asmr","offset":33,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"e93b13cda461482da2940467eb2beed9368e9bb2fff37df3fb6633fc61271a27"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							podcasts & shows (contains authors, no pagination)
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchFullEpisodes&variables={"searchTerm":"asmr","offset":0,"limit":30}&extensions={"persistedQuery":{"version":1,"sha256Hash":"9f996251c9781fabce63f1a9980b5287ea33bc5e8c8953d0c4689b09936067a1"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							episodes
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchDesktop&variables={"searchTerm":"asmr","offset":0,"limit":10,"numberOfTopResults":5,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"da03293d92a2cfc5e24597dcdc652c0ad135e1c64a78fddbf1478a7e096bea44"}}
 | 
				
			||||||
 | 
							??? https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchFullEpisodes&variables={"searchTerm":"asmr","offset":60,"limit":30}&extensions={"persistedQuery":{"version":1,"sha256Hash":"9f996251c9781fabce63f1a9980b5287ea33bc5e8c8953d0c4689b09936067a1"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							profiles
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchUsers&variables={"searchTerm":"asmr","offset":0,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"02026f48ab5001894e598904079b620ebc64f2d53b55ca20c3858abd3a46c5fb"}}
 | 
				
			||||||
 | 
							https://api-partner.spotify.com/pathfinder/v1/query?operationName=searchUsers&variables={"searchTerm":"asmr","offset":30,"limit":30,"numberOfTopResults":20,"includeAudiobooks":true}&extensions={"persistedQuery":{"version":1,"sha256Hash":"02026f48ab5001894e598904079b620ebc64f2d53b55ca20c3858abd3a46c5fb"}}
 | 
				
			||||||
 | 
							*/
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get HTML
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$html =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$ip,
 | 
				
			||||||
 | 
										"https://open.spotify.com/search/" .
 | 
				
			||||||
 | 
										rawurlencode($search) .
 | 
				
			||||||
 | 
										($category != "any" ? "/" . $category : ""),
 | 
				
			||||||
 | 
										[]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to get initial search page");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// grep bearer and client ID
 | 
				
			||||||
 | 
							$this->fuckhtml->load($html);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$script =
 | 
				
			||||||
 | 
								$this->fuckhtml
 | 
				
			||||||
 | 
								->getElementById(
 | 
				
			||||||
 | 
									"session",
 | 
				
			||||||
 | 
									"script"
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($script === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to grep bearer token");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$script =
 | 
				
			||||||
 | 
								json_decode(
 | 
				
			||||||
 | 
									$script["innerHTML"],
 | 
				
			||||||
 | 
									true
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$bearer = $script["accessToken"];
 | 
				
			||||||
 | 
							$client_id = $script["clientId"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// hit client ID endpoint
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$token =
 | 
				
			||||||
 | 
									json_decode(
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$ip,
 | 
				
			||||||
 | 
											"https://clienttoken.spotify.com/v1/clienttoken",
 | 
				
			||||||
 | 
											[ // !! that shit must be sent as json data
 | 
				
			||||||
 | 
												"client_data" => [
 | 
				
			||||||
 | 
													"client_id" => $client_id,
 | 
				
			||||||
 | 
													"client_version" => "1.2.27.93.g7aee53d4",
 | 
				
			||||||
 | 
													"js_sdk_data" => [
 | 
				
			||||||
 | 
														"device_brand" => "unknown",
 | 
				
			||||||
 | 
														"device_id" => "4c7ca20117ca12288ea8fc7118a9118c",
 | 
				
			||||||
 | 
														"device_model" => "unknown",
 | 
				
			||||||
 | 
														"device_name" => "computer",
 | 
				
			||||||
 | 
														"os" => "windows",
 | 
				
			||||||
 | 
														"os_version" => "NT 10.0"
 | 
				
			||||||
 | 
													]
 | 
				
			||||||
 | 
												]
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											self::req_clientid
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										true
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch token");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($token === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode token");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$token = $token["granted_token"]["token"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($get["option"]){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "any":
 | 
				
			||||||
 | 
										$variables = [
 | 
				
			||||||
 | 
											"searchTerm" => $search,
 | 
				
			||||||
 | 
											"offset" => 0,
 | 
				
			||||||
 | 
											"limit" => 10,
 | 
				
			||||||
 | 
											"numberOfTopResults" => 5,
 | 
				
			||||||
 | 
											"includeAudiobooks" => true
 | 
				
			||||||
 | 
										];
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "audiobooks":
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$payload =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$ip,
 | 
				
			||||||
 | 
										"https://api-partner.spotify.com/pathfinder/v1/query",
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"operationName" => "searchDesktop",
 | 
				
			||||||
 | 
											"variables" =>
 | 
				
			||||||
 | 
												json_encode(
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"searchTerm" => $search,
 | 
				
			||||||
 | 
														"offset" => 0,
 | 
				
			||||||
 | 
														"limit" => 10,
 | 
				
			||||||
 | 
														"numberOfTopResults" => 5,
 | 
				
			||||||
 | 
														"includeAudiobooks" => true
 | 
				
			||||||
 | 
													]
 | 
				
			||||||
 | 
												),
 | 
				
			||||||
 | 
											"extensions" =>
 | 
				
			||||||
 | 
												json_encode(
 | 
				
			||||||
 | 
													[
 | 
				
			||||||
 | 
														"persistedQuery" => [
 | 
				
			||||||
 | 
															"version" => 1,
 | 
				
			||||||
 | 
															"sha256Hash" => "21969b655b795601fb2d2204a4243188e75fdc6d3520e7b9cd3f4db2aff9591e" // ?
 | 
				
			||||||
 | 
														]
 | 
				
			||||||
 | 
													]
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										self::req_api,
 | 
				
			||||||
 | 
										$bearer,
 | 
				
			||||||
 | 
										$token
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON results");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($payload == "Token expired"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Grepped spotify token has expired");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$payload = json_decode($payload, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($payload === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON results");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//$payload = json_decode(file_get_contents("scraper/spotify.json"), true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"song" => [],
 | 
				
			||||||
 | 
								"playlist" => [],
 | 
				
			||||||
 | 
								"album" => [],
 | 
				
			||||||
 | 
								"podcast" => [],
 | 
				
			||||||
 | 
								"author" => [],
 | 
				
			||||||
 | 
								"user" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get songs
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["tracksV2"]["items"] as $result){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($result["item"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$result = $result["item"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($result["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$result = $result["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$artist, $artist_link] = $this->get_artists($result["artists"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["song"][] = [
 | 
				
			||||||
 | 
									"title" => $result["name"],
 | 
				
			||||||
 | 
									"description" => null,
 | 
				
			||||||
 | 
									"url" => "https://open.spotify.com/track/" . $result["id"],
 | 
				
			||||||
 | 
									"views" => null,
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" => $artist,
 | 
				
			||||||
 | 
										"url" => $artist_link,
 | 
				
			||||||
 | 
										"avatar" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"thumb" => $this->get_thumb($result["albumOfTrack"]["coverArt"]),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"duration" => $result["duration"]["totalMilliseconds"] / 1000,
 | 
				
			||||||
 | 
									"stream" => [
 | 
				
			||||||
 | 
										"endpoint" => "spotify",
 | 
				
			||||||
 | 
										"url" => "track." . $result["id"]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get playlists
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["playlists"]["items"] as $playlist){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($playlist["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$playlist = $playlist["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$avatar = $this->get_thumb($playlist["ownerV2"]["data"]["avatar"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["playlist"][] = [
 | 
				
			||||||
 | 
									"title" => $playlist["name"],
 | 
				
			||||||
 | 
									"description" => null,
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" => $playlist["ownerV2"]["data"]["name"],
 | 
				
			||||||
 | 
										"url" =>
 | 
				
			||||||
 | 
											"https://open.spotify.com/user/" .
 | 
				
			||||||
 | 
											explode(
 | 
				
			||||||
 | 
												":",
 | 
				
			||||||
 | 
												$playlist["ownerV2"]["data"]["uri"],
 | 
				
			||||||
 | 
												3
 | 
				
			||||||
 | 
											)[2],
 | 
				
			||||||
 | 
										"avatar" => $avatar["url"]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"thumb" => $this->get_thumb($playlist["images"]["items"][0]),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"duration" => null,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										"https://open.spotify.com/playlist/" .
 | 
				
			||||||
 | 
										explode(
 | 
				
			||||||
 | 
											":",
 | 
				
			||||||
 | 
											$playlist["uri"],
 | 
				
			||||||
 | 
											3
 | 
				
			||||||
 | 
										)[2]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get albums
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["albums"]["items"] as $album){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($album["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$album = $album["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$artist, $artist_link] = $this->get_artists($album["artists"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["album"][] = [
 | 
				
			||||||
 | 
									"title" => $album["name"],
 | 
				
			||||||
 | 
									"description" => null,
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" => $artist,
 | 
				
			||||||
 | 
										"url" => $artist_link,
 | 
				
			||||||
 | 
										"avatar" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"thumb" => $this->get_thumb($album["coverArt"]),
 | 
				
			||||||
 | 
									"date" => mktime(0, 0, 0, 0, 32, $album["date"]["year"]),
 | 
				
			||||||
 | 
									"duration" => null,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										"https://open.spotify.com/album/" .
 | 
				
			||||||
 | 
										explode(
 | 
				
			||||||
 | 
											":",
 | 
				
			||||||
 | 
											$album["uri"],
 | 
				
			||||||
 | 
											3
 | 
				
			||||||
 | 
										)[2]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get podcasts
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["podcasts"]["items"] as $podcast){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($podcast["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$podcast = $podcast["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description = [];
 | 
				
			||||||
 | 
								foreach($podcast["topics"]["items"] as $subject){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description[] = $subject["title"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description = implode(", ", $description);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($description == ""){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description = null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["podcast"][] = [
 | 
				
			||||||
 | 
									"title" => $podcast["name"],
 | 
				
			||||||
 | 
									"description" => $description,
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" => $podcast["publisher"]["name"],
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"avatar" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"thumb" => $this->get_thumb($podcast["coverArt"]),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"duration" => null,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										"https://open.spotify.com/show/" .
 | 
				
			||||||
 | 
										explode(
 | 
				
			||||||
 | 
											":",
 | 
				
			||||||
 | 
											$podcast["uri"],
 | 
				
			||||||
 | 
											3
 | 
				
			||||||
 | 
										)[2],
 | 
				
			||||||
 | 
									"stream" => [
 | 
				
			||||||
 | 
										"endpoint" => null,
 | 
				
			||||||
 | 
										"url" => null
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get audio books (put in podcasts)
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["audiobooks"]["items"] as $podcast){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($podcast["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$podcast = $podcast["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description = [];
 | 
				
			||||||
 | 
								foreach($podcast["topics"]["items"] as $subject){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description[] = $subject["title"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$description = implode(", ", $description);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($description == ""){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$description = null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$authors = [];
 | 
				
			||||||
 | 
								foreach($podcast["authors"] as $author){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$authors[] = $author["name"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$authors = implode(", ", $authors);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if($authors == ""){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$authors = null;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$uri =
 | 
				
			||||||
 | 
									explode(
 | 
				
			||||||
 | 
										":",
 | 
				
			||||||
 | 
										$podcast["uri"],
 | 
				
			||||||
 | 
										3
 | 
				
			||||||
 | 
									)[2];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["podcast"][] = [
 | 
				
			||||||
 | 
									"title" => $podcast["name"],
 | 
				
			||||||
 | 
									"description" => $description,
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" => $authors,
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"avatar" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"thumb" => $this->get_thumb($podcast["coverArt"]),
 | 
				
			||||||
 | 
									"date" => strtotime($podcast["publishDate"]["isoString"]),
 | 
				
			||||||
 | 
									"duration" => null,
 | 
				
			||||||
 | 
									"url" => "https://open.spotify.com/show/" . $uri,
 | 
				
			||||||
 | 
									"stream" => [
 | 
				
			||||||
 | 
										"endpoint" => "spotify",
 | 
				
			||||||
 | 
										"url" => "episode." . $uri
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get episodes (and place them in podcasts)
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["episodes"]["items"] as $podcast){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($podcast["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$podcast = $podcast["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["podcast"][] = [
 | 
				
			||||||
 | 
									"title" => $podcast["name"],
 | 
				
			||||||
 | 
									"description" => $this->limitstrlen($podcast["description"]),
 | 
				
			||||||
 | 
									"author" => [
 | 
				
			||||||
 | 
										"name" =>
 | 
				
			||||||
 | 
											isset(
 | 
				
			||||||
 | 
												$podcast["podcastV2"]["data"]["publisher"]["name"]
 | 
				
			||||||
 | 
											) ?
 | 
				
			||||||
 | 
											$podcast["podcastV2"]["data"]["publisher"]["name"]
 | 
				
			||||||
 | 
											: null,
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"avatar" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"thumb" => $this->get_thumb($podcast["coverArt"]),
 | 
				
			||||||
 | 
									"date" => strtotime($podcast["releaseDate"]["isoString"]),
 | 
				
			||||||
 | 
									"duration" => $podcast["duration"]["totalMilliseconds"] / 1000,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										"https://open.spotify.com/show/" .
 | 
				
			||||||
 | 
										explode(
 | 
				
			||||||
 | 
											":",
 | 
				
			||||||
 | 
											$podcast["uri"],
 | 
				
			||||||
 | 
											3
 | 
				
			||||||
 | 
										)[2],
 | 
				
			||||||
 | 
									"stream" => [
 | 
				
			||||||
 | 
										"endpoint" => null,
 | 
				
			||||||
 | 
										"url" => null
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get authors
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["artists"]["items"] as $user){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($user["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$user = $user["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$avatar = $this->get_thumb($user["visuals"]["avatarImage"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["author"][] = [
 | 
				
			||||||
 | 
									"title" =>
 | 
				
			||||||
 | 
										(
 | 
				
			||||||
 | 
											$user["profile"]["verified"] === true ?
 | 
				
			||||||
 | 
											"✓ " : ""
 | 
				
			||||||
 | 
										) .
 | 
				
			||||||
 | 
										$user["profile"]["name"],
 | 
				
			||||||
 | 
									"followers" => null,
 | 
				
			||||||
 | 
									"description" => null,
 | 
				
			||||||
 | 
									"thumb" => $avatar,
 | 
				
			||||||
 | 
									"url" =>
 | 
				
			||||||
 | 
										"https://open.spotify.com/artist/" .
 | 
				
			||||||
 | 
										explode(
 | 
				
			||||||
 | 
											":",
 | 
				
			||||||
 | 
											$user["uri"],
 | 
				
			||||||
 | 
											3
 | 
				
			||||||
 | 
										)[2]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get users
 | 
				
			||||||
 | 
							foreach($payload["data"]["searchV2"]["users"]["items"] as $user){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(isset($user["data"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$user = $user["data"];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$avatar = $this->get_thumb($user["avatar"]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["user"][] = [
 | 
				
			||||||
 | 
									"title" => $user["displayName"] . " (@{$user["id"]})",
 | 
				
			||||||
 | 
									"followers" => null,
 | 
				
			||||||
 | 
									"description" => null,
 | 
				
			||||||
 | 
									"thumb" => $avatar,
 | 
				
			||||||
 | 
									"url" => "https://open.spotify.com/user/" . $user["id"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get_artists($artists){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$artist_out = [];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($artists["items"] as $artist){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$artist_out[] = $artist["profile"]["name"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$artist_out =
 | 
				
			||||||
 | 
								implode(", ", $artist_out);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($artist_out == ""){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return [null, null];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$artist_link =
 | 
				
			||||||
 | 
								$artist === null ?
 | 
				
			||||||
 | 
								null :
 | 
				
			||||||
 | 
								"https://open.spotify.com/artist/" .
 | 
				
			||||||
 | 
								explode(
 | 
				
			||||||
 | 
									":",
 | 
				
			||||||
 | 
									$artists["items"][0]["uri"]
 | 
				
			||||||
 | 
								)[2];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [$artist_out, $artist_link];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get_thumb($cover){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$thumb_out = null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($cover !== null){
 | 
				
			||||||
 | 
								foreach($cover["sources"] as $thumb){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$thumb_out === null ||
 | 
				
			||||||
 | 
										(int)$thumb["width"] > $thumb_out["width"]
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$thumb_out = $thumb;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($thumb_out === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return [
 | 
				
			||||||
 | 
									"url" => null,
 | 
				
			||||||
 | 
									"ratio" => null
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return [
 | 
				
			||||||
 | 
									"url" => $thumb_out["url"],
 | 
				
			||||||
 | 
									"ratio" => "1:1"
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function limitstrlen($text){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
								explode(
 | 
				
			||||||
 | 
									"\n",
 | 
				
			||||||
 | 
									wordwrap(
 | 
				
			||||||
 | 
										str_replace(
 | 
				
			||||||
 | 
											["\n\r", "\r\n", "\n", "\r"],
 | 
				
			||||||
 | 
											" ",
 | 
				
			||||||
 | 
											$text
 | 
				
			||||||
 | 
										),
 | 
				
			||||||
 | 
										300,
 | 
				
			||||||
 | 
										"\n"
 | 
				
			||||||
 | 
									),
 | 
				
			||||||
 | 
									2
 | 
				
			||||||
 | 
								)[0];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1579
									
								
								scraper/startpage.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										257
									
								
								scraper/vsco.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,257 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class vsco{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("vsco");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $bearer = null){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$curlproc = curl_init();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get !== []){
 | 
				
			||||||
 | 
								$get_tmp = http_build_query($get);
 | 
				
			||||||
 | 
								$url .= "?" . $get_tmp;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_URL, $url);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($bearer === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								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",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Sec-GPC: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
									"Sec-Fetch-User: ?1",
 | 
				
			||||||
 | 
									"Priority: u=0, i",
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								curl_setopt($curlproc, CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
									["User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
									"Accept: */*",
 | 
				
			||||||
 | 
									"Accept-Language: en-US",
 | 
				
			||||||
 | 
									"Accept-Encoding: gzip",
 | 
				
			||||||
 | 
									"Referer: https://vsco.co/search/images/" . urlencode($get["query"]),
 | 
				
			||||||
 | 
									"authorization: Bearer " . $bearer,
 | 
				
			||||||
 | 
									"content-type: application/json",
 | 
				
			||||||
 | 
									"x-client-build: 1",
 | 
				
			||||||
 | 
									"x-client-platform: web",
 | 
				
			||||||
 | 
									"DNT: 1",
 | 
				
			||||||
 | 
									"Sec-GPC: 1",
 | 
				
			||||||
 | 
									"Connection: keep-alive",
 | 
				
			||||||
 | 
									"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
									"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
									"Sec-Fetch-Site: same-origin",
 | 
				
			||||||
 | 
									"Priority: u=0",
 | 
				
			||||||
 | 
									"TE: trailers"]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// http2 bypass
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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 image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($get["npt"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$data, $proxy] =
 | 
				
			||||||
 | 
									$this->backend->get(
 | 
				
			||||||
 | 
										$get["npt"], "images"
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$data = json_decode($data, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get bearer token
 | 
				
			||||||
 | 
								try{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$html =
 | 
				
			||||||
 | 
										$this->get(
 | 
				
			||||||
 | 
											$proxy,
 | 
				
			||||||
 | 
											"https://vsco.co/feed"
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								}catch(Exception $error){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to fetch feed page");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								preg_match(
 | 
				
			||||||
 | 
									'/"tkn":"([A-z0-9]+)"/',
 | 
				
			||||||
 | 
									$html,
 | 
				
			||||||
 | 
									$bearer
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($bearer[1])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Failed to grep bearer token");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$data = [
 | 
				
			||||||
 | 
									"pagination" => [
 | 
				
			||||||
 | 
										"query" => $search,
 | 
				
			||||||
 | 
										"page" => 0,
 | 
				
			||||||
 | 
										"size" => 100
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"bearer" => $bearer[1]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$proxy,
 | 
				
			||||||
 | 
										"https://vsco.co/api/2.0/search/images",
 | 
				
			||||||
 | 
										$data["pagination"],
 | 
				
			||||||
 | 
										$data["bearer"]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(!isset($json["results"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to access results object");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($json["results"] as $image){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$image_domain = parse_url("https://" . $image["responsive_url"], PHP_URL_HOST);
 | 
				
			||||||
 | 
								$thumbnail = explode($image_domain, $image["responsive_url"], 2)[1];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(substr($thumbnail, 0, 3) != "/1/"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$thumbnail =
 | 
				
			||||||
 | 
										preg_replace(
 | 
				
			||||||
 | 
											'/^\/[^\/]+/',
 | 
				
			||||||
 | 
											"",
 | 
				
			||||||
 | 
											$thumbnail
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$thumbnail = "https://img.vsco.co/cdn-cgi/image/width=480,height=360" . $thumbnail;
 | 
				
			||||||
 | 
								$size =
 | 
				
			||||||
 | 
									$this->image_ratio(
 | 
				
			||||||
 | 
										(int)$image["dimensions"]["width"],
 | 
				
			||||||
 | 
										(int)$image["dimensions"]["height"]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["image"][] = [
 | 
				
			||||||
 | 
									"title" => $image["description"],
 | 
				
			||||||
 | 
									"source" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => "https://" . $image["responsive_url"],
 | 
				
			||||||
 | 
											"width" => (int)$image["dimensions"]["width"],
 | 
				
			||||||
 | 
											"height" => (int)$image["dimensions"]["height"]
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"url" => $thumbnail,
 | 
				
			||||||
 | 
											"width" => $size[0],
 | 
				
			||||||
 | 
											"height" => $size[1]
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"url" => "https://" . $image["grid"]["domain"] . "/media/" . $image["imageId"]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// get NPT
 | 
				
			||||||
 | 
							$max_page = ceil($json["total"] / 100);
 | 
				
			||||||
 | 
							$data["pagination"]["page"]++;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($max_page > $data["pagination"]["page"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["npt"] =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode($data),
 | 
				
			||||||
 | 
										"images",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function image_ratio($width, $height){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$ratio = [
 | 
				
			||||||
 | 
								480 / $width,
 | 
				
			||||||
 | 
								360 / $height
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($ratio[0] < $ratio[1]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$ratio = $ratio[0];
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$ratio = $ratio[1];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								floor($width * $ratio),
 | 
				
			||||||
 | 
								floor($height * $ratio)
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										246
									
								
								scraper/wiby.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,246 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class wiby{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("wiby");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($page != "web"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return [];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"nsfw" => [
 | 
				
			||||||
 | 
									"display" => "NSFW",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"yes" => "Yes",
 | 
				
			||||||
 | 
										"no" => "No"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"date" => [
 | 
				
			||||||
 | 
									"display" => "Time posted",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"any" => "Any time",
 | 
				
			||||||
 | 
										"day" => "Past day",
 | 
				
			||||||
 | 
										"week" => "Past week",
 | 
				
			||||||
 | 
										"month" => "Past month",
 | 
				
			||||||
 | 
										"year" => "Past year",
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function get($proxy, $url, $get = [], $nsfw){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$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",
 | 
				
			||||||
 | 
								"Cookie: ws={$nsfw}",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Upgrade-Insecure-Requests: 1",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: document",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: navigate",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: none",
 | 
				
			||||||
 | 
								"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"]){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								[$q, $proxy] = $this->backend->get($get["npt"], "web");
 | 
				
			||||||
 | 
								$q = json_decode($q, true);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nsfw = $q["nsfw"];
 | 
				
			||||||
 | 
								unset($q["nsfw"]);
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search = $get["s"];
 | 
				
			||||||
 | 
								if(strlen($search) === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$proxy = $this->backend->get_ip();
 | 
				
			||||||
 | 
								$date = $get["date"];
 | 
				
			||||||
 | 
								$nsfw = $get["nsfw"] == "yes" ? "0" : "1";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$search =
 | 
				
			||||||
 | 
									str_replace(
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"!g",
 | 
				
			||||||
 | 
											"!gi",
 | 
				
			||||||
 | 
											"!gv",
 | 
				
			||||||
 | 
											"!gm",
 | 
				
			||||||
 | 
											"!b",
 | 
				
			||||||
 | 
											"!bi",
 | 
				
			||||||
 | 
											"!bv",
 | 
				
			||||||
 | 
											"!bm",
 | 
				
			||||||
 | 
											"!td",
 | 
				
			||||||
 | 
											"!tw",
 | 
				
			||||||
 | 
											"!tm",
 | 
				
			||||||
 | 
											"!ty",
 | 
				
			||||||
 | 
											"&g",
 | 
				
			||||||
 | 
											"&gi",
 | 
				
			||||||
 | 
											"&gv",
 | 
				
			||||||
 | 
											"&gm",
 | 
				
			||||||
 | 
											"&b",
 | 
				
			||||||
 | 
											"&bi",
 | 
				
			||||||
 | 
											"&bv",
 | 
				
			||||||
 | 
											"&bm",
 | 
				
			||||||
 | 
											"&td",
 | 
				
			||||||
 | 
											"&tw",
 | 
				
			||||||
 | 
											"&tm",
 | 
				
			||||||
 | 
											"&ty",
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"",
 | 
				
			||||||
 | 
										$search
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch($date){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "day": $search = "!td " . $search; break;
 | 
				
			||||||
 | 
									case "week": $search = "!tw " . $search; break;
 | 
				
			||||||
 | 
									case "month": $search = "!tm " . $search; break;
 | 
				
			||||||
 | 
									case "year": $search = "!ty " . $search; break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$q = [
 | 
				
			||||||
 | 
									"q" => $search
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								$html = $this->get(
 | 
				
			||||||
 | 
									$proxy,
 | 
				
			||||||
 | 
									"https://wiby.me/",
 | 
				
			||||||
 | 
									$q,
 | 
				
			||||||
 | 
									$nsfw
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch search page");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							preg_match(
 | 
				
			||||||
 | 
								'/<p class="pin"><blockquote>(?:<\/p>)?<br><a class="more" href="\/\?q=[^"]+&p=([0-9]+)">Find more\.\.\.<\/a><\/blockquote>/',
 | 
				
			||||||
 | 
								$html,
 | 
				
			||||||
 | 
								$nextpage
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(count($nextpage) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage = null;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$nextpage =
 | 
				
			||||||
 | 
									$this->backend->store(
 | 
				
			||||||
 | 
										json_encode([
 | 
				
			||||||
 | 
											"q" => $q["q"],
 | 
				
			||||||
 | 
											"p" => (int)$nextpage[1],
 | 
				
			||||||
 | 
											"nsfw" => $nsfw
 | 
				
			||||||
 | 
										]),
 | 
				
			||||||
 | 
										"web",
 | 
				
			||||||
 | 
										$proxy
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => $nextpage,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							preg_match_all(
 | 
				
			||||||
 | 
								'/<blockquote>[\s]*<a .* href="(.*)">(.*)<\/a>.*<p>(.*)<\/p>[\s]*<\/blockquote>/Ui',
 | 
				
			||||||
 | 
								$html,
 | 
				
			||||||
 | 
								$links
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for($i=0; $i<count($links[0]); $i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["web"][] = [
 | 
				
			||||||
 | 
									"title" => $this->unescapehtml(trim($links[2][$i])),
 | 
				
			||||||
 | 
									"description" => $this->unescapehtml(trim(strip_tags($links[3][$i]), ".\n\r ")),
 | 
				
			||||||
 | 
									"url" => trim($links[1][$i]),
 | 
				
			||||||
 | 
									"date" => null,
 | 
				
			||||||
 | 
									"type" => "web",
 | 
				
			||||||
 | 
									"thumb" => [
 | 
				
			||||||
 | 
										"url" => null,
 | 
				
			||||||
 | 
										"ratio" => null
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"sublink" => [],
 | 
				
			||||||
 | 
									"table" => []
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function unescapehtml($str){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return html_entity_decode(
 | 
				
			||||||
 | 
								str_replace(
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"<br>",
 | 
				
			||||||
 | 
										"<br/>",
 | 
				
			||||||
 | 
										"</br>",
 | 
				
			||||||
 | 
										"<BR>",
 | 
				
			||||||
 | 
										"<BR/>",
 | 
				
			||||||
 | 
										"</BR>",
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
									"\n",
 | 
				
			||||||
 | 
									$str
 | 
				
			||||||
 | 
								),
 | 
				
			||||||
 | 
								ENT_QUOTES | ENT_XML1, 'UTF-8'
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1170
									
								
								scraper/yandex.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										741
									
								
								scraper/yep.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,741 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class yep{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function __construct(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/backend.php";
 | 
				
			||||||
 | 
							$this->backend = new backend("yep");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							include "lib/fuckhtml.php";
 | 
				
			||||||
 | 
							$this->fuckhtml = new fuckhtml();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function getfilters($page){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return [
 | 
				
			||||||
 | 
								"country" => [
 | 
				
			||||||
 | 
									"display" => "Country",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"all" => "All regions",
 | 
				
			||||||
 | 
										"af" => "Afghanistan",
 | 
				
			||||||
 | 
										"al" => "Albania",
 | 
				
			||||||
 | 
										"dz" => "Algeria",
 | 
				
			||||||
 | 
										"as" => "American Samoa",
 | 
				
			||||||
 | 
										"ad" => "Andorra",
 | 
				
			||||||
 | 
										"ao" => "Angola",
 | 
				
			||||||
 | 
										"ai" => "Anguilla",
 | 
				
			||||||
 | 
										"ag" => "Antigua and Barbuda",
 | 
				
			||||||
 | 
										"ar" => "Argentina",
 | 
				
			||||||
 | 
										"am" => "Armenia",
 | 
				
			||||||
 | 
										"aw" => "Aruba",
 | 
				
			||||||
 | 
										"au" => "Australia",
 | 
				
			||||||
 | 
										"at" => "Austria",
 | 
				
			||||||
 | 
										"az" => "Azerbaijan",
 | 
				
			||||||
 | 
										"bs" => "Bahamas",
 | 
				
			||||||
 | 
										"bh" => "Bahrain",
 | 
				
			||||||
 | 
										"bd" => "Bangladesh",
 | 
				
			||||||
 | 
										"bb" => "Barbados",
 | 
				
			||||||
 | 
										"by" => "Belarus",
 | 
				
			||||||
 | 
										"be" => "Belgium",
 | 
				
			||||||
 | 
										"bz" => "Belize",
 | 
				
			||||||
 | 
										"bj" => "Benin",
 | 
				
			||||||
 | 
										"bt" => "Bhutan",
 | 
				
			||||||
 | 
										"bo" => "Bolivia",
 | 
				
			||||||
 | 
										"ba" => "Bosnia and Herzegovina",
 | 
				
			||||||
 | 
										"bw" => "Botswana",
 | 
				
			||||||
 | 
										"br" => "Brazil",
 | 
				
			||||||
 | 
										"bn" => "Brunei Darussalam",
 | 
				
			||||||
 | 
										"bg" => "Bulgaria",
 | 
				
			||||||
 | 
										"bf" => "Burkina Faso",
 | 
				
			||||||
 | 
										"bi" => "Burundi",
 | 
				
			||||||
 | 
										"cv" => "Cabo Verde",
 | 
				
			||||||
 | 
										"kh" => "Cambodia",
 | 
				
			||||||
 | 
										"cm" => "Cameroon",
 | 
				
			||||||
 | 
										"ca" => "Canada",
 | 
				
			||||||
 | 
										"ky" => "Cayman Islands",
 | 
				
			||||||
 | 
										"cf" => "Central African Republic",
 | 
				
			||||||
 | 
										"td" => "Chad",
 | 
				
			||||||
 | 
										"cl" => "Chile",
 | 
				
			||||||
 | 
										"cn" => "China",
 | 
				
			||||||
 | 
										"co" => "Colombia",
 | 
				
			||||||
 | 
										"cg" => "Congo",
 | 
				
			||||||
 | 
										"cd" => "Congo, Democratic Republic",
 | 
				
			||||||
 | 
										"ck" => "Cook Islands",
 | 
				
			||||||
 | 
										"cr" => "Costa Rica",
 | 
				
			||||||
 | 
										"hr" => "Croatia",
 | 
				
			||||||
 | 
										"cu" => "Cuba",
 | 
				
			||||||
 | 
										"cy" => "Cyprus",
 | 
				
			||||||
 | 
										"cz" => "Czechia",
 | 
				
			||||||
 | 
										"ci" => "Côte d'Ivoire",
 | 
				
			||||||
 | 
										"dk" => "Denmark",
 | 
				
			||||||
 | 
										"dj" => "Djibouti",
 | 
				
			||||||
 | 
										"dm" => "Dominica",
 | 
				
			||||||
 | 
										"do" => "Dominican Republic",
 | 
				
			||||||
 | 
										"ec" => "Ecuador",
 | 
				
			||||||
 | 
										"eg" => "Egypt",
 | 
				
			||||||
 | 
										"sv" => "El Salvador",
 | 
				
			||||||
 | 
										"gq" => "Equatorial Guinea",
 | 
				
			||||||
 | 
										"ee" => "Estonia",
 | 
				
			||||||
 | 
										"et" => "Ethiopia",
 | 
				
			||||||
 | 
										"fo" => "Faroe Islands",
 | 
				
			||||||
 | 
										"fj" => "Fiji",
 | 
				
			||||||
 | 
										"fi" => "Finland",
 | 
				
			||||||
 | 
										"fr" => "France",
 | 
				
			||||||
 | 
										"gf" => "French Guiana",
 | 
				
			||||||
 | 
										"pf" => "French Polynesia",
 | 
				
			||||||
 | 
										"ga" => "Gabon",
 | 
				
			||||||
 | 
										"gm" => "Gambia",
 | 
				
			||||||
 | 
										"ge" => "Georgia",
 | 
				
			||||||
 | 
										"de" => "Germany",
 | 
				
			||||||
 | 
										"gh" => "Ghana",
 | 
				
			||||||
 | 
										"gi" => "Gibraltar",
 | 
				
			||||||
 | 
										"gr" => "Greece",
 | 
				
			||||||
 | 
										"gl" => "Greenland",
 | 
				
			||||||
 | 
										"gd" => "Grenada",
 | 
				
			||||||
 | 
										"gp" => "Guadeloupe",
 | 
				
			||||||
 | 
										"gu" => "Guam",
 | 
				
			||||||
 | 
										"gt" => "Guatemala",
 | 
				
			||||||
 | 
										"gg" => "Guernsey",
 | 
				
			||||||
 | 
										"gn" => "Guinea",
 | 
				
			||||||
 | 
										"gy" => "Guyana",
 | 
				
			||||||
 | 
										"ht" => "Haiti",
 | 
				
			||||||
 | 
										"hn" => "Honduras",
 | 
				
			||||||
 | 
										"hk" => "Hong Kong",
 | 
				
			||||||
 | 
										"hu" => "Hungary",
 | 
				
			||||||
 | 
										"is" => "Iceland",
 | 
				
			||||||
 | 
										"in" => "India",
 | 
				
			||||||
 | 
										"id" => "Indonesia",
 | 
				
			||||||
 | 
										"iq" => "Iraq",
 | 
				
			||||||
 | 
										"ie" => "Ireland",
 | 
				
			||||||
 | 
										"im" => "Isle of Man",
 | 
				
			||||||
 | 
										"il" => "Israel",
 | 
				
			||||||
 | 
										"it" => "Italy",
 | 
				
			||||||
 | 
										"jm" => "Jamaica",
 | 
				
			||||||
 | 
										"jp" => "Japan",
 | 
				
			||||||
 | 
										"je" => "Jersey",
 | 
				
			||||||
 | 
										"jo" => "Jordan",
 | 
				
			||||||
 | 
										"kz" => "Kazakhstan",
 | 
				
			||||||
 | 
										"ke" => "Kenya",
 | 
				
			||||||
 | 
										"ki" => "Kiribati",
 | 
				
			||||||
 | 
										"kw" => "Kuwait",
 | 
				
			||||||
 | 
										"kg" => "Kyrgyzstan",
 | 
				
			||||||
 | 
										"la" => "Lao People's Democratic Republic",
 | 
				
			||||||
 | 
										"lv" => "Latvia",
 | 
				
			||||||
 | 
										"lb" => "Lebanon",
 | 
				
			||||||
 | 
										"ls" => "Lesotho",
 | 
				
			||||||
 | 
										"ly" => "Libya",
 | 
				
			||||||
 | 
										"li" => "Liechtenstein",
 | 
				
			||||||
 | 
										"lt" => "Lithuania",
 | 
				
			||||||
 | 
										"lu" => "Luxembourg",
 | 
				
			||||||
 | 
										"mk" => "Macedonia",
 | 
				
			||||||
 | 
										"mg" => "Madagascar",
 | 
				
			||||||
 | 
										"mw" => "Malawi",
 | 
				
			||||||
 | 
										"my" => "Malaysia",
 | 
				
			||||||
 | 
										"mv" => "Maldives",
 | 
				
			||||||
 | 
										"ml" => "Mali",
 | 
				
			||||||
 | 
										"mt" => "Malta",
 | 
				
			||||||
 | 
										"mq" => "Martinique",
 | 
				
			||||||
 | 
										"mr" => "Mauritania",
 | 
				
			||||||
 | 
										"mu" => "Mauritius",
 | 
				
			||||||
 | 
										"yt" => "Mayotte",
 | 
				
			||||||
 | 
										"mx" => "Mexico",
 | 
				
			||||||
 | 
										"fm" => "Micronesia, Federated States of",
 | 
				
			||||||
 | 
										"md" => "Moldova",
 | 
				
			||||||
 | 
										"mc" => "Monaco",
 | 
				
			||||||
 | 
										"mn" => "Mongolia",
 | 
				
			||||||
 | 
										"me" => "Montenegro",
 | 
				
			||||||
 | 
										"ms" => "Montserrat",
 | 
				
			||||||
 | 
										"ma" => "Morocco",
 | 
				
			||||||
 | 
										"mz" => "Mozambique",
 | 
				
			||||||
 | 
										"mm" => "Myanmar",
 | 
				
			||||||
 | 
										"na" => "Namibia",
 | 
				
			||||||
 | 
										"nr" => "Nauru",
 | 
				
			||||||
 | 
										"np" => "Nepal",
 | 
				
			||||||
 | 
										"nl" => "Netherlands",
 | 
				
			||||||
 | 
										"nc" => "New Caledonia",
 | 
				
			||||||
 | 
										"nz" => "New Zealand",
 | 
				
			||||||
 | 
										"ni" => "Nicaragua",
 | 
				
			||||||
 | 
										"ne" => "Niger",
 | 
				
			||||||
 | 
										"ng" => "Nigeria",
 | 
				
			||||||
 | 
										"nu" => "Niue",
 | 
				
			||||||
 | 
										"no" => "Norway",
 | 
				
			||||||
 | 
										"om" => "Oman",
 | 
				
			||||||
 | 
										"pk" => "Pakistan",
 | 
				
			||||||
 | 
										"ps" => "Palestine, State of",
 | 
				
			||||||
 | 
										"pa" => "Panama",
 | 
				
			||||||
 | 
										"pg" => "Papua New Guinea",
 | 
				
			||||||
 | 
										"py" => "Paraguay",
 | 
				
			||||||
 | 
										"pe" => "Peru",
 | 
				
			||||||
 | 
										"ph" => "Philippines",
 | 
				
			||||||
 | 
										"pn" => "Pitcairn",
 | 
				
			||||||
 | 
										"pl" => "Poland",
 | 
				
			||||||
 | 
										"pt" => "Portugal",
 | 
				
			||||||
 | 
										"pr" => "Puerto Rico",
 | 
				
			||||||
 | 
										"qa" => "Qatar",
 | 
				
			||||||
 | 
										"ro" => "Romania",
 | 
				
			||||||
 | 
										"ru" => "Russian Federation",
 | 
				
			||||||
 | 
										"rw" => "Rwanda",
 | 
				
			||||||
 | 
										"re" => "Réunion",
 | 
				
			||||||
 | 
										"sh" => "Saint Helena",
 | 
				
			||||||
 | 
										"kn" => "Saint Kitts and Nevis",
 | 
				
			||||||
 | 
										"lc" => "Saint Lucia",
 | 
				
			||||||
 | 
										"vc" => "Saint Vincent and the Grenadines",
 | 
				
			||||||
 | 
										"ws" => "Samoa",
 | 
				
			||||||
 | 
										"sm" => "San Marino",
 | 
				
			||||||
 | 
										"st" => "Sao Tome and Principe",
 | 
				
			||||||
 | 
										"sa" => "Saudi Arabia",
 | 
				
			||||||
 | 
										"sn" => "Senegal",
 | 
				
			||||||
 | 
										"rs" => "Serbia",
 | 
				
			||||||
 | 
										"sc" => "Seychelles",
 | 
				
			||||||
 | 
										"sl" => "Sierra Leone",
 | 
				
			||||||
 | 
										"sg" => "Singapore",
 | 
				
			||||||
 | 
										"sk" => "Slovakia",
 | 
				
			||||||
 | 
										"si" => "Slovenia",
 | 
				
			||||||
 | 
										"sb" => "Solomon Islands",
 | 
				
			||||||
 | 
										"so" => "Somalia",
 | 
				
			||||||
 | 
										"kr" => "Sourth Korea",
 | 
				
			||||||
 | 
										"za" => "South Africa",
 | 
				
			||||||
 | 
										"es" => "Spain",
 | 
				
			||||||
 | 
										"lk" => "Sri Lanka",
 | 
				
			||||||
 | 
										"sr" => "Suriname",
 | 
				
			||||||
 | 
										"se" => "Sweden",
 | 
				
			||||||
 | 
										"ch" => "Switzerland",
 | 
				
			||||||
 | 
										"tw" => "Taiwan",
 | 
				
			||||||
 | 
										"tj" => "Tajikistan",
 | 
				
			||||||
 | 
										"tz" => "Tanzania",
 | 
				
			||||||
 | 
										"th" => "Thailand",
 | 
				
			||||||
 | 
										"tl" => "Timor-Leste",
 | 
				
			||||||
 | 
										"tg" => "Togo",
 | 
				
			||||||
 | 
										"tk" => "Tokelau",
 | 
				
			||||||
 | 
										"to" => "Tonga",
 | 
				
			||||||
 | 
										"tt" => "Trinidad and Tobago",
 | 
				
			||||||
 | 
										"tn" => "Tunisia",
 | 
				
			||||||
 | 
										"tr" => "Turkey",
 | 
				
			||||||
 | 
										"tm" => "Turkmenistan",
 | 
				
			||||||
 | 
										"ug" => "Uganda",
 | 
				
			||||||
 | 
										"ua" => "Ukraine",
 | 
				
			||||||
 | 
										"ae" => "United Arab Emirates",
 | 
				
			||||||
 | 
										"gb" => "United Kingdom",
 | 
				
			||||||
 | 
										"us" => "United States",
 | 
				
			||||||
 | 
										"uy" => "Uruguay",
 | 
				
			||||||
 | 
										"uz" => "Uzbekistan",
 | 
				
			||||||
 | 
										"vu" => "Vanuatu",
 | 
				
			||||||
 | 
										"ve" => "Venezuela",
 | 
				
			||||||
 | 
										"vn" => "Vietnam",
 | 
				
			||||||
 | 
										"vg" => "Virgin Islands, British",
 | 
				
			||||||
 | 
										"vi" => "Virgin Islands, U.S.",
 | 
				
			||||||
 | 
										"ye" => "Yemen",
 | 
				
			||||||
 | 
										"zm" => "Zambia",
 | 
				
			||||||
 | 
										"zw" => "Zimbabwe"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"nsfw" => [
 | 
				
			||||||
 | 
									"display" => "NSFW",
 | 
				
			||||||
 | 
									"option" => [
 | 
				
			||||||
 | 
										"yes" => "Yes",
 | 
				
			||||||
 | 
										"maybe" => "Maybe",
 | 
				
			||||||
 | 
										"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);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// use http2
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// set ciphers
 | 
				
			||||||
 | 
							curl_setopt(
 | 
				
			||||||
 | 
								$curlproc,
 | 
				
			||||||
 | 
								CURLOPT_SSL_CIPHER_LIST,
 | 
				
			||||||
 | 
								"aes_128_gcm_sha_256,chacha20_poly1305_sha_256,aes_256_gcm_sha_384,ecdhe_ecdsa_aes_128_gcm_sha_256,ecdhe_rsa_aes_128_gcm_sha_256,ecdhe_ecdsa_chacha20_poly1305_sha_256,ecdhe_rsa_chacha20_poly1305_sha_256,ecdhe_ecdsa_aes_256_gcm_sha_384,ecdhe_rsa_aes_256_gcm_sha_384,ecdhe_ecdsa_aes_256_sha,ecdhe_ecdsa_aes_128_sha,ecdhe_rsa_aes_128_sha,ecdhe_rsa_aes_256_sha,rsa_aes_128_gcm_sha_256,rsa_aes_256_gcm_sha_384,rsa_aes_128_sha,rsa_aes_256_sha"
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_ENCODING, ""); // default encoding
 | 
				
			||||||
 | 
							curl_setopt($curlproc, CURLOPT_HTTPHEADER,
 | 
				
			||||||
 | 
								["User-Agent: " . config::USER_AGENT,
 | 
				
			||||||
 | 
								"Accept: */*",
 | 
				
			||||||
 | 
								"Accept-Language: en-US,en;q=0.5",
 | 
				
			||||||
 | 
								"Accept-Encoding: gzip, deflate, br, zstd",
 | 
				
			||||||
 | 
								"Referer: https://yep.com/",
 | 
				
			||||||
 | 
								"Origin: https://yep.com",
 | 
				
			||||||
 | 
								"DNT: 1",
 | 
				
			||||||
 | 
								"Connection: keep-alive",
 | 
				
			||||||
 | 
								"Sec-Fetch-Dest: empty",
 | 
				
			||||||
 | 
								"Sec-Fetch-Mode: cors",
 | 
				
			||||||
 | 
								"Sec-Fetch-Site: same-site",
 | 
				
			||||||
 | 
								"Priority: u=4",
 | 
				
			||||||
 | 
								"TE: trailers"]
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							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){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$country = $get["country"];
 | 
				
			||||||
 | 
							$nsfw = $get["nsfw"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($nsfw){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "yes": $nsfw = "off"; break;
 | 
				
			||||||
 | 
								case "maybe": $nsfw = "moderate"; break;
 | 
				
			||||||
 | 
								case "no": $nsfw = "strict"; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"spelling" => [
 | 
				
			||||||
 | 
									"type" => "no_correction",
 | 
				
			||||||
 | 
									"using" => null,
 | 
				
			||||||
 | 
									"correction" => null
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"answer" => [],
 | 
				
			||||||
 | 
								"web" => [],
 | 
				
			||||||
 | 
								"image" => [],
 | 
				
			||||||
 | 
								"video" => [],
 | 
				
			||||||
 | 
								"news" => [],
 | 
				
			||||||
 | 
								"related" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// https://api.yep.com/fs/2/search?client=web&gl=CA&no_correct=false&q=undefined+variable+javascript&safeSearch=off&type=web
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$this->backend->get_ip(),
 | 
				
			||||||
 | 
										"https://api.yep.com/fs/2/search",
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"client" => "web",
 | 
				
			||||||
 | 
											"gl" => $country == "all" ? $country : strtoupper($country),
 | 
				
			||||||
 | 
											"limit" => "99999",
 | 
				
			||||||
 | 
											"no_correct" => "false",
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"safeSearch" => $nsfw,
 | 
				
			||||||
 | 
											"type" => "web"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_cf($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							//$json = json_decode(file_get_contents("scraper/yep.json"), true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json[1]["correction"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$out["spelling"] = [
 | 
				
			||||||
 | 
									"type" => "not_many",
 | 
				
			||||||
 | 
									"using" => $search,
 | 
				
			||||||
 | 
									"correction" => $json[1]["correction"][1]
 | 
				
			||||||
 | 
								];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json[1]["results"])){
 | 
				
			||||||
 | 
								foreach($json[1]["results"] as $item){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									switch(strtolower($item["type"])){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										case "organic":
 | 
				
			||||||
 | 
											$sublinks = [];
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											if(isset($item["sitelinks"]["full"])){
 | 
				
			||||||
 | 
												
 | 
				
			||||||
 | 
												foreach($item["sitelinks"]["full"] as $link){
 | 
				
			||||||
 | 
													
 | 
				
			||||||
 | 
													$sublinks[] = [
 | 
				
			||||||
 | 
														"title" => $link["title"],
 | 
				
			||||||
 | 
														"date" => null,
 | 
				
			||||||
 | 
														"description" =>
 | 
				
			||||||
 | 
															$this->titledots(
 | 
				
			||||||
 | 
																strip_tags(
 | 
				
			||||||
 | 
																	html_entity_decode(
 | 
				
			||||||
 | 
																		$link["snippet"]
 | 
				
			||||||
 | 
																	)
 | 
				
			||||||
 | 
																)
 | 
				
			||||||
 | 
															),
 | 
				
			||||||
 | 
														"url" => $link["url"]
 | 
				
			||||||
 | 
													];
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											$out["web"][] = [
 | 
				
			||||||
 | 
												"title" => $item["title"],
 | 
				
			||||||
 | 
												"description" =>
 | 
				
			||||||
 | 
													$this->titledots(
 | 
				
			||||||
 | 
														strip_tags(
 | 
				
			||||||
 | 
															html_entity_decode(
 | 
				
			||||||
 | 
																$item["snippet"]
 | 
				
			||||||
 | 
															)
 | 
				
			||||||
 | 
														)
 | 
				
			||||||
 | 
													),
 | 
				
			||||||
 | 
												"url" => $item["url"],
 | 
				
			||||||
 | 
												"date" => strtotime($item["first_seen"]),
 | 
				
			||||||
 | 
												"type" => "web",
 | 
				
			||||||
 | 
												"thumb" => [
 | 
				
			||||||
 | 
													"url" => null,
 | 
				
			||||||
 | 
													"ratio" => null
 | 
				
			||||||
 | 
												],
 | 
				
			||||||
 | 
												"sublink" => $sublinks,
 | 
				
			||||||
 | 
												"table" => []
 | 
				
			||||||
 | 
											];
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json[1]["featured_news"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($json[1]["featured_news"] as $news){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["news"][] = [
 | 
				
			||||||
 | 
										"title" => $news["title"],
 | 
				
			||||||
 | 
										"description" =>
 | 
				
			||||||
 | 
											$this->titledots(
 | 
				
			||||||
 | 
												strip_tags(
 | 
				
			||||||
 | 
													html_entity_decode(
 | 
				
			||||||
 | 
														$news["snippet"]
 | 
				
			||||||
 | 
													)
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
										"date" => strtotime($news["first_seen"]),
 | 
				
			||||||
 | 
										"thumb" =>
 | 
				
			||||||
 | 
											isset($news["img"]) ?
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => $this->unshiturl($news["img"]),
 | 
				
			||||||
 | 
												"ratio" => "16:9"
 | 
				
			||||||
 | 
											] :
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => null,
 | 
				
			||||||
 | 
												"ratio" => null
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
										"url" => $news["url"]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json[1]["featured_images"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($json[1]["featured_images"] as $image){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$image["width"] !== 0 &&
 | 
				
			||||||
 | 
										$image["height"] !== 0
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$thumb_width = $image["width"] >= 260 ? 260 : $image["width"];
 | 
				
			||||||
 | 
										$thumb_height = ceil($image["height"] * ($thumb_width / $image["width"]));
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$width = $image["width"];
 | 
				
			||||||
 | 
										$height = $image["height"];
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$thumb_width = null;
 | 
				
			||||||
 | 
										$thumb_height = null;
 | 
				
			||||||
 | 
										$width = null;
 | 
				
			||||||
 | 
										$height = null;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["image"][] = [
 | 
				
			||||||
 | 
										"title" => $image["title"],
 | 
				
			||||||
 | 
										"source" => [
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => $image["image_id"],
 | 
				
			||||||
 | 
												"width" => $width,
 | 
				
			||||||
 | 
												"height" => $height
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => $image["src"],
 | 
				
			||||||
 | 
												"width" => $thumb_width,
 | 
				
			||||||
 | 
												"height" => $thumb_height
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"url" => $image["host_page"]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function image($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$country = $get["country"];
 | 
				
			||||||
 | 
							$nsfw = $get["nsfw"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($nsfw){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "yes": $nsfw = "off"; break;
 | 
				
			||||||
 | 
								case "maybe": $nsfw = "moderate"; break;
 | 
				
			||||||
 | 
								case "no": $nsfw = "strict"; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"image" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$this->backend->get_ip(), // no nextpage!
 | 
				
			||||||
 | 
										"https://api.yep.com/fs/2/search",
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"client" => "web",
 | 
				
			||||||
 | 
											"gl" => $country == "all" ? $country : strtoupper($country),
 | 
				
			||||||
 | 
											"no_correct" => "false",
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"safeSearch" => $nsfw,
 | 
				
			||||||
 | 
											"type" => "images"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_cf($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json[1]["results"])){
 | 
				
			||||||
 | 
								foreach($json[1]["results"] as $item){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$item["width"] !== 0 &&
 | 
				
			||||||
 | 
										$item["height"] !== 0
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$thumb_width = $item["width"] >= 260 ? 260 : $item["width"];
 | 
				
			||||||
 | 
										$thumb_height = ceil($item["height"] * ($thumb_width / $item["width"]));
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$width = $item["width"];
 | 
				
			||||||
 | 
										$height = $item["height"];
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										$thumb_width = null;
 | 
				
			||||||
 | 
										$thumb_height = null;
 | 
				
			||||||
 | 
										$width = null;
 | 
				
			||||||
 | 
										$height = null;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["image"][] = [
 | 
				
			||||||
 | 
										"title" => $item["title"],
 | 
				
			||||||
 | 
										"source" => [
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => $item["image_id"],
 | 
				
			||||||
 | 
												"width" => $width,
 | 
				
			||||||
 | 
												"height" => $height
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => $item["src"],
 | 
				
			||||||
 | 
												"width" => $thumb_width,
 | 
				
			||||||
 | 
												"height" => $thumb_height
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										"url" => $item["host_page"]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function news($get){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$search = $get["s"];
 | 
				
			||||||
 | 
							if(strlen($search) === 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Search term is empty!");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$country = $get["country"];
 | 
				
			||||||
 | 
							$nsfw = $get["nsfw"];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch($nsfw){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case "yes": $nsfw = "off"; break;
 | 
				
			||||||
 | 
								case "maybe": $nsfw = "moderate"; break;
 | 
				
			||||||
 | 
								case "no": $nsfw = "strict"; break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$out = [
 | 
				
			||||||
 | 
								"status" => "ok",
 | 
				
			||||||
 | 
								"npt" => null,
 | 
				
			||||||
 | 
								"news" => []
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							try{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// https://api.yep.com/fs/2/search?client=web&gl=CA&no_correct=false&q=undefined+variable+javascript&safeSearch=off&type=web
 | 
				
			||||||
 | 
								$json =
 | 
				
			||||||
 | 
									$this->get(
 | 
				
			||||||
 | 
										$this->backend->get_ip(),
 | 
				
			||||||
 | 
										"https://api.yep.com/fs/2/search",
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"client" => "web",
 | 
				
			||||||
 | 
											"gl" => $country == "all" ? $country : strtoupper($country),
 | 
				
			||||||
 | 
											"limit" => "99999",
 | 
				
			||||||
 | 
											"no_correct" => "false",
 | 
				
			||||||
 | 
											"q" => $search,
 | 
				
			||||||
 | 
											"safeSearch" => $nsfw,
 | 
				
			||||||
 | 
											"type" => "news"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
							}catch(Exception $error){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to fetch JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$this->detect_cf($json);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$json = json_decode($json, true);
 | 
				
			||||||
 | 
							//$json = json_decode(file_get_contents("scraper/yep.json"), true);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($json === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Failed to decode JSON");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($json[1]["results"])){
 | 
				
			||||||
 | 
								foreach($json[1]["results"] as $item){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$out["news"][] = [
 | 
				
			||||||
 | 
										"title" => $item["title"],
 | 
				
			||||||
 | 
										"author" => null,
 | 
				
			||||||
 | 
										"description" =>
 | 
				
			||||||
 | 
											$this->titledots(
 | 
				
			||||||
 | 
												strip_tags(
 | 
				
			||||||
 | 
													html_entity_decode(
 | 
				
			||||||
 | 
														$item["snippet"]
 | 
				
			||||||
 | 
													)
 | 
				
			||||||
 | 
												)
 | 
				
			||||||
 | 
											),
 | 
				
			||||||
 | 
										"date" => strtotime($item["first_seen"]),
 | 
				
			||||||
 | 
										"thumb" =>
 | 
				
			||||||
 | 
											isset($item["img"]) ?
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => $this->unshiturl($item["img"]),
 | 
				
			||||||
 | 
												"ratio" => "16:9"
 | 
				
			||||||
 | 
											] :
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"url" => null,
 | 
				
			||||||
 | 
												"ratio" => null
 | 
				
			||||||
 | 
											],
 | 
				
			||||||
 | 
										"url" => $item["url"]
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function detect_cf($payload){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// detect cloudflare page
 | 
				
			||||||
 | 
							$this->fuckhtml->load($payload);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								count(
 | 
				
			||||||
 | 
									$this->fuckhtml
 | 
				
			||||||
 | 
									->getElementsByClassName(
 | 
				
			||||||
 | 
										"cf-wrapper",
 | 
				
			||||||
 | 
										"div"
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								) !== 0
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								throw new Exception("Blocked by Cloudflare. Please follow curl-impersonate installation instructions");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function titledots($title){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$substr = substr($title, -4);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								strpos($substr, "...") !== false ||
 | 
				
			||||||
 | 
								strpos($substr, "…") !== false
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
								return trim(substr($title, 0, -4));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return trim($title);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private function unshiturl($url){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$newurl = parse_url($url, PHP_URL_QUERY);
 | 
				
			||||||
 | 
							parse_str($newurl, $newurl);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(isset($newurl["url"])){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return $newurl["url"];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return $url;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1727
									
								
								scraper/yt.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										573
									
								
								settings.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,573 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Define settings
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					$settings = [
 | 
				
			||||||
 | 
						[
 | 
				
			||||||
 | 
							"name" => "General",
 | 
				
			||||||
 | 
							"settings" => [
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Allow NSFW content",
 | 
				
			||||||
 | 
									"parameter" => "nsfw",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yes",
 | 
				
			||||||
 | 
											"text" => "Yes"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "maybe",
 | 
				
			||||||
 | 
											"text" => "Maybe"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "no",
 | 
				
			||||||
 | 
											"text" => "No"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Theme",
 | 
				
			||||||
 | 
									"parameter" => "theme",
 | 
				
			||||||
 | 
									"options" => []
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Prevent clicking background elements when image viewer is open",
 | 
				
			||||||
 | 
									"parameter" => "bg_noclick",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "no",
 | 
				
			||||||
 | 
											"text" => "No"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yes",
 | 
				
			||||||
 | 
											"text" => "Yes"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						],
 | 
				
			||||||
 | 
						[
 | 
				
			||||||
 | 
							"name" => "Scrapers to use",
 | 
				
			||||||
 | 
							"settings" => [
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Autocomplete<br><i>Picking <span class=\"code-inline\">Auto</span> changes the source dynamically depending of the page's scraper<br><b>Warning:</b> If you edit this field, you will need to re-add the search engine so that the new autocomplete settings are applied!</i>",
 | 
				
			||||||
 | 
									"parameter" => "scraper_ac",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "disabled",
 | 
				
			||||||
 | 
											"text" => "Disabled"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "auto",
 | 
				
			||||||
 | 
											"text" => "Auto"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "brave",
 | 
				
			||||||
 | 
											"text" => "Brave"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ddg",
 | 
				
			||||||
 | 
											"text" => "DuckDuckGo"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yandex",
 | 
				
			||||||
 | 
											"text" => "Yandex"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google",
 | 
				
			||||||
 | 
											"text" => "Google"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "startpage",
 | 
				
			||||||
 | 
											"text" => "Startpage"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "kagi",
 | 
				
			||||||
 | 
											"text" => "Kagi"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "qwant",
 | 
				
			||||||
 | 
											"text" => "Qwant"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ghostery",
 | 
				
			||||||
 | 
											"text" => "Ghostery"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yep",
 | 
				
			||||||
 | 
											"text" => "Yep"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "marginalia",
 | 
				
			||||||
 | 
											"text" => "Marginalia"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yt",
 | 
				
			||||||
 | 
											"text" => "YouTube"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "sc",
 | 
				
			||||||
 | 
											"text" => "SoundCloud"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Web",
 | 
				
			||||||
 | 
									"parameter" => "scraper_web",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ddg",
 | 
				
			||||||
 | 
											"text" => "DuckDuckGo"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "brave",
 | 
				
			||||||
 | 
											"text" => "Brave"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yandex",
 | 
				
			||||||
 | 
											"text" => "Yandex"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google",
 | 
				
			||||||
 | 
											"text" => "Google"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google_cse",
 | 
				
			||||||
 | 
											"text" => "Google CSE"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "startpage",
 | 
				
			||||||
 | 
											"text" => "Startpage"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "qwant",
 | 
				
			||||||
 | 
											"text" => "Qwant"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ghostery",
 | 
				
			||||||
 | 
											"text" => "Ghostery"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yep",
 | 
				
			||||||
 | 
											"text" => "Yep"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "greppr",
 | 
				
			||||||
 | 
											"text" => "Greppr"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "crowdview",
 | 
				
			||||||
 | 
											"text" => "Crowdview"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "mwmbl",
 | 
				
			||||||
 | 
											"text" => "Mwmbl"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "mojeek",
 | 
				
			||||||
 | 
											"text" => "Mojeek"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "solofield",
 | 
				
			||||||
 | 
											"text" => "Solofield"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "marginalia",
 | 
				
			||||||
 | 
											"text" => "Marginalia"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "wiby",
 | 
				
			||||||
 | 
											"text" => "wiby"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "curlie",
 | 
				
			||||||
 | 
											"text" => "Curlie"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Images",
 | 
				
			||||||
 | 
									"parameter" => "scraper_images",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ddg",
 | 
				
			||||||
 | 
											"text" => "DuckDuckGo"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yandex",
 | 
				
			||||||
 | 
											"text" => "Yandex"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "brave",
 | 
				
			||||||
 | 
											"text" => "Brave"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google",
 | 
				
			||||||
 | 
											"text" => "Google"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google_cse",
 | 
				
			||||||
 | 
											"text" => "Google CSE"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "startpage",
 | 
				
			||||||
 | 
											"text" => "Startpage"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "qwant",
 | 
				
			||||||
 | 
											"text" => "Qwant"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yep",
 | 
				
			||||||
 | 
											"text" => "Yep"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "solofield",
 | 
				
			||||||
 | 
											"text" => "Solofield"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "pinterest",
 | 
				
			||||||
 | 
											"text" => "Pinterest"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "fivehpx",
 | 
				
			||||||
 | 
											"text" => "500px"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "vsco",
 | 
				
			||||||
 | 
											"text" => "VSCO"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "imgur",
 | 
				
			||||||
 | 
											"text" => "Imgur"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ftm",
 | 
				
			||||||
 | 
											"text" => "FindThatMeme"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Videos",
 | 
				
			||||||
 | 
									"parameter" => "scraper_videos",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yt",
 | 
				
			||||||
 | 
											"text" => "YouTube"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ddg",
 | 
				
			||||||
 | 
											"text" => "DuckDuckGo"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "brave",
 | 
				
			||||||
 | 
											"text" => "Brave"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yandex",
 | 
				
			||||||
 | 
											"text" => "Yandex"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google",
 | 
				
			||||||
 | 
											"text" => "Google"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "startpage",
 | 
				
			||||||
 | 
											"text" => "Startpage"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "qwant",
 | 
				
			||||||
 | 
											"text" => "Qwant"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "solofield",
 | 
				
			||||||
 | 
											"text" => "Solofield"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "News",
 | 
				
			||||||
 | 
									"parameter" => "scraper_news",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "ddg",
 | 
				
			||||||
 | 
											"text" => "DuckDuckGo"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "brave",
 | 
				
			||||||
 | 
											"text" => "Brave"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "google",
 | 
				
			||||||
 | 
											"text" => "Google"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "startpage",
 | 
				
			||||||
 | 
											"text" => "Startpage"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "qwant",
 | 
				
			||||||
 | 
											"text" => "Qwant"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "yep",
 | 
				
			||||||
 | 
											"text" => "Yep"
 | 
				
			||||||
 | 
										],
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "mojeek",
 | 
				
			||||||
 | 
											"text" => "Mojeek"
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								],
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"description" => "Music",
 | 
				
			||||||
 | 
									"parameter" => "scraper_music",
 | 
				
			||||||
 | 
									"options" => [
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											"value" => "sc",
 | 
				
			||||||
 | 
											"text" => "SoundCloud"
 | 
				
			||||||
 | 
										]//,
 | 
				
			||||||
 | 
										//[
 | 
				
			||||||
 | 
										//	"value" => "spotify",
 | 
				
			||||||
 | 
										//	"text" => "Spotify"
 | 
				
			||||||
 | 
										//]
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Set theme collection
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					$themes = glob("static/themes/*");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$settings[0]["settings"][1]["options"][] = [
 | 
				
			||||||
 | 
						"value" => "Dark",
 | 
				
			||||||
 | 
						"text" => "Dark"
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					foreach($themes as $theme){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$theme = explode(".", basename($theme))[0];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$settings[0]["settings"][1]["options"][] = [
 | 
				
			||||||
 | 
							"value" => $theme,
 | 
				
			||||||
 | 
							"text" => $theme
 | 
				
			||||||
 | 
						];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Set cookies
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					if($_POST){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						$loop = &$_POST;
 | 
				
			||||||
 | 
					}elseif(count($_GET) !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// redirect user to front page
 | 
				
			||||||
 | 
						$loop = &$_GET;
 | 
				
			||||||
 | 
						header("Location: /");
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						// refresh cookie dates
 | 
				
			||||||
 | 
						$loop = &$_COOKIE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					foreach($loop as $key => $value){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($key == "theme"){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($value == config::DEFAULT_THEME){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								unset($_COOKIE[$key]);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								setcookie(
 | 
				
			||||||
 | 
									"theme",
 | 
				
			||||||
 | 
									"",
 | 
				
			||||||
 | 
									[
 | 
				
			||||||
 | 
										"expires" => -1, // removes cookie
 | 
				
			||||||
 | 
										"samesite" => "Lax",
 | 
				
			||||||
 | 
										"path" => "/"
 | 
				
			||||||
 | 
									]
 | 
				
			||||||
 | 
								);
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}else{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($settings as $title){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								foreach($title["settings"] as $list){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										$list["parameter"] == $key &&
 | 
				
			||||||
 | 
										$list["options"][0]["value"] == $value
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										unset($_COOKIE[$key]);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										setcookie(
 | 
				
			||||||
 | 
											$key,
 | 
				
			||||||
 | 
											"",
 | 
				
			||||||
 | 
											[
 | 
				
			||||||
 | 
												"expires" => -1, // removes cookie
 | 
				
			||||||
 | 
												"samesite" => "Lax",
 | 
				
			||||||
 | 
												"path" => "/"
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										continue 3;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(!is_string($value)){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							continue;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$key = trim($key);
 | 
				
			||||||
 | 
						$value = trim($value);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$_COOKIE[$key] = $value;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						setcookie(
 | 
				
			||||||
 | 
							$key,
 | 
				
			||||||
 | 
							$value,
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"expires" => strtotime("+400 days"), // maximal cookie ttl in chrome
 | 
				
			||||||
 | 
								"samesite" => "Lax",
 | 
				
			||||||
 | 
								"path" => "/"
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include "lib/frontend.php";
 | 
				
			||||||
 | 
					$frontend = new frontend();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						$frontend->load(
 | 
				
			||||||
 | 
							"header_nofilters.html",
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								"title" => "Settings",
 | 
				
			||||||
 | 
								"class" => ""
 | 
				
			||||||
 | 
							]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$left =
 | 
				
			||||||
 | 
						'<h1>Settings</h1>' .
 | 
				
			||||||
 | 
						'<form method="post" autocomplete="off">' .
 | 
				
			||||||
 | 
							'By clicking <div class="code-inline">Update settings!</div>, a plaintext <div class="code-inline">key=value</div> cookie will be stored on your browser. When selecting a default setting, the parameter is removed from your cookies.';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$c = count($_COOKIE);
 | 
				
			||||||
 | 
					$code = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if($c !== 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$left .=
 | 
				
			||||||
 | 
							'<br><br>Your current cookie looks like this:' .
 | 
				
			||||||
 | 
							'<div class="code">';
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$ca = 0;
 | 
				
			||||||
 | 
						foreach($_COOKIE as $key => $value){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$code .= $key . "=" . $value;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$ca++;
 | 
				
			||||||
 | 
							if($ca !== $c){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$code .= "; ";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$left .= $frontend->highlightcode($code);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$left .= '</div>';
 | 
				
			||||||
 | 
					}else{
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$left .=
 | 
				
			||||||
 | 
							'<br><br>You currently don\'t have any cookies set.';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
					$left .=
 | 
				
			||||||
 | 
						'<div class="settings">';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					foreach($settings as $title){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$left .= '<h2>' . $title["name"] . '</h2>';
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						foreach($title["settings"] as $setting){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$left .=
 | 
				
			||||||
 | 
								'<div class="setting">' .
 | 
				
			||||||
 | 
									'<div class="title">' . $setting["description"] . '</div>' .
 | 
				
			||||||
 | 
									'<select name="' . $setting["parameter"] . '">';
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($setting["parameter"] == "theme"){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(!isset($_COOKIE["theme"])){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									$_COOKIE["theme"] = config::DEFAULT_THEME;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							foreach($setting["options"] as $option){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$left .=
 | 
				
			||||||
 | 
									'<option value="' . $option["value"] . '"';
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									isset($_COOKIE[$setting["parameter"]]) &&
 | 
				
			||||||
 | 
									$_COOKIE[$setting["parameter"]] == $option["value"]
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									$left .= ' selected';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								$left .= '>' . $option["text"] . '</option>';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$left .= '</select></div>';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$left .=
 | 
				
			||||||
 | 
						'</div>' .
 | 
				
			||||||
 | 
						'<div class="settings-submit">' .
 | 
				
			||||||
 | 
							'<input type="submit" value="Update settings!">' .
 | 
				
			||||||
 | 
							'<a href="../">< Go back</a>' .
 | 
				
			||||||
 | 
						'</div>' .
 | 
				
			||||||
 | 
						'</form>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(count($_GET) === 0){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$code = [];
 | 
				
			||||||
 | 
						foreach($_COOKIE as $key => $value){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$code[] = rawurlencode($key) . "=" . rawurlencode($value);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$code = implode("&", $code);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if($code != ""){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$code = "?" . $code;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						echo
 | 
				
			||||||
 | 
							$frontend->load(
 | 
				
			||||||
 | 
								"search.html",
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									"timetaken" => null,
 | 
				
			||||||
 | 
									"class" => "",
 | 
				
			||||||
 | 
									"right-left" =>			
 | 
				
			||||||
 | 
										'<div class="infobox"><h2>Preference link</h2>Following this link will re-apply all cookies configured here and will redirect you to the front page. Useful if your browser clears out cookies after a browsing session.<br><br>' .
 | 
				
			||||||
 | 
										'<a href="settings' . $code . '">Bookmark me!</a>' .
 | 
				
			||||||
 | 
										'</div>',
 | 
				
			||||||
 | 
									"right-right" => "",
 | 
				
			||||||
 | 
									"left" => $left
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										35
									
								
								sitemap.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,35 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Content-Type: application/xml");
 | 
				
			||||||
 | 
					include "data/config.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$domain =
 | 
				
			||||||
 | 
						htmlspecialchars(
 | 
				
			||||||
 | 
							(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "https" : "http") .
 | 
				
			||||||
 | 
							'://' . $_SERVER["HTTP_HOST"]
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo
 | 
				
			||||||
 | 
						'<?xml version="1.0" encoding="UTF-8"?>' .
 | 
				
			||||||
 | 
						'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
 | 
				
			||||||
 | 
							'<url>' .
 | 
				
			||||||
 | 
								'<loc>' . $domain . '/</loc>' .
 | 
				
			||||||
 | 
								'<lastmod>2023-07-31T07:56:12+03:00</lastmod>' .
 | 
				
			||||||
 | 
							'</url>' .
 | 
				
			||||||
 | 
							'<url>' .
 | 
				
			||||||
 | 
								'<loc>' . $domain . '/about</loc>' .
 | 
				
			||||||
 | 
								'<lastmod>2023-07-31T07:56:12+03:00</lastmod>' .
 | 
				
			||||||
 | 
							'</url>' .
 | 
				
			||||||
 | 
							'<url>' .
 | 
				
			||||||
 | 
								'<loc>' . $domain . '/instances</loc>' .
 | 
				
			||||||
 | 
								'<lastmod>2023-07-31T07:56:12+03:00</lastmod>' .
 | 
				
			||||||
 | 
							'</url>' .
 | 
				
			||||||
 | 
							'<url>' .
 | 
				
			||||||
 | 
								'<loc>' . $domain . '/settings</loc>' .
 | 
				
			||||||
 | 
								'<lastmod>2023-07-31T07:56:12+03:00</lastmod>' .
 | 
				
			||||||
 | 
							'</url>' .
 | 
				
			||||||
 | 
							'<url>' .
 | 
				
			||||||
 | 
								'<loc>' . $domain . '/api.txt</loc>' .
 | 
				
			||||||
 | 
								'<lastmod>2023-07-31T07:56:12+03:00</lastmod>' .
 | 
				
			||||||
 | 
							'</url>' .
 | 
				
			||||||
 | 
						'</urlset>';
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								static/404.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 216 B  | 
							
								
								
									
										985
									
								
								static/client.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
					@ -0,0 +1,985 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Global functions
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					function htmlspecialchars(str){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var map = {
 | 
				
			||||||
 | 
							'&': '&',
 | 
				
			||||||
 | 
							'<': '<',
 | 
				
			||||||
 | 
							'>': '>',
 | 
				
			||||||
 | 
							'"': '"',
 | 
				
			||||||
 | 
							"'": '''
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return str.replace(/[&<>"']/g, function(m){return map[m];});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function htmlspecialchars_decode(str){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var map = {
 | 
				
			||||||
 | 
							'&': '&',
 | 
				
			||||||
 | 
							'<': '<',
 | 
				
			||||||
 | 
							'>': '>',
 | 
				
			||||||
 | 
							'"': '"',
 | 
				
			||||||
 | 
							''': "'"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return str.replace(/&|<|>|"|'/g, function(m){return map[m];});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function is_click_within(elem, classname, is_id = false){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						while(true){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(elem === null){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								(
 | 
				
			||||||
 | 
									is_id === false &&
 | 
				
			||||||
 | 
									elem.className == classname
 | 
				
			||||||
 | 
								) ||
 | 
				
			||||||
 | 
								(
 | 
				
			||||||
 | 
									is_id === true &&
 | 
				
			||||||
 | 
									elem.id == classname
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return elem;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							elem = elem.parentElement;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Prevent GET parameter pollution
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					var form = document.getElementsByTagName("form");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(
 | 
				
			||||||
 | 
						form.length !== 0 &&
 | 
				
			||||||
 | 
						window.location.pathname != "/" &&
 | 
				
			||||||
 | 
						window.location.pathname != "/settings.php" &&
 | 
				
			||||||
 | 
						window.location.pathname != "/settings"
 | 
				
			||||||
 | 
					){
 | 
				
			||||||
 | 
						form = form[0];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var scraper_dropdown = document.getElementsByName("scraper")[0];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						scraper_dropdown.addEventListener("change", function(choice){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							submit(form);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						form.addEventListener("submit", function(e){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							e.preventDefault();
 | 
				
			||||||
 | 
							submit(e.srcElement);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function submit(e){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var GET = "";
 | 
				
			||||||
 | 
						var first = true;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if((s = document.getElementsByName("s")).length !== 0){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							GET += "?s=" + encodeURIComponent(s[0].value).replaceAll("%20", "+");
 | 
				
			||||||
 | 
							first = false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						Array.from(
 | 
				
			||||||
 | 
							e.getElementsByTagName("select")
 | 
				
			||||||
 | 
						).concat(
 | 
				
			||||||
 | 
							Array.from(
 | 
				
			||||||
 | 
								e.getElementsByTagName("input")
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						).forEach(function(el){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							var firstelem = el.getElementsByTagName("option");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								(
 | 
				
			||||||
 | 
									(
 | 
				
			||||||
 | 
										firstelem.length === 0 ||
 | 
				
			||||||
 | 
										firstelem[0].value != el.value
 | 
				
			||||||
 | 
									) &&
 | 
				
			||||||
 | 
									el.name != "" &&
 | 
				
			||||||
 | 
									el.value != "" &&
 | 
				
			||||||
 | 
									el.name != "s"
 | 
				
			||||||
 | 
								) ||
 | 
				
			||||||
 | 
								el.name == "scraper" ||
 | 
				
			||||||
 | 
								el.name == "nsfw"
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(first){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									GET += "?";
 | 
				
			||||||
 | 
									first = false;
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									GET += "&";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								GET += encodeURIComponent(el.name).replaceAll("%20", "+") + "=" + encodeURIComponent(el.value).replaceAll("%20", "+");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						window.location.href = GET;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
						Hide show more button when it's not needed on answers
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					var answer_div = document.getElementsByClassName("answer");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(answer_div.length !== 0){
 | 
				
			||||||
 | 
						answer_div = Array.from(answer_div);
 | 
				
			||||||
 | 
						var spoiler_button_div = Array.from(document.getElementsByClassName("spoiler-button"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// execute on pageload
 | 
				
			||||||
 | 
						hide_show_more();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						window.addEventListener("resize", hide_show_more);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						function hide_show_more(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							var height = window.innerWidth >= 1000 ? 600 : 200;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for(i=0; i<answer_div.length; i++){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(answer_div[i].scrollHeight < height){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									spoiler_button_div[i].style.display = "none";
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									document.getElementById(spoiler_button_div[i].htmlFor).checked = true;
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									spoiler_button_div[i].style.display = "block";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					switch(document.location.pathname){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						case "/web":
 | 
				
			||||||
 | 
						case "/web.php":
 | 
				
			||||||
 | 
							var image_class = "image";
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						case "/images":
 | 
				
			||||||
 | 
						case "/images.php":
 | 
				
			||||||
 | 
							var image_class = "thumb";
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							var image_class = null;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(image_class !== null){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Add popup to document
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						var popup_bg = document.createElement("div");
 | 
				
			||||||
 | 
						popup_bg.id = "popup-bg";
 | 
				
			||||||
 | 
						document.body.appendChild(popup_bg);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// enable/disable pointer events
 | 
				
			||||||
 | 
						if(!document.cookie.includes("bg_noclick=yes")){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							popup_bg.style.pointerEvents = "none";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var popup_status = document.createElement("div");
 | 
				
			||||||
 | 
						popup_status.id = "popup-status";
 | 
				
			||||||
 | 
						document.body.appendChild(popup_status);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var popup_body = document.createElement("div");
 | 
				
			||||||
 | 
						popup_body.id = "popup";
 | 
				
			||||||
 | 
						document.body.appendChild(popup_body);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// import popup
 | 
				
			||||||
 | 
						var popup_body = document.getElementById("popup");
 | 
				
			||||||
 | 
						var popup_status = document.getElementById("popup-status");
 | 
				
			||||||
 | 
						var popup_image = null; // is set later on popup click
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// image metadata
 | 
				
			||||||
 | 
						var collection = []; // will contain width, height, image URL
 | 
				
			||||||
 | 
						var collection_index = 0;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// event handling helper variables
 | 
				
			||||||
 | 
						var is_popup_shown = false;
 | 
				
			||||||
 | 
						var mouse_down = false;
 | 
				
			||||||
 | 
						var mouse_move = false;
 | 
				
			||||||
 | 
						var move_x = 0;
 | 
				
			||||||
 | 
						var move_y = 0;
 | 
				
			||||||
 | 
						var target_is_popup = false;
 | 
				
			||||||
 | 
						var mirror_x = false;
 | 
				
			||||||
 | 
						var mirror_y = false;
 | 
				
			||||||
 | 
						var rotation = 0;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Image dragging (mousedown)
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						document.addEventListener("mousedown", function(div){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(div.buttons !== 1){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							mouse_down = true;
 | 
				
			||||||
 | 
							mouse_move = false;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(is_click_within(div.target, "popup", true) === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								target_is_popup = false;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								target_is_popup = true;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var pos = popup_body.getBoundingClientRect();
 | 
				
			||||||
 | 
								move_x = div.x - pos.x;
 | 
				
			||||||
 | 
								move_y = div.y - pos.y;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Image dragging (mousemove)
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						document.addEventListener("mousemove", function(pos){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								target_is_popup &&
 | 
				
			||||||
 | 
								mouse_down
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								mouse_move = true;
 | 
				
			||||||
 | 
								movepopup(popup_body, pos.clientX - move_x, pos.clientY - move_y);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Image dragging (mouseup)
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						document.addEventListener("mouseup", function(){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							mouse_down = false;
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Image popup open
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						document.addEventListener("click", function(click){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// should our click trigger image open?
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								elem = is_click_within(click.target, image_class) ||
 | 
				
			||||||
 | 
								click.target.classList.contains("openimg")
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								event.preventDefault();
 | 
				
			||||||
 | 
								is_popup_shown = true;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// reset position params
 | 
				
			||||||
 | 
								mirror_x = false;
 | 
				
			||||||
 | 
								mirror_y = false;
 | 
				
			||||||
 | 
								rotation = 0;
 | 
				
			||||||
 | 
								scale = 60;
 | 
				
			||||||
 | 
								collection_index = 0;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// get popup data
 | 
				
			||||||
 | 
								if(elem === true){
 | 
				
			||||||
 | 
									// we clicked a simple image preview
 | 
				
			||||||
 | 
									elem = click.target;
 | 
				
			||||||
 | 
									var image_url = elem.getAttribute("src");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(image_url.startsWith("/proxy")){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										var match = image_url.match(/i=([^&]+)/);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(match !== null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											image_url = decodeURIComponent(match[1]);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										image_url = htmlspecialchars_decode(image_url);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var w = Math.round(click.target.naturalWidth);
 | 
				
			||||||
 | 
									var h = Math.round(click.target.naturalHeight);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										w === 0 ||
 | 
				
			||||||
 | 
										h === 0
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										w = 100;
 | 
				
			||||||
 | 
										h = 100;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									collection = [
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											"url": image_url,
 | 
				
			||||||
 | 
											"width": w,
 | 
				
			||||||
 | 
											"height": h
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var title = "No description provided";
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(click.target.title != ""){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										title = click.target.title;
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(click.target.alt != ""){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											title = click.target.alt;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(image_class == "thumb"){
 | 
				
			||||||
 | 
										// we're inside image.php
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										elem =
 | 
				
			||||||
 | 
											elem
 | 
				
			||||||
 | 
											.parentElement
 | 
				
			||||||
 | 
											.parentElement;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										var image_url = elem.getElementsByTagName("a")[1].href;
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// we're inside web.php
 | 
				
			||||||
 | 
										var image_url = elem.href;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									collection =
 | 
				
			||||||
 | 
										JSON.parse(
 | 
				
			||||||
 | 
											elem.getAttribute("data-json")
 | 
				
			||||||
 | 
										);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var imagesize = elem.getElementsByTagName("img")[0];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var imagesize_w = 0;
 | 
				
			||||||
 | 
									var imagesize_h = 0;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(imagesize.complete){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										imagesize_w = imagesize.naturalWidth;
 | 
				
			||||||
 | 
										imagesize_h = imagesize.naturalHeight;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										imagesize_w === 0 ||
 | 
				
			||||||
 | 
										imagesize_h === 0
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										imagesize_w = 100;
 | 
				
			||||||
 | 
										imagesize_h = 100;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									for(var i=0; i<collection.length; i++){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(collection[i].width === null){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											collection[i].width = imagesize_w;
 | 
				
			||||||
 | 
											collection[i].height = imagesize_h;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var title = elem.title;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// prepare HTML
 | 
				
			||||||
 | 
								var html =
 | 
				
			||||||
 | 
									'<div id="popup-num">(' + collection.length + ')</div>' + 
 | 
				
			||||||
 | 
									'<div id="popup-dropdown">' +
 | 
				
			||||||
 | 
										'<select name="viewer-res" onchange="changeimage(event)">';
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								for(i=0; i<collection.length; i++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(collection[i].url.startsWith("data:")){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										var domain = "<Base64 Data>";
 | 
				
			||||||
 | 
									}else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										var domain = new URL(collection[i].url).hostname;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									html += '<option value="' + i + '">' + '(' + collection[i].width + 'x' + collection[i].height + ') ' + domain + '</option>';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								popup_status.innerHTML =
 | 
				
			||||||
 | 
									html + '</select></div>' +
 | 
				
			||||||
 | 
									'<a href="' + htmlspecialchars(image_url) + '" rel="noreferrer nofollow "id="popup-title">' + htmlspecialchars(title) + '</a>';
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								popup_body.innerHTML =
 | 
				
			||||||
 | 
									'<img src="' + getproxylink(collection[0].url) + '" draggable="false" id="popup-image">';
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// make changes to DOM
 | 
				
			||||||
 | 
								popup_body.style.display = "block";
 | 
				
			||||||
 | 
								popup_bg.style.display = "block";
 | 
				
			||||||
 | 
								popup_status.style.display = "table";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// store for rotation functions & changeimage()
 | 
				
			||||||
 | 
								popup_image = document.getElementById("popup-image");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								scalepopup(collection[collection_index], scale);
 | 
				
			||||||
 | 
								centerpopup();
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// click inside the image viewer
 | 
				
			||||||
 | 
								// resize image
 | 
				
			||||||
 | 
								if(is_click_within(click.target, "popup", true)){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(mouse_move === false){
 | 
				
			||||||
 | 
										scale = 80;
 | 
				
			||||||
 | 
										scalepopup(collection[collection_index], scale);
 | 
				
			||||||
 | 
										centerpopup();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(is_click_within(click.target, "popup-status", true) === false){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// click outside the popup while its open
 | 
				
			||||||
 | 
										// close it
 | 
				
			||||||
 | 
										if(is_popup_shown){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											hidepopup();
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Scale image viewer
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						popup_body.addEventListener("wheel", function(scroll){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							event.preventDefault();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								scroll.altKey ||
 | 
				
			||||||
 | 
								scroll.ctrlKey ||
 | 
				
			||||||
 | 
								scroll.shiftKey
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var increment = 7;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var increment = 14;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(scroll.wheelDelta > 0){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// scrolling up
 | 
				
			||||||
 | 
								scale = scale + increment;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// scrolling down
 | 
				
			||||||
 | 
								if(scale - increment > 7){
 | 
				
			||||||
 | 
									scale = scale - increment;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// calculate relative size before scroll
 | 
				
			||||||
 | 
							var pos = popup_body.getBoundingClientRect();
 | 
				
			||||||
 | 
							var x = (scroll.x - pos.x) / pos.width;
 | 
				
			||||||
 | 
							var y = (scroll.y - pos.y) / pos.height;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							scalepopup(collection[collection_index], scale);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// move popup to % we found
 | 
				
			||||||
 | 
							pos = popup_body.getBoundingClientRect();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							movepopup(
 | 
				
			||||||
 | 
								popup_body,
 | 
				
			||||||
 | 
								scroll.clientX - (x * pos.width),
 | 
				
			||||||
 | 
								scroll.clientY - (y * pos.height)
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Keyboard controls
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						document.addEventListener("keydown", function(key){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// close popup
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								is_popup_shown &&
 | 
				
			||||||
 | 
								key.keyCode === 27
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								hidepopup();
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(is_popup_shown === false){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								key.altKey ||
 | 
				
			||||||
 | 
								key.ctrlKey ||
 | 
				
			||||||
 | 
								key.shiftKey
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// mirror image
 | 
				
			||||||
 | 
								switch(key.keyCode){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 37:
 | 
				
			||||||
 | 
										// left
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										mirror_x = true;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 38:
 | 
				
			||||||
 | 
										// up
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										mirror_y = false;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 39:
 | 
				
			||||||
 | 
										// right
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										mirror_x = false;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 40:
 | 
				
			||||||
 | 
										// down
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										mirror_y = true;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// rotate image
 | 
				
			||||||
 | 
								switch(key.keyCode){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 37:
 | 
				
			||||||
 | 
										// left
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										rotation = -90;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 38:
 | 
				
			||||||
 | 
										// up
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										rotation = 0;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 39:
 | 
				
			||||||
 | 
										// right
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										rotation = 90;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case 40:
 | 
				
			||||||
 | 
										// down
 | 
				
			||||||
 | 
										key.preventDefault();
 | 
				
			||||||
 | 
										rotation = -180;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							popup_image.style.transform =
 | 
				
			||||||
 | 
								"scale(" +
 | 
				
			||||||
 | 
									(mirror_x ? "-1" : "1") +
 | 
				
			||||||
 | 
									", " +
 | 
				
			||||||
 | 
									(mirror_y ? "-1" : "1") +
 | 
				
			||||||
 | 
								") " +
 | 
				
			||||||
 | 
								"rotate(" +
 | 
				
			||||||
 | 
									rotation + "deg" +
 | 
				
			||||||
 | 
								")";
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function getproxylink(url){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if(url.startsWith("data:")){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return htmlspecialchars(url);
 | 
				
			||||||
 | 
						}else{
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return '/proxy?i=' + encodeURIComponent(url);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function hidepopup(){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						is_popup_shown = false;
 | 
				
			||||||
 | 
						popup_status.style.display = "none";
 | 
				
			||||||
 | 
						popup_body.style.display = "none";
 | 
				
			||||||
 | 
						popup_bg.style.display = "none";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function scalepopup(size, scale){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var ratio =
 | 
				
			||||||
 | 
							Math.min(
 | 
				
			||||||
 | 
								(window.innerWidth * (scale / 100)) / collection[collection_index].width, (window.innerHeight * (scale / 100)) / collection[collection_index].height
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						popup_body.style.width = size.width * ratio + "px";
 | 
				
			||||||
 | 
						popup_body.style.height = size.height * ratio + "px";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function centerpopup(){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						var size = popup_body.getBoundingClientRect();
 | 
				
			||||||
 | 
						var size = {
 | 
				
			||||||
 | 
							"width": parseInt(size.width),
 | 
				
			||||||
 | 
							"height": parseInt(size.height)
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						movepopup(
 | 
				
			||||||
 | 
							popup_body,
 | 
				
			||||||
 | 
							(window.innerWidth / 2) - (size.width / 2),
 | 
				
			||||||
 | 
							(window.innerHeight / 2) - (size.height / 2)
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function movepopup(popup_body, x, y){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						popup_body.style.left = x + "px";
 | 
				
			||||||
 | 
						popup_body.style.top = y + "px";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function changeimage(event){
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// reset rotation params
 | 
				
			||||||
 | 
						mirror_x = false;
 | 
				
			||||||
 | 
						mirror_y = false;
 | 
				
			||||||
 | 
						rotation = 0;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						scale = 60;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						collection_index = parseInt(event.target.value);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// we set innerHTML otherwise old image lingers a little
 | 
				
			||||||
 | 
						popup_body.innerHTML =
 | 
				
			||||||
 | 
							'<img src="' + getproxylink(collection[collection_index].url) + '" draggable="false" id="popup-image">';
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// store for rotation functions & changeimage()
 | 
				
			||||||
 | 
						popup_image = document.getElementById("popup-image");
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						scalepopup(collection[collection_index], scale);
 | 
				
			||||||
 | 
						centerpopup();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var searchbox_wrapper = document.getElementsByClassName("searchbox");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(searchbox_wrapper.length !== 0){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						searchbox_wrapper = searchbox_wrapper[0];
 | 
				
			||||||
 | 
						var searchbox = searchbox_wrapper.getElementsByTagName("input")[1];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Textarea shortcuts
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						document.addEventListener("keydown", function(key){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							switch(key.keyCode){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								case 191:
 | 
				
			||||||
 | 
									// 191 = /
 | 
				
			||||||
 | 
									if(document.activeElement.tagName == "INPUT"){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// already focused, ignore
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(
 | 
				
			||||||
 | 
										typeof is_popup_shown != "undefined" &&
 | 
				
			||||||
 | 
										is_popup_shown
 | 
				
			||||||
 | 
									){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										hidepopup();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									window.scrollTo(0, 0);
 | 
				
			||||||
 | 
									searchbox.focus();
 | 
				
			||||||
 | 
									key.preventDefault();
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							Autocompleter
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						if( // make sure the user wants it
 | 
				
			||||||
 | 
							document.cookie.includes("scraper_ac=") &&
 | 
				
			||||||
 | 
							document.cookie.includes("scraper_ac=disabled") === false
 | 
				
			||||||
 | 
						){
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							var autocomplete_cache = [];
 | 
				
			||||||
 | 
							var focuspos = -1;
 | 
				
			||||||
 | 
							var list = [];
 | 
				
			||||||
 | 
							var autocomplete_div = document.getElementsByClassName("autocomplete")[0];
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(
 | 
				
			||||||
 | 
								document.cookie.includes("scraper_ac=auto") &&
 | 
				
			||||||
 | 
								typeof scraper_dropdown != "undefined"
 | 
				
			||||||
 | 
							){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var ac_req_appendix = "&scraper=" + scraper_dropdown.value;
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var ac_req_appendix = "";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							function getsearchboxtext(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var value =
 | 
				
			||||||
 | 
									searchbox.value
 | 
				
			||||||
 | 
									.trim()
 | 
				
			||||||
 | 
									.replace(
 | 
				
			||||||
 | 
										/ +/g,
 | 
				
			||||||
 | 
										" "
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
									.toLowerCase();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return value;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							searchbox.addEventListener("input", async function(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// ratelimit on input only
 | 
				
			||||||
 | 
								// dont ratelimit if we already have res
 | 
				
			||||||
 | 
								if(typeof autocomplete_cache[getsearchboxtext()] != "undefined"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									await getac();
 | 
				
			||||||
 | 
								}else{
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									await getac_ratelimit();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							async function getac(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								var curvalue = getsearchboxtext();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(curvalue == ""){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// hide autocompleter
 | 
				
			||||||
 | 
									autocomplete_div.style.display = "none";
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(typeof autocomplete_cache[curvalue] == "undefined"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									/*
 | 
				
			||||||
 | 
										Fetch autocomplete
 | 
				
			||||||
 | 
									*/
 | 
				
			||||||
 | 
									// make sure we dont fetch same thing twice
 | 
				
			||||||
 | 
									autocomplete_cache[curvalue] = [];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var res = await fetch("/api/v1/ac?s=" + (encodeURIComponent(curvalue).replaceAll("%20", "+")) + ac_req_appendix);
 | 
				
			||||||
 | 
									if(!res.ok){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									var json = await res.json();
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									autocomplete_cache[curvalue] = json[1];
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(curvalue == getsearchboxtext()){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										render_ac(curvalue, autocomplete_cache[curvalue]);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								render_ac(curvalue, autocomplete_cache[curvalue]);	
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							var ac_func = null;
 | 
				
			||||||
 | 
							function getac_ratelimit(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return new Promise(async function(resolve, reject){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if(ac_func !== null){
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										clearTimeout(ac_func);
 | 
				
			||||||
 | 
									}//else{
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// no ratelimits
 | 
				
			||||||
 | 
										//getac();
 | 
				
			||||||
 | 
									//}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									ac_func =
 | 
				
			||||||
 | 
										setTimeout(function(){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											ac_func = null;
 | 
				
			||||||
 | 
											getac(); // get results after 100ms of no keystroke
 | 
				
			||||||
 | 
											resolve();
 | 
				
			||||||
 | 
										}, 200);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							function render_ac(query, list){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(list.length === 0){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									autocomplete_div.style.display = "none";
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								html = "";
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// prepare regex
 | 
				
			||||||
 | 
								var highlight = query.split(" ");
 | 
				
			||||||
 | 
								var regex = [];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								for(var k=0; k<highlight.length; k++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// espace regex
 | 
				
			||||||
 | 
									regex.push(
 | 
				
			||||||
 | 
										highlight[k].replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
 | 
				
			||||||
 | 
									);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								regex = new RegExp(highlight.join("|"), "gi");
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								for(var i=0; i<list.length; i++){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									html +=
 | 
				
			||||||
 | 
										'<div tabindex="0" class="entry" onclick="handle_entry_click(this);">' +
 | 
				
			||||||
 | 
											htmlspecialchars(
 | 
				
			||||||
 | 
												list[i]
 | 
				
			||||||
 | 
											).replace(
 | 
				
			||||||
 | 
												regex,
 | 
				
			||||||
 | 
												'<u>$&</u>'
 | 
				
			||||||
 | 
											) +
 | 
				
			||||||
 | 
										'</div>';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								autocomplete_div.innerHTML = html;
 | 
				
			||||||
 | 
								autocomplete_div.style.display = "block";
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							var should_focus = false;
 | 
				
			||||||
 | 
							document.addEventListener("keydown", function(event){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(event.key == "Escape"){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									document.activeElement.blur();
 | 
				
			||||||
 | 
									focuspos = -1;
 | 
				
			||||||
 | 
									autocomplete_div.style.display = "none";
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(
 | 
				
			||||||
 | 
									is_click_within(event.target, "searchbox") === false ||
 | 
				
			||||||
 | 
									typeof autocomplete_cache[getsearchboxtext()] == "undefined"
 | 
				
			||||||
 | 
								){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								switch(event.key){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "ArrowUp":
 | 
				
			||||||
 | 
										event.preventDefault();
 | 
				
			||||||
 | 
										focuspos--;
 | 
				
			||||||
 | 
										if(focuspos === -2){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											focuspos = autocomplete_cache[getsearchboxtext()].length - 1;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "ArrowDown":
 | 
				
			||||||
 | 
									case "Tab":
 | 
				
			||||||
 | 
										event.preventDefault();
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										focuspos++;
 | 
				
			||||||
 | 
										if(focuspos >= autocomplete_cache[getsearchboxtext()].length){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											focuspos = -1;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									case "Enter":
 | 
				
			||||||
 | 
										should_focus = true;
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if(focuspos !== -1){
 | 
				
			||||||
 | 
											
 | 
				
			||||||
 | 
											// replace input content
 | 
				
			||||||
 | 
											event.preventDefault();
 | 
				
			||||||
 | 
											searchbox.value =
 | 
				
			||||||
 | 
												autocomplete_div.getElementsByClassName("entry")[focuspos].innerText;
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									default:
 | 
				
			||||||
 | 
										focuspos = -1;
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if(focuspos === -1){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									searchbox.focus();
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								autocomplete_div.getElementsByClassName("entry")[focuspos].focus();
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							window.addEventListener("blur", function(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								autocomplete_div.style.display = "none";
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							document.addEventListener("keyup", function(event){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// handle ENTER key on entry
 | 
				
			||||||
 | 
								if(should_focus){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									should_focus = false;
 | 
				
			||||||
 | 
									searchbox.focus();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							document.addEventListener("mousedown", function(event){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// hide input if click is outside
 | 
				
			||||||
 | 
								if(is_click_within(event.target, "searchbox") === false){
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									autocomplete_div.style.display = "none";
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							function handle_entry_click(event){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								searchbox.value = event.innerText;
 | 
				
			||||||
 | 
								focuspos = -1;
 | 
				
			||||||
 | 
								searchbox.focus();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							searchbox.addEventListener("focus", function(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								focuspos = -1;
 | 
				
			||||||
 | 
								getac();
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								static/icon/amazon.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/appstore.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/call.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 2.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/directions.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.6 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/facebook.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 555 B  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/gamespot.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.6 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/github.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 508 B  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/googleplay.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/imdb.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/instagram.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/itunes.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/microsoft.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/quora.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 835 B  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/reddit.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/rottentomatoes.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 468 B  | 
							
								
								
									
										
											BIN
										
									
								
								static/icon/sciencedirect.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 354 B  |