|
@@ -19,23 +19,37 @@ def get_or_create_videogame(
|
|
|
|
|
|
game_dict = lookup_game_from_hltb(name_or_id)
|
|
game_dict = lookup_game_from_hltb(name_or_id)
|
|
|
|
|
|
|
|
+ if not game_dict:
|
|
|
|
+ game_dict = lookup_game_from_igdb(name_or_id)
|
|
|
|
+
|
|
if not game_dict:
|
|
if not game_dict:
|
|
return
|
|
return
|
|
|
|
|
|
# Create missing platforms and prep for loading after create
|
|
# Create missing platforms and prep for loading after create
|
|
platform_ids = []
|
|
platform_ids = []
|
|
- for platform in game_dict.get("platforms", []):
|
|
|
|
- p, _created = VideoGamePlatform.objects.get_or_create(name=platform)
|
|
|
|
- platform_ids.append(p.id)
|
|
|
|
- game_dict.pop("platforms")
|
|
|
|
|
|
+ if "platforms" in game_dict.keys():
|
|
|
|
+ for platform in game_dict.get("platforms", []):
|
|
|
|
+ p, _created = VideoGamePlatform.objects.get_or_create(
|
|
|
|
+ name=platform
|
|
|
|
+ )
|
|
|
|
+ platform_ids.append(p.id)
|
|
|
|
+ game_dict.pop("platforms")
|
|
|
|
+
|
|
|
|
+ cover_url = game_dict.pop("cover_url")
|
|
|
|
+
|
|
|
|
+ screenshot_url = ""
|
|
|
|
+ if "screenshot_url" in game_dict.keys():
|
|
|
|
+ screenshot_url = game_dict.pop("screenshot_url")
|
|
|
|
+
|
|
|
|
+ genres = []
|
|
|
|
+ if "genres" in game_dict.keys():
|
|
|
|
+ genres = game_dict.pop("genres")
|
|
|
|
|
|
game, game_created = VideoGame.objects.get_or_create(
|
|
game, game_created = VideoGame.objects.get_or_create(
|
|
hltb_id=game_dict.get("hltb_id")
|
|
hltb_id=game_dict.get("hltb_id")
|
|
)
|
|
)
|
|
|
|
|
|
if game_created or force_update:
|
|
if game_created or force_update:
|
|
- cover_url = game_dict.pop("cover_url")
|
|
|
|
-
|
|
|
|
VideoGame.objects.filter(pk=game.id).update(**game_dict)
|
|
VideoGame.objects.filter(pk=game.id).update(**game_dict)
|
|
game.refresh_from_db()
|
|
game.refresh_from_db()
|
|
|
|
|
|
@@ -43,6 +57,15 @@ def get_or_create_videogame(
|
|
if platform_ids:
|
|
if platform_ids:
|
|
game.platforms.add(*platform_ids)
|
|
game.platforms.add(*platform_ids)
|
|
|
|
|
|
|
|
+ if genres:
|
|
|
|
+ game.genre.add(*genres)
|
|
|
|
+
|
|
|
|
+ if not game.screenshot and screenshot_url:
|
|
|
|
+ r = requests.get(screenshot_url)
|
|
|
|
+ if r.status_code == 200:
|
|
|
|
+ fname = f"{game.title}_{game.uuid}.jpg"
|
|
|
|
+ game.screenshot.save(fname, ContentFile(r.content), save=True)
|
|
|
|
+
|
|
# Go get cover image if the URL is present
|
|
# Go get cover image if the URL is present
|
|
if cover_url and not game.hltb_cover:
|
|
if cover_url and not game.hltb_cover:
|
|
headers = {"User-Agent": "Vrobbler 0.11.12"}
|
|
headers = {"User-Agent": "Vrobbler 0.11.12"}
|