Skip to content

Commit

Permalink
Merge pull request #18 from zurdi15/develop
Browse files Browse the repository at this point in the history
filename parentheses are now omitted when searching game in IGDB
  • Loading branch information
zurdi15 authored Mar 28, 2023
2 parents 3f00a0b + a36a3a2 commit f627ba0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backend/src/handler/igdb_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import functools
import re
from time import time

import requests
Expand Down Expand Up @@ -65,9 +66,11 @@ def get_rom_details(self, filename: str, p_igdb_id: int, r_igdb_id: str) -> dict

else:
if p_igdb_id:
search_term: str = re.sub('[\(\[].*?[\)\]]', '', filename_no_ext)
try:

res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
data=f"search \"{filename_no_ext}\";fields id, slug, name, summary; where platforms=[{p_igdb_id}] & category=0;").json()[0]
data=f"search \"{search_term}\";fields id, slug, name, summary; where platforms=[{p_igdb_id}] & category=0;").json()[0]
igdb_id = res_details['id']
slug = res_details['slug']
name = res_details['name']
Expand All @@ -78,7 +81,7 @@ def get_rom_details(self, filename: str, p_igdb_id: int, r_igdb_id: str) -> dict
except IndexError:
try:
res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
data=f"search \"{filename_no_ext}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}] & category=10;").json()[0]
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}] & category=10;").json()[0]
igdb_id = res_details['id']
slug = res_details['slug']
name = res_details['name']
Expand All @@ -89,7 +92,7 @@ def get_rom_details(self, filename: str, p_igdb_id: int, r_igdb_id: str) -> dict
except IndexError:
try:
res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
data=f"search \"{filename_no_ext}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()[0]
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()[0]
igdb_id = res_details['id']
slug = res_details['slug']
name = res_details['name']
Expand All @@ -112,8 +115,9 @@ def get_rom_details(self, filename: str, p_igdb_id: int, r_igdb_id: str) -> dict

@check_twitch_token
def get_matched_roms(self, filename: str, p_igdb_id: int) -> list:
search_term: str = re.sub('[\(\[].*?[\)\]]', '', filename.split('.')[0])
matched_roms: list = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
data=f"search \"{filename.split('.')[0]}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()
for rom in matched_roms:
res_details: dict = requests.post("https://api.igdb.com/v4/covers/", headers=self.headers,
data=f"fields url; where game={rom['id']};").json()[0]
Expand Down

0 comments on commit f627ba0

Please sign in to comment.