Exemple #1
0
 def get_installer_files(self, installer, installer_file_id):
     try:
         links = get_gog_download_links(installer.service_appid,
                                        installer.runner)
     except HTTPError:
         raise UnavailableGame(
             "Couldn't load the download links for this game")
     if not links:
         raise UnavailableGame("Could not fing GOG game")
     files = []
     file_id_provided = False  # Only assign installer_file_id once
     for index, link in enumerate(links):
         url = link["url"] if isinstance(link, dict) else link
         filename = link["filename"]
         if filename.lower().endswith(
             (".exe", ".sh")) and not file_id_provided:
             file_id = installer_file_id
             file_id_provided = True
         else:
             file_id = "gog_file_%s" % index
         files.append(
             InstallerFile(installer.game_slug, file_id, {
                 "url": url,
                 "filename": filename,
             }))
     if not file_id_provided:
         raise UnavailableGame(
             "Unable to determine correct file to launch installer")
     return files
Exemple #2
0
 def get_installer_files(self, installer, installer_file_id):
     try:
         downloads = self.get_downloads(installer.service_appid)
         gog_installers = self.get_installers(downloads, installer.runner)
         if not gog_installers:
             return []
         if len(gog_installers) > 1:
             logger.warning(
                 "More than 1 GOG installer found, picking first.")
         _installer = gog_installers[0]
         links = self.query_download_links(_installer)
     except HTTPError:
         raise UnavailableGame(
             "Couldn't load the download links for this game")
     if not links:
         raise UnavailableGame("Could not fing GOG game")
     _installer_files = defaultdict(dict)  # keyed by filename
     for link in links:
         filename = link["filename"]
         if filename.lower().endswith(".xml"):
             if filename != installer_file_id:
                 filename = filename[:-4]
             _installer_files[filename]["checksum_url"] = link["url"]
             continue
         _installer_files[filename]["id"] = link["id"]
         _installer_files[filename]["url"] = link["url"]
         _installer_files[filename]["filename"] = filename
         _installer_files[filename]["total_size"] = link["total_size"]
     files = []
     file_id_provided = False  # Only assign installer_file_id once
     for _file_id in _installer_files:
         installer_file = _installer_files[_file_id]
         if "url" not in installer_file:
             raise ValueError("Invalid installer file %s" % installer_file)
         filename = installer_file["filename"]
         if filename.lower().endswith(
             (".exe", ".sh")) and not file_id_provided:
             file_id = installer_file_id
             file_id_provided = True
         else:
             file_id = _file_id
         files.append(
             InstallerFile(
                 installer.game_slug, file_id, {
                     "url": installer_file["url"],
                     "filename": installer_file["filename"],
                     "checksum_url": installer_file.get("checksum_url")
                 }))
     if not file_id_provided:
         raise UnavailableGame(
             "Unable to determine correct file to launch installer")
     if self.selected_extras:
         for extra_file in self.get_extra_files(downloads, installer):
             files.append(extra_file)
     return files
Exemple #3
0
 def get_download_info(self, downlink):
     """Return file download information"""
     logger.info("Getting download info for %s", downlink)
     try:
         response = self.make_api_request(downlink)
     except HTTPError:
         raise UnavailableGame()
     if not response:
         raise UnavailableGame()
     for field in ("checksum", "downlink"):
         field_url = response[field]
         parsed = urlparse(field_url)
         query = dict(parse_qsl(parsed.query))
         response[field + "_filename"] = os.path.basename(query.get("path") or parsed.path)
     return response
Exemple #4
0
    def get_installer_files(self, installer, installer_file_id):
        if not self.is_connected():
            self.login()
        if not self.is_connected():
            logger.warning("Not connected to GOG, not returning any files")
            return []
        try:
            downloads = self.get_downloads(installer.service_appid)
            gog_installers = self.get_installers(downloads, installer.runner)
            if not gog_installers:
                return []
            if len(gog_installers) > 1:
                logger.warning(
                    "More than 1 GOG installer found, picking first.")
            _installer = gog_installers[0]
            links = self.query_download_links(_installer)
        except HTTPError:
            raise UnavailableGame(
                "Couldn't load the download links for this game")
        if not links:
            raise UnavailableGame("Could not fing GOG game")

        files = []
        file_id_provided = False  # Only assign installer_file_id once
        for index, link in enumerate(links):
            if isinstance(link, dict):
                url = link["url"]
            else:
                url = link
            filename = link["filename"]
            if filename.lower().endswith(
                (".exe", ".sh")) and not file_id_provided:
                file_id = installer_file_id
                file_id_provided = True
            else:
                file_id = "gog_file_%s" % index
            files.append(
                InstallerFile(installer.game_slug, file_id, {
                    "url": url,
                    "filename": filename,
                }))
        if not file_id_provided:
            raise UnavailableGame(
                "Unable to determine correct file to launch installer")
        if self.selected_extras:
            for extra_file in self.get_extra_files(downloads, installer):
                files.append(extra_file)
        return files
