def change_extension(self):
        # Change default path

        ext1 = '.mjpeg_tmp'
        ext2 = '.mjpeg'

        path_file1 = ClassUtils.load_path_by_date(self.current_date_file, self.cam_number, ext1)
        path_file2 = ClassUtils.load_path_by_date(self.current_date_file, self.cam_number, ext2)

        if not os.path.exists(path_file1):
            print('Path 1 does not exist')
        else:
            os.rename(path_file1, path_file2)
    def load_frame(self, date: datetime):
        logger.debug(self._frame_date)

        logger.debug('Get frame to load')

        date_file = ClassUtils.get_date_file(date)

        # Check fist if date is in list
        found = False

        for frame_item in self._frame_info_list:
            date_video = frame_item['date_video']
            if date_video == date_file:
                found = True
                self._frame_date = date_file
                self._frame_info = frame_item['frame_info']
                break

        if not found:
            logger.debug('Loading file name')
            logger.debug(date_file)
            file_path = ClassUtils.load_path_by_date(date_file,
                                                     self._cam_number,
                                                     self._extension)

            if not path.exists(file_path):
                # Avoid exceptions - Video partial
                print('Path does not exists {0}'.format(file_path))
                frame_info = []
                self._frame_info = frame_info
                self._frame_date = date_file

                if self._last_frame is None:
                    raise Exception('Fist video must exist!')

                self._frame_info_list.append({
                    'date_video': date_file,
                    'frame_info': frame_info
                })
            else:
                logger.debug('Loading video from path')
                frame_info = ClassMjpegReader.process_video_mjpegx(file_path)

                self._frame_info = frame_info
                self._frame_date = date_file

                logger.debug('Frame counter: {0}'.format(len(frame_info)))

                # Must be true -> First frame to send -> Avoid exceptions
                if self._last_frame is None:
                    self._last_frame = frame_info[0]

                self._frame_info_list.append({
                    'date_video': date_file,
                    'frame_info': frame_info
                })

        return self._load_frame_by_date(date)
    def save_frame_info(self):
        for frame_item in self._frame_info_list:
            frame_info = frame_item['frame_info']
            date_video = frame_item['date_video']

            path_video = ClassUtils.load_path_by_date(date_video,
                                                      self._cam_number,
                                                      self._extension)

            # Converting video from list
            ClassMjpegConverter.save_video_from_list_frames(
                path_video, frame_info)
            logger.info('Video saved in path {0}'.format(path_video))

        logger.debug('Done converting videos')
    def save_data(self):
        if len(self.buffer) > 0:
            ext = '.mjpeg_tmp'
            path_file = ClassUtils.load_path_by_date(self.current_date_file, self.cam_number, ext)

            path_folder = os.path.dirname(path_file)

            # Creating path folder if does not exist
            if not os.path.exists(path_folder):
                os.makedirs(path_folder)

            with open(path_file, 'ab') as f:
                f.write(self.buffer)

            # Reset buffer
            self.buffer = bytes()