parent
52dfa3fe76
commit
cb91cd5d2f
1 changed files with 70 additions and 45 deletions
|
@ -4,7 +4,7 @@ class SteamBridge extends BridgeAbstract {
|
||||||
const NAME = 'Steam Bridge';
|
const NAME = 'Steam Bridge';
|
||||||
const URI = 'https://store.steampowered.com/';
|
const URI = 'https://store.steampowered.com/';
|
||||||
const CACHE_TIMEOUT = 3600; // 1h
|
const CACHE_TIMEOUT = 3600; // 1h
|
||||||
const DESCRIPTION = 'Returns games list';
|
const DESCRIPTION = 'Returns apps list';
|
||||||
const MAINTAINER = 'jacknumber';
|
const MAINTAINER = 'jacknumber';
|
||||||
const PARAMETERS = array(
|
const PARAMETERS = array(
|
||||||
'Wishlist' => array(
|
'Wishlist' => array(
|
||||||
|
@ -47,16 +47,6 @@ class SteamBridge extends BridgeAbstract {
|
||||||
'AED' => 'ae',
|
'AED' => 'ae',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'sort' => array(
|
|
||||||
'name' => 'Sort by',
|
|
||||||
'type' => 'list',
|
|
||||||
'values' => array(
|
|
||||||
'Rank' => 'rank',
|
|
||||||
'Date Added' => 'added',
|
|
||||||
'Name' => 'name',
|
|
||||||
'Price' => 'price',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'only_discount' => array(
|
'only_discount' => array(
|
||||||
'name' => 'Only discount',
|
'name' => 'Only discount',
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
|
@ -68,49 +58,44 @@ class SteamBridge extends BridgeAbstract {
|
||||||
|
|
||||||
$username = $this->getInput('username');
|
$username = $this->getInput('username');
|
||||||
$params = array(
|
$params = array(
|
||||||
'cc' => $this->getInput('currency'),
|
'cc' => $this->getInput('currency')
|
||||||
'sort' => $this->getInput('sort')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$url = self::URI . 'wishlist/id/' . $username . '/?' . http_build_query($params);
|
$url = self::URI . 'wishlist/id/' . $username . '?' . http_build_query($params);
|
||||||
|
|
||||||
$jsonDataRegex = '/var g_rg(?:WishlistData|AppInfo) = ([^;]*)/';
|
$targetVariable = 'g_rgAppInfo';
|
||||||
$content = getContents($url)
|
$sort = array();
|
||||||
|
|
||||||
|
$html = '';
|
||||||
|
$html = getSimpleHTMLDOM($url)
|
||||||
or returnServerError("Could not request Steam Wishlist. Tried:\n - $url");
|
or returnServerError("Could not request Steam Wishlist. Tried:\n - $url");
|
||||||
|
|
||||||
preg_match_all($jsonDataRegex, $content, $matches, PREG_SET_ORDER, 0);
|
$jsContent = $html->find('.responsive_page_template_content script', 0)->innertext;
|
||||||
|
|
||||||
$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) {
|
|
||||||
|
|
||||||
$sortedElementList[$app["priority"] - 1] = $app["appid"];
|
|
||||||
|
|
||||||
|
if(preg_match('/var ' . $targetVariable . ' = (.*?);/s', $jsContent, $matches)) {
|
||||||
|
$appsData = json_decode($matches[1]);
|
||||||
|
} else {
|
||||||
|
returnServerError("Could not parse JS variable ($targetVariable) in page content.");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($sortedElementList as $appId) {
|
foreach($appsData as $id => $element) {
|
||||||
|
|
||||||
$app = $fullAppList[$appId];
|
$appType = $element->type;
|
||||||
$gameTitle = $app["name"];
|
$appIsBuyable = 0;
|
||||||
$gameUri = "http://store.steampowered.com/app/" . $appId . "/";
|
$appHasDiscount = 0;
|
||||||
$gameImg = $app["capsule"];
|
$appIsFree = 0;
|
||||||
|
|
||||||
$item = array();
|
if($element->subs) {
|
||||||
$item['uri'] = $gameUri;
|
$appIsBuyable = 1;
|
||||||
$item['title'] = $gameTitle;
|
|
||||||
|
|
||||||
if(count($app["subs"]) > 0) {
|
if($element->subs[0]->discount_pct) {
|
||||||
if($app["subs"][0]["discount_pct"] != 0) {
|
|
||||||
|
|
||||||
$item['promoValue'] = $app["subs"][0]["discount_pct"];
|
$appHasDiscount = 1;
|
||||||
$item['oldPrice'] = $app["subs"][0]["price"] / 100 / ((100 - $gamePromoValue / 100));
|
$discountBlock = str_get_html($element->subs[0]->discount_block);
|
||||||
$item['newPrice'] = $app["subs"][0]["price"] / 100;
|
$appDiscountValue = $discountBlock->find('.discount_pct', 0)->plaintext;
|
||||||
$item['price'] = $item['newPrice'];
|
$appOldPrice = $discountBlock->find('.discount_original_price', 0)->plaintext;
|
||||||
|
$appNewPrice = $discountBlock->find('.discount_final_price', 0)->plaintext;
|
||||||
$item['hasPromo'] = true;
|
$appPrice = $appNewPrice;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -118,15 +103,55 @@ class SteamBridge extends BridgeAbstract {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['price'] = $app["subs"][0]["price"] / 100;
|
$appPrice = $element->subs[0]->price / 100;
|
||||||
$item['hasPromo'] = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if($this->getInput('only_discount')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($element->free) && $element->free = 1) {
|
||||||
|
$appIsFree = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = array();
|
||||||
|
$item['uri'] = "http://store.steampowered.com/app/$id/";
|
||||||
|
$item['title'] = $element->name;
|
||||||
|
$item['type'] = $appType;
|
||||||
|
$item['cover'] = str_replace('_292x136', '', $element->capsule);
|
||||||
|
$item['timestamp'] = $element->added;
|
||||||
|
$item['isBuyable'] = $appIsBuyable;
|
||||||
|
$item['hasDiscount'] = $appHasDiscount;
|
||||||
|
$item['isFree'] = $appIsFree;
|
||||||
|
$item['priority'] = $element->priority;
|
||||||
|
|
||||||
|
if($appIsBuyable) {
|
||||||
|
$item['price'] = floatval(str_replace(',', '.', $appPrice));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($appHasDiscount) {
|
||||||
|
|
||||||
|
$item['discount']['value'] = $appDiscountValue;
|
||||||
|
$item['discount']['oldPrice'] = floatval(str_replace(',', '.', $appOldPrice));
|
||||||
|
$item['discount']['newPrice'] = floatval(str_replace(',', '.', $appNewPrice));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items[] = $item;
|
$item['enclosures'] = array();
|
||||||
|
$item['enclosures'][] = str_replace('_292x136', '', $element->capsule);
|
||||||
|
|
||||||
|
foreach($element->screenshots as $screenshot) {
|
||||||
|
$item['enclosures'][] = substr($element->capsule, 0, -31) . $screenshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sort[$id] = $element->priority;
|
||||||
|
|
||||||
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array_multisort($sort, SORT_ASC, $this->items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue