diff options
| author | jvoisin | 2018-10-22 16:45:30 +0200 |
|---|---|---|
| committer | jvoisin | 2018-10-22 16:56:05 +0200 |
| commit | 44f267a5964ea8dbb59c26c319e43fad84afb45a (patch) | |
| tree | f943cac833ff09ebbbcfac64315d61b6d4f5b73f /libmat2/video.py | |
| parent | 5bc88faedf457f32c007a60a5145bec0dca60523 (diff) | |
Improve problematic filenames support
Diffstat (limited to 'libmat2/video.py')
| -rw-r--r-- | libmat2/video.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/libmat2/video.py b/libmat2/video.py index 658affa..2fa65e8 100644 --- a/libmat2/video.py +++ b/libmat2/video.py | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import subprocess | 2 | import subprocess |
| 3 | import logging | ||
| 3 | 4 | ||
| 4 | from . import exiftool | 5 | from . import exiftool |
| 5 | 6 | ||
| @@ -23,13 +24,10 @@ class AVIParser(exiftool.ExiftoolParser): | |||
| 23 | 'SampleRate', 'AvgBytesPerSec', 'BitsPerSample', | 24 | 'SampleRate', 'AvgBytesPerSec', 'BitsPerSample', |
| 24 | 'Duration', 'ImageSize', 'Megapixels'} | 25 | 'Duration', 'ImageSize', 'Megapixels'} |
| 25 | 26 | ||
| 26 | def remove_all(self) -> bool: | 27 | |
| 27 | """ | 28 | def __remove_all_internal(self, filename: str): |
| 28 | TODO: handle problematic filenames starting with `-` and `--`, | ||
| 29 | check exiftool.py | ||
| 30 | """ | ||
| 31 | cmd = [_get_ffmpeg_path(), | 29 | cmd = [_get_ffmpeg_path(), |
| 32 | '-i', self.filename, # input file | 30 | '-i', filename, # input file |
| 33 | '-y', # overwrite existing output file | 31 | '-y', # overwrite existing output file |
| 34 | '-loglevel', 'panic', # Don't show log | 32 | '-loglevel', 'panic', # Don't show log |
| 35 | '-hide_banner', # hide the banner | 33 | '-hide_banner', # hide the banner |
| @@ -40,10 +38,13 @@ class AVIParser(exiftool.ExiftoolParser): | |||
| 40 | '-flags:v', '+bitexact', # don't add any metadata | 38 | '-flags:v', '+bitexact', # don't add any metadata |
| 41 | '-flags:a', '+bitexact', # don't add any metadata | 39 | '-flags:a', '+bitexact', # don't add any metadata |
| 42 | self.output_filename] | 40 | self.output_filename] |
| 41 | subprocess.check_call(cmd) | ||
| 43 | 42 | ||
| 43 | def remove_all(self) -> bool: | ||
| 44 | try: | 44 | try: |
| 45 | subprocess.check_call(cmd) | 45 | self._handle_problematic_filename(self.__remove_all_internal) |
| 46 | except subprocess.CalledProcessError: | 46 | except subprocess.CalledProcessError as e: |
| 47 | logging.error("Something went wrong during the processing of %s: %s", self.filename, e) | ||
| 47 | return False | 48 | return False |
| 48 | return True | 49 | return True |
| 49 | 50 | ||
