Example #1
0
    def delete_channel_or_recorder_by_name(self, channel_name, infocfg=None):
        """deletes all channels or recorders by given channel name.

        ignores when there's no id for a matched channel name,
        or when there are no channels in the returned json.
        """
        if infocfg is None:
            # query device for configured channels
            try:
                infocfg = self.get_infocfg()
            except Exception as e:
                msg = 'failed to delete channel/recorder(%s); ' % channel_name
                msg += 'GET infocfg for device(%s) - %s' % (
                        self.url, e.message)
                logging.getLogger(__name__).error(msg)
                raise e

        if 'channels' in infocfg:
            for c in infocfg['channels']:
                if c['name'].strip() == channel_name:
                    try:
                        WebUiChannel.delete_channel(
                                client=self, channel_id=c['id'])
                    except Exception as e:
                        msg = 'failed to delete channel(%s)(%s)' \
                                % (c['id'], c['name'])
                        msg += ' from device(%s)' % self.url
                        msg += ' - %s' % e.message
                        logging.getLogger(__name__).error(msg)
                        raise e

        if 'recorders' in infocfg:
            for r in infocfg['recorders']:
                if r['name'].strip() == channel_name:
                    try:
                        WebUiChannel.delete_recorder(
                                client=self, recorder_id=r['id'])
                    except Exception as e:
                        msg = 'failed to delete recorder(%s)(%s)' \
                                % (r['id'], r['name'])
                        msg += ' from device(%s)' % self.url
                        msg += ' - %s' % e.message
                        logging.getLogger(__name__).error(msg)
                        raise e
        return True
Example #2
0
 def set_channel_rtmp(
         self, channel_id, rtmp_url, rtmp_stream, rtmp_usr, rtmp_pwd):
     """configs rtmp-push for live streaming in given channel."""
     return WebUiChannel.set_channel_rtmp(
             client=self,
             channel_id=channel_id,
             rtmp_url=rtmp_url,
             rtmp_stream=rtmp_stream,
             rtmp_usr=rtmp_usr,
             rtmp_pwd=rtmp_pwd)
Example #3
0
    def get_infocfg(self):
        try:
            r_infocfg = WebUiChannel.get_infocfg(client=self)
        except Exception as e:
            msg = 'failed to GET infocfg for device({}) - {}'.format(
                    self.url, e.message)
            logging.getLogger(__name__).error(msg)
            raise e

        return r_infocfg
Example #4
0
    def set_channel_layout(self, channel_id, layout, layout_id='1'):
        """set source layout for channel.

        layout must be a json string.
        """
        return WebUiChannel.set_channel_layout(
                client=self,
                channel_id=channel_id,
                layout=layout,
                layout_id=layout_id)
Example #5
0
    def create_recorder(self, recorder_name):
        """creates new recorder with given recorder_name."""
        recorder_id = None
        try:
            recorder_id = WebUiChannel.create_recorder(client=self)
        except Exception as e:
            msg = 'failed to create recorder(%s) - %s' % \
                    (recorder_name, e.message)
            logging.getLogger(__name__).error(msg)
            raise e
        try:
            WebUiChannel.rename_recorder(
                    client=self,
                    recorder_id=recorder_id,
                    recorder_name=recorder_name)
        except Exception as e:
            msg = 'failed to rename recorder(%s)(%s) - %s' % \
                    (recorder_id, recorder_name, e.message)
            logging.getLogger(__name__).error(msg)
            raise e

        return recorder_id
Example #6
0
    def create_channel(self, channel_name):
        """creates new channel with given channel_name."""
        logger = logging.getLogger(__name__)
        channel_id = None
        try:
            channel_id = WebUiChannel.create_channel(client=self)
        except Exception as e:
            msg = 'failed to create channel(%s) - %s' % \
                    (channel_name, e.message)
            logger.error(msg)
            raise e
        try:
            WebUiChannel.rename_channel(
                    client=self, channel_id=channel_id,
                    channel_name=channel_name)
        except Exception as e:
            msg = 'failed to rename channel(%s)(%s) - %s' % \
                    (channel_id, channel_name, e.message)
            logger.error(msg)
            raise e

        return channel_id
Example #7
0
 def set_recorder_settings(
         self, recorder_id,
         recording_timelimit_in_minutes=360,         # 6h
         recording_sizelimit_in_kbytes=64000000,  # 64G
         output_format='avi',  # or mov, mp4, ts(mpeg-ts)
         user_prefix='',       # prefix for recording file
         afu_enabled='on',     # this means auto-upload disabled!
         upnp_enabled=''):
     """configs settings for give recorder_id."""
     return WebUiChannel.set_recorder_settings(
             client=self,
             recorder_id=recorder_id,
             recording_timelimit_in_minutes=recording_timelimit_in_minutes,
             recording_sizelimit_in_kbytes=recording_sizelimit_in_kbytes,
             output_format=output_format,
             user_prefix=user_prefix,
             afu_enabled=afu_enabled,
             upnp_enabled=upnp_enabled)
Example #8
0
 def delete_channel(self, channel_id):
     """deletes given channel_id."""
     return WebUiChannel.delete_channel(
             client=self, channel_id=channel_id)
Example #9
0
 def delete_recorder(self, recorder_id):
     """deletes given recorder_id."""
     return WebUiChannel.delete_recorder(
             client=self, recorder_id=recorder_id)
Example #10
0
 def set_recorder_channels(self, recorder_id, channel_list):
     return WebUiChannel.set_recorder_channels(
             client=self,
             recorder_id=recorder_id,
             channel_list=channel_list)