-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Ahmard/scraper/new
- Loading branch information
Showing
4 changed files
with
122 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use Uticlass\Others\FireFiles; | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
$webpageUrl = 'https://firefiles.org/5m6rzmnb7v54'; //The Mandalorian S01E06 | ||
|
||
$fileLink = FireFiles::init($webpageUrl)->get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
|
||
namespace Uticlass\Others; | ||
|
||
|
||
use Guzwrap\Core\Post; | ||
use Guzwrap\Core\Redirect; | ||
use Guzwrap\Request; | ||
use GuzzleHttp\Cookie\CookieJar; | ||
use Psr\Http\Message\ResponseInterface; | ||
use QL\Dom\Elements; | ||
use Queliwrap\Client; | ||
use Uticlass\Core\Scraper; | ||
|
||
/** | ||
* Class FireFiles | ||
* @package Uticlass\Others | ||
* @link https://firefiles.org/ | ||
*/ | ||
class FireFiles extends Scraper | ||
{ | ||
private ?string $firstRedirectedUrl = null; | ||
|
||
private string $domain = 'https://firefiles.org'; | ||
|
||
public function __construct(string $url) | ||
{ | ||
parent::__construct($url); | ||
|
||
$this->useRequest( | ||
Request::withCookie(new CookieJar()) | ||
->redirects(function (Redirect $redirect) { | ||
$redirect->max(10); | ||
}) | ||
); | ||
} | ||
|
||
public function get(): string | ||
{ | ||
$inputs = []; | ||
Client::get($this->url) | ||
->useRequest($this->request) | ||
->onHeaders(function (ResponseInterface $response) { | ||
if (!$this->firstRedirectedUrl) { | ||
$this->firstRedirectedUrl = $this->domain . $response->getHeaderLine('Location'); | ||
} | ||
}) | ||
->execute() | ||
->find('#container > form input') | ||
->each(function (Elements $input) use (&$inputs) { | ||
$inputs[$input->attr('name')] = $input->attr('value'); | ||
}); | ||
|
||
return $this->secondPage($inputs); | ||
} | ||
|
||
private function secondPage(array $inputs) | ||
{ | ||
$secondInputs = []; | ||
Client::post(function (Post $post) use ($inputs) { | ||
$post->url($this->firstRedirectedUrl); | ||
foreach ($inputs as $name => $value) { | ||
$post->field($name, $value); | ||
} | ||
}) | ||
->useRequest($this->request) | ||
->execute() | ||
->find('form input') | ||
->each(function (Elements $input) use (&$secondInputs) { | ||
$secondInputs[$input->attr('name')] = $input->attr('value'); | ||
}); | ||
|
||
return $this->thirdPage($secondInputs); | ||
} | ||
|
||
private function thirdPage(array $inputs): string | ||
{ | ||
$buttonOnClickAttr = Client::post(function (Post $post) use ($inputs) { | ||
$post->url($this->firstRedirectedUrl); | ||
foreach ($inputs as $name => $value) { | ||
$post->field($name, $value); | ||
} | ||
}) | ||
->useRequest($this->request) | ||
->execute() | ||
->find('button[id="downloadbtn"]') | ||
->attr('onclick'); | ||
|
||
preg_match("@window\.open\('(.*)','_self'\)@", $buttonOnClickAttr, $matches); | ||
|
||
return $matches[1]; | ||
} | ||
} |