Esempio n. 1
0
def restart_stream_if_live():
    """Command to restart the streaming by disconnecting the obs live, then reconnecting it."""
    try:
        ret = send_command_to_obs('GetStreamingStatus', {})
        if not ret['streaming']:
            return

        send_command_to_obs('StopStreaming', {})
        time.sleep(5)
        send_command_to_obs('StartStreaming', {})
    except Exception as e:
        logging.exception(e)
Esempio n. 2
0
    def post_obs_stream_stop(auth_token):
        """
        @api {post} /api/obs/stream/stop OBSStreamStop
        @apiVersion 1.1.0
        @apiName OBSStreamStop
        @apiGroup StreamSystem
        @apiDescription Stop the streaming by OBS.

        @apiHeader {String} Authorization 'Bearer <Auth_Token>'
        @apiError (Errors){String} AuthorizationHeaderInvalid Authorization Header is Invalid.
        @apiError (Errors){String} AuthTokenExpired Token has expired, must be refreshed by client.
        @apiError (Errors){String} AuthTokenInvalid Token is invalid, decode is impossible.
        @apiError (Errors){String} ClientAccessImpossible This type of client can't access target endpoint.
        @apiError (Errors){String} ClientAccessRefused Client has no scope access to target endpoint.

        @apiError (Errors){String} OBSInternalError Error communicating to OBS.
        @apiError (Errors){String} OBSNotStreaming OBS is not currently streaming.
        """
        try:
            result = send_command_to_obs('StopStreaming', {})
            if ('status' in result and result['status'] == 'error'
                    and result['error'] == 'streaming not active'):
                return jsonify({
                    'success': 'no',
                    'error': 'OBSNotStreaming',
                    'payload': {}
                }), 200
            return jsonify({'success': 'yes', 'error': '', 'payload': {}}), 200
        except Exception as e:
            logging.error(e)
            return jsonify({
                'success': 'no',
                'error': 'InternalOBSError',
                'payload': {}
            }), 200
Esempio n. 3
0
    def post_obs_scene_update(auth_token):
        """
        @api {post} /api/obs/scene/update OBSSceneUpdate
        @apiVersion 1.1.0
        @apiName OBSSceneUpdate
        @apiGroup StreamSystem
        @apiDescription Change the OBS active scene to a new one.

        @apiHeader {String} Authorization 'Bearer <Auth_Token>'
        @apiError (Errors){String} AuthorizationHeaderInvalid Authorization Header is Invalid.
        @apiError (Errors){String} AuthTokenExpired Token has expired, must be refreshed by client.
        @apiError (Errors){String} AuthTokenInvalid Token is invalid, decode is impossible.
        @apiError (Errors){String} ClientAccessImpossible This type of client can't access target endpoint.
        @apiError (Errors){String} ClientAccessRefused Client has no scope access to target endpoint.

        @apiError (Errors){String} OBSInternalError Error communicating to OBS.

        @apiParam {String} scene Name of the scene to change to.
        @apiError (Errors){String} SceneParameterMissing Scene is not present in the parameters.
        @apiError (Errors){String} SceneParameterInvalid Scene is not valid String.
        @apiError (Errors){String} SceneDoesNotExist Specified scene does not exist in OBS.
        """
        data = request.get_json(force=True)

        # scene checks
        scene = data.get('scene', None)
        if scene is None:
            return jsonify({
                'success': 'no',
                'error': 'SceneParameterMissing',
                'payload': {}
            }), 200
        if not isinstance(scene, str) or len(scene) == 0:
            return jsonify({
                'success': 'no',
                'error': 'SceneParameterInvalid',
                'payload': {}
            }), 200

        # Send command to obs
        try:
            result = send_command_to_obs('SetCurrentScene',
                                         {'scene-name': scene})
            if ('status' in result and result['status'] == 'error'
                    and result['error'] == 'requested scene does not exist'):
                return jsonify({
                    'success': 'no',
                    'error': 'SceneDoesNotExist',
                    'payload': {}
                }), 200
            return jsonify({'success': 'yes', 'error': '', 'payload': {}}), 200
        except Exception as e:
            logging.error(e)
            return jsonify({
                'success': 'no',
                'error': 'InternalOBSError',
                'payload': {}
            }), 200
Esempio n. 4
0
    def get_playlist(auth_token):
        """
        @api {get} /api/obs/playlist/get OBSPlaylistGet
        @apiVersion 1.1.0
        @apiName OBSPlaylistGet
        @apiGroup StreamSystem
        @apiDescription Get OBS playlist content for replay.

        @apiHeader {String} Authorization 'Bearer <Auth_Token>'
        @apiError (Errors){String} AuthorizationHeaderInvalid Authorization Header is Invalid.
        @apiError (Errors){String} AuthTokenExpired Token has expired, must be refreshed by client.
        @apiError (Errors){String} AuthTokenInvalid Token is invalid, decode is impossible.
        @apiError (Errors){String} ClientAccessImpossible This type of client can't access target endpoint.
        @apiError (Errors){String} ClientAccessRefused Client has no scope access to target endpoint.

        @apiError (Errors){String} OBSInternalError Error communicating to OBS.

        @apiSuccess {String[]} files List of file paths inside the playlist.
        """
        try:
            files = []
            result = send_command_to_obs('GetSourceSettings',
                                         {'sourceName': 'RediffPlaylist'})
            if result['status'] == 'error' or 'playlist' not in result[
                    'sourceSettings']:
                return jsonify({
                    'success': 'no',
                    'error': 'InternalOBSError',
                    'payload': {}
                }), 200
            len_path = len(app.config['OBS_PLAYLIST_PATH']) + 1
            for file in result['sourceSettings']['playlist']:
                files.append(file['value'][len_path:])
            return jsonify({
                'success': 'yes',
                'error': '',
                'payload': {
                    'files': files
                }
            }), 200
        except Exception as e:
            logging.error(e)
            return jsonify({
                'success': 'no',
                'error': 'InternalOBSError',
                'payload': {}
            }), 200
Esempio n. 5
0
    def get_obs_scene_list(auth_token):
        """
        @api {get} /api/obs/scene/list OBSSceneList
        @apiVersion 1.1.0
        @apiName OBSSceneList
        @apiGroup StreamSystem
        @apiDescription List the available scenes in OBS.

        @apiHeader {String} Authorization 'Bearer <Auth_Token>'
        @apiError (Errors){String} AuthorizationHeaderInvalid Authorization Header is Invalid.
        @apiError (Errors){String} AuthTokenExpired Token has expired, must be refreshed by client.
        @apiError (Errors){String} AuthTokenInvalid Token is invalid, decode is impossible.
        @apiError (Errors){String} ClientAccessImpossible This type of client can't access target endpoint.
        @apiError (Errors){String} ClientAccessRefused Client has no scope access to target endpoint.

        @apiError (Errors){String} OBSInternalError Error communicating to OBS.
        @apiSuccess {String[]} scenes All available scenes with their name as Strings.
        @apiSuccess {String} active_scene Active scene.
        """
        scenes = []
        try:
            result = send_command_to_obs('GetSceneList', {})
            for scene in result['scenes']:
                scenes.append(scene['name'])
            return jsonify({
                'success': 'yes',
                'error': '',
                'payload': {
                    'scenes': scenes,
                    'active_scene': result['current-scene']
                }
            }), 200
        except Exception as e:
            logging.error(e)
            return jsonify({
                'success': 'no',
                'error': 'InternalOBSError',
                'payload': {}
            }), 200
