Catches exceptions when reading mkv containers and return without crashing program.
This commit is contained in:
@@ -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:
|
||||||
|
try:
|
||||||
mkv = MKV(f)
|
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user