platypush.plugins.media

class platypush.plugins.media.MediaPlugin(media_dirs: Optional[List[str]] = None, download_dir: Optional[str] = None, env: Optional[Dict[str, str]] = None, volume: Optional[Union[float, int]] = None, torrent_plugin: str = 'torrent', *args, **kwargs)[source]

Generic plugin to interact with a media player.

Requires:

  • A media player installed (supported so far: mplayer, vlc, mpv, omxplayer, chromecast)

  • python-libtorrent (pip install python-libtorrent), optional, for torrent support over native library

  • rtorrent installed - optional, for torrent support over rtorrent

  • youtube-dl installed on your system (see your distro instructions), optional for YouTube support

  • requests (pip install requests), optional, for local files over HTTP streaming supporting

  • ffmpeg,optional, to get media files metadata

To start the local media stream service over HTTP you will also need the platypush.backend.http.HttpBackend backend enabled.

__init__(media_dirs: Optional[List[str]] = None, download_dir: Optional[str] = None, env: Optional[Dict[str, str]] = None, volume: Optional[Union[float, int]] = None, torrent_plugin: str = 'torrent', *args, **kwargs)[source]
Parameters
  • media_dirs – Directories that will be scanned for media files when a search is performed (default: none)

  • download_dir – Directory where external resources/torrents will be downloaded (default: ~/Downloads)

  • env – Environment variables key-values to pass to the player executable (e.g. DISPLAY, XDG_VTNR, PULSE_SINK etc.)

  • volume – Default volume for the player (default: None, maximum volume).

  • torrent_plugin

    Optional plugin to be used for torrent download. Possible values:

    • torrent - native libtorrent-based plugin (default)

    • rtorrent - torrent support over rtorrent RPC/XML interface (recommended)

    • webtorrent - torrent support over webtorrent (unstable)

download(url, filename=None, directory=None)[source]

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

get_media_file_duration(filename)[source]

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

next()[source]

Play the next item in the queue

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

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)

start_streaming(media, subtitles=None, download=False)[source]

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"
}
class platypush.plugins.media.PlayerState(value)[source]

An enumeration.