Esempio n. 6
0
    def get_obs_status(auth_token):
        """
        @api {get} /api/obs/status OBSStatus
        @apiVersion 1.1.0
        @apiName OBSStatus
        @apiGroup StreamSystem
        @apiDescription Get OBS streaming and recording status.

        @apiHeader {String} Authorization 'Bearer <Auth_Token>'
        @apiError (Errors){String} AuthorizationHeaderInvalid Authorization Header is Invalid.
        @apiError (Errors){String} AuthTokenExpired Token has expired, must be refreshed by client.
        @apiError (Errors){String} AuthTokenInvalid Token is invalid, decode is impossible.
        @apiError (Errors){String} ClientAccessImpossible This type of client can't access target endpoint.
        @apiError (Errors){String} ClientAccessRefused Client has no scope access to target endpoint.

        @apiError (Errors){String} OBSInternalError Error communicating to OBS.
        @apiSuccess {Boolean} recording Status of the OBS record.
        @apiSuccess {Boolean} streaming Status of the OBS stream.
        """
        try:
            result = send_command_to_obs('GetStreamingStatus', {})
            return jsonify({
                'success': 'yes',
                'error': '',
                'payload': {
                    'recording': result['recording'],
                    'streaming': result['streaming']
                }
            }), 200
        except Exception as e:
            logging.error(e)
            return jsonify({
                'success': 'no',
                'error': 'InternalOBSError',
                'payload': {}
            }), 200
Esempio n. 7
0
    def post_playlist_update(auth_token):
        """
        @api {post} /api/obs/playlist/update OBSPlaylistUpdate
        @apiVersion 1.1.0
        @apiName OBSPlaylistUpdate
        @apiGroup StreamSystem
        @apiDescription Set OBS playlist content for replay.

        @apiHeader {String} Authorization 'Bearer <Auth_Token>'
        @apiError (Errors){String} AuthorizationHeaderInvalid Authorization Header is Invalid.
        @apiError (Errors){String} AuthTokenExpired Token has expired, must be refreshed by client.
        @apiError (Errors){String} AuthTokenInvalid Token is invalid, decode is impossible.
        @apiError (Errors){String} ClientAccessImpossible This type of client can't access target endpoint.
        @apiError (Errors){String} ClientAccessRefused Client has no scope access to target endpoint.

        @apiError (Errors){String} OBSInternalError Error communicating to OBS.

        @apiParam {String[]} files List of file paths to build the playlist from.
        @apiError (Errors){String} FilesParameterMissing files is not present in the parameters.
        @apiError (Errors){String} FilesParameterInvalid files is not list of valid file paths.
        @apiError (Errors){String} AtLeastOneFileDoesntExist files is not list of valid file paths.
        """
        data = request.get_json(force=True)

        # files checks
        files = data.get('files', None)
        if files is None:
            return jsonify({
                'success': 'no',
                'error': 'FilesParameterMissing',
                'payload': {}
            }), 200
        if not isinstance(files, list):
            return jsonify({
                'success': 'no',
                'error': 'FilesParameterInvalid',
                'payload': {}
            }), 200
        for file in files:
            path = os.path.join(app.config['VOD_PATH'], file)
            if not os.path.isfile(path):
                return jsonify({
                    'success': 'no',
                    'error': 'AtLeastOneFileDoesntExist',
                    'payload': {
                        'file': file
                    }
                }), 200
        path_files = [{
            'value': os.path.join(app.config['OBS_PLAYLIST_PATH'], x)
        } for x in files]

        try:
            result = send_command_to_obs(
                'SetSourceSettings', {
                    'sourceName': 'RediffPlaylist',
                    'sourceSettings': {
                        'playlist': path_files
                    }
                })
            if result['status'] == 'error':
                logging.error(result)
                return jsonify({
                    'success': 'no',
                    'error': 'InternalOBSError',
                    'payload': {}
                }), 200
            return jsonify({'success': 'yes', 'error': '', 'payload': {}}), 200
        except Exception as e:
            logging.error(e)
            return jsonify({
                'success': 'no',
                'error': 'InternalOBSError',
                'payload': {}
            }), 200