class, webtorrent_port=None, *args, **kwargs)[source]

Plugin to download and stream videos using webtorrent


  • webtorrent installed on your system (npm install -g webtorrent)

  • webtorrent-cli installed on your system (npm install -g webtorrent-cli)

  • A media plugin configured for streaming (e.g. media.mplayer, media.vlc, media.mpv or media.omxplayer)

__init__(webtorrent_bin=None, webtorrent_port=None, *args, **kwargs)[source]

media.webtorrent will use the default media player plugin you have configured (e.g. mplayer, omxplayer, mpv) to stream the torrent.

  • webtorrent_bin (str) – Path to your webtorrent executable. If not set, then Platypush will search for the right executable in your PATH

  • webtorrent_port (int) – Port where the webtorrent will be running streaming server will be running (default: 8000)

download(resource, **kwargs)[source]

Download a media URL

  • url – Media URL

  • filename – Media filename (default: URL filename)

  • directory – Destination directory (default: download_dir)


The absolute path to the downloaded file


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

load(resource, **kwargs)[source]

Load a torrent resource in the player.


Play the next item in the queue

play(resource, player=None, download_only=False, **player_args)[source]

Download and stream a torrent

  • resource (str) – Play a resource, as a magnet link, torrent URL or torrent file path

  • player (str) – If set, use this plugin type as a player for the torrent. Supported types: ‘mplayer’, ‘vlc’, ‘omxplayer’, ‘chromecast’, ‘mpv’. If not set, then the default configured media plugin will be used.

  • player_args (dict) – Any arguments to pass to the player plugin’s play() method

  • download_only (bool) – If false then it will start streaming the torrent on the local player once the download starts, otherwise it will just download it (default: false)


Quit the player

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

Perform a video search.

  • 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)

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>

  • 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


dict containing the streaming URL.Example:

    "id": "0123456abcdef.mp4",
    "source": "file:///mnt/media/movies/movie.mp4",
    "mime_type": "video/mp4",
    "url": ""

Get the current player state.


A dictionary containing the current state.


output = {
    "state": "play"  # or "stop" or "pause"

Stop the playback


An enumeration.