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
1
2

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 function run(string $url) {
        $kernel = new Kernel();
        $kernel->run();
        $this->scrape($url);
        while (count($this->urls)) {
            foreach ($this->urls as $url) {
                $output = $kernel->get('Output');
                $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);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

Run crawler & get all torrents from YTS

php index.php
1

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

Last Updated: 1/3/2020, 7:47:51 AM