Client#

nrk-psapi.

class nrk_psapi.api.NrkPodcastAPI[source]#

Bases: object

NrkPodcastAPI(auth_client: ‘NrkAuthClient’ = <factory>, disable_credentials_storage: ‘bool’ = False, user_agent: ‘str | None’ = None, enable_cache: ‘bool’ = True, cache_directory: ‘str | None’ = None, request_timeout: ‘int’ = 15, session: ‘ClientSession | None’ = None, _close_session: ‘bool’ = False)

auth_client: NrkAuthClient#

The authentication client.

Type:

auth_client (NrkAuthClient)

disable_credentials_storage: bool = False#

Whether to disable credential storage.

user_agent: str | None = None#

User agent string.

enable_cache: bool = True#

Enable caching, defaults to True.

cache_directory: str | None = None#

Cache directory, defaults to (in order):

  1. Value of environment variable NRK_PSAPI_CACHE_DIR

  2. ~/.cache/nrk-psapi

request_timeout: int = 15#

Request timeout in seconds, defaults to 15.

session: ClientSession | None = None#

Optional web session to use for requests.

async save_credentials(filename=None)[source]#

Save the current authentication credentials to a file.

Parameters:

filename (PathLike | None) – The file to save the credentials to. If None, uses the default location.

Return type:

None

async load_credentials(filename=None)[source]#

Load authentication credentials from a file.

Parameters:

filename (PathLike | None) – The file to load the credentials from. If None, uses the default location.

Return type:

None

async ipcheck()[source]#

Check if IP is blocked.

Return type:

IpCheck

async send_message(podcast_id, message, *, anonymous=False, phone=None)[source]#

Send a message to a podcast.

Parameters:
  • podcast_id (str) – Id of the podcast

  • message (str) – Message to send

  • anonymous (bool, optional) – Anonymous. Defaults to False.

  • phone (str, optional) – Phone number. Defaults to None.

Return type:

None

async get_playback_manifest(item_id, *, podcast=False, program=False, channel=False)[source]#

Get the manifest for an episode/program/channel.

Parameters:
  • item_id (str) – Media id

  • channel (bool, optional) – Media is a channel. Defaults to False.

  • program (bool, optional) – Media is a program. Defaults to False.

  • podcast (bool, optional) – Media is a podcast. Defaults to False.

Return type:

PodcastManifest

async get_playback_metadata(item_id, *, podcast=False, program=False, channel=False)[source]#

Get the metadata for an episode/program/channel.

Parameters:
  • item_id (str, optional) – Media id

  • channel (bool, optional) – Media is a channel. Defaults to False.

  • program (bool, optional) – Media is a program. Defaults to False.

  • podcast (bool, optional) – Media is a podcast. Defaults to False.

Return type:

PodcastMetadata

async get_episode(podcast_id, episode_id)[source]#

Get episode.

Parameters:
  • podcast_id (str) – Podcast ID.

  • episode_id (str) – Episode ID.

Return type:

Episode

async get_series_type(series_id)[source]#

Get series type.

Parameters:

series_id (str) – Series ID.

Return type:

SeriesType

async get_podcast_type(podcast_id)[source]#

Get podcast type.

Parameters:

podcast_id (str) – Podcast ID.

Return type:

SeriesType

async get_series_season(series_id, season_id)[source]#

Get series season.

Parameters:
  • series_id (str) – Series ID.

  • season_id (str) – Season ID.

Return type:

Season

async get_series_episodes(series_id, season_id=None, *, page_size=None, page=1)[source]#

Get series episodes.

Parameters:
  • series_id (str) – Series ID.

  • season_id (str, optional) – Season ID.

  • page_size (int, optional) – Number of episodes to return per page (defaults to 50)

  • page (int, optional) – Page number, set to -1 for all (defaults to 1)

Return type:

list[Episode]

async get_live_channel(channel_id)[source]#

Get live channel.

Parameters:

channel_id (str) – Channel ID.

Return type:

Channel

async get_program(program_id)[source]#

Get program.

Parameters:

program_id (str) – Program ID.

Return type:

Program

async get_podcast(podcast_id)[source]#

Get podcast.

Parameters:

podcast_id (str) – Podcast ID.

Return type:

