ocrmypdf-auto icon indicating copy to clipboard operation
ocrmypdf-auto copied to clipboard

Feature request: Add prefix/suffix to filename with timestamp and/or unique number before moving to archive folder

Open spirkaa opened this issue 4 years ago • 2 comments

Add prefix/suffix to filename with human-readable timestamp (datetime.now().strftime("%Y-%m-%d %H:%M:%S")) and/or unique number before moving to archive folder. In my opinion, all files must stay in archive folder without overwriting.

My scanner (HP 426dn) can't generate unique filename with timestamp by himself, and when he scanning to empty folder (/inbox), filename is always myscan0001.pdf, meaning after ocrmypdf-auto proccessing this file and moving it to archive folder, previously scanned file will be overwritten.

spirkaa avatar Feb 05 '21 08:02 spirkaa

This!! in addition to that, it would be great if I could just specify the filename, so my files get names like 2022-11-12_17-22-10.pdf

whirlfire avatar Nov 12 '22 16:11 whirlfire

I kinda made it work by changing the following in ocrmypdf-auto.py:

   def _map_output_path(self, input_path):
        if self.output_mode == AutoOcrScheduler.MIRROR_TREE:
            return self.output_dir / (input_path - self.input_dir)
        else:
            assert self.output_mode == AutoOcrScheduler.SINGLE_FOLDER
#            output_path = self.output_dir / (input_path.name)
            output_path = self.output_dir / '{}{}'.format(datetime.now().strftime('%Y-%m-%d_%H-%M-%S'),input_path.suffix)
            unique = 1
#            if output_path.exists() or output_path in self.current_outputs:
#                suffix = '.{}.{}{}'.format(datetime.now().strftime('%Y%m%d'), unique, output_path.suffix)
#               output_path = output_path.with_suffix(suffix)

            while output_path.exists() or output_path in self.current_outputs:
                unique = unique + 1
                output_path = self.output_dir / '{}_{}{}'.format(datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), unique,input_path.suffix)
#               output_path = output_path.with_suffix('.{}{}'.format(unique, output_path.suffix), depth=2)
            return output_path

I then mapped it to the container (docker compose):

volumes:      
      - "/path/to/modded/file/ocrmypdf-auto_modded.py:/app/ocrmypdf-auto.py"
      - "/etc/localtime:/etc/localtime:ro"

whirlfire avatar Nov 12 '22 17:11 whirlfire