Esempio n. 1
0
    def get(self):
        global player
        global BUILT_PATH

        args = getInput()
        print('argsid : ', args["id"])
        # print('argsinterval: ', args["interval"])
        pathToTrack = None
        subs = None
        srtFileName = None

        for track in NEW_TRACK_ARRAY:
            if track["ID"] == args["id"]:
                srtFileName = splitext(track["Path"])[0] + ".srt"
                if os.path.isfile(str(BUILT_PATH) + srtFileName):
                    print(srtFileName)
                    start_time = time.time()
                    print("Loading SRT file " + srtFileName + " - " +
                          str(start_time))
                    subs = srtopen(BUILT_PATH + srtFileName)
                    #subs = srtstream(BUILT_PATH + srtFileName)
                    end_time = time.time()
                    print("Finished loading SRT file " + srtFileName + " - " +
                          str(end_time))
                    print("Total time elapsed: " + str(end_time - start_time))
                pathToTrack = BUILT_PATH + track["Path"]

        if pathToTrack is None or not os.path.isfile(pathToTrack):
            print('Bad file path, will not attempt to play...')
            return jsonify(1)

        response = player.fadeDown(pathToTrack, int(args["interval"]), subs,
                                   BUILT_PATH + srtFileName)

        return jsonify(response)
Esempio n. 2
0
    def start(self, path, subs, subsPath, syncTime=None):
        self.player.status(self.status)
        self.status["source"] = path
        self.status["subsPath"] = subsPath

        print("***************  start  ********************")

        if os.path.isfile(subsPath):
            start_time = time.time()
            print("Loading SRT file " + subsPath + " - " + str(start_time))
            subs = srtopen(subsPath)
            #subs = srtstream(subsPath)
            end_time = time.time()
            print("Finished loading SRT file " + subsPath + " - " +
                  str(end_time))
            print("Total time elapsed: " + str(end_time - start_time) +
                  " seconds")

        if self.isSlave():
            # wait until the sync time to fire everything off
            print('Slave: Syncing start!')

        if self.isMaster():
            print('Master, sending start!')
            self.player.primeForStart(path)
            syncTime = self.sendSlaveCommand('start')

        self.started = True
        response = self.player.start(path, syncTime, self.isMaster())

        try:
            print('In Player: ', id(self.player))
            self.lighting.start(self.player, subs)
        except Exception as e:
            print('Lighting failed: ', e)

        return response
Esempio n. 3
0
# >>> print_some_times()
# 930343690.257
# From print_time 930343695.274
# From print_time 930343700.273
# 930343701.301


def time_convert(t):
    block, milliseconds = str(t).split(",")
    hours, minutes, seconds = block.split(":")
    return (int(hours), int(minutes), int(seconds), int(milliseconds))


if __name__ == "__main__":

    subs = srtopen(srtFilename)

    print("Number of events", len(subs))

    # s = scheduler(time, sleep)

    # global ipcon

    ipcon.connect(HOST, PORT)

    # Register Enumerate Callback
    ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate)

    # Trigger Enumerate
    ipcon.enumerate()
Esempio n. 4
0
def main():
    global subs
    global player
    global bridge
    global SRT_FILENAME, AUDIO_FILENAME, MAX_BRIGHTNESS, TICK_TIME, HUE_IP_ADDRESS
    parser = argparse.ArgumentParser(description="LushRoom sound and light command-line player")
    # group = parser.add_mutually_exclusive_group()
    # group.add_argument("-v", "--verbose", action="store_true")
    # group.add_argument("-q", "--quiet", action="store_true")
    parser.add_argument("-s","--srt", default=SRT_FILENAME, help=".srt file name for lighting events")
    parser.add_argument("-a","--audio", default=AUDIO_FILENAME, help="audio file for sound stream")
    parser.add_argument("-b","--brightness", default=MAX_BRIGHTNESS, help="maximum brightness")
    parser.add_argument("-t","--time", default=TICK_TIME, help="time between events")
    parser.add_argument("--hue", default=HUE_IP_ADDRESS, help="Philips Hue bridge IP address")

    args = parser.parse_args()

    print(args)

    if PLAY_AUDIO:
        player = vlc.MediaPlayer(AUDIO_FILENAME)
        event_manager = player.event_manager()
        event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, end_callback)

    if PLAY_HUE:
        # b = Bridge('lushroom-hue.local')
        bridge = Bridge(HUE_IP_ADDRESS, config_file_path="/media/usb/python_hue")
        # If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
        bridge.connect()
        # Get the bridge state (This returns the full dictionary that you can explore)
        bridge.get_api()
        lights = bridge.lights
        # Print light names
        for l in lights:
            print(l.name)
            #print(dir(l))
        # Set brightness of each light to 10
        for l in lights:
            l.brightness = 1

        # Get a dictionary with the light name as the key
        light_names = bridge.get_light_objects('name')
        print("Light names:", light_names)

    subs = srtopen(SRT_FILENAME)

    print("Number of lighting events",len(subs))

    scheduler = BackgroundScheduler()
    scheduler.add_job(tick, 'interval', seconds=TICK_TIME)
    # scheduler.start(paused=True)
    if PLAY_AUDIO:
        player.play()
    scheduler.start(paused=False)

    try:
        # This is here to simulate application activity (which keeps the main thread alive).
        while True:
            sleep(0.01)
            try:
                if keyboard.is_pressed('p'): # pause
                    scheduler.pause()
                    player.pause()
                elif keyboard.is_pressed('r'): # resume
                    scheduler.resume()
                    player.play()
                # elif keyboard.is_pressed('s'): # stop
                #     scheduler.shutdown()
                #     player.stop()
                #     exit(0)
            except:
                pass
    except (KeyboardInterrupt, SystemExit):
        # Not strictly necessary if daemonic mode is enabled but should be done if possible
        scheduler.shutdown()
        player.stop()
