Example #1
0
 def loadGameInCache(self, game):
     self.cache_by_zxdb_id[game.zxdb_id] = game
     for release in game.releases:
         for name in release.getAllAliases():
             name = getSearchStringFromGameName(name)
             if not self.cache_by_name.get(name):
                 self.cache_by_name[name] = [game]
             elif game not in self.cache_by_name[name]:
                 self.cache_by_name[name].append(game)
         for file in release.files:
             self.cache_by_md5[file.md5] = game
             if not self.cache_by_crc32.get(file.crc32):
                 self.cache_by_crc32[file.crc32] = []
             self.cache_by_crc32[file.crc32].append(game)
Example #2
0
 def getGameByName(self, game_name):
     if self.cache_by_name:
         game_name = getSearchStringFromGameName(game_name)
         games = self.cache_by_name.get(game_name)
     else:
         sql = SELECT_GAME_SQL_START + \
             'WHERE game.name=? '
         sql += SELECT_GAME_SQL_END
         raw_data = self.cur.execute(sql, [game_name]).fetchall()
         games = self.getGamesFromRawData(raw_data)
     if not games:
         print('Game', game_name, 'not found')
         return None
     elif len(games) == 1:
         return games[0]
     else:
         print('Ambiguity not resolved for', game_name)
         return None
Example #3
0
 def getGameByFilePath(self, filepath):
     filename = os.path.basename(filepath)
     game_release = re.sub(TOSEC_REGEX, '', filename).strip()
     version = re.findall('v[0-9].*', game_release)
     if version:
         game_release = game_release.replace(version[0], '').strip()
     if self.cache_by_name:
         search_string = getSearchStringFromGameName(game_release)
         games = self.cache_by_name.get(search_string)
         if not games:
             if ' - ' in game_release:
                 search_string = getSearchStringFromGameName(
                     game_release.split(' - ')[0])
                 games = self.cache_by_name.get(search_string)
             elif ' + ' in game_release:
                 search_string = getSearchStringFromGameName(
                     game_release.split(' + ')[0])
                 games = self.cache_by_name.get(search_string)
     else:
         game_release = '%' + '%'.join([
             x for x in game_release.split(' ') if x not in GAME_PREFIXES
         ]) + '%'
         sql = SELECT_GAME_SQL_START
         sql += 'WHERE game.wos_id IN ' \
                '(SELECT wos_id FROM game_release ' \
                'WHERE game_release.name LIKE ?)'
         sql += SELECT_GAME_SQL_END
         raw_data = self.cur.execute(sql, [game_release]).fetchall()
         games = self.getGamesFromRawData(raw_data)
         if not games:
             if '%-%' in game_release:
                 game_release = game_release.split('%-%')[0] + "%"
                 raw_data = self.cur.execute(sql, [game_release]).fetchall()
                 games = self.getGamesFromRawData(raw_data)
             elif '%+%' in game_release:
                 game_release = game_release.split('%+%')[0] + "%"
                 raw_data = self.cur.execute(sql, [game_release]).fetchall()
                 games = self.getGamesFromRawData(raw_data)
     if not games:
         return None
     game_file = GameFile(filepath)
     if len(games) == 1:
         game = games[0]
         for release in game.releases:
             if release.getYear() == game_file.game.getYear():
                 return game
             release_publisher = getSearchStringFromGameName(
                 release.getPublisher())
             game_file_publisher = getSearchStringFromGameName(
                 game_file.game.getPublisher())
             if release_publisher == game_file_publisher:
                 return game
     candidates = []
     for game in games:
         for release in game.releases:
             release_publisher = getSearchStringFromGameName(
                 release.getPublisher())
             game_file_publisher = getSearchStringFromGameName(
                 game_file.game.getPublisher())
             if game_file_publisher in release_publisher:
                 candidates.append(game)
     if len(candidates) == 1:
         return candidates[0]
     else:
         for game in candidates:
             for release in game.releases:
                 if release.getYear() == game_file.game.getYear():
                     return game
     return None