|
|
@ -29,7 +29,9 @@ class MediaDescriptor:
|
|
|
|
#407 remove as well
|
|
|
|
#407 remove as well
|
|
|
|
EXCLUDED_MEDIA_TAGS = ["creation_time"]
|
|
|
|
EXCLUDED_MEDIA_TAGS = ["creation_time"]
|
|
|
|
|
|
|
|
|
|
|
|
SEASON_EPISODE_STREAM_LANGUAGE_MATCH = '[sS]([0-9]+)[eE]([0-9]+)_([0-9]+)_([a-z]{3})(?:_([A-Z]{3}))*'
|
|
|
|
SEASON_EPISODE_STREAM_LANGUAGE_DISPOSITIONS_MATCH = '[sS]([0-9]+)[eE]([0-9]+)_([0-9]+)_([a-z]{3})(?:_([A-Z]{3}))*'
|
|
|
|
|
|
|
|
STREAM_LANGUAGE_DISPOSITIONS_MATCH = '[sS]([0-9]+)[eE]([0-9]+)_([0-9]+)_([a-z]{3})(?:_([A-Z]{3}))*'
|
|
|
|
|
|
|
|
|
|
|
|
SUBTITLE_FILE_EXTENSION = 'vtt'
|
|
|
|
SUBTITLE_FILE_EXTENSION = 'vtt'
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
def __init__(self, **kwargs):
|
|
|
@ -396,27 +398,33 @@ class MediaDescriptor:
|
|
|
|
|
|
|
|
|
|
|
|
def searchSubtitleFiles(self, searchDirectory, prefix):
|
|
|
|
def searchSubtitleFiles(self, searchDirectory, prefix):
|
|
|
|
|
|
|
|
|
|
|
|
sesl_match = re.compile(MediaDescriptor.SEASON_EPISODE_STREAM_LANGUAGE_MATCH)
|
|
|
|
sesld_match = re.compile(f"{prefix}_{MediaDescriptor.SEASON_EPISODE_STREAM_LANGUAGE_DISPOSITIONS_MATCH}")
|
|
|
|
|
|
|
|
sld_match = re.compile(f"{prefix}_{MediaDescriptor.STREAM_LANGUAGE_DISPOSITIONS_MATCH}")
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFileDescriptors = []
|
|
|
|
subtitleFileDescriptors = []
|
|
|
|
|
|
|
|
|
|
|
|
for subtitleFilename in os.listdir(searchDirectory):
|
|
|
|
for subtitleFilename in os.listdir(searchDirectory):
|
|
|
|
if subtitleFilename.startswith(prefix) and subtitleFilename.endswith(
|
|
|
|
if subtitleFilename.startswith(prefix) and subtitleFilename.endswith(
|
|
|
|
"." + MediaDescriptor.SUBTITLE_FILE_EXTENSION
|
|
|
|
"." + MediaDescriptor.SUBTITLE_FILE_EXTENSION
|
|
|
|
):
|
|
|
|
):
|
|
|
|
sesl_result = sesl_match.search(subtitleFilename)
|
|
|
|
|
|
|
|
if sesl_result is not None:
|
|
|
|
sesld_result = sesld_match.search(subtitleFilename)
|
|
|
|
|
|
|
|
sld_result = None if not sesld_result is None else sld_match.search(subtitleFilename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not sesld_result is None:
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFilePath = os.path.join(searchDirectory, subtitleFilename)
|
|
|
|
subtitleFilePath = os.path.join(searchDirectory, subtitleFilename)
|
|
|
|
if os.path.isfile(subtitleFilePath):
|
|
|
|
if os.path.isfile(subtitleFilePath):
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFileDescriptor = {}
|
|
|
|
subtitleFileDescriptor = {}
|
|
|
|
subtitleFileDescriptor["path"] = subtitleFilePath
|
|
|
|
subtitleFileDescriptor["path"] = subtitleFilePath
|
|
|
|
subtitleFileDescriptor["season"] = int(sesl_result.group(1))
|
|
|
|
subtitleFileDescriptor["season"] = int(sesld_result.group(1))
|
|
|
|
subtitleFileDescriptor["episode"] = int(sesl_result.group(2))
|
|
|
|
subtitleFileDescriptor["episode"] = int(sesld_result.group(2))
|
|
|
|
subtitleFileDescriptor["index"] = int(sesl_result.group(3))
|
|
|
|
subtitleFileDescriptor["index"] = int(sesld_result.group(3))
|
|
|
|
subtitleFileDescriptor["language"] = sesl_result.group(4)
|
|
|
|
subtitleFileDescriptor["language"] = sesld_result.group(4)
|
|
|
|
|
|
|
|
|
|
|
|
dispSet = set()
|
|
|
|
dispSet = set()
|
|
|
|
dispCaptGroups = sesl_result.groups()
|
|
|
|
dispCaptGroups = sesld_result.groups()
|
|
|
|
numCaptGroups = len(dispCaptGroups)
|
|
|
|
numCaptGroups = len(dispCaptGroups)
|
|
|
|
if numCaptGroups > 4:
|
|
|
|
if numCaptGroups > 4:
|
|
|
|
for groupIndex in range(numCaptGroups - 4):
|
|
|
|
for groupIndex in range(numCaptGroups - 4):
|
|
|
@ -427,6 +435,29 @@ class MediaDescriptor:
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFileDescriptors.append(subtitleFileDescriptor)
|
|
|
|
subtitleFileDescriptors.append(subtitleFileDescriptor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not sld_result is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFilePath = os.path.join(searchDirectory, subtitleFilename)
|
|
|
|
|
|
|
|
if os.path.isfile(subtitleFilePath):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFileDescriptor = {}
|
|
|
|
|
|
|
|
subtitleFileDescriptor["path"] = subtitleFilePath
|
|
|
|
|
|
|
|
subtitleFileDescriptor["index"] = int(sld_result.group(1))
|
|
|
|
|
|
|
|
subtitleFileDescriptor["language"] = sld_result.group(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dispSet = set()
|
|
|
|
|
|
|
|
dispCaptGroups = sld_result.groups()
|
|
|
|
|
|
|
|
numCaptGroups = len(dispCaptGroups)
|
|
|
|
|
|
|
|
if numCaptGroups > 2:
|
|
|
|
|
|
|
|
for groupIndex in range(numCaptGroups - 2):
|
|
|
|
|
|
|
|
disp = TrackDisposition.fromIndicator(dispCaptGroups[groupIndex + 2])
|
|
|
|
|
|
|
|
if disp is not None:
|
|
|
|
|
|
|
|
dispSet.add(disp)
|
|
|
|
|
|
|
|
subtitleFileDescriptor["disposition_set"] = dispSet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subtitleFileDescriptors.append(subtitleFileDescriptor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.__logger.debug(f"searchSubtitleFiles(): Available subtitle files {subtitleFileDescriptors}")
|
|
|
|
self.__logger.debug(f"searchSubtitleFiles(): Available subtitle files {subtitleFileDescriptors}")
|
|
|
|
|
|
|
|
|
|
|
|
return subtitleFileDescriptors
|
|
|
|
return subtitleFileDescriptors
|
|
|
@ -450,7 +481,8 @@ class MediaDescriptor:
|
|
|
|
[
|
|
|
|
[
|
|
|
|
d
|
|
|
|
d
|
|
|
|
for d in availableFileSubtitleDescriptors
|
|
|
|
for d in availableFileSubtitleDescriptors
|
|
|
|
if d["season"] == int(season) and d["episode"] == int(episode)
|
|
|
|
if ((season == -1 and episode == -1)
|
|
|
|
|
|
|
|
or (d["season"] == int(season) and d["episode"] == int(episode)))
|
|
|
|
],
|
|
|
|
],
|
|
|
|
key=lambda d: d["index"],
|
|
|
|
key=lambda d: d["index"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|