Ejemplo n.º 1
0
 def lmsLogon(self, host, port):
     try:
         sc = Server(hostname=host, port=port)
         sc.connect()
     except:
         sc = None
     return sc
Ejemplo n.º 2
0
def player_change_process(textSync, volumeSync, playingSync, mac, host, port):
    try:

        # Http version
        sv = Server(hostname=host, port=port)
        sv.connect(update=False)

        # Telnet
        sc = RClient(hostname=host,
                     port=port,
                     mac_filter=mac,
                     textSync=textSync,
                     playingSync=playingSync,
                     volumeSync=volumeSync)
        sc.connect(update=False)

        print "Logged in: %s" % sv.logged_in
        print "Version: %s" % sv.get_version()

        sc.hplayer = sv.get_player(mac)
        trackname = sc.hplayer.get_track_title().strip()
        artist = sc.hplayer.get_track_artist().strip()

        sc.setText(artist, trackname)

        sc.start()
    except (KeyboardInterrupt, SystemExit):
        print "Exiting LMS Telnet Process"
Ejemplo n.º 3
0
    def connect_to_server(self):
        server = Server(hostname=self.server_hostname, port=self.server_port)
        server.connect()

        logger = logging.getLogger("LMS")
        logger.info("Logged in: %s" % server.logged_in)
        logger.info("Version: %s" % server.get_version())

        return server
Ejemplo n.º 4
0
def local_change_process(textSync, text2Sync, volumeSync, playingSync, MAC,
                         host, port):

    try:
        sc = Server(hostname=host, port=port)
        sc.connect(update=False)

        print "Logged in: %s" % sc.logged_in
        print "Version: %s" % sc.get_version()

        localVolume = volumeSync.value
        localPlaying = playingSync.value

        player = sc.get_player(unicode(MAC))

        if player:
            localVolume = player.get_volume()
            text2Sync.value = player.get_name()
            volumeSync.value = localVolume
            print player.get_mode()

            mode = player.get_mode()

            if mode == "play":
                localPlaying = 1
            elif mode == "stop":
                localPlaying = -1
            else:
                localPlaying = 0

            playingSync.value = localPlaying
            print "Controlling player: %s (%s)" % (player.get_name(), MAC)
        else:
            print "No Player found"

        while (1):
            if player:
                if localVolume != volumeSync.value:
                    # Volume Changed by hardware
                    localVolume = volumeSync.value
                    player.set_volume(localVolume)

                if localPlaying != playingSync.value:
                    # State Changed by hardware
                    localPlaying = playingSync.value
                    if localPlaying == 1:
                        player.unpause()
                    elif localPlaying == 0:
                        player.pause()
                    elif localPlaying == -1:
                        pass  # stop
            time.sleep(0.5)
    except (KeyboardInterrupt, SystemExit):
        print "Exiting Player Update Process"
Ejemplo n.º 5
0
 def setHostname(self, hostname):
     if self.loaded:
         logging.warning('Cannot change hostname, without a restart')
         return
     self.sc = Server(hostname=hostname)
     try:
         self.sc.connect()
     except:
         logging.error("Cannot connect to squeezebox server")
         return
     for player in self.sc.players:
         self.deviceManager.addDevice(Player(player))
     self.deviceManager.finishedLoading('squeezebox')
     self.loaded = True
Ejemplo n.º 6
0
def connect_to_player_at_server(playername, hostname):
    """Connects to a Squeezbox player connected to a server by
    their name.

    Args:
        playername (string): name of player
        hostname (string): hostname of Squeezbox server

    Returns:
        pylms.player.Player
    """
    server = Server(hostname=hostname)

    server.connect()
    players = [ply for ply in server.get_players() if ply.name == playername]
    if len(players) < 1:
        raise RuntimeError(('No player named %s connected to '
                            'server named %s') % (playername, hostname))
    return players[0]
Ejemplo n.º 7
0
            sys.exit(-1)
        else:
            setattr(namespace, self.dest, values)


agi = AGI()

parser = argparse.ArgumentParser(description='Process LMS commands.')
parser.add_argument('player', type=str, nargs=1, help="MAC adress of player", action=VerifyMacaddressAction)
parser.add_argument('command', type=str, nargs=1, default="mode",
                    choices=['mode', 'start', 'stop', 'toggle', 'pause', 'unpause'],
                    help='Command to execute on LMS player')

args = parser.parse_args()

sc = Server(hostname="lms.wi.kettenbach-it.de", port=9090)
sc.connect()
sq = sc.get_player(args.player[0])  # type: Player

if sq is None:
    sys.stderr.write("Player not found")
    sys.exit(-1)

if args.command[0] == "mode":
    # agi.set_variable("LMSSTATUS", str(sq.get_mode()))
    # agi_set_varaible is broken: https://github.com/rdegges/pyst2/issues/19
    print("SET VARIABLE LMSSTATUS " + sq.get_mode())

if args.command[0] == "stop":
    sq.stop()
Ejemplo n.º 8
0
#!/usr/bin/env python

from pylms.server import Server
from pylms.player import Player

sc = Server(hostname="192.168.16.2", port=9090)
sc.connect()

print "Logged in: %s" % sc.logged_in
print "Version: %s" % sc.get_version()

sq = sc.get_player("00:00:00:00:00:44")

#print "Name: %s | Mode: %s | Time: %s | Connected: %s | WiFi: %s" % (sq.get_name(), sq.get_mode(), sq.get_time_elapsed(), sq.is_connected, sq.get_wifi_signal_strength())

#print sc.request("radios 0 100000")
#print sq.request("local items 0 100000")
#print sq.request("local playlist play item_id:7cec804f.15")
print sq.request(
    "playlist play file:///E:/Public%20Shares/Music/Playlists/Test%20JD.m3u")
Ejemplo n.º 9
0
# If not, see <https://creativecommons.org/licenses/by-sa/3.0/>

from pylms.server import Server
from pylms.player import Player
import subprocess

HOST = '192.168.1.30'
PORT = 9090
USER = ''
PW = ''
SPI_DEV = '/dev/spidev0.1'
SPI_ADR = '00'
BW_TOOLS = '/home/pi/bw_rpi_tools/bw_spi/bw_lcd'
PLAYER_ID = '00:04:20:26:97:a0'

sc = Server(hostname=HOST, port=PORT, username=USER, password=PW)
sc.connect()

sq = sc.get_player(PLAYER_ID)

title = sq.get_track_title()[0:20]
artist = sq.get_track_artist()[0:20]


def write_lcd(pos, content):
    subprocess.call(
        ['sudo', BW_TOOLS, '-a', SPI_ADR, '-D', SPI_DEV, '-T', pos, content])


def clear_lcd():
    subprocess.call(['sudo', BW_TOOLS, '-a', SPI_ADR, '-D', SPI_DEV, '-C'])
Ejemplo n.º 10
0
def get_squeeze_player(server, player):
    print 'Connecting to server[%s] player[%s]' % (server, player)
    sc = Server(hostname=server, port=9090)
    sc.connect()
    return sc.get_player(player)
Ejemplo n.º 11
0
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
from pylms.server import Server
from pylms.player import Player

sc = Server(hostname="192.168.2.109", port=9090, username="", password="")
sc.connect()

#print "Logged in: %s" % sc.logged_in
#print "Version: %s" % sc.get_version()

sq = sc.get_player("b8:27:eb:3c:1b:be")

phatbeat.set_all(0,128,0,0.1)
phatbeat.show()
time.sleep(1)
phatbeat.clear()
phatbeat.show()
	
GPIO.setmode(GPIO.BCM)

GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def myCallback(channel):
  if channel == 6:
Ejemplo n.º 12
0
def main(argv):
    """LCD MANAGER APP FOR LMS"""
    lmsserver = "127.0.0.1"
    lmsplayer = ""
    lcd_address = "0x3f"
    lcd_w = 20
    verbose = True
    clock_mode = False

    try:
        opts, args = getopt.getopt(argv,"hs:p:w:l:c",["server=","player=","lcd_width=","lcd_address=","clock"])
    except getopt.GetoptError:
        printhelp()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            printhelp()
            sys.exit()
        elif opt in ("-s", "--server"):
            lmsserver = arg
        elif opt in ("-p", "--player"):
            lmsplayer = arg
        elif opt in("-w","--lcd_width"):
            lcd_w = int(arg)
        elif opt in("-l","--lcd_address"):
            lcd_address = arg    
        elif opt in("-c","--clock"):
            clock_mode = True    
           

    myLCD = LCD(int(lcd_address,16), lcd_w)
    #myLCD.lcd_string"1234567890123456",1)
    myLCD.lcd_string("   TVC Audio    ",1)
    myLCD.lcd_string("  LMS LCD INFO  ",2)
    sleep(2)
    myLCD.lcd_string("(C)2017 Renaud  ",1)
    myLCD.lcd_string("Coustellier     ",2)
    sleep(1)
    
    sc = Server(hostname=lmsserver, port=9090, username="******", password="******")

    # Server connection
    # Clock mode waiting connection
    connected = False
    while connected <> True:
        try:
            sc.connect()
            sleep(1)
            connected = True
        except Exception as e:
            LCDTime(myLCD, lcd_w) 
            #myLCD.lcd_string(str(e),1)
    
    myLCD.lcd_string("LMS SERVER",1)
    myLCD.lcd_string("LMS v.: %s" % sc.get_version(),2)
    sleep(2)
    
    while sc.get_player_count() == 0:
        LCDTime(myLCD, lcd_w)
        sleep(2)
    
    if lmsplayer <> "":
        while True:
            LCDTime(myLCD, lcd_w)
            sq = playerAutodetect(sc, myLCD)
            ipPlayer = str(sq.get_ip_address())
            ipPlayer = ipPlayer[0:ipPlayer.find(":")]
            if ipPlayer == lmsplayer:
                break
            sleep(3)
    else:
        myLCD.lcd_string("autodetect player",3)
        myLCD.lcd_string("in play mode",3)
        sq = playerAutodetect(sc, myLCD)

    playerName = sq.get_name()
    playerModel = sq.get_model()
    
    if lcd_w == 20:
        myLCD.lcd_string(playerName,3)
        myLCD.lcd_string(playerModel,4)
    sleep(2)
    
    if lcd_w == 16:
        # 16x2 LCD Code
        while True:
            try:
                modePlayer = sq.get_mode()  
                if modePlayer == "pause":
                    myLCD.lcd_string("mode = pause",1)
                    myLCD.lcd_string(time.strftime('%Y-%m-%d %H:%M:%S'),2)
                    sleep(2)
                elif modePlayer == "stop":
                    LCDTime(myLCD, lcd_w)
                    sleep(2)
                    # when "stop", looking for a running player except if player defined by user...  
                    if lmsplayer == "":
                        sq = playerAutodetect(sc, myLCD)
                        
                elif modePlayer == "play":
                    trackAlbum = sq.get_track_album()
                    currentTrack = sq.get_track_current_title()
                    trackArtist = sq.get_track_artist()
                    currentVolume = sq.get_volume()
                    
                    print ("")
                    print ("album:" + trackAlbum)
                    print ("artist:" + trackArtist)
                    print ("title:" + currentTrack)

                    myLCD.lcd_string("Alb." + trackAlbum,1)
                    myLCD.lcd_string("Art." + trackArtist,2)
                    sleep(2)
                    myLCD.lcd_string(trackAlbum,1)
                    myLCD.lcd_string(trackArtist,2)
                    
                    td =  "/" + lms_time_to_string(sq.get_track_duration())        
                    ptc = str(sq.playlist_track_count()) 
                    linestatus = 0
                    charOffset = 0
                    while True:
                        linestatus = linestatus + 1
                        volume = (" - Volume %" + str(sq.get_volume()) )
                        #te =  "time " + lms_time_to_string(sq.get_time_elapsed())
                        te = lms_time_to_string(sq.get_time_elapsed()) 
                        te = te + td
                        cti = str(sq.playlist_current_track_index())
                        
                        if len(cti) > 1 and len(ptc) > 1:
                            if linestatus % 4 == 0:
                                te = te + "  /" + ptc
                            else:
                                
                                te = te + "  " + cti + "/"
                        else:
                            te = te + " " + cti + "/" + ptc
                        
                        while currentVolume != sq.get_volume():
                            # Volume
                            currentVolume = sq.get_volume()
                            myLCD.lcd_string("Volume %" + str(currentVolume), 1)    
                            sleep(0.3)
                        if linestatus < 2:
                            myLCD.lcd_string("tle:" + currentTrack, 1)
                            myLCD.lcd_string(te, 2)
                        else: 
                            # Track Name
                            if len(currentTrack) <= lcd_w:
                                # LENGHT is < LCD LCD_WIDTH
                                myLCD.lcd_string(currentTrack, 1)
                            else:
                                # LENGHT is > LCD_WIDTH
                                charOffset = linestatus - 2
                                myLCD.lcd_string(currentTrack[charOffset:], 1) 
                                if linestatus + lcd_w > len(currentTrack):
                                    linestatus = 0       
                            myLCD.lcd_string(te, 2)    
                        if sq.get_track_current_title() != currentTrack or sq.get_mode() !="play" :
                            # change detected
                            myLCD.lcd_string("Track/mode chang", 1)
                            myLCD.lcd_string("pls wait...     ", 2)
                            linestatus = 0
                            break
                        sleep(0.65)
            except:
                lcd(lcd_w)
               
    else:
        # 20x4 LCD Code
        while True:
            try:
            #if True == True:
                modePlayer = sq.get_mode()
                if modePlayer == "pause":
                    myLCD.lcd_string(sq.get_name(),1)
                    myLCD.lcd_string("Mode = Pause",2)
                    line3 = "RJ45"
                    ipPlayer = sq.get_ip_address()
                    ipPlayer = ipPlayer[0:ipPlayer.find(":")]
                    if int(sq.get_wifi_signal_strength()) > 1:
                        line3 = "wifi" + str(sq.get_wifi_signal_strength())
                    line3 = line3 + " " + ipPlayer
                    myLCD.lcd_string(line3,3)
                    myLCD.lcd_string(time.strftime('%Y-%m-%d %H:%M:%S'),4)
                    sleep(0.5)
                elif modePlayer == "stop":
                    LCDTime(myLCD, lcd_w)
                    sleep(2)
                    
                    if lmsplayer == "":
                        # when player mode is stop, looking for another running player except if...
                        sq = playerAutodetect(sc, myLCD)
                          
                elif modePlayer == "play" and lmsplayer == "":
                    trackAlbum = sq.get_track_album()
                    currentTrack = sq.get_track_current_title()
                    trackArtist = sq.get_track_artist()
                    currentVolume = sq.get_volume()
                    if verbose == True:
                        print ("")
                        print ("album:" + trackAlbum)
                        print ("artist:" + trackArtist)
                        print ("title:" + currentTrack)

                    td =  "/" + lms_time_to_string(sq.get_track_duration())                          
                    linestatus = 0
                    charOffset = 0
                    
                    while True:
                        if modePlayer <> "play":
                            break
                        linestatus = linestatus + 1
                        volume = (" - Volume %" + str(sq.get_volume()) )
                        te = lms_time_to_string(sq.get_time_elapsed()) 
                        te = te + td
                        te = te + "   " + str(sq.playlist_current_track_index()) + "/" + str(sq.playlist_track_count())
                        while currentVolume != sq.get_volume():
                            # Volume
                            currentVolume = sq.get_volume()
                            myLCD.lcd_string("Volume %" + str(currentVolume), 1)    
                            sleep(.25)
                        if sq.get_track_current_title() != currentTrack or sq.get_mode() !="play" :
                            # change detected
                            myLCD.lcd_string("Track/mode chang", 1)
                            #myLCD.lcd_string("pls wait...     ", 2)
                            break    
                        
                        # Track Name
                        myLCD.lcd_string(trackArtist, 1)
                        myLCD.lcd_string(trackAlbum, 2)
                        #----------------------------
                        if len(currentTrack) <= lcd_w:
                            # LENGHT is < LCD LCD_WIDTH
                            myLCD.lcd_string(currentTrack, 3)
                        else:
                            # LENGHT is > LCD_WIDTH
                            charOffset = linestatus - 1
                            myLCD.lcd_string(currentTrack[charOffset:], 3) 
                            if linestatus + lcd_w > len(currentTrack):
                                linestatus = 0       
                        #myLCD.lcd_string(currentTrack, 3)
                        if clock_mode != True:
                            myLCD.lcd_string(te, 4)
                            sleep(0.5)
                        else:
                            myLCD.lcd_string(time.strftime('%Y-%m-%d %H:%M:%S'),4)
                            sleep(0.5)
            except: #Exception as e:
            #else:
                #myLCD.lcd_string(str(e), 3)
                sq = playerAutodetect(sc, myLCD)
                sleep(2)
Ejemplo n.º 13
0
from PIL import Image, ImageDraw
from time import sleep
from rotary_class import RotaryEncoder
from pylms.server import Server
from pylms.player import Player
import textwrap

#sc = Server(hostname="192.168.0.211", port=9090, username="******", password="******")

# CHANGE the following to your LMS IP Address: hostIP, player_id
hostIP = '192.168.0.211'  # Change to the IP Address of your Logitech Media Server (LMS) - check your router

# insert miniz player MAC address here from LMS/Settings/Information
player_id = 'b8:27:eb:93:bb:81'

sc = Server(hostname=hostIP, port=9090)  # used for volume and play/pause
scNP = Server(hostname=hostIP,
              port=9090)  # used only to get Now Playing cover.jpg

sleep(60)  # allow time for LMS to start, otherwise get ConnectionError 111
sc.connect()
scNP.connect()

sq = sc.get_player(player_id)
sqNP = scNP.get_player(
    player_id
)  # UGLY KLUDGE! Avoids conflict with volume routine which caused bad refresh on album cover.jpg

DISPLAY = pi3d.Display.create(use_pygame=True, samples=4)
DISPLAY.set_background(0, 0, 0, 1)  #r,g,b and alpha
shader = pi3d.Shader("uv_flat")
Ejemplo n.º 14
-1
    def __init__(self, basicOnly=False):

        #optionally pass in a player MAC here to connect to a different player for the info display
        #if MAC is not None:
        #  log("Using MAC " + MAC)
        #  PLAYERMAC = MAC

        #serverIP still null, something went wrong...
        if SERVERIP == "":
            notify("Can't find LMS server",
                   "Try manually configuring one in XSqueeze settings")
            sys.exit()

        log("Attempting to connect to LMS named [" + SERVERNAME +
            "] at IP:  " + SERVERIP + " on CLI port: " + SERVERPORT)
        try:
            self.sc = Server(hostname=SERVERIP,
                             port=SERVERPORT,
                             username=SERVERUSER,
                             password=SERVERPASS)
            self.sc.connect()
            log("LMS Logged in: %s" % self.sc.logged_in)
            log("LMS Version: %s" % self.sc.get_version())
        except:
            log(" Couldn't connect to server!")
            notify(LANGUAGE(19613), LANGUAGE(19614))
            raise

        #connect to player
        log("Attempting to connect to player: " + PLAYERMAC)
        try:
            self.sb = self.sc.get_player(PLAYERMAC)
            if self.sb:
                log("Connected to: %s" % PLAYERMAC)
                state = self.sb.get_power_state()
                log("Power state is: " + str(state))
            else:
                log("Player is None! %s" % PLAYERMAC)
                raise Exception
        except Exception as inst:
            log(" Couldn't connect to player: " + PLAYERMAC, inst)
            notify(LANGUAGE(19615), LANGUAGE(19616))
            raise

        #initialise if we're called from XSqueeze as opposed to the chooser
        try:
            if not basicOnly:
                self.currentTrack = None
                self.coverURLs = None
                self.playlistDetails = None
                self.updatePlaylistDetails()
                self.updateCoverArtURLs()
                #if the user wants music to start straight away...
                if SENDPLAYONSTART:
                    self.sb.request("play")
        except Exception as inst:
            log(
                " Error in initialisation of XSqueeze after connection to: " +
                PLAYERMAC, inst)
            raise