Big torrents list

I make a little script based on Scraper & Kernel. This script crawl YTS website for found all torrents.

Installation

composer require mediashare/kernel
composer require mediashare/scraper
Bash

Script

<?php
// ./index.php
require 'vendor/autoload.php';

use Mediashare\Kernel\Kernel;
use Mediashare\Scraper\Scraper;

$url = "https://yts.vc/movie/the-lion-king-2019-319eeb/";
$crawler = new class {
    public $crawled = [];
    public $urls = [];
    public $torrents = [];
    public functio run(string $url) {
        $kernel = new Kernel();
        $kernel->run();
        $output = $kernel->get('Output');
        $this->scrape($url);
        while (count($this->urls)) {
            foreach ($this->urls as $url) {
                $output->progressBar(
                    count($this->crawled), 
                    (count($this->crawled) + count($this->urls)), 
                    '['.count($this->crawled).'/'.(count($this->crawled) + count($this->urls)).']'.' '.$url);
                $this->scrape($url);
            }
        }
    }

    public function scrape(string $url) {
        $this->crawled[$url] = $url;
        $scraper = new Scraper($url);
        $scraper->run();
        $this->getUrls($scraper);
        unset($this->urls[$url]);
        $this->getTorrents($scraper);
    }

    public function getUrls(Scraper $scraper) {
        foreach ($scraper->webpage->links as $link) {
            $isExcluded = false;
            $link = (string) $link;
            if (strpos($link, 'https://yts.vc') === false):
                $isExcluded = true;
            elseif (strpos($link, '/assets/') || strpos($link, '/magnet:?')):
                $isExcluded = true;
            elseif (!empty($this->crawled[$link])):
                $isExcluded = true;
            endif;
            if (!$isExcluded):
                $this->urls[$link] = $link;
            endif;
        }
    }

    public function getTorrents(Scraper $scraper) {
        $found = false;
        foreach ($scraper->webpage->links as $link) {
            $link = (string) $link;
            if (strpos($link, '/assets/torrents/')):
                $found = true;
                $this->torrents[$link] = [
                    'title' => $scraper->dom->filter('h1')->text(),
                    'url' => $link
                ];
            endif;
        }
        if ($found):
            $this->write();
        endif;
    }

    public function write() {
        $file = fopen("torrents.json", "w") or die("Unable to open file!");
        fwrite($file, json_encode($this->torrents));
        fclose($file);
    }
};
$crawler->run($url);
PHP

Run crawler & get all torrents from YTS

php index.php
Bash

Output is torrents.json file with titles & torrents url in array.


MarquandT

Ethical Hacker ~ Web Developper ~ Hosting Provider ~ Crypto Enthusiast ~ Automation Expert Bitcoin donation: 32Uu4NKGnxSPC7UukYXVyRHwbppbQpKVki

Comments

You must login to send a comment.