コード例 #1
0
ファイル: nowplaying.py プロジェクト: scottwashi/plugins
def np_cb(word, word_eol, userdata):
    player_ids = tuple(pympris.available_players())
    player_num = len(player_ids)
    player_names = [
        pympris.MediaPlayer(_id).root.Identity for _id in player_ids
    ]

    # TODO: commands for next/pause
    if player_num == 0:
        print('NP: No player found running.')
    elif player_num == 1:
        mp = pympris.MediaPlayer(player_ids[0], session_bus)
        print_nowplaying(mp)
    elif len(word) == 2:
        player = word[1]
        if player in player_names:
            index = player_names.index(player)
            mp = pympris.MediaPlayer(player_ids[index])
            print_nowplaying(mp)
        else:
            print('NP: Player {} not found.'.format(player))
    else:
        print('You have multple players running please insert a name:\n\t',
              ' '.join(player_names))

    return hexchat.EAT_ALL
コード例 #2
0
ファイル: server.py プロジェクト: maxammann/mpris-server
def try_connect():
    global mpris
    players_ids = list(pympris.available_players())

    if not players_ids:
        raise pympris.PyMPRISException("No players found")

    print("Available players : " + str(players_ids))

    mpris = pympris.MediaPlayer(players_ids[0], bus)
    print("Using " + str(mpris.root.Identity))
コード例 #3
0
def pull_song():
    try:
        players_ids = list(pympris.available_players())
        mp = pympris.MediaPlayer(players_ids[0], bus)
        metadata = metadata = mp.player.Metadata
        title = str(metadata['xesam:title'])
        artist = str(metadata['xesam:artist'][0])
        Nowplay = title + " by " + artist
    except (IndexError, KeyError):
        # Rhythm box will make metadata empty when nothing is playing, this also catches no players at all
        Nowplay = ""
    return Nowplay
コード例 #4
0
    def __init__(s, dest, path, pids, n):
        PID_DEST = "org.freedesktop.DBus"
        PID_PATH = "/"
        PID_IFACE = PID_DEST

        bus = dbus.SessionBus()
        pidObj = bus.get_object(PID_DEST, PID_PATH)
        pidIface = dbus.Interface(pidObj, PID_IFACE)
        s.players = []

        if(len(pids) > 1):
            for e in bus.list_names():
                if dest in e:
                    pid = pidIface.GetConnectionUnixProcessID(e)
                    if pid in pids:
                        s.players.append(pympris.MediaPlayer(e).player)
                        pids.remove(pid)
        else:
            s.players.append(pympris.MediaPlayer(dest).player)

        players_ids = list(pympris.available_players())
        s.name = n
コード例 #5
0
ファイル: nowplaying.py プロジェクト: BFCatalin/plugins
def np_cb(word, word_eol, userdata):
	player_ids = tuple(pympris.available_players())
	player_num = len(player_ids)
	player_names = [pympris.MediaPlayer(_id).root.Identity for _id in player_ids]

	# TODO: commands for next/pause
	if player_num == 0:
		print('NP: No player found running.')
	elif player_num == 1:
		mp = pympris.MediaPlayer(player_ids[0], session_bus)
		print_nowplaying(mp)
	elif len(word) == 2:
		player = word[1]
		if player in player_names:
			index = player_names.index(player)
			mp = pympris.MediaPlayer(player_ids[index])
			print_nowplaying(mp)
		else:
			print('NP: Player {} not found.'.format(player))
	else:
		print('You have multple players running please insert a name:\n\t', ' '.join(player_names))

	return hexchat.EAT_ALL
コード例 #6
0
ファイル: musicSpeak.py プロジェクト: moomoomoo309/MusicSpeak
    dest=u"dtFormatStr",
    help=u"The datetime format string used by the program to log "
    u"when the song changes.")
args = parser.parse_args()
TTSProgram = args.TTSProgram or TTSProgram
voiceFormatStr = args.voiceFormatStr or voiceFormatStr
dtFormatStr = args.dtFormatStr or dtFormatStr

SongData = namedtuple(u"SongData", (u"artist", u"album", u"title"))

players = []
lastSong = dict()
while True:
    try:
        del players[:]
        for playerName in available_players():
            players.append(MediaPlayer(playerName))
        for player in players:
            if player.player.PlaybackStatus == u"Playing":
                meta = player.player.Metadata
            else:
                continue  # Cuts down on the indentation.
            if u"xesam:artist" in meta and u"xesam:title" in meta and u"xesam:album" in meta:
                song = SongData(artist=meta[u"xesam:artist"],
                                title=u"" + meta[u"xesam:title"],
                                album=u"" + meta[u"xesam:album"])
            else:
                continue  # Cuts down on the indentation.
            if player.player.name not in lastSong or song != lastSong[
                    player.player.name]:
                lastSong[player.player.name] = song
コード例 #7
0
ファイル: spotifly.py プロジェクト: kauzu/spotifly
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import pympris
import time

dbLoop = DBusGMainLoop()
bus = dbus.SessionBus(mainloop=dbLoop)

players = list(pympris.available_players())

spotify = pympris.MediaPlayer(players[0], bus)

while True:
    time.sleep(25)
    spotify.player.Next()
    
コード例 #8
0
ファイル: views.py プロジェクト: wistful/webmpris
def check_player_id(player_id):
    """return True if player_id exists otherwise False"""
    return player_id in pympris.available_players()
コード例 #9
0
ファイル: views.py プロジェクト: wistful/webmpris
def get_players(request):
    """view returs list of players ids"""
    items = list(pympris.available_players())
    return response_json(items, status=200)
コード例 #10
0
ファイル: example.py プロジェクト: TingPing/pympris
from __future__ import print_function
from gi.repository 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(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()