Rss-Bridge/bridges/SteamBridge.php

133 lines
3 KiB
PHP
Raw Normal View History

2017-07-17 15:45:58 +02:00
<?php
class SteamBridge extends BridgeAbstract {
const NAME = 'Steam Bridge';
2018-03-07 11:24:33 +01:00
const URI = 'https://store.steampowered.com/';
2017-07-17 15:45:58 +02:00
const CACHE_TIMEOUT = 3600; // 1h
const DESCRIPTION = 'Returns games list';
const MAINTAINER = 'jacknumber';
const PARAMETERS = array(
'Wishlist' => array(
'username' => array(
'name' => 'Username',
'required' => true,
),
'currency' => array(
'name' => 'Currency',
'type' => 'list',
'values' => array(
// source: http://steam.steamlytics.xyz/currencies
'USD' => 'us',
'GBP' => 'gb',
'EUR' => 'fr',
'CHF' => 'ch',
'RUB' => 'ru',
'BRL' => 'br',
'JPY' => 'jp',
'SEK' => 'se',
'IDR' => 'id',
'MYR' => 'my',
'PHP' => 'ph',
'SGD' => 'sg',
'THB' => 'th',
'KRW' => 'kr',
'TRY' => 'tr',
'MXN' => 'mx',
'CAD' => 'ca',
'NZD' => 'nz',
'CNY' => 'cn',
'INR' => 'in',
'CLP' => 'cl',
'PEN' => 'pe',
'COP' => 'co',
'ZAR' => 'za',
'HKD' => 'hk',
'TWD' => 'tw',
'SRD' => 'sr',
'AED' => 'ae',
),
),
'sort' => array(
'name' => 'Sort by',
'type' => 'list',
'values' => array(
'Rank' => 'rank',
'Date Added' => 'added',
'Name' => 'name',
'Price' => 'price',
)
),
'only_discount' => array(
'name' => 'Only discount',
'type' => 'checkbox',
)
)
);
public function collectData(){
$username = $this->getInput('username');
$params = array(
2018-03-07 11:24:33 +01:00
'cc' => $this->getInput('currency'),
'sort' => $this->getInput('sort')
2017-07-17 15:45:58 +02:00
);
2018-03-07 11:24:33 +01:00
$url = self::URI . 'wishlist/id/' . $username . '/?' . http_build_query($params);
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$jsonDataRegex = '/var g_rg(?:WishlistData|AppInfo) = ([^;]*)/';
$content = getContents($url)
2017-07-17 15:45:58 +02:00
or returnServerError("Could not request Steam Wishlist. Tried:\n - $url");
2018-03-07 11:24:33 +01:00
preg_match_all($jsonDataRegex, $content, $matches, PREG_SET_ORDER, 0);
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$appList = json_decode($matches[0][1], true);
$fullAppList = json_decode($matches[1][1], true);
//var_dump($matches[1][1]);
//var_dump($fullAppList);
$sortedElementList = array_fill(0, count($appList), 0);
foreach($appList as $app) {
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$sortedElementList[$app["priority"] - 1] = $app["appid"];
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
}
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
foreach($sortedElementList as $appId) {
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$app = $fullAppList[$appId];
$gameTitle = $app["name"];
$gameUri = "http://store.steampowered.com/app/" . $appId . "/";
$gameImg = $app["capsule"];
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$item = array();
$item['uri'] = $gameUri;
$item['title'] = $gameTitle;
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
if(count($app["subs"]) > 0) {
if($app["subs"][0]["discount_pct"] != 0) {
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$item['promoValue'] = $app["subs"][0]["discount_pct"];
$item['oldPrice'] = $app["subs"][0]["price"] / 100 / ((100 - $gamePromoValue / 100));
$item['newPrice'] = $app["subs"][0]["price"] / 100;
$item['price'] = $item['newPrice'];
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$item['hasPromo'] = true;
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
} else {
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
if($this->getInput('only_discount')) {
continue;
}
2017-07-17 15:45:58 +02:00
2018-03-07 11:24:33 +01:00
$item['price'] = $app["subs"][0]["price"] / 100;
$item['hasPromo'] = false;
}
2017-07-17 15:45:58 +02:00
}
$this->items[] = $item;
2018-03-07 11:24:33 +01:00
2017-07-17 15:45:58 +02:00
}
2018-03-07 11:24:33 +01:00
2017-07-17 15:45:58 +02:00
}
}