diff options
author | Alexander Hayden <alexhayden25@gmail.com> | 2020-12-31 17:30:52 -0500 |
---|---|---|
committer | Alexander Hayden <alexhayden25@gmail.com> | 2020-12-31 17:30:52 -0500 |
commit | c6073dd9bd1a25e2c494110b8a660ce333c5509f (patch) | |
tree | bec3c571bcee0e2af05d41b07ede854e00cbbd6e /util.py | |
parent | 26994267d81f623933af58367f8fad23d757d057 (diff) | |
parent | 746bfe5d7422e2db2ba924d31e4311d928729d2b (diff) | |
download | modpackman-c6073dd9bd1a25e2c494110b8a660ce333c5509f.tar.gz modpackman-c6073dd9bd1a25e2c494110b8a660ce333c5509f.zip |
Merge new modpackman into master; update Jeffrey 2
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 50 |
1 files changed, 30 insertions, 20 deletions
@@ -236,28 +236,37 @@ def find_cdn(ffx, url, version): Returns the direct Forge CDN download URL """ try: - # This goes to the "all files" page, where we get a table view of all - ffx.get(url + '/files/all') - mod_versions = ffx.find_elements_by_class_name("listing")[0].find_elements_by_xpath("tbody/tr") # extract the table of files from the page - row_info = collections.namedtuple("row_info", ["type", "filename", "cdn_id", "game_version"]) # create a custom tuple because data - rows = [] - for version_entry in mod_versions: - # parse out the four fields that we use - entry_cells = version_entry.find_elements_by_tag_name("td") - release_type = entry_cells[0].text - # Note that this is NOT the final filename - this is just the "release name". - filename = urllib.parse.quote(entry_cells[1].find_elements_by_tag_name("a")[0].text) + # This goes to the "all files" page, where we get a table view of all + page_index = 0; + while True: + ffx.get(url + f'/files/all?page={page_index}') + mod_versions = ffx.find_elements_by_class_name("listing")[0].find_elements_by_xpath("tbody/tr") # extract the table of files from the page + row_info = collections.namedtuple("row_info", ["type", "filename", "cdn_id", "game_version"]) # create a custom tuple because data + rows = [] + for version_entry in mod_versions: + # parse out the four fields that we use + entry_cells = version_entry.find_elements_by_tag_name("td") + release_type = entry_cells[0].text + # Note that this is NOT the final filename - this is just the "release name". + filename = urllib.parse.quote(entry_cells[1].find_elements_by_tag_name("a")[0].text) + try: + game_version = tuple([int(x) for x in entry_cells[4].find_element_by_class_name("mr-2").text.split(".")]) # get game version and convert to tuple + except: + game_version = (0, 0, 0) + cdn_id = entry_cells[1].find_element_by_tag_name("a").get_property("href").split("/")[-1] + + #TODO make this configurable + if 'fabric' not in filename.lower() or 'forge' in filename.lower(): + rows.append(row_info(release_type, filename, cdn_id, game_version)) + rows.sort(key=lambda x: x.game_version, reverse=True) try: - game_version = tuple([int(x) for x in entry_cells[4].find_element_by_class_name("mr-2").text.split(".")]) # get game version and convert to tuple - except: - game_version = (0, 0, 0) - cdn_id = entry_cells[1].find_element_by_tag_name("a").get_property("href").split("/")[-1] + best_row = next(x for x in rows if x.game_version <= version) + break + except StopIteration: + if len(ffx.find_elements_by_class_name("pagination-next--inactive")) != 0: + raise + page_index += 1 - #TODO make this configurable - if 'fabric' not in filename.lower() or 'forge' in filename.lower(): - rows.append(row_info(release_type, filename, cdn_id, game_version)) - rows.sort(key=lambda x: x.game_version, reverse=True) - best_row = next(x for x in rows if x.game_version <= version) # We need to find the real, ForgeCDN compatible filename now by going to the file page. ffx.get(f'{url}/files/{best_row.cdn_id}') @@ -271,6 +280,7 @@ def find_cdn(ffx, url, version): except: # import traceback; traceback.print_exc() + print(f"[!] Failed to retrieve valid CDN URL for {url}") return None |