From 849eaeb50edd2fd06866578d4f93abb5193ffd01 Mon Sep 17 00:00:00 2001 From: Tobias Alexander Franke Date: Sun, 16 Jun 2019 20:21:48 +0200 Subject: [PATCH] [SteamCommunityBridge] Add Workshop category (#1172) --- bridges/SteamCommunityBridge.php | 72 ++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/bridges/SteamCommunityBridge.php b/bridges/SteamCommunityBridge.php index 56ea257c..9919a4b5 100644 --- a/bridges/SteamCommunityBridge.php +++ b/bridges/SteamCommunityBridge.php @@ -20,7 +20,8 @@ class SteamCommunityBridge extends BridgeAbstract { 'values' => array( 'Artwork' => 'images', 'Screenshots' => 'screenshots', - 'Videos' => 'videos' + 'Videos' => 'videos', + 'Workshop' => 'workshop' ) ) ) @@ -32,7 +33,7 @@ class SteamCommunityBridge extends BridgeAbstract { protected function getMainPage() { $category = $this->getInput('category'); - $html = getSimpleHTMLDOM($this->getURI() . '/?p=1&browsefilter=mostrecent') + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not fetch Steam data.'); return $html; @@ -56,12 +57,17 @@ class SteamCommunityBridge extends BridgeAbstract { } public function getURI() { + if ($this->getInput('category') === 'workshop') + return self::URI . '/workshop/browse/?appid=' + . $this->getInput('i') . '&browsesort=mostrecent'; + return self::URI . '/app/' . $this->getInput('i') . '/' - . $this->getInput('category'); + . $this->getInput('category') + . '/?p=1&browsefilter=mostrecent'; } - public function collectData() { + private function collectMedia() { $category = $this->getInput('category'); $html = $this->getMainPage(); $cards = $html->find('div.apphub_Card'); @@ -124,4 +130,62 @@ class SteamCommunityBridge extends BridgeAbstract { break; } } + + private function collectWorkshop() { + $category = $this->getInput('category'); + $html = $this->getMainPage(); + $workShopItems = $html->find('div.workshopItem'); + + foreach($workShopItems as $workShopItem) { + $author = $workShopItem->find('div.workshopItemAuthorName', 0)->find('a', 0); + $author = $author->innertext; + + $fileRating = $workShopItem->find('img.fileRating', 0); + + $uri = $workShopItem->find('a.ugc', 0)->getAttribute('href'); + + $htmlItem = getSimpleHTMLDOMCached($uri); + + $title = $htmlItem->find('div.workshopItemTitle', 0)->innertext; + $date = $htmlItem->find('div.detailsStatRight', 0)->innertext; + $description = $htmlItem->find('div.workshopItemDescription', 0)->innertext; + + $previewImage = $htmlItem->find('#previewImage', 0); + + $htmlTags = $htmlItem->find('div.workshopTags'); + + $tags = ''; + + foreach($htmlTags as $htmlTag) { + if ($tags !== '') + $tags .= ','; + + $tags .= $htmlTag->find('a', 0)->innertext; + } + + // create item + $item = array(); + $item['title'] = $title; + $item['uri'] = $uri; + $item['timestamp'] = strtotime($date); + $item['author'] = $author; + $item['categories'] = $category; + + $item['content'] = '

' + . $previewImage . '

' . $fileRating + . '

' . $description . '

'; + + $this->items[] = $item; + + if (count($this->items) >= 10) + break; + } + } + + public function collectData() { + if ($this->getInput('category') === 'workshop') + $this->collectWorkshop(); + else + $this->collectMedia(); + } }