add some anime subtitle scripts

main
Gabe Farrell 9 months ago
parent d291b2d718
commit c5aadb59fd

@ -0,0 +1,78 @@
#!/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 files
mapfile -t subtitle_files < <(find "$SUBTITLE_DIR" -type f -name "*${episode_id}*.ass")
if [[ ${#subtitle_files[@]} -eq 0 ]]; then
echo "Warning: No subtitle files found for $video_file"
continue
fi
# Define output file
output_file="$MUXED_DIR/${episode_id}.mkv"
echo "Muxing: $video_file + subtitles (${subtitle_files[*]}) -> $output_file"
# Mux using mkvmerge (video+audio from video file, all matching .ass subtitle files, remove existing subtitles)
mkvmerge -o "$output_file" \
--no-subtitles "$video_file" \
"${subtitle_files[@]}"
done
echo "Muxing complete."

@ -0,0 +1,78 @@
#!/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."

@ -0,0 +1,32 @@
#!/bin/bash
# Ensure mkvpropedit and mkvmerge are installed
if ! command -v mkvpropedit &> /dev/null || ! command -v mkvmerge &> /dev/null; then
echo "Error: mkvpropedit and mkvmerge are required. Please install mkvtoolnix."
exit 1
fi
# Check if input file is provided
if [[ -z "$1" ]]; then
echo "Usage: $0 <input.mkv>"
exit 1
fi
INPUT_FILE="$1"
echo "Processing: $INPUT_FILE"
# Get all subtitle track IDs
subtitle_tracks=($(mkvmerge -i "$INPUT_FILE" | awk -F ': ' '/subtitles/ {print $1}' | awk '{print $3}'))
if [[ ${#subtitle_tracks[@]} -gt 0 ]]; then
echo "Setting track:s1 name to Dialogue"
mkvpropedit "$INPUT_FILE" --edit track:s1 --set name="Dialogue"
if [[ ${#subtitle_tracks[@]} -gt 1 ]]; then
echo "Setting track:s2 name to Signs & Songs"
mkvpropedit "$INPUT_FILE" --edit track:s2 --set name="Signs & Songs"
fi
fi
echo "Subtitle track titles updated successfully."
Loading…
Cancel
Save