Beispiel #1
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game["slug"]
        sync_required = False
        local_game = pga.get_game_by_field(slug, "slug")
        if not local_game:
            continue
        if local_game[
                "updated"] and remote_game["updated"] > local_game["updated"]:
            # The remote game's info is more recent than the local game
            sync_required = True
        else:
            for key in remote_game.keys():
                if (key in local_game.keys() and remote_game[key]
                        and not local_game[key]):
                    # Remote game has data that is missing from the local game.
                    logger.info("Key %s is not present, forcing update", key)
                    sync_required = True
                    break

        if not sync_required:
            continue

        logger.debug("Syncing details for %s", slug)
        game_id = pga.add_or_update(
            id=local_game["id"],
            name=local_game["name"],
            runner=local_game["runner"],
            slug=slug,
            year=remote_game["year"],
            updated=remote_game["updated"],
            steamid=remote_game["steamid"],
        )
        updated.add(game_id)

        if not local_game.get(
                "has_custom_banner") and remote_game["banner_url"]:
            path = resources.get_icon_path(slug, resources.BANNER)
            resources.download_media(remote_game["banner_url"],
                                     path,
                                     overwrite=True)
        if not local_game.get("has_custom_icon") and remote_game["icon_url"]:
            path = resources.get_icon_path(slug, resources.ICON)
            resources.download_media(remote_game["icon_url"],
                                     path,
                                     overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #2
0
    def fetch_icon(self, slug):
        if not self.media_loaded:
            self.games_to_refresh.add(slug)
            return

        for media_type in ('banner', 'icon'):
            url = self.medias[media_type].get(slug)
            if url:
                download_media(url, get_icon_path(slug, media_type))
                self.emit('icon-loaded', slug, media_type)
Beispiel #3
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game['slug']
        sync_required = False
        local_game = pga.get_game_by_field(slug, 'slug')
        if not local_game:
            continue

        if local_game[
                'updated'] and remote_game['updated'] > local_game['updated']:
            # The remote game's info is more recent than the local game
            sync_required = True
        else:
            for key in remote_game.keys():
                if key in local_game.keys(
                ) and remote_game[key] and not local_game[key]:
                    # Remote game has data that is missing from the local game.
                    sync_required = True
                    break

        if not sync_required:
            continue

        logger.debug("Syncing details for %s" % slug)
        game_id = pga.add_or_update(name=local_game['name'],
                                    runner=local_game['runner'],
                                    slug=slug,
                                    year=remote_game['year'],
                                    updated=remote_game['updated'],
                                    steamid=remote_game['steamid'])
        updated.add(game_id)

        if not local_game.get(
                'has_custom_banner') and remote_game['banner_url']:
            path = resources.get_icon_path(slug, resources.BANNER)
            resources.download_media(remote_game['banner_url'],
                                     path,
                                     overwrite=True)
        if not local_game.get('has_custom_icon') and remote_game['icon_url']:
            path = resources.get_icon_path(slug, resources.ICON)
            resources.download_media(remote_game['icon_url'],
                                     path,
                                     overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #4
0
    def fetch_icon(self, slug):
        if not self.media_loaded:
            self.games_to_refresh.add(slug)
            return

        for media_type in ("banner", "icon"):
            url = self.medias[media_type].get(slug)
            if url:
                logger.debug("Getting %s for %s: %s", media_type, slug, url)
                download_media(url, get_icon_path(slug, media_type))
                self.emit("icon-loaded", slug, media_type)
Beispiel #5
0
 def get_banner(cls, gog_game):
     """Return the path to the game banner.
     Downloads the banner if not present.
     """
     image_url = "https:%s_prof_game_100x60.jpg" % gog_game['image']
     image_hash = gog_game['image'].split("/")[-1]
     cache_dir = os.path.join(settings.CACHE_DIR, "gog/banners/small/")
     if not system.path_exists(cache_dir):
         os.makedirs(cache_dir)
     cache_path = os.path.join(cache_dir, "%s.jpg" % image_hash)
     if not system.path_exists(cache_path):
         download_media(image_url, cache_path)
     return cache_path
Beispiel #6
0
 def get_banner(cls, gog_game):
     """Return the path to the game banner.
     Downloads the banner if not present.
     """
     image_url = "https:%s_prof_game_100x60.jpg" % gog_game["image"]
     image_hash = gog_game["image"].split("/")[-1]
     cache_dir = os.path.join(settings.CACHE_DIR, "gog/banners/small/")
     if not system.path_exists(cache_dir):
         os.makedirs(cache_dir)
     cache_path = os.path.join(cache_dir, "%s.jpg" % image_hash)
     if not system.path_exists(cache_path):
         download_media(image_url, cache_path)
     return cache_path
Beispiel #7
0
 def get_icon(cls, gog_game):
     """Download the icon for the game and return the local path"""
     icon_url = gog_game["icon"]
     cache_dir = os.path.join(settings.CACHE_DIR, "humblebundle/icons/")
     if not system.path_exists(cache_dir):
         os.makedirs(cache_dir)
     icon_filename = os.path.basename(urlparse(icon_url).path)
     if not icon_filename:
         return ""
     cache_path = os.path.join(cache_dir, icon_filename)
     if not system.path_exists(cache_path):
         download_media(icon_url, cache_path)
     return cache_path
Beispiel #8
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game['slug']
        sync_required = False
        local_game = pga.get_game_by_field(slug, 'slug')
        if not local_game:
            continue

        if local_game['updated'] and remote_game['updated'] > local_game['updated']:
            # The remote game's info is more recent than the local game
            sync_required = True
        else:
            for key in remote_game.keys():
                if key in local_game.keys() and remote_game[key] and not local_game[key]:
                    # Remote game has data that is missing from the local game.
                    sync_required = True
                    break

        if not sync_required:
            continue

        logger.debug("Syncing details for %s" % slug)
        game_id = pga.add_or_update(
            name=local_game['name'],
            runner=local_game['runner'],
            slug=slug,
            year=remote_game['year'],
            updated=remote_game['updated'],
            steamid=remote_game['steamid']
        )
        updated.add(game_id)

        if not local_game.get('has_custom_banner') and remote_game['banner_url']:
            path = resources.get_icon_path(slug, resources.BANNER)
            resources.download_media(remote_game['banner_url'], path, overwrite=True)
        if not local_game.get('has_custom_icon') and remote_game['icon_url']:
            path = resources.get_icon_path(slug, resources.ICON)
            resources.download_media(remote_game['icon_url'], path, overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #9
0
def get_user_info():
    """Retrieves the user info to cache it locally"""
    credentials = read_api_key()
    if not credentials:
        return []
    url = settings.SITE_URL + "/api/users/me"
    request = http.Request(url, headers={"Authorization": "Token " + credentials["token"]})
    response = request.get()
    account_info = response.json
    if not account_info:
        logger.warning("Unable to fetch user info for %s", credentials["username"])
    with open(USER_INFO_FILE_PATH, "w") as token_file:
        json.dump(account_info, token_file, indent=2)
    if account_info.get("avatar_url"):
        resources.download_media(account_info["avatar_url"], USER_ICON_FILE_PATH)
Beispiel #10
0
def get_user_info():
    """Retrieves the user info to cache it locally"""
    credentials = read_api_key()
    if not credentials:
        return []
    url = settings.SITE_URL + "/api/users/me"
    request = http.Request(url, headers={"Authorization": "Token " + credentials["token"]})
    response = request.get()
    account_info = response.json
    if not account_info:
        logger.warning("Unable to fetch user info for %s", credentials["username"])
    with open(USER_INFO_FILE_PATH, "w") as token_file:
        json.dump(account_info, token_file, indent=2)
    if account_info.get("avatar_url"):
        resources.download_media(account_info["avatar_url"], USER_ICON_FILE_PATH)
Beispiel #11
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game["slug"]
        sync_required = False
        local_game = pga.get_game_by_field(slug, "slug")
        if not local_game:
            continue
        if local_game["updated"] and remote_game["updated"] > local_game["updated"]:
            # The remote game's info is more recent than the local game
            sync_required = True

        if not sync_required:
            continue

        logger.debug("Syncing details for %s", slug)
        game_id = pga.add_or_update(
            id=local_game["id"],
            name=local_game["name"],
            runner=local_game["runner"],
            slug=slug,
            year=remote_game["year"],
            updated=remote_game["updated"],
            steamid=remote_game["steamid"],
        )
        updated.add(game_id)

        if not local_game.get("has_custom_banner") and remote_game["banner_url"]:
            path = resources.get_banner_path(slug)
            resources.download_media(remote_game["banner_url"], path, overwrite=True)
        if not local_game.get("has_custom_icon") and remote_game["icon_url"]:
            path = resources.get_icon_path(slug)
            resources.download_media(remote_game["icon_url"], path, overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated
Beispiel #12
0
def sync_game_details(remote_library):
    """Update local game details,

    :return: A set of ids of the updated games.
    """
    if not remote_library:
        return set()
    updated = set()

    for remote_game in remote_library:
        slug = remote_game["slug"]
        sync_required = False
        local_game = pga.get_game_by_field(slug, "slug")
        if not local_game:
            continue
        if local_game["updated"] and remote_game["updated"] > local_game["updated"]:
            # The remote game's info is more recent than the local game
            sync_required = True

        if not sync_required:
            continue

        logger.debug("Syncing details for %s", slug)
        game_id = pga.add_or_update(
            id=local_game["id"],
            name=local_game["name"],
            runner=local_game["runner"],
            slug=slug,
            year=remote_game["year"],
            updated=remote_game["updated"],
            steamid=remote_game["steamid"],
        )
        updated.add(game_id)

        if not local_game.get("has_custom_banner") and remote_game["banner_url"]:
            path = resources.get_banner_path(slug)
            resources.download_media(remote_game["banner_url"], path, overwrite=True)
        if not local_game.get("has_custom_icon") and remote_game["icon_url"]:
            path = resources.get_icon_path(slug)
            resources.download_media(remote_game["icon_url"], path, overwrite=True)

    if updated:
        logger.debug("%d games updated", len(updated))
    return updated