Beispiel #1
0
    def execute_action(action):
        result = {'success': True, 'message': '', 'action': action}

        # get the action
        if (action in ['pause', 'resume']):
            # store the new value
            utils.write_db(
                db, utils.DB_PLAYER_STATUS,
                {'running': action == 'resume'})  # eval to True/False
            result['message'] = f"Action {action} executed"
        elif (action in ['next', 'prev']):
            config = utils.get_configuration(db)

            if (config['mode'] == 'dir'):
                nextVideo = utils.read_db(db, utils.DB_LAST_PLAYED_FILE)

                # use the info parser to find the next or previous video
                info = VideoInfo(utils.get_configuration(db))
                if (action == 'next'):
                    nextVideo = info.find_next_video(nextVideo['file'])
                else:
                    nextVideo = info.find_prev_video(nextVideo['file'])

                # save the video file
                utils.write_db(db, utils.DB_LAST_PLAYED_FILE, nextVideo)
                result['message'] = f"Next video will be {nextVideo['name']}"
            else:
                result['success'] = False
                result[
                    'message'] = 'Cannot use next/prev actions when in file mode'
        elif (action == 'seek'):
            # get the seek amount as a percent
            data = request.get_json(force=True)

            if ('amount' in data and data['amount'] > 0
                    and data['amount'] <= 100):
                nextVideo = utils.read_db(db, utils.DB_LAST_PLAYED_FILE)

                if ('file' in nextVideo):
                    # see to this value
                    info = VideoInfo(utils.get_configuration(db))
                    nextVideo = info.seek_video(nextVideo, data['amount'])

                    result[
                        'message'] = f"Seeking to {data['amount']:.2f} percent on next update"
                    result['data'] = nextVideo

                    # save the new position
                    utils.write_db(db, utils.DB_LAST_PLAYED_FILE, nextVideo)
                else:
                    result['success'] = False
                    result['message'] = 'No video loaded to seek'
            else:
                result['success'] = False
                result['message'] = 'Value must be between 0 and 100'
        else:
            result['success'] = False
            result['message'] = 'Not a valid control action'

        return jsonify(result)
Beispiel #2
0
    def save_configuration():
        result = {'success': True, 'message': 'Settings Updated'}

        # get the request data and do some verification
        data = request.get_json(force=True)

        # if passed get current config
        currentConfig = utils.get_configuration(db)

        # merge changed values into current and save
        currentConfig.update(data)

        checkConfig = utils.validate_configuration(currentConfig)

        if (checkConfig[0]):
            utils.write_db(db, utils.DB_CONFIGURATION, currentConfig)
        else:
            result['success'] = False
            result['message'] = checkConfig[1]

        return jsonify(result)
Beispiel #3
0
# setup the screen and database connection
epd = displayfactory.load_display_driver(args.epd)

# pull width/height from driver
width = epd.width
height = epd.height

db = redis.Redis('localhost', decode_responses=True)

# default to False as default settings probably won't load a video
if (not db.exists(utils.DB_PLAYER_STATUS)):
    utils.write_db(db, utils.DB_PLAYER_STATUS, {'running': False})
    utils.write_db(db, utils.DB_LAST_RUN, {'last_run': 0})

# load the player configuration
config = utils.get_configuration(db)

logging.info(
    f"Starting with options Frame Increment: {config['increment']} frames, " +
    f"Video start: {config['start']} seconds, Ending Cutoff: {config['end']} seconds, "
    f"Updating on schedule: {config['update']}")

# start the web app
webAppThread = threading.Thread(name='Web App',
                                target=webapp.webapp_thread,
                                args=(args.port, args.debug, logHandlers))
webAppThread.setDaemon(True)
webAppThread.start()

# set to now, or now + 60 depending on if we are showing the splash screen
now = datetime.now(
Beispiel #4
0
 def get_configuration():
     return jsonify(utils.get_configuration(db))
Beispiel #5
0
 def setup_analyze():
     return render_template('analyze.html',
                            config=utils.get_configuration(db))
Beispiel #6
0
 def setup_view():
     return render_template('setup.html',
                            config=utils.get_configuration(db))
Beispiel #7
0
 def index():
     return render_template('index.html',
                            status=utils.read_db(db,
                                                 utils.DB_PLAYER_STATUS),
                            config=utils.get_configuration(db))