Merge branch 'refactor' of github.com:KevinMidboe/seasonedParser into refactor
This commit is contained in:
@@ -22,9 +22,6 @@ from utils import sanitize, refine
|
|||||||
logging.basicConfig(filename=env.logfile, level=logging.INFO)
|
logging.basicConfig(filename=env.logfile, level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
#: Supported archive extensions
|
|
||||||
ARCHIVE_EXTENSIONS = ('.rar',)
|
|
||||||
|
|
||||||
def search_external_subtitles(path, directory=None):
|
def search_external_subtitles(path, directory=None):
|
||||||
dirpath, filename = os.path.split(path)
|
dirpath, filename = os.path.split(path)
|
||||||
dirpath = dirpath or '.'
|
dirpath = dirpath or '.'
|
||||||
@@ -128,7 +125,8 @@ def scan_videos(path):
|
|||||||
# scan for videos
|
# scan for videos
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
# filter on videos and archives
|
# filter on videos and archives
|
||||||
if not (filename.endswith(VIDEO_EXTENSIONS) or filename.endswith(ARCHIVE_EXTENSIONS)):
|
if not (filename.endswith(VIDEO_EXTENSIONS)):
|
||||||
|
logging.debug('Skipping non-video file %s', filename)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# skip hidden files
|
# skip hidden files
|
||||||
|
|||||||
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