From 4417f6af4f26620a80e1fc904d9035f89b8fcb3e Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Mon, 3 Mar 2025 10:40:24 -0500 Subject: [PATCH] first --- attach_font.sh | 32 ++++++++++++++++++++ change_jpn_sub_to_eng.sh | 58 ++++++++++++++++++++++++++++++++++++ detect_missing_fonts.sh | 18 +++++++++++ fix_font_mime.sh | 32 ++++++++++++++++++++ fix_font_mime_single_file.sh | 29 ++++++++++++++++++ 5 files changed, 169 insertions(+) create mode 100755 attach_font.sh create mode 100755 change_jpn_sub_to_eng.sh create mode 100755 detect_missing_fonts.sh create mode 100755 fix_font_mime.sh create mode 100755 fix_font_mime_single_file.sh diff --git a/attach_font.sh b/attach_font.sh new file mode 100755 index 0000000..ab1138c --- /dev/null +++ b/attach_font.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Check if correct number of arguments is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 /path/to/font.ttf" + exit 1 +fi + +FONT_FILE="$1" + +# Check if the font file exists +if [ ! -f "$FONT_FILE" ]; then + echo "Error: Font file not found!" + exit 1 +fi + +# Find and process all .mkv files +find . -type f -name "*.mkv" | while read -r mkv_file; do + echo "Processing: $mkv_file" + + mkvpropedit "$mkv_file" \ + --attachment-name "$(basename "$FONT_FILE")" \ + --attachment-mime-type application/x-truetype-font \ + --add-attachment "$FONT_FILE" + + if [ $? -eq 0 ]; then + echo "Successfully added font to: $mkv_file" + else + echo "Failed to add font to: $mkv_file" + fi +done + diff --git a/change_jpn_sub_to_eng.sh b/change_jpn_sub_to_eng.sh new file mode 100755 index 0000000..f40fdaa --- /dev/null +++ b/change_jpn_sub_to_eng.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Check if ffmpeg is installed +if ! command -v ffmpeg &> /dev/null; then + echo "Error: ffmpeg is not installed. Install ffmpeg to use this script." + exit 1 +fi + +# Check if directory argument is provided +if [ -z "$1" ]; then + echo "Usage: $0 [--dry-run]" + exit 1 +fi + +dir="$1" +dry_run=false + +# Check for --dry-run option +if [[ "$2" == "--dry-run" ]]; then + dry_run=true +fi + +# Find all .mkv files recursively +find "$dir" -type f -name "*.mkv" | while read -r file; do + echo "Processing: $file" + + # Get subtitle stream indices with language "jpn" + mapfile -t subtitle_streams < <(ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "$file" | awk -F, '$2 == "jpn" {print NR-1, $1}') + + if [[ ${#subtitle_streams[@]} -eq 0 ]]; then + echo "No Japanese subtitle tracks found in $file. Skipping..." + continue + fi + + # Temporary output file + output_file="${file%.mkv}_modified.mkv" + + # Build ffmpeg metadata arguments + ffmpeg_args=() + for stream_info in "${subtitle_streams[@]}"; do + read -r stream_index track_id <<< "$stream_info" + echo "Changing subtitle track ID $track_id (subtitle index $stream_index) to English in $file" + ffmpeg_args+=("-metadata:s:s:$stream_index" "language=eng") + done + + # Print the command if dry-run is enabled + echo "ffmpeg -i \"$file\" -map 0 -c copy \"${ffmpeg_args[@]}\" \"$output_file\"" + + if [ "$dry_run" = false ]; then + ffmpeg -i "$file" -map 0 -c copy "${ffmpeg_args[@]}" "$output_file" && mv "$output_file" "$file" + fi + + echo "Finished processing: $file" + +done + +echo "All done!" + diff --git a/detect_missing_fonts.sh b/detect_missing_fonts.sh new file mode 100755 index 0000000..f312ef2 --- /dev/null +++ b/detect_missing_fonts.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Function to check attachments in a file +check_attachments() { + local file="$1" + # Use mkvinfo to get the details of the file, specifically looking for 'attachments' + if ! mkvmerge -i "$file" | grep -q "Attachment"; then + # If there are no attachments, print the filename + echo "$file" + fi +} + +# Export the function so it can be used with find +export -f check_attachments + +# Recursively find all .mkv files and check for attachments +find . -type f -name "*.mkv" -exec bash -c 'check_attachments "$0"' {} \; + diff --git a/fix_font_mime.sh b/fix_font_mime.sh new file mode 100755 index 0000000..ced01ed --- /dev/null +++ b/fix_font_mime.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Check if mkvpropedit is installed +if ! command -v mkvpropedit &> /dev/null; then + echo "Error: mkvpropedit is not installed. Install mkvtoolnix package." + exit 1 +fi + +# Check if a directory is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +DIRECTORY="$1" + +# Check if directory exists +if [ ! -d "$DIRECTORY" ]; then + echo "Error: Directory '$DIRECTORY' not found." + exit 1 +fi + +# Find and process all .mkv files in the directory +find "$DIRECTORY" -type f -name "*.mkv" | while read -r MKV_FILE; do + echo "Processing: $MKV_FILE" + mkvpropedit "$MKV_FILE" --attachment-mime-type "application/x-font-otf" --update-attachment "mime-type:application/vnd.ms-opentype" + mkvpropedit "$MKV_FILE" --attachment-mime-type "application/x-font-otf" --update-attachment "mime-type:font/otf" + mkvpropedit "$MKV_FILE" --attachment-mime-type "application/x-font-ttf" --update-attachment "mime-type:font/ttf" +done + +echo "All applicable MKV files updated successfully." + diff --git a/fix_font_mime_single_file.sh b/fix_font_mime_single_file.sh new file mode 100755 index 0000000..cd942d0 --- /dev/null +++ b/fix_font_mime_single_file.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Check if the argument is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Assign the MKV filename to a variable +MKV_FILE="$1" + +# Run the mkvpropedit commands +mkvpropedit "$MKV_FILE" --attachment-mime-type "application/x-font-otf" --update-attachment "mime-type:application/vnd.ms-opentype" +if [ $? -gt 1 ]; then + echo "Error processing mime-type: application/vnd.ms-opentype for $MKV_FILE" +fi + +mkvpropedit "$MKV_FILE" --attachment-mime-type "application/x-font-otf" --update-attachment "mime-type:font/otf" +if [ $? -gt 1 ]; then + echo "Error processing mime-type: font/otf for $MKV_FILE" +fi + +mkvpropedit "$MKV_FILE" --attachment-mime-type "application/x-font-ttf" --update-attachment "mime-type:font/ttf" +if [ $? -gt 1 ]; then + echo "Error processing mime-type: font/ttf for $MKV_FILE" +fi + +echo "Finished processing $MKV_FILE" +