Utilities#

nrk_psapi.utils.get_nested_items(data, items_key)[source]#

Get nested items from a dictionary based on the provided items_key.

Return type:

list[dict[str, any]]

Parameters:
nrk_psapi.utils.get_image(images, min_size=None)[source]#
Return type:

Image | None

Parameters:
nrk_psapi.utils.sanitize_string(s, delimiter='_')[source]#

Sanitize a string to be used as a URL parameter.

Parameters:
async nrk_psapi.utils.fetch_file_info(url, session=None)[source]#

Retrieve content-length and content-type for the given URL.

Return type:

FetchedFileInfo

Parameters:
  • url (URL | str)

  • session (ClientSession | None)

nrk_psapi.utils.parse_aspect_ratio(ar)[source]#
Return type:

Fraction

Parameters:

ar (str)

async nrk_psapi.utils.tiled_images(image_urls, tile_size=100, columns=3, aspect_ratio=None, *, session=None)[source]#

Generate a tiled image from a list of image URLs.

Parameters:
  • image_urls (list[str]) – List of image URLs to tile.

  • tile_size (int) – Size of each tile in pixels.

  • columns (int) – Number of columns in the tiled image.

  • aspect_ratio (str | None) – Desired aspect ratio of the resulting image, e.g. “16:9”. If not provided, the aspect ratio will be a result of the number of image_urls divided by columns.

  • session (ClientSession | None) – Optional aiohttp session to use. If not provided, a new session will be created.

Return type:

bytes