def fetch_icons(game_slugs, callback=None): no_banners = [slug for slug in game_slugs if not has_icon(slug, BANNER)] no_icons = [slug for slug in game_slugs if not has_icon(slug, ICON)] # Remove duplicate slugs missing_media_slugs = list(set(no_banners) | set(no_icons)) if not missing_media_slugs: return response = api.get_games(game_slugs=missing_media_slugs) if not response: logger.warning('Unable to get games from API') return results = response['results'] while response.get('next'): page_match = re.search(r'page=(\d+)', response['next']) if page_match: page = page_match.group(1) else: logger.error("No page found in %s", response['next']) break response = api.get_games(game_slugs=missing_media_slugs, page=page) if not response: logger.warning("Unable to get response for page %s", page) break else: results += response.get('results', []) banner_downloads = [] icon_downloads = [] updated_slugs = [] for game in results: if game['slug'] in no_banners: banner_url = game['banner_url'] if banner_url: dest_path = get_icon_path(game['slug'], BANNER) banner_downloads.append((game['banner_url'], dest_path)) updated_slugs.append(game['slug']) if game['slug'] in no_icons: icon_url = game['icon_url'] if icon_url: dest_path = get_icon_path(game['slug'], ICON) icon_downloads.append((game['icon_url'], dest_path)) updated_slugs.append(game['slug']) updated_slugs = list(set(updated_slugs)) # Deduplicate slugs downloads = banner_downloads + icon_downloads with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor: for url, dest_path in downloads: executor.submit(download_media, url, dest_path) if updated_slugs and callback: callback(updated_slugs)
def fetch_icons(game_slugs, callback=None): no_banners = [slug for slug in game_slugs if not has_icon(slug, BANNER)] no_icons = [slug for slug in game_slugs if not has_icon(slug, ICON)] # Remove duplicate slugs missing_media_slugs = list(set(no_banners) | set(no_icons)) if not missing_media_slugs: return response = api.get_games(game_slugs=missing_media_slugs) if not response: logger.warning('Unable to get games from API') return results = response['results'] while response['next']: page_match = re.search(r'page=(\d+)', response['next']) if page_match: page = page_match.group(1) else: logger.error("No page found in %s", response['next']) break response = api.get_games(game_slugs=missing_media_slugs, page=page) results += response['results'] banner_downloads = [] icon_downloads = [] updated_slugs = [] for game in results: if game['slug'] in no_banners: banner_url = game['banner_url'] if banner_url: dest_path = get_icon_path(game['slug'], BANNER) banner_downloads.append((game['banner_url'], dest_path)) updated_slugs.append(game['slug']) if game['slug'] in no_icons: icon_url = game['icon_url'] if icon_url: dest_path = get_icon_path(game['slug'], ICON) icon_downloads.append((game['icon_url'], dest_path)) updated_slugs.append(game['slug']) updated_slugs = list(set(updated_slugs)) # Deduplicate slugs downloads = banner_downloads + icon_downloads with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor: for url, dest_path in downloads: executor.submit(download_media, url, dest_path) if updated_slugs and callback: callback(updated_slugs)
def run_no_installer_dialog(self): """Open dialog for 'no script available' situation.""" dlg = NoInstallerDialog(self) if dlg.result == dlg.MANUAL_CONF: game_data = pga.get_game_by_field(self.game_slug, 'slug') if game_data and 'slug' in game_data: # Game data already exist locally. game = Game(game_data['id']) else: # Try to load game data from remote. games = api.get_games([self.game_slug]) if games and len(games) >= 1: remote_game = games[0] game_data = { 'name': remote_game['name'], 'slug': remote_game['slug'], 'year': remote_game['year'], 'updated': remote_game['updated'], 'steamid': remote_game['steamid'] } game = Game(pga.add_game(**game_data)) else: game = None AddGameDialog( self.parent, game=game, callback=lambda: self.notify_install_success(game_data['id'])) elif dlg.result == dlg.NEW_INSTALLER: webbrowser.open(settings.GAME_URL % self.game_slug)
def run_no_installer_dialog(self): """Open dialog for 'no script available' situation.""" dlg = NoInstallerDialog(self) if dlg.result == dlg.MANUAL_CONF: game_data = pga.get_game_by_field(self.game_slug, 'slug') if game_data and 'slug' in game_data: # Game data already exist locally. game = Game(game_data['id']) else: # Try to load game data from remote. games = api.get_games([self.game_slug]) if games and len(games) >= 1: remote_game = games[0] game_data = { 'name': remote_game['name'], 'slug': remote_game['slug'], 'year': remote_game['year'], 'updated': remote_game['updated'], 'steamid': remote_game['steamid'] } game = Game(pga.add_game(**game_data)) else: game = None AddGameDialog( self.parent, game=game, callback=lambda: self.notify_install_success(game_data['id']) ) elif dlg.result == dlg.NEW_INSTALLER: webbrowser.open(settings.GAME_URL % self.game_slug)
def fetch_icons(game_slugs, callback=None): no_banners = [slug for slug in game_slugs if not has_icon(slug, BANNER)] no_icons = [slug for slug in game_slugs if not has_icon(slug, ICON)] # Remove duplicate slugs missing_media_slugs = list(set(no_banners) | set(no_icons)) if not missing_media_slugs: logger.debug("No icon are missing") return logger.debug("Requesting missing icons from API for %d games", len(missing_media_slugs)) results = api.get_games(game_slugs=missing_media_slugs) new_icon = False banner_downloads = [] icon_downloads = [] updated_slugs = [] for game in results: if game['slug'] in no_banners: banner_url = game['banner_url'] if banner_url: dest_path = get_icon_path(game['slug'], BANNER) banner_downloads.append((game['banner_url'], dest_path)) updated_slugs.append(game['slug']) if game['slug'] in no_icons: icon_url = game['icon_url'] if icon_url: dest_path = get_icon_path(game['slug'], ICON) icon_downloads.append((game['icon_url'], dest_path)) updated_slugs.append(game['slug']) new_icon = True updated_slugs = list(set(updated_slugs)) # Deduplicate slugs downloads = banner_downloads + icon_downloads if downloads: logger.debug("Downloading %d files", len(downloads)) with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: futs = [ executor.submit(download_media, url, dest_path) for url, dest_path in downloads ] concurrent.futures.wait(futs) if new_icon: udpate_desktop_icons() if updated_slugs and callback: callback(updated_slugs)
def fetch_icons(game_slugs, callback=None): no_banners = [slug for slug in game_slugs if not has_icon(slug, BANNER)] no_icons = [slug for slug in game_slugs if not has_icon(slug, ICON)] # Remove duplicate slugs missing_media_slugs = list(set(no_banners) | set(no_icons)) if not missing_media_slugs: return results = api.get_games(game_slugs=missing_media_slugs) new_icon = False banner_downloads = [] icon_downloads = [] updated_slugs = [] for game in results: if game['slug'] in no_banners: banner_url = game['banner_url'] if banner_url: dest_path = get_icon_path(game['slug'], BANNER) banner_downloads.append((game['banner_url'], dest_path)) updated_slugs.append(game['slug']) if game['slug'] in no_icons: icon_url = game['icon_url'] if icon_url: dest_path = get_icon_path(game['slug'], ICON) icon_downloads.append((game['icon_url'], dest_path)) updated_slugs.append(game['slug']) new_icon = True updated_slugs = list(set(updated_slugs)) # Deduplicate slugs downloads = banner_downloads + icon_downloads with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor: futs = [executor.submit(download_media, url, dest_path) for url, dest_path in downloads] concurrent.futures.wait(futs) if (new_icon): udpate_desktop_icons() if updated_slugs and callback: callback(updated_slugs)