mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-04-24 06:37:16 -04:00
Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
commit
29e1050a4a
2 changed files with 44 additions and 16 deletions
|
@ -54,9 +54,13 @@ class SystemLogs(Resource):
|
|||
include = include.casefold()
|
||||
exclude = exclude.casefold()
|
||||
|
||||
# regular expression to identify the start of a log record (timestamp-based)
|
||||
record_start_pattern = re.compile(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}")
|
||||
|
||||
with io.open(get_log_file_path(), encoding='UTF-8') as file:
|
||||
raw_lines = file.read()
|
||||
lines = raw_lines.split('|\n')
|
||||
multi_line_record = []
|
||||
for line in lines:
|
||||
if line == '':
|
||||
continue
|
||||
|
@ -86,18 +90,34 @@ class SystemLogs(Resource):
|
|||
skip = exclude in compare_line
|
||||
if skip:
|
||||
continue
|
||||
raw_message = line.split('|')
|
||||
raw_message_len = len(raw_message)
|
||||
if raw_message_len > 3:
|
||||
log = dict()
|
||||
log["timestamp"] = raw_message[0]
|
||||
log["type"] = raw_message[1].rstrip()
|
||||
log["message"] = raw_message[3]
|
||||
if raw_message_len > 4 and raw_message[4] != '\n':
|
||||
log['exception'] = raw_message[4].strip('\'').replace(' ', '\u2003\u2003')
|
||||
else:
|
||||
log['exception'] = None
|
||||
logs.append(log)
|
||||
# check if the line has a timestamp that matches the start of a new log record
|
||||
if record_start_pattern.match(line):
|
||||
if multi_line_record:
|
||||
# finalize the multi line record and update the exception of the last entry
|
||||
last_log = logs[-1]
|
||||
last_log["exception"] += "\n" + "\n".join(multi_line_record)
|
||||
# reset for the next multi-line record
|
||||
multi_line_record = []
|
||||
raw_message = line.split('|')
|
||||
raw_message_len = len(raw_message)
|
||||
if raw_message_len > 3:
|
||||
log = dict()
|
||||
log["timestamp"] = raw_message[0]
|
||||
log["type"] = raw_message[1].rstrip()
|
||||
log["message"] = raw_message[3]
|
||||
if raw_message_len > 4 and raw_message[4] != '\n':
|
||||
log['exception'] = raw_message[4].strip('\'').replace(' ', '\u2003\u2003')
|
||||
else:
|
||||
log['exception'] = None
|
||||
logs.append(log)
|
||||
else:
|
||||
# accumulate lines that do not have new record header timestamps
|
||||
multi_line_record.append(line.strip())
|
||||
|
||||
if multi_line_record:
|
||||
# finalize the multi line record and update the exception of the last entry
|
||||
last_log = logs[-1]
|
||||
last_log["exception"] += "\n".join(multi_line_record)
|
||||
|
||||
logs.reverse()
|
||||
return marshal(logs, self.get_response_model, envelope='data')
|
||||
|
|
|
@ -158,10 +158,18 @@ def encode_audio_stream(path, ffmpeg_path, audio_stream_language=None):
|
|||
# Use the ISO 639-2 code if available
|
||||
audio_stream_language = get_ISO_639_2_code(audio_stream_language)
|
||||
logger.debug(f"Whisper will use the '{audio_stream_language}' audio stream for {path}")
|
||||
inp = inp[f'a:m:language:{audio_stream_language}']
|
||||
|
||||
out, _ = inp.output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=16000, af="aresample=async=1") \
|
||||
.run(cmd=[ffmpeg_path, "-nostdin"], capture_stdout=True, capture_stderr=True)
|
||||
# 0 = Pick first stream in case there are multiple language streams of the same language,
|
||||
# otherwise ffmpeg will try to combine multiple streams, but our output format doesn't support that.
|
||||
# The first stream is probably the correct one, as later streams are usually commentaries
|
||||
lang_map = f"0:m:language:{audio_stream_language}"
|
||||
else:
|
||||
# there is only one stream, so just use that one
|
||||
lang_map = ""
|
||||
out, _ = (
|
||||
inp.output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=16000, af="aresample=async=1")
|
||||
.global_args("-map", lang_map)
|
||||
.run(cmd=[ffmpeg_path, "-nostdin"], capture_stdout=True, capture_stderr=True)
|
||||
)
|
||||
|
||||
except ffmpeg.Error as e:
|
||||
logger.warning(f"ffmpeg failed to load audio: {e.stderr.decode()}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue