Пример #1
0
def download_logo(twitch_helix_api, streamer, streamer_id):
    logo_url = twitch_helix_api.get_profile_image_url(streamer_id)

    logo_raw_path = f"static/images/logo_{streamer}.png"

    # returns bytes
    logo_image_bytes = BaseAPI(None).get_binary(logo_url)

    # write full-size image...
    with open(logo_raw_path, "wb") as logo_raw_file:
        logo_raw_file.write(logo_image_bytes)
Пример #2
0
def download_sub_badge(twitch_badges_api, streamer, streamer_id,
                       subscriber_badge_version):
    try:
        subscriber_badge = twitch_badges_api.get_channel_subscriber_badge(
            streamer_id, subscriber_badge_version)
    except BadgeNotFoundError as e:
        log.warn(f"Unable to download subscriber badge: {e}")
        return

    subscriber_badge_path = f"static/images/badge_sub_{streamer}.png"

    # returns bytes
    subscriber_badge_bytes = BaseAPI(None).get_binary(
        subscriber_badge.image_url_1x)

    # write image...
    with open(subscriber_badge_path, "wb") as subscriber_badge_file:
        subscriber_badge_file.write(subscriber_badge_bytes)
Пример #3
0
def download_logo(twitch_helix_api: TwitchHelixAPI,
                  streamer: UserBasics) -> None:
    logo_url = twitch_helix_api.get_profile_image_url(streamer.id)

    if logo_url is None:
        log.warn(
            f"Failed to query Twitch API for the profile image url of streamer {streamer.login}"
        )
        return

    logo_raw_path = f"static/images/logo_{streamer.login}.png"

    # returns bytes
    logo_image_bytes = BaseAPI(None).get_binary(logo_url)

    # write full-size image...
    with open(logo_raw_path, "wb") as logo_raw_file:
        logo_raw_file.write(logo_image_bytes)
Пример #4
0
def download_logo(twitch_helix_api, streamer, streamer_id):
    logo_url = twitch_helix_api.get_profile_image_url(streamer_id)

    logo_raw_path = f"static/images/logo_{streamer}.png"
    logo_tn_path = f"static/images/logo_{streamer}_tn.png"

    # returns bytes
    logo_image_bytes = BaseAPI(None).get_binary(logo_url)

    # write full-size image...
    with open(logo_raw_path, "wb") as logo_raw_file:
        logo_raw_file.write(logo_image_bytes)

    # decode downloaded image
    read_stream = BytesIO(logo_image_bytes)
    pil_image = Image.open(read_stream)

    # downscale and save the thumbnail
    pil_image.thumbnail((64, 64), Image.ANTIALIAS)
    pil_image.save(logo_tn_path, "png")