media.kodi

media.kodi

class platypush.plugins.media.kodi.MediaKodiPlugin(host, http_port=8080, websocket_port=9090, username=None, password=None, **kwargs)[source]

Plugin to interact with a Kodi media player instance

Requires:

  • kodi-json (pip install kodi-json)

__init__(host, http_port=8080, websocket_port=9090, username=None, password=None, **kwargs)[source]
Parameters:
  • host (str) – Kodi host name or IP

  • http_port (int) – Kodi JSON RPC web port. Remember to enable “Allow remote control via HTTP” in Kodi service settings -> advanced configuration and “Allow remote control from applications” on this system and, optionally, on other systems if the Kodi server is on another machine

  • websocket_port (int) – Kodi JSON RPC websocket port, used to receive player events

  • username (str) – Kodi username (optional)

  • password (str) – Kodi password (optional)

back(offset=30, player_id=None, *args, **kwargs)[source]

Move the player execution backward by delta_seconds

Parameters:
  • offset (float) – Backward seek duration (default: 30 seconds)

  • player_id – ID of the target player (default: configured/current player).

back_btn(*args, **kwargs)[source]

Simulate a back input event

clean_audio_library(*args, **kwargs)[source]

Clean the audio library

clean_video_library(*args, **kwargs)[source]

Clean the video library

down(*args, **kwargs)[source]

Simulate a down input event

download(url, filename=None, directory=None)

Download a media URL

Parameters:
  • url – Media URL

  • filename – Media filename (default: URL filename)

  • directory – Destination directory (default: download_dir)

Returns:

The absolute path to the downloaded file

forward(offset=30, player_id=None, *args, **kwargs)[source]

Move the player execution forward by delta_seconds

Parameters:
  • offset (float) – Forward seek duration (default: 30 seconds)

  • player_id – ID of the target player (default: configured/current player).

fullscreen(*args, **kwargs)[source]

Set/unset fullscreen mode

get_active_players()[source]

Get the list of active players

get_albums(*args, **kwargs)[source]

Get the list of albums in the audio library

get_artists(*args, **kwargs)[source]

Get the list of artists in the audio library

get_media_file_duration(filename)

Get the duration of a media file in seconds. Requires ffmpeg

get_movies(*args, **kwargs)[source]

Get the list of movies on the Kodi server

get_songs(*args, **kwargs)[source]

Get the list of songs in the audio library

is_muted(*args, **kwargs)[source]

Return the muted status of the application

left(*args, **kwargs)[source]

Simulate a left input event

mute(*args, **kwargs)[source]

Mute/unmute the application

next()

Play the next item in the queue

notify(title, message, *args, **kwargs)[source]

Send a notification to the Kodi UI

pause(player_id=None, *args, **kwargs)[source]

Play/pause the current media

play(resource, *args, **kwargs)[source]

Open and play the specified file or URL

Parameters:

resource – URL or path to the media to be played

quit(*args, **kwargs)[source]

Quit the application

repeat(player_id=None, repeat=None, *args, **kwargs)[source]

Set/unset repeat mode

right(*args, **kwargs)[source]

Simulate a right input event

scan_audio_library(*args, **kwargs)[source]

Scan the audio library

scan_video_library(*args, **kwargs)[source]

Scan the video library

search(query, types=None, queue_results=False, autoplay=False, search_timeout=60)

Perform a video search.

Parameters:
  • query (str) – Query string, video name or partial name

  • types (list) – Video types to search (default: ["youtube", "file", "torrent"])

  • queue_results (bool) – Append the results to the current playing queue (default: False)

  • autoplay (bool) – Play the first result of the search (default: False)

  • search_timeout (float) – Search timeout (default: 60 seconds)

seek(position, player_id=None, *args, **kwargs)[source]

Move to the specified time position in seconds

Parameters:
  • position (float) – Seek time in seconds

  • player_id – ID of the target player (default: configured/current player).

select(*args, **kwargs)[source]

Simulate a select input event

send_text(text, *args, **kwargs)[source]

Simulate a send_text input event

Parameters:

text (str) – Text to send

set_position(position, player_id=None, *args, **kwargs)[source]

Move to the specified time position in seconds

Parameters:
  • position (float) – Seek time in seconds

  • player_id – ID of the target player (default: configured/current player).

set_volume(volume, *args, **kwargs)[source]

Set the application volume

Parameters:

volume (int) – Volume to set between 0 and 100

shuffle(player_id=None, shuffle=None, *args, **kwargs)[source]

Set/unset shuffle mode

start_streaming(media, subtitles=None, download=False)

Starts streaming local media over the specified HTTP port. The stream will be available to HTTP clients on http://{this-ip}:{http_backend_port}/media/<media_id>

Parameters:
  • media (str) – Media to stream

  • subtitles (str) – Path or URL to the subtitles track to be used

  • download (bool) – Set to True if you prefer to download the file from the streaming link instead of streaming it

Returns:

dict containing the streaming URL.Example:

{
    "id": "0123456abcdef.mp4",
    "source": "file:///mnt/media/movies/movie.mp4",
    "mime_type": "video/mp4",
    "url": "http://192.168.1.2:8008/media/0123456abcdef.mp4"
}
stop(player_id=None, *args, **kwargs)[source]

Stop the current media

up(*args, **kwargs)[source]

Simulate an up input event

voldown(step=10.0, *args, **kwargs)[source]

Volume down (default: -10%)

volup(step=10.0, *args, **kwargs)[source]

Volume up (default: +10%)