I’m trying to print a progress bar while executing ffmpeg but I’m having trouble getting the total number of frames and the current frame being processed. The error I get is AttributeError: 'NoneType' object has no attribute 'groups'. I’ve copied the function from this program and for some reason it works there but not here, even though I haven’t changed that part.

main.py

    pattern_duration = re.compile(
        'duration[ \t\r]?:[ \t\r]?(.+?),[ \t\r]?start', re.IGNORECASE)
    pattern_progress = re.compile('time=(.+?)[ \t\r]?bitrate', re.IGNORECASE)

    def execute_ffmpeg(self, manager, cmd):
        proc = expect.spawn(cmd, encoding='utf-8')
        self.update_progress_bar(proc, manager)
        self.raise_ffmpeg_error(proc)

    def update_progress_bar(self, proc, manager):
        total = self.get_total_frames(proc)
        cont = 0
        pbar = self.initialize_progress_bar(manager)
        try:
            proc.expect(pattern_duration)
            while True:
                progress = self.get_current_frame(proc)
                percent = progress / total * 100
                pbar.update(percent - cont)
                cont = percent
        except expect.EOF:
            pass
        finally:
            if pbar is not None:
                pbar.close()

    def raise_ffmpeg_error(self, proc):
        proc.expect(expect.EOF)
        res = proc.before
        res += proc.read()
        exitstatus = proc.wait()
        if exitstatus:
            raise ffmpeg.Error('ffmpeg', '', res)
    
    def initialize_progress_bar(self, manager):
        pbar = None
        pbar = manager.counter(
            total=100,
            desc=self.path.rsplit(os.path.sep, 1)[-1],
            unit='%',
            bar_format=BAR_FMT,
            counter_format=COUNTER_FMT,
            leave=False
        )
        return pbar

    def get_total_frames(self, proc):
        return sum(map(lambda x: float(
            x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':')))))

    def get_current_frame(self, proc):
        proc.expect(pattern_progress)
        return sum(map(lambda x: float(
                    x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':')))))