def _gather_information(self, game): game_cover_path = self._set_up_path( os.path.join(self.cover_cache, game)) game_cache_path = self._set_up_path(os.path.join(self.api_cache, game)) json_file = self._get_json_data(game_cache_path, game) try: json_data = json.load(open(json_file)) except: xbmcgui.Dialog().notification( self.core().string('name'), self.core().string('scraper_failed') % (game, self.name())) if json_file is not None and os.path.isfile(json_file): os.remove(json_file) return ApiResponse() if json_data['Response'] != 'False': json_data['posters'] = [] cover_path = self._dump_image(game_cover_path, json_data['Poster']) if cover_path is not None: json_data['posters'].append(cover_path) del json_data['Poster'] response = dict((k.lower(), v) for k, v in json_data.iteritems()) if 'genre' in response: response['genre'] = response.get('genre').split(',') response['genre'] = [ str(v).strip() for v in response.get('genre') ] return ApiResponse.from_dict(**response) else: return ApiResponse()
def _gather_information(self, game): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, game)) game_cache_path = self._set_up_path(os.path.join(self.api_cache, game)) file_path = os.path.join(game_cache_path, game+'.json') try: cp = ConfigParser.ConfigParser() cp.read(self.plugin.get_setting('api_key_file', str)) igdb_api_key = cp.get('API', 'igdb') except: xbmcgui.Dialog().notification( self.core().string('name'), self.core().string('scraper_failed') % (game, self.name()) ) return ApiResponse() url_opener = urllib2.build_opener() url_opener.addheaders = [ ('Accept', 'application/json'), ('Authorization', 'Token token=%s' % igdb_api_key) ] if not os.path.isfile(file_path): query_string = 'search?q=%s' % game response = url_opener.open(self.api_url % query_string) if response.getcode() in [200, 304]: search_results = json.load(url_opener.open(self.api_url % query_string)) print search_results if len(search_results) > 0: best_match_id = search_results['games'][0]['id'] else: return None else: raise IOError("Server failed with status code %s" % response.getcode()) else: best_match_id = None try: json_data = json.load(open(self._get_json_data(url_opener, game_cache_path, game, best_match_id))) except IOError: return None json_data = json_data['game'] api_response = ApiResponse() api_response.year = date_parser.parse(json_data['release_date']).year api_response.plot = json_data['summary'].encode('utf-8') for genre in json_data['genres']: api_response.genre.append(genre['name'].encode('utf-8')) if json_data['cover'] is not None: img_id = json_data['cover']['id'] cover_path = self._dump_image(game_cover_path, self.api_img_url % ('cover_big', img_id)) if cover_path is not None: api_response.posters.append(cover_path) return api_response
def _gather_information(self, nvapp, game): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, nvapp.id)) game_cache_path = self._set_up_path(os.path.join(self.api_cache, nvapp.id)) file_path = os.path.join(game_cache_path, game+'.json') try: cp = ConfigParser.ConfigParser() cp.read(self.plugin.get_setting('api_key_file', str)) igdb_api_key = cp.get('API', 'igdb') except: xbmcgui.Dialog().notification( self.core.string('name'), self.core.string('scraper_failed') % (game, self.name()) ) return ApiResponse() url_opener = urllib2.build_opener() url_opener.addheaders = [ ('Accept', 'application/json'), ('Authorization', 'Token token=%s' % igdb_api_key) ] if not os.path.isfile(file_path): query_string = 'search?q=%s' % game response = url_opener.open(self.api_url % query_string) if response.getcode() in [200, 304]: search_results = json.load(url_opener.open(self.api_url % query_string)) print search_results if len(search_results) > 0: best_match_id = search_results['games'][0]['id'] else: return None else: raise IOError("Server failed with status code %s" % response.getcode()) else: best_match_id = None try: json_data = json.load(open(self._get_json_data(url_opener, game_cache_path, game, best_match_id))) except IOError: return None json_data = json_data['game'] api_response = ApiResponse() api_response.year = date_parser.parse(json_data['release_date']).year api_response.plot = json_data['summary'].encode('utf-8') for genre in json_data['genres']: api_response.genre.append(genre['name'].encode('utf-8')) if json_data['cover'] is not None: img_id = json_data['cover']['id'] cover_path = self._dump_image(game_cover_path, self.api_img_url % ('cover_big', img_id)) if cover_path is not None: api_response.posters.append(cover_path) return api_response
def get_game_information(self, nvapp): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, nvapp.id)) response = ApiResponse() response.name = nvapp.title raw_box_art = self.nvhttp.get_box_art(nvapp.id) cover_path = self._dump_image_from_data(game_cover_path, nvapp.id, raw_box_art) response.posters.append(cover_path) return response
def get_game_information(self, nvapp): game_cover_path = self._set_up_path( os.path.join(self.cover_cache, nvapp.id)) response = ApiResponse() response.name = nvapp.title raw_box_art = self.nvhttp.get_box_art(nvapp.id) cover_path = self._dump_image_from_data(game_cover_path, nvapp.id, raw_box_art) response.posters.append(cover_path) return response
def _gather_information(self, game): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, game)) game_cache_path = self._set_up_path(os.path.join(self.api_cache, game)) json_file = self._get_json_data(game_cache_path, game) try: json_data = json.load(open(json_file)) except: xbmcgui.Dialog().notification( self.core().string('name'), self.core().string('scraper_failed') % (game, self.name()) ) if json_file is not None and os.path.isfile(json_file): os.remove(json_file) return ApiResponse() if json_data['Response'] != 'False': json_data['posters'] = [] cover_path = self._dump_image(game_cover_path, json_data['Poster']) if cover_path is not None: json_data['posters'].append(cover_path) del json_data['Poster'] response = dict((k.lower(), v) for k, v in json_data.iteritems()) if 'genre' in response: response['genre'] = response.get('genre').split(',') response['genre'] = [str(v).strip() for v in response.get('genre')] return ApiResponse.from_dict(**response) else: return ApiResponse()
def _gather_information(self, game): game_cover_path = self._set_up_path(os.path.join(self.cover_cache, game)) game_fanart_path = self._set_up_path(os.path.join(self.fanart_cache, game)) xml_response_file = self._get_xml_data(game) try: xml_root = ElementTree(file=xml_response_file).getroot() except: xbmcgui.Dialog().notification( self.core.string('name'), self.core.string('scraper_failed') % (game, self.name()) ) if xml_response_file is not None and os.path.isfile(xml_response_file): os.remove(xml_response_file) return ApiResponse() dict_response = self._parse_xml_to_dict(xml_root) if dict_response: posters = dict_response['posters'] dict_response['posters'] = [] for poster in posters: dict_response['posters'].append(self._dump_image(game_cover_path, poster)) local_arts = {} for art in dict_response.get('fanarts'): art.set_thumb(self._dump_image(game_fanart_path, art.get_thumb())) local_arts[os.path.basename(art.get_thumb())] = art dict_response['fanarts'] = local_arts return ApiResponse.from_dict(**dict_response)
def get_game_information(self, game_name): if self.plugin.get_setting('api_key_file', str) == "": return ApiResponse() request_name = game_name.replace(" ", "+").replace(":", "") response = self._gather_information(request_name) response.name = game_name return response
def _gather_information(self, nvapp, game): game_cover_path = self._set_up_path( os.path.join(self.cover_cache, nvapp.id)) game_fanart_path = self._set_up_path( os.path.join(self.fanart_cache, nvapp.id)) xml_response_file = self._get_xml_data(nvapp.id, game) try: xml_root = ElementTree(file=xml_response_file).getroot() except: xbmcgui.Dialog().notification( self.core.string('name'), self.core.string('scraper_failed') % (game, self.name())) if xml_response_file is not None and os.path.isfile( xml_response_file): os.remove(xml_response_file) return ApiResponse() dict_response = self._parse_xml_to_dict(xml_root) if dict_response: posters = dict_response['posters'] dict_response['posters'] = [] for poster in posters: dict_response['posters'].append( self._dump_image(game_cover_path, poster)) local_arts = {} for art in dict_response.get('fanarts'): art.set_thumb( self._dump_image(game_fanart_path, art.get_thumb())) local_arts[os.path.basename(art.get_thumb())] = art dict_response['fanarts'] = local_arts return ApiResponse.from_dict(**dict_response)