Catches exceptions when reading mkv containers and return without crashing program.
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/utils.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/utils.py
									
									
									
									
									
								
							| @@ -7,7 +7,7 @@ import re | |||||||
| import struct | import struct | ||||||
|  |  | ||||||
| from babelfish import Error as BabelfishError, Language | from babelfish import Error as BabelfishError, Language | ||||||
| from enzyme import MKV | from enzyme import MalformedMKVError, MKV | ||||||
|  |  | ||||||
| def sanitize(string, ignore_characters=None): | def sanitize(string, ignore_characters=None): | ||||||
|     """Sanitize a string to strip special characters. |     """Sanitize a string to strip special characters. | ||||||
| @@ -58,7 +58,14 @@ def refine(video, embedded_subtitles=True, **kwargs): | |||||||
|     extension = os.path.splitext(video.name)[1] |     extension = os.path.splitext(video.name)[1] | ||||||
|     if extension == '.mkv': |     if extension == '.mkv': | ||||||
|         with open(video.name, 'rb') as f: |         with open(video.name, 'rb') as f: | ||||||
|             mkv = MKV(f) |             try: | ||||||
|  |                 mkv = MKV(f) | ||||||
|  |             except MalformedMKVError: | ||||||
|  |                 logging.error('Failed to parse mkv, malformed file') | ||||||
|  |                 return | ||||||
|  |             except KeyError: | ||||||
|  |                 logging.error('Key error while opening file, uncompatible mkv container') | ||||||
|  |                 return | ||||||
|  |  | ||||||
|         # main video track |         # main video track | ||||||
|         if mkv.video_tracks: |         if mkv.video_tracks: | ||||||
| @@ -125,4 +132,4 @@ def refine(video, embedded_subtitles=True, **kwargs): | |||||||
|         else: |         else: | ||||||
|             logging.debug('MKV has no subtitle track') |             logging.debug('MKV has no subtitle track') | ||||||
|     else: |     else: | ||||||
|         logging.debug('Unsupported video extension %s', extension) |         logging.debug('Unsupported video extension %s', extension) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user