|
@@ -120,13 +120,13 @@ def scan(files):
|
|
|
# Loop end
|
|
# Loop end
|
|
|
media.append(info)
|
|
media.append(info)
|
|
|
logger.debug(f"Found media: {info}")
|
|
logger.debug(f"Found media: {info}")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Return
|
|
# Return
|
|
|
return media
|
|
return media
|
|
|
|
|
|
|
|
def mux(media):
|
|
def mux(media):
|
|
|
logger.debug(f"Muxing {len(media)} files")
|
|
logger.debug(f"Muxing {len(media)} files")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Find groups
|
|
# Find groups
|
|
|
groups = {}
|
|
groups = {}
|
|
|
for file in media:
|
|
for file in media:
|
|
@@ -140,7 +140,7 @@ def mux(media):
|
|
|
# Merge groups
|
|
# Merge groups
|
|
|
for (g_base, group) in groups.items():
|
|
for (g_base, group) in groups.items():
|
|
|
logger.debug(f"Merging group: {group[0]['base']}")
|
|
logger.debug(f"Merging group: {group[0]['base']}")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Skip groups that do not need muxing
|
|
# Skip groups that do not need muxing
|
|
|
if len(group) == 1:
|
|
if len(group) == 1:
|
|
|
if 'mux_vers' in group[0] and group[0]['mux_vers'] and group[0]['mux_vers'] >= mux_vers:
|
|
if 'mux_vers' in group[0] and group[0]['mux_vers'] and group[0]['mux_vers'] >= mux_vers:
|
|
@@ -165,13 +165,13 @@ def mux(media):
|
|
|
if len(videos) != 1:
|
|
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: {group[0]['base']}")
|
|
|
continue
|
|
continue
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Build args
|
|
# Build args
|
|
|
final = group[0]['path'].parent.joinpath(f'{group[0]['base']}.mkv')
|
|
final = group[0]['path'].parent.joinpath(f'{group[0]['base']}.mkv')
|
|
|
temp = final.with_suffix('.mkv-remux')
|
|
temp = final.with_suffix('.mkv-remux')
|
|
|
args = [ 'mkvmerge', '--default-language', lang_default, '-o', temp ]
|
|
args = [ 'mkvmerge', '--default-language', lang_default, '-o', temp ]
|
|
|
args.append(videos[0]['path'])
|
|
args.append(videos[0]['path'])
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Subtitles get language and SDH metadata
|
|
# Subtitles get language and SDH metadata
|
|
|
# Index is always 0; these files contain only one stream
|
|
# Index is always 0; these files contain only one stream
|
|
|
for sub in subs:
|
|
for sub in subs:
|
|
@@ -230,10 +230,10 @@ def mux(media):
|
|
|
|
|
|
|
|
def lang(media):
|
|
def lang(media):
|
|
|
logger.debug(f"Language processing {len(media)} files")
|
|
logger.debug(f"Language processing {len(media)} files")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for file in media:
|
|
for file in media:
|
|
|
logger.debug(f"Lang: {file['name']}")
|
|
logger.debug(f"Lang: {file['name']}")
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Skip files tha do not need lang processing
|
|
# Skip files tha do not need lang processing
|
|
|
if not file['ext'] in video_ext:
|
|
if not file['ext'] in video_ext:
|
|
|
logger.debug(f"Skipping non-video item: {file['path']}")
|
|
logger.debug(f"Skipping non-video item: {file['path']}")
|
|
@@ -241,14 +241,14 @@ def lang(media):
|
|
|
if 'lang_vers' in file and file['lang_vers'] and file['lang_vers'] >= lang_vers:
|
|
if 'lang_vers' in file and file['lang_vers'] and file['lang_vers'] >= lang_vers:
|
|
|
logger.debug(f"Skipping item with current lang_vers: {file['path']}")
|
|
logger.debug(f"Skipping item with current lang_vers: {file['path']}")
|
|
|
continue
|
|
continue
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Probe streams
|
|
# Probe streams
|
|
|
streams = probe.probe(file['path'])
|
|
streams = probe.probe(file['path'])
|
|
|
for stream in streams:
|
|
for stream in streams:
|
|
|
if not 'index' in stream:
|
|
if not 'index' in stream:
|
|
|
logger.error(f"No index for stream ({file['name']}): {stream}")
|
|
logger.error(f"No index for stream ({file['name']}): {stream}")
|
|
|
continue
|
|
continue
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Find missing and undefined languages for subtitle and audio streams
|
|
# Find missing and undefined languages for subtitle and audio streams
|
|
|
updates = []
|
|
updates = []
|
|
|
for stream in streams:
|
|
for stream in streams:
|
|
@@ -272,12 +272,12 @@ def lang(media):
|
|
|
if propedit.returncode != 0:
|
|
if propedit.returncode != 0:
|
|
|
logger.error(f"propedit error ({propedit.returncode}): {propedit.stdout.decode('utf-8')}")
|
|
logger.error(f"propedit error ({propedit.returncode}): {propedit.stdout.decode('utf-8')}")
|
|
|
continue
|
|
continue
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Set xattr
|
|
# Set xattr
|
|
|
if not write_xattr(file['path'], lang_xattr, lang_vers):
|
|
if not write_xattr(file['path'], lang_xattr, lang_vers):
|
|
|
continue
|
|
continue
|
|
|
file['lang_vers'] = lang_vers
|
|
file['lang_vers'] = lang_vers
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# Execute
|
|
# Execute
|
|
|
for (parent, dirs, files) in root.walk():
|
|
for (parent, dirs, files) in root.walk():
|
|
|
logger.debug(f"Walking: {parent}")
|
|
logger.debug(f"Walking: {parent}")
|