Move LRC check elsewhere
This commit is contained in:
28
subgen.py
28
subgen.py
@@ -645,21 +645,18 @@ def delete_model():
|
|||||||
model = None
|
model = None
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def isAudioFileExtension(file_extension):
|
def :
|
||||||
return file_extension.casefold() in \
|
return file_extension.casefold() in \
|
||||||
AUDIO_EXTENSIONS
|
AUDIO_EXTENSIONS
|
||||||
|
|
||||||
def write_lrc(result, file_path):
|
def write_lrc(result, file_path):
|
||||||
if not os.path.exists(file_path):
|
with open(file_path, "w") as file:
|
||||||
with open(file_path, "w") as file:
|
for segment in result.segments:
|
||||||
for segment in result.segments:
|
minutes, seconds = divmod(int(segment.start), 60)
|
||||||
minutes, seconds = divmod(int(segment.start), 60)
|
fraction = int((segment.start - int(segment.start)) * 100)
|
||||||
fraction = int((segment.start - int(segment.start)) * 100)
|
# remove embedded newlines in text, since some players ignore text after newlines
|
||||||
# remove embedded newlines in text, since some players ignore text after newlines
|
text = segment.text[:].replace('\n', '')
|
||||||
text = segment.text[:].replace('\n', '')
|
file.write(f"[{minutes:02d}:{seconds:02d}.{fraction:02d}]{text}\n")
|
||||||
file.write(f"[{minutes:02d}:{seconds:02d}.{fraction:02d}]{text}\n")
|
|
||||||
else:
|
|
||||||
logging.debug(f"The file {file_path} already exists. Skipping LRC creation.")
|
|
||||||
|
|
||||||
def gen_subtitles(file_path: str, transcription_type: str, force_language : LanguageCode = LanguageCode.NONE) -> None:
|
def gen_subtitles(file_path: str, transcription_type: str, force_language : LanguageCode = LanguageCode.NONE) -> None:
|
||||||
"""Generates subtitles for a video file.
|
"""Generates subtitles for a video file.
|
||||||
@@ -1043,6 +1040,15 @@ def have_to_skip(file_path: str, transcribe_language: LanguageCode) -> bool:
|
|||||||
Returns:
|
Returns:
|
||||||
True if subtitle generation should be skipped; otherwise, False.
|
True if subtitle generation should be skipped; otherwise, False.
|
||||||
"""
|
"""
|
||||||
|
file_name, file_extension = os.path.splitext(file_path)
|
||||||
|
if isAudioFileExtension(file_extension) and lrc_for_audio_files:
|
||||||
|
lrc_file_path = file_name + '.lrc'
|
||||||
|
|
||||||
|
# Check if the file already exists
|
||||||
|
if os.path.exists(lrc_file_path):
|
||||||
|
logging.debug(f"The file {lrc_file_path} already exists. Skipping LRC creation.")
|
||||||
|
return True
|
||||||
|
|
||||||
if skip_unknown_language and transcribe_language == LanguageCode.NONE:
|
if skip_unknown_language and transcribe_language == LanguageCode.NONE:
|
||||||
logging.debug(f"{file_path} has unknown language, skipping.")
|
logging.debug(f"{file_path} has unknown language, skipping.")
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user