You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.9 KiB
79 lines
1.9 KiB
#!/bin/bash
|
|
|
|
# Ensure mkvmerge is installed
|
|
if ! command -v mkvmerge &> /dev/null; then
|
|
echo "Error: mkvmerge is not installed. Please install mkvtoolnix."
|
|
exit 1
|
|
fi
|
|
|
|
# Default directories
|
|
VIDEO_DIR=""
|
|
SUBTITLE_DIR=""
|
|
MUXED_DIR=""
|
|
|
|
# Parse arguments
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case "$1" in
|
|
--vidsrc)
|
|
VIDEO_DIR="$2"
|
|
shift 2
|
|
;;
|
|
--subsrc)
|
|
SUBTITLE_DIR="$2"
|
|
shift 2
|
|
;;
|
|
-o)
|
|
MUXED_DIR="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Ensure required arguments are provided
|
|
if [[ -z "$VIDEO_DIR" || -z "$SUBTITLE_DIR" || -z "$MUXED_DIR" ]]; then
|
|
echo "Usage: $0 --vidsrc <video_directory> --subsrc <subtitle_directory> -o <output_directory>"
|
|
exit 1
|
|
fi
|
|
|
|
# Create output directory
|
|
mkdir -p "$MUXED_DIR"
|
|
|
|
# Process each video file
|
|
for video_file in "$VIDEO_DIR"/*.mkv; do
|
|
[[ -e "$video_file" ]] || continue
|
|
|
|
# Extract SxxExx pattern
|
|
episode_id=$(basename "$video_file" | grep -oE 'S[0-9]{2}E[0-9]{2}')
|
|
|
|
if [[ -z "$episode_id" ]]; then
|
|
echo "Skipping $video_file (no episode pattern found)"
|
|
continue
|
|
fi
|
|
|
|
# Find matching subtitle file
|
|
subtitle_file=$(find "$SUBTITLE_DIR" -type f -name "*${episode_id}*.mkv" | head -n 1)
|
|
|
|
if [[ -z "$subtitle_file" ]]; then
|
|
echo "Warning: No subtitle file found for $video_file"
|
|
continue
|
|
fi
|
|
|
|
# Define output file
|
|
output_file="$MUXED_DIR/${episode_id}.mkv"
|
|
|
|
echo "Muxing: $video_file + $subtitle_file -> $output_file"
|
|
|
|
# Mux using mkvmerge (video+audio from video file, subtitles+attachments from subtitle file)
|
|
mkvmerge -o "$output_file" \
|
|
--no-subtitles "$video_file" \
|
|
--no-video --no-audio "$subtitle_file"
|
|
|
|
done
|
|
|
|
echo "Muxing complete."
|
|
|