Exemple #5
0
 def prepare_game_files(self):
     """Gathers necessary files before iterating through them."""
     # If this is a GOG installer, download required files.
     if not self.service:
         return
     if not self.service_appid:
         raise UnavailableGame("No ID for the game on %s" % self.service)
     installer_file_id = self.pop_user_provided_file()
     if not installer_file_id:
         raise UnavailableGame("Installer has no user provided file")
     installer_files = self.service.get_installer_files(
         self, installer_file_id)
     if not installer_files:
         raise UnavailableGame("Unable to get the game on %s" %
                               self.service.name)
     for installer_file in installer_files:
         self.files.append(installer_file)
Exemple #6
0
 def _get_installer_links(self, installer, downloads):
     """Return links to downloadable files from a list of downloads"""
     try:
         gog_installers = self.get_installers(downloads, installer.runner)
         if not gog_installers:
             return []
         if len(gog_installers) > 1:
             logger.warning(
                 "More than 1 GOG installer found, picking first.")
         _installer = gog_installers[0]
         return self.query_download_links(_installer)
     except HTTPError as err:
         raise UnavailableGame(
             "Couldn't load the download links for this game") from err
Exemple #7
0
 def get_installer_files(self, installer, installer_file_id):
     try:
         downloads = self.get_downloads(installer.service_appid)
     except HTTPError as err:
         raise UnavailableGame(
             "Couldn't load the downloads for this game") from err
     links = self._get_installer_links(installer, downloads)
     if links:
         files = self._format_links(installer, installer_file_id, links)
     else:
         files = []
     if self.selected_extras:
         for extra_file in self.get_extra_files(downloads, installer):
             files.append(extra_file)
     return files
Exemple #8
0
 def get_installer_files(self, installer, installer_file_id):
     """Replace the user provided file with download links from Humble Bundle"""
     try:
         link = get_humble_download_link(installer.service_appid, installer.runner)
     except Exception as ex:
         logger.exception("Failed to get Humble Bundle game: %s", ex)
         raise UnavailableGame
     if not link:
         raise UnavailableGame("No game found on Humble Bundle")
     filename = link.split("?")[0].split("/")[-1]
     return [
         InstallerFile(installer.game_slug, installer_file_id, {
             "url": link,
             "filename": filename
         })
     ]
Exemple #9
0
 def _format_links(self, installer, installer_file_id, links):
     _installer_files = defaultdict(dict)  # keyed by filename
     for link in links:
         try:
             filename = link["filename"]
         except KeyError:
             logger.error("Invalid link: %s", link)
             raise
         if filename.lower().endswith(".xml"):
             if filename != installer_file_id:
                 filename = filename[:-4]
             _installer_files[filename]["checksum_url"] = link["url"]
             continue
         _installer_files[filename]["id"] = link["id"]
         _installer_files[filename]["url"] = link["url"]
         _installer_files[filename]["filename"] = filename
         _installer_files[filename]["total_size"] = link["total_size"]
     files = []
     file_id_provided = False  # Only assign installer_file_id once
     for _file_id in _installer_files:
         installer_file = _installer_files[_file_id]
         if "url" not in installer_file:
             raise ValueError("Invalid installer file %s" % installer_file)
         filename = installer_file["filename"]
         if filename.lower().endswith(
             (".exe", ".sh")) and not file_id_provided:
             file_id = installer_file_id
             file_id_provided = True
         else:
             file_id = _file_id
         files.append(
             InstallerFile(
                 installer.game_slug, file_id, {
                     "url": installer_file["url"],
                     "filename": installer_file["filename"],
                     "checksum_url": installer_file.get("checksum_url")
                 }))
     if not file_id_provided:
         raise UnavailableGame(
             "Unable to determine correct file to launch installer")
     return files