|
|
@@ -22,6 +22,7 @@ meta_default = {
|
|
|
'path': None,
|
|
|
'name': '',
|
|
|
'ext': '',
|
|
|
+ 'group': '',
|
|
|
'lang': None,
|
|
|
'sdh': False,
|
|
|
'mux_vers': None,
|
|
|
@@ -90,8 +91,7 @@ def scan(files):
|
|
|
try:
|
|
|
m = re_media.search(info['name'])
|
|
|
if m and len(m.groups()) == 4:
|
|
|
- info['base'] = m.group(1)
|
|
|
- info['g_base'] = info['base'].lower()
|
|
|
+ info['group'] = m.group(1)
|
|
|
|
|
|
try:
|
|
|
lang = langcodes.Language.get(m.group(2).lower())
|
|
|
@@ -130,16 +130,18 @@ def mux(media):
|
|
|
# Find groups
|
|
|
groups = {}
|
|
|
for file in media:
|
|
|
- if 'g_base' in file:
|
|
|
- g_base = file['g_base']
|
|
|
- if file['g_base'] not in groups:
|
|
|
- groups[g_base] = []
|
|
|
- if file not in groups[g_base]:
|
|
|
- groups[g_base].append(file)
|
|
|
+ if not file['group']:
|
|
|
+ logger.debug(f"Skipping non-grouped file: {file['name']}")
|
|
|
+ continue
|
|
|
+ gnorm = file['group'].lower()
|
|
|
+ if gnorm not in groups:
|
|
|
+ groups[gnorm] = []
|
|
|
+ if file not in groups[gnorm]:
|
|
|
+ groups[gnorm].append(file)
|
|
|
|
|
|
# Merge groups
|
|
|
- for (g_base, group) in groups.items():
|
|
|
- logger.debug(f"Merging group: {group[0]['base']}")
|
|
|
+ for group in groups.values():
|
|
|
+ logger.debug(f"Muxing group: {group[0]['group']}")
|
|
|
|
|
|
# Skip groups that do not need muxing
|
|
|
if len(group) == 1:
|
|
|
@@ -153,21 +155,23 @@ def mux(media):
|
|
|
videos = []
|
|
|
for file in group:
|
|
|
if file['ext'] in video_ext:
|
|
|
- logger.debug(f"Found video: {file['path'].name}")
|
|
|
+ logger.debug(f"Found video: {file['name']}")
|
|
|
videos.append(file)
|
|
|
- else:
|
|
|
- logger.debug(f"Found subtitle: {file['path'].name}")
|
|
|
+ elif file['ext'] in subs_ext:
|
|
|
+ logger.debug(f"Found subtitle: {file['name']}")
|
|
|
subs.append(file)
|
|
|
+ else:
|
|
|
+ logger.warning(f"Skipping unexpected source while muxing: {file['name']}")
|
|
|
# Track total size for post-mux verification
|
|
|
size += file['path'].stat().st_size
|
|
|
|
|
|
# We should find exactly one video in the group
|
|
|
if len(videos) != 1:
|
|
|
- logger.error(f"Did not find exactly 1 video: {group[0]['base']}")
|
|
|
+ logger.error(f"Did not find exactly 1 video in group: {group[0]['group']}")
|
|
|
continue
|
|
|
|
|
|
# Build args
|
|
|
- final = group[0]['path'].parent.joinpath(f'{group[0]['base']}.mkv')
|
|
|
+ final = videos[0]['path'].parent.joinpath(f'{videos[0]['group']}.mkv')
|
|
|
temp = final.with_suffix('.mkv-remux')
|
|
|
args = [ 'mkvmerge', '--default-language', lang_default, '-o', temp ]
|
|
|
args.append(videos[0]['path'])
|
|
|
@@ -216,6 +220,7 @@ def mux(media):
|
|
|
info['path'] = final
|
|
|
info['name'] = final.name
|
|
|
info['ext'] = 'mkv'
|
|
|
+ info['group'] = videos[0]['group']
|
|
|
info['mux_vers'] = mux_vers
|
|
|
media.append(info)
|
|
|
except BaseException as e:
|
|
|
@@ -225,7 +230,7 @@ def mux(media):
|
|
|
elif final.stat().st_size < (min_size * size):
|
|
|
err = 'Output file too small'
|
|
|
if err is not None:
|
|
|
- logger.error(f"Rename error ({final}): {e}")
|
|
|
+ logger.error(f"Rename error ({final}): {err}")
|
|
|
continue
|
|
|
|
|
|
def lang(media):
|
|
|
@@ -234,7 +239,7 @@ def lang(media):
|
|
|
for file in media:
|
|
|
logger.debug(f"Lang: {file['name']}")
|
|
|
|
|
|
- # Skip files tha do not need lang processing
|
|
|
+ # Skip files that do not need lang processing
|
|
|
if not file['ext'] in video_ext:
|
|
|
logger.debug(f"Skipping non-video item: {file['path']}")
|
|
|
continue
|