From 6355dd47c12d5f1b2a992e62f8b1e0f1dc2348bf Mon Sep 17 00:00:00 2001 From: Dummerle Date: Wed, 9 Jun 2021 13:25:57 +0200 Subject: [PATCH] Add support for bundles --- rare/components/tabs/shop/shop_info.py | 8 +++++++- rare/components/tabs/shop/shop_models.py | 15 +++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/rare/components/tabs/shop/shop_info.py b/rare/components/tabs/shop/shop_info.py index ff73cbc5..e76f934f 100644 --- a/rare/components/tabs/shop/shop_info.py +++ b/rare/components/tabs/shop/shop_info.py @@ -34,10 +34,14 @@ class ShopGameInfo(QWidget, Ui_shop_info): self.dev.setText(self.tr("Loading")) self.image.setPixmap(QPixmap()) self.data = data + is_bundle = False + for i in data["categories"]: + if "bundles" in i.get("path", ""): + is_bundle = True # init API request locale = QLocale.system().name().split("_")[0] - url = f"https://store-content.ak.epicgames.com/api/{locale}/content/products/{slug}" + url = f"https://store-content.ak.epicgames.com/api/{locale}/content/{'products' if not is_bundle else 'bundles'}/{slug}" # game = api_utils.get_product(slug, locale) self.request = self.manager.get(QNetworkRequest(QUrl(url))) self.request.finished.connect(self.data_received) @@ -55,6 +59,7 @@ class ShopGameInfo(QWidget, Ui_shop_info): logging.info(self.slug, error.errorString()) return else: + logger.error("Data failed") return else: return @@ -88,3 +93,4 @@ class ShopGameInfo(QWidget, Ui_shop_info): def button_clicked(self): webbrowser.open("https://www.epicgames.com/store/de/p/" + self.slug) + diff --git a/rare/components/tabs/shop/shop_models.py b/rare/components/tabs/shop/shop_models.py index 37a25b98..b9b9b594 100644 --- a/rare/components/tabs/shop/shop_models.py +++ b/rare/components/tabs/shop/shop_models.py @@ -46,6 +46,7 @@ class ShopGame: @classmethod def from_json(cls, api_data: dict, search_data: dict): + print(api_data) if isinstance(api_data, list): for product in api_data: if product["_title"] == "home": @@ -53,22 +54,24 @@ class ShopGame: break tmp = cls() - tmp.title = api_data.get("productName", "undefined") + if "pages" in api_data.keys(): + api_data = api_data["pages"][0] + tmp.title = api_data.get("productName", api_data.get("_title", "fail")) tmp.image_urls = _ImageUrlModel.from_json(search_data["keyImages"]) - links = api_data["pages"][0]["data"]["socialLinks"] + links = api_data["data"]["socialLinks"] tmp.links = [] for item in links: if item.startswith("link"): tmp.links.append(tuple((item.replace("link", ""), links[item]))) - tmp.available_voice_langs = api_data["pages"][0]["data"]["requirements"]["languages"] + tmp.available_voice_langs = api_data["data"]["requirements"]["languages"] tmp.reqs = [] - for i, system in enumerate(api_data["pages"][0]["data"]["requirements"]["systems"]): + for i, system in enumerate(api_data["data"]["requirements"]["systems"]): tmp.reqs.append({"name": system["systemType"], "value": []}) for req in system["details"]: tmp.reqs[i]["value"].append(tuple((req["minimum"], req["recommended"]))) - tmp.publisher = api_data["pages"][0]["data"]["meta"].get("publisher", "undefined") - tmp.developer = api_data["pages"][0]["data"]["meta"].get("developer", "undefined") + tmp.publisher = api_data["data"]["meta"].get("publisher", "undefined") + tmp.developer = api_data["data"]["meta"].get("developer", "undefined") tmp.price = search_data['price']['totalPrice']['fmtPrice']['originalPrice'] tmp.discount_price = search_data['price']['totalPrice']['fmtPrice']['discountPrice']