示例#1
0
    async def _process_package_info_response(self, body):
        logger.info("Processing message PICSProductInfoResponse")
        message = steammessages_clientserver_pb2.CMsgClientPICSProductInfoResponse()
        message.ParseFromString(body)
        apps_to_parse = []

        for info in message.packages:
            await self.package_info_handler(str(info.packageid))
            if info.packageid == 0:
                # Packageid 0 contains trash entries for every user
                logger.info("Skipping packageid 0 ")
                continue
            package_content = vdf.binary_loads(info.buffer[4:])
            for app in package_content[str(info.packageid)]['appids']:
                await self.app_info_handler(mother_appid=str(info.packageid), appid=str(package_content[str(info.packageid)]['appids'][app]))
                apps_to_parse.append(package_content[str(info.packageid)]['appids'][app])

        for info in message.apps:
            app_content = vdf.loads(info.buffer[:-1].decode('utf-8', 'replace'))
            try:
                if app_content['appinfo']['common']['type'].lower() == 'game':
                    logger.info(f"Retrieved game {app_content['appinfo']['common']['name']}")
                    await self.app_info_handler(appid=str(app_content['appinfo']['appid']), title=app_content['appinfo']['common']['name'], game=True)
                else:
                    await self.app_info_handler(appid=str(app_content['appinfo']['appid']), game=False)
            except KeyError:
                # Unrecognized app type
                await self.app_info_handler(appid=str(app_content['appinfo']['appid']), game=False)

        if len(apps_to_parse) > 0:
            logger.info(f"Apps to parse {apps_to_parse}, {len(apps_to_parse)} entries")
            await self.get_apps_info(apps_to_parse)
    async def _process_product_info_response(self, body):
        logger.debug("Processing message PICSProductInfoResponse")
        message = steammessages_clientserver_pb2.CMsgClientPICSProductInfoResponse(
        )
        message.ParseFromString(body)
        apps_to_parse = []

        def product_info_handler(packages, apps):
            for info in packages:
                self.package_info_handler()

                package_id = str(info.packageid)
                package_content = vdf.binary_loads(info.buffer[4:])
                package = package_content.get(package_id)
                if package is None:
                    continue

                for app in package['appids'].values():
                    appid = str(app)
                    self.app_info_handler(package_id=package_id, appid=appid)
                    apps_to_parse.append(app)

            for info in apps:
                app_content = vdf.loads(info.buffer[:-1].decode(
                    'utf-8', 'replace'))
                appid = str(app_content['appinfo']['appid'])
                try:
                    type_ = app_content['appinfo']['common']['type'].lower()
                    title = app_content['appinfo']['common']['name']
                    parent = None
                    if 'extended' in app_content['appinfo'] and type_ == 'dlc':
                        parent = app_content['appinfo']['extended'][
                            'dlcforappid']
                        logger.debug(f"Retrieved dlc {title} for {parent}")
                    if type == 'game':
                        logger.debug(f"Retrieved game {title}")
                    self.app_info_handler(appid=appid,
                                          title=title,
                                          type=type_,
                                          parent=parent)
                except KeyError:
                    logger.warning(f"Unrecognized app structure {app_content}")
                    self.app_info_handler(appid=appid,
                                          title='unknown',
                                          type='unknown',
                                          parent=None)

        loop = asyncio.get_running_loop()
        await loop.run_in_executor(None, product_info_handler,
                                   message.packages, message.apps)

        if len(apps_to_parse) > 0:
            logger.debug("Apps to parse: %s", str(apps_to_parse))
            await self.get_apps_info(apps_to_parse)
    async def _process_package_info_response(self, body):
        logger.info("Processing message PICSProductInfoResponse")
        message = steammessages_clientserver_pb2.CMsgClientPICSProductInfoResponse(
        )
        message.ParseFromString(body)
        apps_to_parse = []

        for info in message.packages:
            await self.package_info_handler()

            package_id = str(info.packageid)
            package_content = vdf.binary_loads(info.buffer[4:])
            package = package_content.get(package_id)
            if package is None:
                continue

            for app in package['appids'].values():
                appid = str(app)
                await self.app_info_handler(package_id=package_id, appid=appid)
                apps_to_parse.append(app)

        for info in message.apps:
            app_content = vdf.loads(info.buffer[:-1].decode(
                'utf-8', 'replace'))
            appid = str(app_content['appinfo']['appid'])
            try:
                type_ = app_content['appinfo']['common']['type'].lower()
                title = app_content['appinfo']['common']['name']
                if type == 'game':
                    logger.info(f"Retrieved game {title}")
                await self.app_info_handler(appid=appid,
                                            title=title,
                                            type=type_)
            except KeyError:
                logger.info(f"Unrecognized app structure {app_content}")
                await self.app_info_handler(appid=appid,
                                            title='unknown',
                                            type='unknown')

        if len(apps_to_parse) > 0:
            logger.info(
                f"Apps to parse {apps_to_parse}, {len(apps_to_parse)} entries")
            await self.get_apps_info(apps_to_parse)