diff --git a/humble_downloader/humble_api/model/trove_order.py b/humble_downloader/humble_api/model/trove_order.py index 03c7bb7..0f82529 100644 --- a/humble_downloader/humble_api/model/trove_order.py +++ b/humble_downloader/humble_api/model/trove_order.py @@ -5,6 +5,7 @@ from .subproduct import Subproduct from .product import Product from sys import stderr +import json class TroveOrder(Order): @@ -28,29 +29,33 @@ def __init__(self, trove_page_html_text, hapi): return tree = lxml.html.fromstring(trove_page_html_text) - trove_products = tree.find_class("trove-product-detail") + trove_data_element = tree.get_element_by_id("webpack-monthly-trove-data") + trove_raw_json = trove_data_element.text_content() + trove_json_obj = json.loads(trove_raw_json) subproducts = [] - for product_lxml in trove_products: - if len(product_lxml.find_class('js-download-button')) == 0: # Download button means valid product - continue - platforms = product_lxml.find_class("trove-platform-selector") - product = {'human_name': product_lxml.find_class('product-human-name')[0].text, - 'machine_name': product_lxml.attrib['data-machine-name'], + + for trove_id, trove_data in trove_json_obj['displayItemData'].items(): + product = {'human_name': trove_data['human-name'], + 'machine_name': trove_data['machine_name'], 'downloads': [], 'payee': {} # TODO: put something better here } - for p in platforms: + for platform, platform_data in trove_data['downloads'].items(): pp = dict() - pp['platform'] = p.attrib['data-platform'] - pp['download_identifier'] = p.attrib['data-url'] - pp['machine_name'] = p.attrib['data-machine-name'] + pp['platform'] = platform + pp['download_identifier'] = platform_data['url']['web'] + pp['machine_name'] = platform_data['machine_name'] signed = hapi.get_signed_trove_url(pp['machine_name'], pp['download_identifier']) pp['download_struct'] = [{ 'url': { 'web': signed.get('signed_url', None), 'bittorrent': signed.get('signed_torrent_url', None) - } + }, + 'file_size': platform_data.get('file_size'), + 'human_size': platform_data.get('size'), + 'md5': platform_data.get('md5'), + 'sha1': platform_data.get('sha1') }] pp['options_dict'] = None # TODO: What is this? product['downloads'].append(pp) diff --git a/test/fake_library/fake_library.py b/test/fake_library/fake_library.py index 85013dc..751fcd4 100644 --- a/test/fake_library/fake_library.py +++ b/test/fake_library/fake_library.py @@ -13,12 +13,12 @@ class FakeLibrary: gamekeys_list = [] local_path = "" - def __init__(self, hapi, unlock_trove=True): + def __init__(self, hapi): self.local_path = path.dirname(__file__) self.update_gamekeys(hapi) self.prepare_fake_answer_list_gamekeys(hapi) self.prepare_fake_answers_keys(hapi) - self.prepare_fake_answer_trove(hapi, unlock_trove) + self.prepare_fake_answer_trove(hapi) def update_gamekeys(self, hapi): self.gamekeys_list = [] @@ -26,11 +26,11 @@ def update_gamekeys(self, hapi): self.gamekeys_list.append(path.basename(filename)[0:-4]) self.gamekeys_list.append(hapi.TROVE_GAMEKEY) - def prepare_fake_answer_trove(self, hapi, unlock_trove): + def prepare_fake_answer_trove(self, hapi): httpretty.register_uri( httpretty.GET, hapi.TROVE_PAGE_URL, - self.get_trove_answer(unlock_trove) + self.readfile("trove.html") ) httpretty.register_uri( httpretty.POST, @@ -49,12 +49,6 @@ def prepare_fake_answers_keys(self, hapi): def get_answer_for(self, key): return self.readfile(key + ".key") - def get_trove_answer(self, unlock_trove): - if unlock_trove: - return self.readfile("trove_OK.html") - else: - return self.readfile("trove_KO.html") - def prepare_fake_answer_list_gamekeys(self, hapi): string = "[\n" for key in self.gamekeys_list[:-1]: # Skip the trove key, as it is not reported by the API @@ -74,4 +68,4 @@ def readfile(self, relative_path): file = open(abs_path, "r") text = file.read() file.close() - return text \ No newline at end of file + return text diff --git a/test/fake_library/trove_OK.html b/test/fake_library/trove.html similarity index 54% rename from test/fake_library/trove_OK.html rename to test/fake_library/trove.html index 313f0a1..6bdc7c2 100644 --- a/test/fake_library/trove_OK.html +++ b/test/fake_library/trove.html @@ -12273,5 +12273,21 @@