def search(self, gamename, platform=None): #use description to search for the game name as the name attribute also contains the region pattern = "\<description\>(.*%s.*)\</description\>" % GameNameUtil( ).prepare_gamename_for_searchrequest(gamename) if platform in self._MAME_style_platforms: pattern = 'name="(.*%s.*)"' % GameNameUtil( ).prepare_gamename_for_searchrequest(gamename) results = [] try: fh = xbmcvfs.File(self._get_xml_path()) text = fh.read() text = util.html_unescape(text) fh.close() for line in text.splitlines(): #HACK: Apostrophes are removed in prepare_gamename_for_searchrequest. So we also have to do it here. result = re.search(pattern, line.replace("'", "")) if result: gamename = result.groups()[0] results.append({ 'id': gamename, 'title': gamename, 'SearchKey': [gamename] }) except Exception as e: log.error(e) raise return results
def search(self, gamename, platform=None): #use description to search for the game name as the name attribute also contains the region #FIXME TODO #currently not working with MAME xml files as the rom files don't use the friendly game name pattern = "\<description\>(.*%s.*)\</description\>" % GameNameUtil( ).prepare_gamename_for_searchrequest(gamename) results = [] try: with io.open(self._get_xml_path(), 'r', encoding="utf-8") as xmlfile: for line in xmlfile: result = re.search(pattern, line) if result: gamename = result.groups()[0] results.append({ 'id': gamename, 'title': gamename, 'SearchKey': [gamename] }) except Exception as e: log.error(e) raise return results
def matchGamename(self, results, gamenameFromFile, checkSubtitle): for idx, result in enumerate(results): try: # Check if the result has the correct platform (if needed) found_platform = self.resolveParseResult(result, 'PlatformSearchKey') if found_platform != '' and self.expected_platform != found_platform: log.info("Platform mismatch. %s != %s. Result will be skipped." % ( self.expected_platform, found_platform)) continue searchKey = self.resolveParseResult(result, 'SearchKey') # keep it for later reference searchkey_orig = searchKey gamename_orig = gamenameFromFile # if no searchkey is specified first result is valid (1 file per game scenario) if searchkey_orig == '': log.info("No searchKey found. Using first result") return result log.info("Comparing %s with %s" % (gamename_orig, searchkey_orig)) if gamename_orig == searchkey_orig: # perfect match return result # normalize name and searchkey before comparison gnu = GameNameUtil() gamename_normalized = gnu.normalize_name(gamename_orig) searchkey_normalized = gnu.normalize_name(searchkey_orig) log.info("Try normalized names. Comparing %s with %s" % (gamename_normalized, searchkey_normalized)) if gamename_normalized == searchkey_normalized: # perfect match return result #strip additional info from gamename gamename_stripped = gnu.strip_addinfo_from_name(gamename_orig) gamename_stripped = gnu.normalize_name(gamename_stripped) log.info("Try with stripped additional info. Comparing %s with %s" % (gamename_stripped, searchkey_normalized)) if gamename_stripped == searchkey_normalized: # perfect match return result except Exception, (exc): log.warn("An error occured while matching the best result: " + str(exc))
def _get_search_params(self, **kwargs): print 'returning ' + kwargs['gamename'] return { 'title': '%s' % GameNameUtil().prepare_gamename_for_searchrequest( kwargs['gamename']), 'api_key': self._apikey, 'platform': self.get_platform_for_scraper(kwargs['platform']), 'format': 'brief' }
def _get_search_params(self, **kwargs): return { 'api_key': self._apikey, 'filter': 'platform:%s,name:%s' % (self.get_platform_for_scraper(kwargs['platform']), GameNameUtil().prepare_gamename_for_searchrequest( kwargs['gamename'])), 'format': 'json', 'field_list': 'id,guid,name,release_date' }
def _get_search_params(self, **kwargs): return { 'name': GameNameUtil().prepare_gamename_for_searchrequest( kwargs['gamename']), 'filter[platform]': self.get_platform_for_scraper(kwargs['platform']), 'apikey': self._api_key, 'fields': self._fields, 'include': self._include }
def matchGamename(self, results, gamenameFromFile): for idx, result in enumerate(results): try: # Check if the result has the correct platform (if needed) found_platform = self.resolveParseResult( result, 'PlatformSearchKey') if found_platform != '' and self.expected_platform != found_platform: log.info( "Platform mismatch. %s != %s. Result will be skipped." % (self.expected_platform, found_platform)) continue searchKey = self.resolveParseResult(result, 'SearchKey') # keep it for later reference searchkey_orig = searchKey gamename_orig = gamenameFromFile # if no searchkey is specified first result is valid (1 file per game scenario) if searchkey_orig == '': log.info("No searchKey found. Using first result") return result log.info("Comparing %s with %s" % (gamename_orig, searchkey_orig)) if gamename_orig == searchkey_orig: # perfect match return result # normalize name and searchkey before comparison gnu = GameNameUtil() gamename_normalized = gnu.normalize_name(gamename_orig) searchkey_normalized = gnu.normalize_name(searchkey_orig) log.info("Try normalized names. Comparing %s with %s" % (gamename_normalized, searchkey_normalized)) if gamename_normalized == searchkey_normalized: # perfect match return result #strip additional info from gamename gamename_stripped = gnu.strip_addinfo_from_name(gamename_orig) gamename_stripped = gnu.normalize_name(gamename_stripped) log.info( "Try with stripped additional info. Comparing %s with %s" % (gamename_stripped, searchkey_normalized)) if gamename_stripped == searchkey_normalized: # perfect match return result except Exception as exc: log.warn("An error occured while matching the best result: " + str(exc)) log.info("No result found for gamename %s" % gamenameFromFile) return None