Library to control media players using MPRIS2 interfaces
Project description
pympris is a Python library used
to control media players using MPRIS2 interfaces.
Usage
=====
::
import gobject
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import pympris
dbus_loop = DBusGMainLoop()
bus = dbus.SessionBus(mainloop=dbus_loop)
# get unique ids for all available players
players_ids = list(pympris.available_players())
mp = pympris.MediaPlayer(players_ids[1], bus)
# mp.root implements org.mpris.MediaPlayer2 interface
# mp.player implements org.mpris.MediaPlayer2.Player
# mp.track_list implements org.mpris.MediaPlayer2.TrackList
# mp.playlists implements org.mpris.MediaPlayer2.Playlists
# print player Identity
print mp.root.Identity
if mp.root.CanRaise:
mp.root.Raise()
if mp.player.CanPlay and mp.player.CanPause:
mp.player.PlayPause()
mp.player.Volume = mp.player.Volume*2
if mp.player.CanGoNext:
mp.player.Next()
tracks = mp.track_list.Tracks
for track_id in tracks:
print track_id
if len(tracks) > 1:
mp.track_list.RemoveTrack(tracks[-1])
mp.track_list.GoTo(tracks[0])
n = mp.playlists.PlaylistCount
ordering = pympris.PlaylistOrdering.LastPlayDate
playlists = mp.playlists.GetPlaylists(0, n, ordering, reversed=False)
pl_id, pl_name, pl_icon = playlists[-2]
mp.playlists.ActivatePlaylist(pl_id)
# setup signal handlers
def seeked(x):
print(x)
def PlaylistChanged(arg):
print "PlaylistChanged", arg
def TrackMetadataChanged(track_id, metadata):
print "TrackMetadataChanged", track_id, metadata
def TrackListReplaced(tracks, current_track):
print "TrackListReplaced", tracks, current_track
def TrackAdded(metadata, after_track):
print "TrackAdded", metadata, after_track
def TrackRemoved(track_id):
print "TrackRemoved", track_id
mp.player.register_signal_handler('Seeked', seeked)
mp.playlists.register_signal_handler('PlaylistChanged', PlaylistChanged)
mp.track_list.register_signal_handler('TrackMetadataChanged',
TrackMetadataChanged)
mp.track_list.register_signal_handler('TrackListReplaced', TrackListReplaced)
mp.track_list.register_signal_handler('TrackAdded', TrackAdded)
mp.track_list.register_signal_handler('TrackRemoved', TrackRemoved)
loop = gobject.MainLoop()
loop.run()
to control media players using MPRIS2 interfaces.
Usage
=====
::
import gobject
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import pympris
dbus_loop = DBusGMainLoop()
bus = dbus.SessionBus(mainloop=dbus_loop)
# get unique ids for all available players
players_ids = list(pympris.available_players())
mp = pympris.MediaPlayer(players_ids[1], bus)
# mp.root implements org.mpris.MediaPlayer2 interface
# mp.player implements org.mpris.MediaPlayer2.Player
# mp.track_list implements org.mpris.MediaPlayer2.TrackList
# mp.playlists implements org.mpris.MediaPlayer2.Playlists
# print player Identity
print mp.root.Identity
if mp.root.CanRaise:
mp.root.Raise()
if mp.player.CanPlay and mp.player.CanPause:
mp.player.PlayPause()
mp.player.Volume = mp.player.Volume*2
if mp.player.CanGoNext:
mp.player.Next()
tracks = mp.track_list.Tracks
for track_id in tracks:
print track_id
if len(tracks) > 1:
mp.track_list.RemoveTrack(tracks[-1])
mp.track_list.GoTo(tracks[0])
n = mp.playlists.PlaylistCount
ordering = pympris.PlaylistOrdering.LastPlayDate
playlists = mp.playlists.GetPlaylists(0, n, ordering, reversed=False)
pl_id, pl_name, pl_icon = playlists[-2]
mp.playlists.ActivatePlaylist(pl_id)
# setup signal handlers
def seeked(x):
print(x)
def PlaylistChanged(arg):
print "PlaylistChanged", arg
def TrackMetadataChanged(track_id, metadata):
print "TrackMetadataChanged", track_id, metadata
def TrackListReplaced(tracks, current_track):
print "TrackListReplaced", tracks, current_track
def TrackAdded(metadata, after_track):
print "TrackAdded", metadata, after_track
def TrackRemoved(track_id):
print "TrackRemoved", track_id
mp.player.register_signal_handler('Seeked', seeked)
mp.playlists.register_signal_handler('PlaylistChanged', PlaylistChanged)
mp.track_list.register_signal_handler('TrackMetadataChanged',
TrackMetadataChanged)
mp.track_list.register_signal_handler('TrackListReplaced', TrackListReplaced)
mp.track_list.register_signal_handler('TrackAdded', TrackAdded)
mp.track_list.register_signal_handler('TrackRemoved', TrackRemoved)
loop = gobject.MainLoop()
loop.run()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pympris-1.4.tar.gz
(8.9 kB
view details)
Built Distributions
pympris-1.4-py32-none-any.whl
(14.7 kB
view details)
pympris-1.4-py27-none-any.whl
(14.7 kB
view details)
pympris-1.4-py3.2.egg
(28.2 kB
view details)
pympris-1.4-py2.7.egg
(27.7 kB
view details)
File details
Details for the file pympris-1.4.tar.gz
.
File metadata
- Download URL: pympris-1.4.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96d3e374da2878dc50c66981aa5f6b978a209d8d99f276546665b62bfd180b02 |
|
MD5 | 15316d901bc39571908a378132ae2b1b |
|
BLAKE2b-256 | 8e68ee563db51e657f4479e62e42040555469ba89fddc4c9b7c01ab4dfbe8880 |
File details
Details for the file pympris-1.4-py32-none-any.whl
.
File metadata
- Download URL: pympris-1.4-py32-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3.2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 337992ecdda9bcc8f5dde0695fdb9557545601486039b3b6770da3e0142ca6de |
|
MD5 | c64cec0fe69a7b4cb3fd30e45bc8b644 |
|
BLAKE2b-256 | 16f3c7017f103cf6ac15800593c589859f45832b0333375ea9a89bc67945615c |
File details
Details for the file pympris-1.4-py27-none-any.whl
.
File metadata
- Download URL: pympris-1.4-py27-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 2.7
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02c521b52eedc197279b96789b55d07076f19ff3eddbf1ab8436c9838f5ed06e |
|
MD5 | 89412c658b76ff6a363a696f5425a393 |
|
BLAKE2b-256 | 7a9e854b495bc0577210a0f50c8a396e16f4006c87db8e644cc783cafc6c64d9 |
File details
Details for the file pympris-1.4-py3.2.egg
.
File metadata
- Download URL: pympris-1.4-py3.2.egg
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c00b32b66e9bbc15886e73e0ff69713b92afd0e3eab7a45ad17699ac7ddd118 |
|
MD5 | 2cbf2ae0735c17f560007a793ccb21af |
|
BLAKE2b-256 | f3df8a6a445b1b4672f23e440c07ba197b162cb76152cb6d7fd7c722a04fd959 |
File details
Details for the file pympris-1.4-py2.7.egg
.
File metadata
- Download URL: pympris-1.4-py2.7.egg
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8f492d0e2747ae670ff59462f4d096a2c3078f82f059afbcc412d58cadc27e1 |
|
MD5 | 04098f0fbf8591334cc06e0493dfc943 |
|
BLAKE2b-256 | b32c0f22d2a47c38bc645aea99e1f545b18bf0d2a32c9513c7634a7162c33a65 |