Podcast | PodcastStandard | PodcastUmbrella | PodcastSequential

async get_podcasts(podcast_ids)[source]#

Get podcasts.

Parameters:

podcast_ids (list[str]) – List of podcast ids.

Return type:

list[Podcast]

async get_podcast_season(podcast_id, season_id)[source]#

Get podcast season.

Parameters:
  • podcast_id (str) – Podcast ID

  • season_id (str) – Season ID

Return type:

Season

async get_podcast_episodes(podcast_id, season_id=None, *, page_size=None, page=None)[source]#

Get podcast episodes.

Parameters:
  • podcast_id (str) – Podcast ID

  • season_id (str, optional) – Season ID

  • page_size (int, optional) – Number of episodes to return per page (defaults to 50)

  • page (int, optional) – Page number, set to -1 for all (defaults to 1)

Return type:

list[Episode]

async get_all_podcasts()[source]#

Get all podcasts.

Return type:

list[SeriesListItem]

async get_series(series_id)[source]#

Get series.

Parameters:

series_id (str) – Series ID.

Return type:

Podcast

async get_recommendations(item_id, context_id=None, limit=None)[source]#

Get recommendations.

Parameters:
  • item_id (str) – A id of a series/program/episode/season etc.

  • context_id (RecommendationContext, optional) – Which context (front page, series page, etc.) the user is in.

  • limit (int, optional) – Number of recommendations returned (max 25). Defaults to 12.

Return type:

Recommendation

async count_new_favourited_episodes(favourite_level=None, since=None)[source]#

Count new episodes.

Parameters:
  • favourite_level (FavouriteLevel | None)

  • since (datetime | None)

async get_user_favorites(manual_only=False, sort_order=SortOrder.DESCENDING, key=None, page_size=None)[source]#

Get user favorites.

Parameters:
async add_user_favourite(item_type, item_id)[source]#

Add user favourite.

Parameters:
  • item_type (str)

  • item_id (str)

async browse(letter=None, category=None, per_page=50, page=1)[source]#

Browse all series, podcast and umbrella seasons, optionally filtered by category.

Alphabetical listing of all series, podcasts and umbrella seasons that are not excluded from search results in given category. Categories correspond to those in from radio_pages(). For the category ‘podcast’, all podcasts are listed, also those excluded from search results.

Parameters:
  • category (str, optional) – Category. Defaults to None, which will list all.

  • letter (SingleLetter, optional) – A single letter.

  • per_page (int, optional) – Number of items per page. Defaults to 50.

  • page (int, optional) – Page number. Defaults to 1.

Return type:

CategoriesResponse

async search(query, per_page=50, page=1, search_type=None)[source]#

Search anything.

Parameters:
  • query (str) – Search query.

  • per_page (int, optional) – Number of items per page. Defaults to 50.

  • page (int, optional) – Page number. Defaults to 1.

  • search_type (SearchResultType, optional) – Search type, one of SearchResultType. Defaults to all.

Return type:

SearchResponse

async search_suggest(query)[source]#

Search autocomplete/auto-suggest.

Parameters:

query (str) – Search query

Return type:

list[str]

async radio_pages()[source]#

Get radio pages.

Return type:

Pages

async radio_page(page_id, section_id=None)[source]#

Get radio page.

Parameters:
  • page_id (str) – Name of the page, e.g. ‘discover’.

  • section_id (str, optional) – Web friendly title of the section, e.g. ‘krim-fra-virkeligheten’.

Return type:

Page | Included | None

async curated_podcasts()[source]#

Get curated podcasts. This is a wrapper around radio_page(), with the section_id set to “podcast” and some logic to make it easier to use for accessing curated podcasts.

Return type:

Curated

async fetch_file_info(url)[source]#

Proxies call to utils.fetch_file_info(), passing on session.

Return type:

FetchedFileInfo

Parameters:

url (URL | str)

async generate_tiled_images(image_urls, tile_size=100, columns=3, aspect_ratio=None)[source]#

Proxies call to utils.tiled_images(), passing on session.

Return type:

bytes

Parameters:
  • image_urls (list[str])

  • tile_size (int)

  • columns (int)

  • aspect_ratio (str | None)

async close()[source]#

Close open client session.

Return type:

None