Client class to use Xtream API.
Connect to a server using Xtream API, authorize, get user and server information, get live/vod/series information, get categories, get epgs, download a playlist or build one from JSON data.
__init__(
url: str,
username: str,
password: str,
headers: Optional[Dict[str, str]] = None
) → Noneinit method to initialize the client.
Set up request session and instance variables.
Args:
server_url(str): Required server url.username(str): Required username.password(str): Required password.headers(Params | None, optional): Optional headers to pass to requests. Default headers are set to a browser user agent.
TODO: m3u8 playlists?, retry error handling may need more work
List output formats allowed by the server.
Returns:
List[str]: List of output formats
Headers used by this XC instance in http requests
Returns:
Params: a dictionary to use for headers in an http request
Stream output format for live streams, either '' or one of the valid types allowed by the server.
Returns:
str: the current output_type for this XC instance
Password used by this XC instance
Returns:
str: the password used by this XC instance
Playlist type to create, either 'm3u' or 'm3u_plus' Only creating m3u for now.
Returns:
str: the current playlist_type for this XC instance
Server Info. Contains the server_info data obtained during authorization. No setter defined, only auth sets this.
Raises:
XCAuthError: if auth fails
Returns:
JSON: dictionary of server_info data
Server url used by this XC instance
Returns:
str: the server url being used by this XC instance
User info from the server. Contains the user_info data obtained during authorization. No setter defined, only auth sets this.
Raises:
XCAuthError: If auth fails
Returns:
JSON: a dictionary with the user info from the server
Username used by this XC instance
Returns:
str: the username being used by this XC instance
auth() → boolBasic request to get user and server info.
Returns:
bool: True if successful
build_m3u_from_category(
category: Dict[str, Any],
file_path: str | None = None,
tvg_chno: int | None = None,
include_extm3u: bool | None = False
) → List[str]Build an m3u from a single category. Optionally includes #EXTM3U line at the beginning.
Args:
category(JSON): JSON data with category information. A single item from what you would receive from get_categories.file_path(str): Optional file path to save playlist to.tvg_chno(int | None, optional): Optional channel number to start numbering from if using tvg-chno. Defaults to None.include_extm3u(bool | None, optional): Includes #EXTM3U line at the beginning of the playlist. Defaults to False.
Returns:
List[str]: m3u data as a list of strings
build_m3u_from_json(
file_path: str | None = None,
live: bool | None = False,
vod: bool | None = False,
series: bool | None = False,
tvg_chno: int | None = None,
include_extm3u: bool | None = True
) → List[str]Build and optionally write an m3u from JSON data from the server. Proceeds by category, no other sorting is done. Optionally includes #EXTM3U line at the beginning. If no stream types are selected, defaults to live streams.
Args:
file_path(str | None, optional): Write m3u to this path if provided. Defaults to None.live(bool | None, optional): Get all live streams. Defaults to False.vod(bool | None, optional): Get all vod streams. Defaults to False.series(bool | None, optional): Get all series streams. Defaults to False.tvg_chno(int | None, optional): If outputting a tvg-chno field, start at this number. Defaults to None.include_extm3u(bool | None, optional): Include the #EXTM3U line if using this to write a file. Defaults to True.
Raises:
ValueError: at least one stream type needs to be True
Returns:
List[str]: m3u data in a list of strings
get_categories(
live: bool | None = False,
vod: bool | None = False,
series: bool | None = False
) → List[Dict[str, Any]]Get Live, VOD, and/or Series categories. You can combine multiple types in one call. Returns Live categories by default.
Args:
live(bool | None, optional): Get live categories. Defaults to True.vod(bool | None, optional): Get vod categories. Defaults to False.series(bool | None, optional): Get series categories. Defaults to False.
Raises:
ValueError: if no category types are selected
Returns:
List[JSON]: List of JSON data for categories
get_epg(stream_id: int | str | None = None) → Dict[str, Any]Get EPG data for all streams, or for a specific stream with stream_id.
Not sure if this is widely used. Use get_xmltv if needed.
Args:
stream_id(int | str | None, optional): Optional stream id to use. Defaults to None.
Returns:
JSON: JSON data for the streams
get_info(
stream_id: int | str,
vod: bool | None = None,
series: bool | None = None
) → Dict[str, Any]Get info for a VOD or Series id
Args:
stream_id(int | str): stream id to get info forvod(bool): use stream_id to get vod infoseries(bool): use stream_id to get series info
Raises:
ValueError: invalid or missing arguments
Returns:
JSON: JSON data for the stream id
get_m3u(file_path: str | None = None) → strGet m3u from the server, and save to file path if provided.
This endpoint might be missing. Be ready for errors.
Args:
file_path(str | None, optional): Save m3u to this path if provided. Defaults to None.
Returns:
str: String containing m3u data
get_panel() → Dict[str, Any]Get panel info from panel_api endpoint
This returns a lot of info such as user/server/stream information, but user and server info did not have as much data as an auth call. More may be missing. Not sure of the use case for this.
Returns:
JSON: JSON data for a lot of different things, but not as complete
get_short_epg(stream_id: int | str) → Dict[str, Any]Get short epg for a stream id.
Not sure if this is widely used. Use get_xmltv if needed.
Args:
stream_id(int | str): stream id to use
Returns:
JSON: JSON epg data
get_streams(
live: bool | None = None,
vod: bool | None = False,
series: bool | None = False,
category_id: int | str | None = None
) → List[Dict[str, Any]]Get all selected stream types from the server, optionally restricted by category.
Gets multiple types at a time. Defaults to live streams if no types are set to True.
Args:
live(bool | None, optional): Get Live streams. Defaults to False.vod(bool | None, optional): Get VOD streams. Defaults to False.series(bool | None, optional): Get Series streams. Defaults to False.category_id(int | str | None, optional): Optional category id to get streams from. Defaults to None.
Raises:
ValueError: if both vod and series are True
Returns:
List[JSON]: List of JSON data for streams
get_xmltv(file_path: str | None = None) → strGet XML epg data from the server, and save to file_path if provided.
Args:
file_path(str | None, optional): Save xml to this path if provided . Defaults to None.
Returns:
str: String containing xml epg data
Exception raised for 404 errors.
__init__(message: str, code: int | None = None)Exception raised for 503 errors.
__init__(message: str, code: int | None = None)Exception raised for authentication errors.
__init__(message: str, code: int | None = None)This filefile was automatically generated via lazydocs.