/** * Parse curse.com HTML for project properties * * @param string $html * @return array */ public function parse($html) { $this->crawler->add($html); // Return null if this isn't a content page if (!$this->crawler->filter('ul.details-list .game')->exists()) { return null; } $properties = ['title' => $this->crawler->filter('meta[property="og:title"]')->attr('content'), 'game' => $this->crawler->filter('ul.details-list .game')->text(), 'category' => $this->crawler->filter('#breadcrumbs-wrapper ul.breadcrumbs li a')->eq(2)->text(), 'url' => $this->crawler->filter('meta[property="og:url"]')->attr('content'), 'thumbnail' => $this->crawler->filter('meta[property="og:image"]')->attr('content'), 'authors' => $this->crawler->filter('ul.authors li a')->each(function ($node, $i) { return $node->text(); }), 'downloads' => ['monthly' => $this->crawler->filter('ul.details-list .average-downloads')->number(), 'total' => $this->crawler->filter('ul.details-list .downloads')->number()], 'favorites' => $this->crawler->filter('ul.details-list .favorited')->number(), 'likes' => $this->crawler->filter('li.grats span.project-rater')->number(), 'updated_at' => $this->crawler->filter('ul.details-list .updated .standard-date')->eq(0)->attrAsTime('data-epoch'), 'created_at' => $this->crawler->filter('ul.details-list .updated .standard-date')->eq(1)->attrAsTime('data-epoch'), 'project_url' => $this->crawler->filter('ul.details-list .curseforge a')->attr('href'), 'release_type' => $this->crawler->filter('ul.details-list .release')->value(), 'license' => $this->crawler->filter('ul.details-list .license')->value(), 'files' => $this->crawler->filter('table.project-file-listing tr')->eachWithoutNull(function ($node, $i) { if ($i === 0) { return; } // skip the table heading return ['id' => (int) $node->filter('td a')->eq(0)->finalUrlSegment('href'), 'url' => 'http://curse.com' . $node->filter('td a')->eq(0)->attr('href'), 'name' => $node->filter('td a')->eq(0)->text(), 'type' => strtolower($node->filter('td')->eq(1)->text()), 'version' => $node->filter('td')->eq(2)->text(), 'downloads' => $node->filter('td')->eq(3)->number(), 'created_at' => $node->filter('td .standard-date')->attrAsTime('data-epoch')]; })]; return $properties; }