Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions howlongtobeatpy/howlongtobeatpy/HTMLRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchModifiers(Enum):
class HTMLRequests:
BASE_URL = 'https://howlongtobeat.com/'
REFERER_HEADER = BASE_URL
SEARCH_URL = BASE_URL + "api/lookup"
SEARCH_URL = BASE_URL + "api/s" # should update this to some kind of regex for api/[any alphanumeric characters here] to be more future proof since this keeps changing
GAME_URL = BASE_URL + "game"

@staticmethod
Expand Down Expand Up @@ -116,7 +116,7 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
if api_key_result is None:
api_key_result = HTMLRequests.send_website_request_getcode(True)
# Make the request
# The main method currently is the call to api/lookup/key
# The main method currently is the call to the API search URL
search_url_with_key = HTMLRequests.SEARCH_URL + "/" + api_key_result
payload = HTMLRequests.get_search_request_data(game_name, search_modifiers, page, None)
resp = requests.post(search_url_with_key, headers=headers, data=payload, timeout=60)
Expand Down Expand Up @@ -145,7 +145,7 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
if api_key_result is None:
api_key_result = await HTMLRequests.async_send_website_request_getcode(True)
# Make the request
# The main method currently is the call to api/lookup/key
# The main method currently is the call to the API search URL
search_url_with_key = HTMLRequests.SEARCH_URL + "/" + api_key_result
payload = HTMLRequests.get_search_request_data(game_name, search_modifiers, page, None)
async with aiohttp.ClientSession() as session:
Expand Down Expand Up @@ -253,8 +253,8 @@ def extract_api_from_script(script_content: str):
if matches:
key = ''.join(matches)
return key
# Test 2 - The API Key is in format fetch("/api/lookup/".concat("X").concat("Y")...
concat_api_key_pattern = r'\/api\/lookup\/"(?:\.concat\("[^"]*"\))*'
# Test 2 - The API Key is in format fetch("/api/[word here]/".concat("X").concat("Y")...
concat_api_key_pattern = r'\/api\/\w+\/"(?:\.concat\("[^"]*"\))*'
matches = re.findall(concat_api_key_pattern, script_content)
if matches:
matches = str(matches).split('.concat')
Expand All @@ -267,7 +267,7 @@ def extract_api_from_script(script_content: str):
@staticmethod
def send_website_request_getcode(parse_all_scripts: bool):
"""
Function that send a request to howlongtobeat to scrape the /api/lookup key
Function that send a request to howlongtobeat to scrape the API key
@return: The string key to use
"""
# Make the post request and return the result if is valid
Expand All @@ -294,7 +294,7 @@ def send_website_request_getcode(parse_all_scripts: bool):
@staticmethod
async def async_send_website_request_getcode(parse_all_scripts: bool):
"""
Function that send a request to howlongtobeat to scrape the /api/lookup key
Function that send a request to howlongtobeat to scrape the key used in the search URL
@return: The string key to use
"""
# Make the post request and return the result if is valid
Expand Down
Loading