Skip to content

Commit

Permalink
[SteamBridge] Follow source changes (RSS-Bridge#1143)
Browse files Browse the repository at this point in the history
* Follow source data fetching changes
* Improve media path building
* Improve price fetching and display
  • Loading branch information
JackNUMBER authored and logmanoriginal committed Jun 6, 2019
1 parent d2535d9 commit 88489c2
Showing 1 changed file with 28 additions and 63 deletions.
91 changes: 28 additions & 63 deletions bridges/SteamBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,12 @@ class SteamBridge extends BridgeAbstract {
const MAINTAINER = 'jacknumber';
const PARAMETERS = array(
'Wishlist' => array(
'username' => array(
'name' => 'Username',
'userid' => array(
'name' => 'Steamid64 (find it on steamid.io)',
'title' => 'User ID (17 digits). Find your user ID with steamid.io or steamidfinder.com',
'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',
),
'exampleValue' => '76561198821231205',
'pattern' => '[0-9]{17}',
),
'only_discount' => array(
'name' => 'Only discount',
Expand All @@ -56,27 +24,15 @@ class SteamBridge extends BridgeAbstract {

public function collectData(){

$username = $this->getInput('username');
$params = array(
'cc' => $this->getInput('currency')
);

$url = self::URI . 'wishlist/id/' . $username . '?' . http_build_query($params);
$userid = $this->getInput('userid');

$targetVariable = 'g_rgAppInfo';
$sourceUrl = self::URI . 'wishlist/profiles/' . $userid . '/wishlistdata?p=0';
$sort = array();

$html = '';
$html = getSimpleHTMLDOM($url)
or returnServerError("Could not request Steam Wishlist. Tried:\n - $url");
$json = getContents($sourceUrl)
or returnServerError('Could not get content from wishlistdata (' . $sourceUrl . ')');

$jsContent = $html->find('.responsive_page_template_content script', 0)->innertext;

if(preg_match('/var ' . $targetVariable . ' = (.*?);/s', $jsContent, $matches)) {
$appsData = json_decode($matches[1]);
} else {
returnServerError("Could not parse JS variable ($targetVariable) in page content.");
}
$appsData = json_decode($json);

foreach($appsData as $id => $element) {

Expand All @@ -87,23 +43,22 @@ public function collectData(){

if($element->subs) {
$appIsBuyable = 1;
$priceBlock = str_get_html($element->subs[0]->discount_block);
$appPrice = str_replace('--', '00', $priceBlock->find('.discount_final_price', 0)->plaintext);

if($element->subs[0]->discount_pct) {

$appHasDiscount = 1;
$discountBlock = str_get_html($element->subs[0]->discount_block);
$appDiscountValue = $discountBlock->find('.discount_pct', 0)->plaintext;
$appOldPrice = $discountBlock->find('.discount_original_price', 0)->plaintext;
$appNewPrice = $discountBlock->find('.discount_final_price', 0)->plaintext;
$appPrice = $appNewPrice;

} else {

if($this->getInput('only_discount')) {
continue;
}

$appPrice = $element->subs[0]->price / 100;
}

} else {
Expand All @@ -117,34 +72,44 @@ public function collectData(){
}
}

$coverUrl = str_replace('_292x136', '', strtok($element->capsule, '?'));
$picturesPath = pathinfo($coverUrl)['dirname'] . '/';

$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['cover'] = $coverUrl;
$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));
$item['content'] = $appPrice;

}

if($appIsFree) {
$item['content'] = 'Free';
}

if($appHasDiscount) {

$item['discount']['value'] = $appDiscountValue;
$item['discount']['oldPrice'] = floatval(str_replace(',', '.', $appOldPrice));
$item['discount']['newPrice'] = floatval(str_replace(',', '.', $appNewPrice));
$item['discount']['oldPrice'] = $appOldPrice;
$item['content'] = '<s>' . $appOldPrice . '</s> <b>' . $appPrice . '</b> (' . $appDiscountValue . ')';

}

$item['enclosures'] = array();
$item['enclosures'][] = str_replace('_292x136', '', $element->capsule);
$item['enclosures'][] = $coverUrl;

foreach($element->screenshots as $screenshot) {
$item['enclosures'][] = substr($element->capsule, 0, -31) . $screenshot;
foreach($element->screenshots as $screenshotFileName) {
$item['enclosures'][] = $picturesPath . $screenshotFileName;
}

$sort[$id] = $element->priority;
Expand Down

0 comments on commit 88489c2

Please sign in to comment.