Esempio n. 5
0
def main():
    global subs, player, bridge, scheduler, ipcon, dmx
    global SRT_FILENAME, AUDIO_FILENAME, MAX_BRIGHTNESS, TICK_TIME, HUE_IP_ADDRESS, DEBUG, VERBOSE
    parser = argparse.ArgumentParser(description="LushRoom sound and light command-line player. \
        Press Esc to exit, P to pause and R to resume.")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v", "--verbose", action="store_true")
    group.add_argument("-q", "--quiet", action="store_true")
    parser.add_argument("-d", "--debug", action="store_true")
    parser.add_argument("-s","--srt", default=SRT_FILENAME, help=".srt file name for lighting events")
    parser.add_argument("-a","--audio", default=AUDIO_FILENAME, help="audio file for sound stream")
    parser.add_argument("-b","--brightness", default=MAX_BRIGHTNESS, help="maximum brightness")
    parser.add_argument("-t","--time", default=TICK_TIME, help="time between events")
    parser.add_argument("--hue", default=HUE_IP_ADDRESS, help="Philips Hue bridge IP address")

    args = parser.parse_args()

    MAX_BRIGHTNESS = int(args.brightness)
    SRT_FILENAME = args.srt
    AUDIO_FILENAME = args.audio
    TICK_TIME = float(args.time)
    HUE_IP_ADDRESS = args.hue
    VERBOSE = args.verbose
    DEBUG = args.debug

    if DEBUG:
        print(args)


    ipcon.connect(HOST, PORT)

    # Register Enumerate Callback
    ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate)

    # Trigger Enumerate
    ipcon.enumerate()

    sleep(2)

    if DEBUG:
        print(tfIDs)

    dmxcount = 0
    for tf in tfIDs:
        # try:
        if True:
            # print(len(tf[0]))

            if len(tf[0])<=3: # if the device UID is 3 characters it is a bricklet
                if tf[1] in deviceIDs:
                    if VERBOSE:
                        print(tf[0],tf[1], getIdentifier(tf))
                if tf[1] == 285: # DMX Bricklet
                    if dmxcount == 0:
                        print("Registering %s as slave DMX device for capturing DMX frames" % tf[0])
                        dmx = BrickletDMX(tf[0], ipcon)
                        dmx.set_dmx_mode(dmx.DMX_MODE_MASTER)
                        # channels = int((int(MAX_BRIGHTNESS)/255.0)*ones(512,)*255)
                        # dmx.write_frame([255,255])
                        sleep(1)
                        # channels = int((int(MAX_BRIGHTNESS)/255.0)*zeros(512,)*255)
                        # dmx.write_frame(channels)
                    dmxcount += 1

    if PLAY_AUDIO:
        player = vlc.MediaPlayer(AUDIO_FILENAME)
        event_manager = player.event_manager()
        event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, end_callback)

    if PLAY_HUE:
        # b = Bridge('lushroom-hue.local')
        bridge = Bridge(HUE_IP_ADDRESS)
        # If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
        bridge.connect()
        # Get the bridge state (This returns the full dictionary that you can explore)
        bridge.get_api()
        lights = bridge.lights
        # Print light names
        for l in lights:
            print(l.name)
            #print(dir(l))
        for l in lights:
            # print(dir(l))
            l.on = False
        sleep(1)
        for l in lights:
            l.on = True
            l.brightness = MAX_BRIGHTNESS

        # Get a dictionary with the light name as the key
        light_names = bridge.get_light_objects('name')
        print("Light names:", light_names)

    subs = srtopen(SRT_FILENAME)

    print("Number of lighting events",len(subs))
    # print("PLAY_HUE", PLAY_HUE)


    scheduler = BackgroundScheduler()
    scheduler.add_job(tick, 'interval', seconds=TICK_TIME, misfire_grace_time=10, max_instances=4096, coalesce=True)
    if PLAY_AUDIO:
        player.play()
    scheduler.start(paused=False)

    with keyboard.Listener(
        # on_press=on_press,
        on_release=on_release, suppress=False) as listener:
        try:
            listener.join()
        except ExitException as e:
            print("Exiting ...")