Example #1
0
    def get_library(self):
        if not self.active_token:
            return

        games = []
        current_page = 1
        all_pages_processed = False
        url = "https://embed.gog.com/account/getFilteredProducts"

        tags = {}

        while not all_pages_processed:
            params = {
                'mediaType': 1,  # 1 means game
                'page': current_page,
            }
            response = self.__request(url, params=params)
            total_pages = response["totalPages"]

            if response["tags"]:
                for tag in response["tags"]:
                    tags[tag["id"]] = tag["name"]

            for product in response["products"]:
                try:
                    if product["id"] not in IGNORE_GAME_IDS:
                        if not product["url"]:
                            print("{} ({}) has no store page url".format(
                                product["title"], product['id']))
                        supported_platforms = []
                        if product["worksOn"]["Linux"]:
                            supported_platforms.append("linux")
                        if product["worksOn"]["Windows"]:
                            supported_platforms.append("windows")
                        if product["worksOn"]["Mac"]:
                            supported_platforms.append("mac")
                        ptags = []
                        if product["tags"]:
                            for tag in product["tags"]:
                                ptags.append(tags[tag])
                        release_date = None
                        if "releaseDate" in product:
                            release_date = product["releaseDate"]
                        game = Game(name=product["title"],
                                    url=product["url"],
                                    game_id=product["id"])
                        game.updates = 0
                        game.image_url = product["image"]
                        game.installed = 0
                        game.tags = ptags if len(ptags) > 0 else None
                        game.set_main_genre(product["category"])
                        game.supported_platforms = supported_platforms
                        game.release_date = release_date
                        games.append(game)
                except Exception as e:
                    print(e)
            if current_page == total_pages:
                all_pages_processed = True
            current_page += 1
        return games
Example #2
0
 def __update(self, game: Game = None):
     GLib.idle_add(self.__update_to_state, game.state.UPDATING, game)
     game.install_dir = self.__get_install_dir(game)
     try:
         if os.path.exists(game.keep_path):
             install_game(self.game,
                          self.keep_path,
                          parent_window=self.parent)
         else:
             install_game(self.game,
                          self.update_path,
                          parent_window=self.parent)
     except (FileNotFoundError, BadZipFile):
         GLib.idle_add(self.__update_to_state, game.state.UPDATABLE, game)
         return
     # reset updates count flag
     game.updates = 0
     GLib.idle_add(self.__update_to_state, game.state.INSTALLED, game)