Добавить необязательные субтитры при склейке серий.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+36
-9
@@ -9,12 +9,39 @@ action_merge_mkv() {
|
||||
local video_file="$1"
|
||||
local audio_file="$2"
|
||||
local final_output_file="$3"
|
||||
local subtitle_file="$4"
|
||||
|
||||
mkvmerge \
|
||||
-o "$TEMP_MERGE_FILE" \
|
||||
--track-order 1:0,0:0 \
|
||||
--language 0:rus "$audio_file" \
|
||||
"$video_file" \
|
||||
# Файл 0 — аудио, 1 — видео, 2 — субтитры (если заданы).
|
||||
# Порядок дорожек: видео, новая аудиодорожка, затем субтитры.
|
||||
local -a merge_cmd=()
|
||||
|
||||
if [[ -n "$subtitle_file" ]]; then
|
||||
merge_cmd=(
|
||||
mkvmerge
|
||||
-o "$TEMP_MERGE_FILE"
|
||||
--track-order 1:0,0:0,2:0
|
||||
--language 0:rus "$audio_file"
|
||||
"$video_file"
|
||||
--language 0:rus
|
||||
)
|
||||
local subtitle_lower="${subtitle_file,,}"
|
||||
case "$subtitle_lower" in
|
||||
*.srt|*.ass|*.ssa|*.sub|*.txt)
|
||||
merge_cmd+=(--sub-charset 0:UTF-8)
|
||||
;;
|
||||
esac
|
||||
merge_cmd+=("$subtitle_file")
|
||||
else
|
||||
merge_cmd=(
|
||||
mkvmerge
|
||||
-o "$TEMP_MERGE_FILE"
|
||||
--track-order 1:0,0:0
|
||||
--language 0:rus "$audio_file"
|
||||
"$video_file"
|
||||
)
|
||||
fi
|
||||
|
||||
"${merge_cmd[@]}" \
|
||||
&& \
|
||||
mv "$TEMP_MERGE_FILE" "$final_output_file"
|
||||
}
|
||||
@@ -37,12 +64,12 @@ run_processing() {
|
||||
|
||||
local skip_count=0
|
||||
local pending_count=0
|
||||
local triplet video audio output
|
||||
local triplet video audio output subtitle
|
||||
# Снимок на момент старта. Файл, появившийся уже в этом запуске,
|
||||
# нельзя считать «и так был» — иначе отчёт завысит число обработанных.
|
||||
local -A ALREADY_PRESENT=()
|
||||
for triplet in "${FILE_TRIPLETS[@]}"; do
|
||||
IFS=$'\t' read -r video audio output <<< "$triplet"
|
||||
IFS=$'\t' read -r video audio output subtitle <<< "$triplet"
|
||||
if output_file_exists "$output"; then
|
||||
ALREADY_PRESENT["$output"]=1
|
||||
skip_count=$((skip_count + 1))
|
||||
@@ -82,7 +109,7 @@ run_processing() {
|
||||
local total_files=${#FILE_TRIPLETS[@]}
|
||||
local current_file_num=0
|
||||
|
||||
while IFS=$'\t' read -r video audio output; do
|
||||
while IFS=$'\t' read -r video audio output subtitle; do
|
||||
((current_file_num++))
|
||||
local progress_before=$(( ((current_file_num - 1) * 100) / total_files ))
|
||||
|
||||
@@ -104,7 +131,7 @@ run_processing() {
|
||||
|
||||
case "$CURRENT_ACTION" in
|
||||
"MERGE")
|
||||
action_merge_mkv "$video" "$audio" "$output" >/dev/null 2>&1 ;;
|
||||
action_merge_mkv "$video" "$audio" "$output" "$subtitle" >/dev/null 2>&1 ;;
|
||||
"SYMLINK")
|
||||
action_create_symlink "$video" "$output" >/dev/null 2>&1 ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user