SteamBridge.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. class SteamBridge extends BridgeAbstract {
  3. const NAME = 'Steam Bridge';
  4. const URI = 'https://store.steampowered.com/';
  5. const CACHE_TIMEOUT = 3600; // 1h
  6. const DESCRIPTION = 'Returns apps list';
  7. const MAINTAINER = 'jacknumber';
  8. const PARAMETERS = array(
  9. 'Wishlist' => array(
  10. 'username' => array(
  11. 'name' => 'Username',
  12. 'required' => true,
  13. ),
  14. 'currency' => array(
  15. 'name' => 'Currency',
  16. 'type' => 'list',
  17. 'values' => array(
  18. // source: http://steam.steamlytics.xyz/currencies
  19. 'USD' => 'us',
  20. 'GBP' => 'gb',
  21. 'EUR' => 'fr',
  22. 'CHF' => 'ch',
  23. 'RUB' => 'ru',
  24. 'BRL' => 'br',
  25. 'JPY' => 'jp',
  26. 'SEK' => 'se',
  27. 'IDR' => 'id',
  28. 'MYR' => 'my',
  29. 'PHP' => 'ph',
  30. 'SGD' => 'sg',
  31. 'THB' => 'th',
  32. 'KRW' => 'kr',
  33. 'TRY' => 'tr',
  34. 'MXN' => 'mx',
  35. 'CAD' => 'ca',
  36. 'NZD' => 'nz',
  37. 'CNY' => 'cn',
  38. 'INR' => 'in',
  39. 'CLP' => 'cl',
  40. 'PEN' => 'pe',
  41. 'COP' => 'co',
  42. 'ZAR' => 'za',
  43. 'HKD' => 'hk',
  44. 'TWD' => 'tw',
  45. 'SRD' => 'sr',
  46. 'AED' => 'ae',
  47. ),
  48. ),
  49. 'only_discount' => array(
  50. 'name' => 'Only discount',
  51. 'type' => 'checkbox',
  52. )
  53. )
  54. );
  55. public function collectData(){
  56. $username = $this->getInput('username');
  57. $params = array(
  58. 'cc' => $this->getInput('currency')
  59. );
  60. $url = self::URI . 'wishlist/id/' . $username . '?' . http_build_query($params);
  61. $targetVariable = 'g_rgAppInfo';
  62. $sort = array();
  63. $html = '';
  64. $html = getSimpleHTMLDOM($url)
  65. or returnServerError("Could not request Steam Wishlist. Tried:\n - $url");
  66. $jsContent = $html->find('.responsive_page_template_content script', 0)->innertext;
  67. if(preg_match('/var ' . $targetVariable . ' = (.*?);/s', $jsContent, $matches)) {
  68. $appsData = json_decode($matches[1]);
  69. } else {
  70. returnServerError("Could not parse JS variable ($targetVariable) in page content.");
  71. }
  72. foreach($appsData as $id => $element) {
  73. $appType = $element->type;
  74. $appIsBuyable = 0;
  75. $appHasDiscount = 0;
  76. $appIsFree = 0;
  77. if($element->subs) {
  78. $appIsBuyable = 1;
  79. if($element->subs[0]->discount_pct) {
  80. $appHasDiscount = 1;
  81. $discountBlock = str_get_html($element->subs[0]->discount_block);
  82. $appDiscountValue = $discountBlock->find('.discount_pct', 0)->plaintext;
  83. $appOldPrice = $discountBlock->find('.discount_original_price', 0)->plaintext;
  84. $appNewPrice = $discountBlock->find('.discount_final_price', 0)->plaintext;
  85. $appPrice = $appNewPrice;
  86. } else {
  87. if($this->getInput('only_discount')) {
  88. continue;
  89. }
  90. $appPrice = $element->subs[0]->price / 100;
  91. }
  92. } else {
  93. if($this->getInput('only_discount')) {
  94. continue;
  95. }
  96. if(isset($element->free) && $element->free = 1) {
  97. $appIsFree = 1;
  98. }
  99. }
  100. $item = array();
  101. $item['uri'] = "http://store.steampowered.com/app/$id/";
  102. $item['title'] = $element->name;
  103. $item['type'] = $appType;
  104. $item['cover'] = str_replace('_292x136', '', $element->capsule);
  105. $item['timestamp'] = $element->added;
  106. $item['isBuyable'] = $appIsBuyable;
  107. $item['hasDiscount'] = $appHasDiscount;
  108. $item['isFree'] = $appIsFree;
  109. $item['priority'] = $element->priority;
  110. if($appIsBuyable) {
  111. $item['price'] = floatval(str_replace(',', '.', $appPrice));
  112. }
  113. if($appHasDiscount) {
  114. $item['discount']['value'] = $appDiscountValue;
  115. $item['discount']['oldPrice'] = floatval(str_replace(',', '.', $appOldPrice));
  116. $item['discount']['newPrice'] = floatval(str_replace(',', '.', $appNewPrice));
  117. }
  118. $item['enclosures'] = array();
  119. $item['enclosures'][] = str_replace('_292x136', '', $element->capsule);
  120. foreach($element->screenshots as $screenshot) {
  121. $item['enclosures'][] = substr($element->capsule, 0, -31) . $screenshot;
  122. }
  123. $sort[$id] = $element->priority;
  124. $this->items[] = $item;
  125. }
  126. array_multisort($sort, SORT_ASC, $this->items);
  127. }
  128. }