Skip to content

Instantly share code, notes, and snippets.

@fionera
Created November 10, 2018 16:57
Show Gist options
  • Save fionera/e55cf1356a4a23601d265978436623b2 to your computer and use it in GitHub Desktop.
Save fionera/e55cf1356a4a23601d265978436623b2 to your computer and use it in GitHub Desktop.
YivesMirrorCrawler
<?php
include_once 'vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$client = new React\HttpClient\Client($loop);
function crawlSoftwareTypes()
{
global $client;
$request = $client->request('GET', 'https://yivesmirror.com/api/list/all');
$request->on('response', function ($response) {
$softwareTypes = '';
$response->on('data', function ($chunk) use (&$softwareTypes) {
$softwareTypes .= $chunk;
});
$response->on('end', function () use (&$softwareTypes) {
$softwareTypes = json_decode($softwareTypes, true);
foreach ($softwareTypes as $softwareType) {
crawlVersionList($softwareType);
}
});
});
$request->end();
}
function crawlVersionList(string $softwareType)
{
global $client;
$request = $client->request('GET', 'https://yivesmirror.com/api/list/' . $softwareType);
$request->on('response', function ($response) use ($softwareType) {
$versions = '';
$response->on('data', function ($chunk) use (&$versions) {
$versions .= $chunk;
});
$response->on('end', function () use (&$versions, $softwareType) {
$versions = json_decode($versions, true);
foreach ($versions as $version) {
crawlInfo($softwareType, $version);
}
});
});
$request->end();
}
function crawlInfo(string $softwareType, string $version)
{
global $client;
$request = $client->request('GET', 'https://yivesmirror.com/api/file/' . $softwareType . '/' . $version);
$request->on('response', function ($response) {
$info = '';
$response->on('data', function ($chunk) use (&$info) {
$info .= $chunk;
});
$response->on('end', function () use (&$info) {
$info = json_decode($info, true);
$link = $info['direct_link'] . "\n";
file_put_contents('links.txt', $link, FILE_APPEND | LOCK_EX);
});
});
$request->end();
}
crawlSoftwareTypes();
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment