Пример #1
0
def connect(config):
    # Connect to SBS
    sbs = Server(hostname=config['host'], 
                 port=config['port'], 
                 username=config['user'], 
                 password=config['passwd'] )

    # Check connection
    try:
        sbs.connect()
        if sbs.logged_in:
            logging.info("Connected to Squeezebox Server v%s on %s:%s", sbs.get_version(), config['host'], config['port'])
        else:
            logging.critical("Could not connect to server, possible wrong credentials")
            exit(1)
    except socketerror:
        logging.critical("Network is unreachable (check network connection and/or IP/port settings of your SB server)")
        p = Popen(["play", "noconnection.wav"], stdout=nulfp.fileno(), stderr=nulfp.fileno())
        return None, None

    # Additional info
    sq = sbs.get_player(config['mac'])
    logging.info("Copying behaviour of SB '%s'", sq.get_name())
    logging.info("Mode: %s | Time: %s | Connected: %s | WiFi: %s", 
                 sq.get_mode(), sq.get_time_elapsed(), 
                 sq.is_connected, sq.get_wifi_signal_strength())

    # All the magic: in this request we subscribe to all playlist events,
    # time changes, and volume changes
    sbs.request(quote("subscribe time,playlist,mixer volume", safe=" "))

    return sbs, sq
Пример #2
0
def setup():

    import sys
    from socket import error as socketerror
    import configparser
    from module.pysqueezecenter.server import Server
    from module.pysqueezecenter.player import Player
    # Python2 compatibility
    try:
        from urllib.parse import unquote
    except ImportError:
        from urllib import unquote

    print("No config file found, please provide the following details. The default is provided between brackets.")

    config = {}

    config['host'] = input("IP address of Squeezebox Server [127.0.0.1]: ")
    config['port'] = input("Port of Squeezebox Server [9090]: ")
    config['user'] = input("Username of server's CLI []: ")
    config['passwd'] = input("Password of server's CLI []: ")

    if not config['host']:
        config['host'] = "127.0.0.1"

    if not config['port']:
        config['port'] = "9090"

    sbs = Server(hostname=config['host'], 
                 port=config['port'], 
                 username=config['user'], 
                 password=config['passwd'] )

    print()
    try:
        sbs.connect()
        if sbs.logged_in:
            print("Succesfully connected to Squeezebox Server v%s on %s:%s" % ( sbs.get_version(), config['host'], config['port'] ))
        else:
            print("Could not connect to server, possible wrong credentials, run %s again" % sys.argv[0])
            sys.exit(1)
    except socketerror:
        print("Network is unreachable, check ip/port settings and run %s again." % sys.argv[0])
        sys.exit(1)

    print()
    print("The following players are connected to the server:")
    players = sbs.get_players()

    for i in range(len(players)):
        player = str(players[i]).replace("Player: ","")
        print("[%i]: %s" % (i+1, player))

    answer = int(input("Press the number which MAC address you want to use: "))-1
    config['mac'] = str(players[answer]).replace("Player: ","")

    print()
    sq = sbs.get_player(config['mac'])
    print("Path to current song in playlist, use this as a hint for the following question.")
    print(unquote(sq.get_track_path()))


    config['remotefolder'] = input("Remote folder where music resides on Squeezebox Server, e.g. file:///path/to/music []: ")
    config['localfolder'] = input("Local folder where music resides locally, e.g. /path/to/music []: ")
    config['driver'] = input("Music driver to use [alsa]: ")
    config['output'] = input("Audio device to use e.g.plughw:0,0 []: ")

    setupconfig = configparser.RawConfigParser()

    setupconfig.add_section('global')
    setupconfig.set('global', 'host', config['host'])
    setupconfig.set('global', 'port', config['port'])
    setupconfig.set('global', 'user', config['user'])
    setupconfig.set('global', 'passwd', config['passwd'])
    setupconfig.set('global', 'mac', config['mac'])
    setupconfig.set('global', 'remotefolder', config['remotefolder'])
    setupconfig.set('global', 'localfolder', config['localfolder'])
    setupconfig.set('global', 'driver', config['driver'])
    setupconfig.set('global', 'output', config['output'])


    with open('sbcc.cfg', 'wb') as configfile:
        setupconfig.write(configfile)

    print("Configuration is setup successfully!")

    return config