parent
a90a40eb58
commit
3a223888ac
@ -0,0 +1 @@
|
|||||||
|
my-venv
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
for file in *.mkv; do mkvpropedit "$file" --add-track-statistics-tags; done
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if argument is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <file_or_directory>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Function to process a single file
|
||||||
|
process_file() {
|
||||||
|
local input_file="$1"
|
||||||
|
local output_file="${input_file%.*}_converted.mkv"
|
||||||
|
echo "Processing: $input_file -> $output_file"
|
||||||
|
ffmpeg -i "$input_file" -map 0 -pix_fmt yuv420p10le -c:v libx265 -preset slow -crf 18 -c:a aac -b:a 192k -c:s copy -x265-params profile=main10 "$output_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# If argument is a file, process it
|
||||||
|
if [ -f "$1" ]; then
|
||||||
|
process_file "$1"
|
||||||
|
elif [ -d "$1" ]; then
|
||||||
|
# If argument is a directory, process all .mkv files in it
|
||||||
|
for file in "$1"/*.mkv; do
|
||||||
|
[ -e "$file" ] || continue # Skip if no matching files
|
||||||
|
process_file "$file"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "Error: $1 is not a valid file or directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if mkvmerge is installed
|
||||||
|
if ! command -v mkvmerge &> /dev/null; then
|
||||||
|
echo "Error: mkvmerge not found. Please install mkvtoolnix."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Process each .mkv file in the current directory
|
||||||
|
for mkv in *.mkv; do
|
||||||
|
# Skip if no .mkv files exist
|
||||||
|
[[ -e "$mkv" ]] || continue
|
||||||
|
|
||||||
|
base_name="${mkv%.mkv}"
|
||||||
|
|
||||||
|
# Unset all subtitle tracks in the MKV file before adding new ones
|
||||||
|
echo "Executing command: mkvmerge -o temp.mkv --no-subtitles \"$mkv\""
|
||||||
|
if mkvmerge -o temp.mkv --no-subtitles "$mkv"; then
|
||||||
|
echo "Subtitle tracks unset successfully."
|
||||||
|
|
||||||
|
# Mux the new subtitle files with the language "eng"
|
||||||
|
echo "Executing command: mkvmerge -o out.mkv \"temp.mkv\" --language 0:eng \"${base_name}\"*.srt"
|
||||||
|
if mkvmerge -o out.mkv "temp.mkv" --language 0:eng "${base_name}"*.srt; then
|
||||||
|
echo "Muxing successful, replacing original file and deleting subtitles."
|
||||||
|
mv out.mkv "$mkv"
|
||||||
|
rm -f "${base_name}"*.srt
|
||||||
|
else
|
||||||
|
echo "Muxing failed, keeping original files."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up temporary file
|
||||||
|
rm -f temp.mkv
|
||||||
|
else
|
||||||
|
echo "Failed to unset subtitles, keeping original files."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if mkvmerge is installed
|
||||||
|
if ! command -v mkvmerge &> /dev/null; then
|
||||||
|
echo "Error: mkvmerge not found. Please install mkvtoolnix."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Process each .mkv file in the current directory
|
||||||
|
for mkv in *.mkv; do
|
||||||
|
# Skip if no .mkv files exist
|
||||||
|
[[ -e "$mkv" ]] || continue
|
||||||
|
|
||||||
|
base_name="${mkv%.mkv}"
|
||||||
|
|
||||||
|
# Execute the mkvmerge command with a simplified approach
|
||||||
|
echo "Executing command: mkvmerge -o out.mkv \"$mkv\" \"${base_name}\"*.srt"
|
||||||
|
if mkvmerge -o out.mkv "$mkv" "${base_name}"*.srt; then
|
||||||
|
echo "Muxing successful, replacing original file and deleting subtitles."
|
||||||
|
mv out.mkv "$mkv"
|
||||||
|
rm -f "${base_name}"*.srt
|
||||||
|
else
|
||||||
|
echo "Muxing failed, keeping original files."
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import glob
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
def parse_xml(file_path):
|
||||||
|
"""Parse XML content from a file and return an ElementTree object."""
|
||||||
|
try:
|
||||||
|
with open(file_path, "r", encoding="utf-8") as file:
|
||||||
|
return etree.parse(file)
|
||||||
|
except etree.XMLSyntaxError:
|
||||||
|
print(f"Error parsing XML in {file_path}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def update_target_file(source_tree, target_tree):
|
||||||
|
"""Update XML properties in the target file only if they exist in the source file."""
|
||||||
|
source_root = source_tree.getroot()
|
||||||
|
target_root = target_tree.getroot()
|
||||||
|
|
||||||
|
source_elements = {elem.tag: elem for elem in source_root}
|
||||||
|
|
||||||
|
for target_elem in target_root:
|
||||||
|
if target_elem.tag in source_elements:
|
||||||
|
target_elem.text = source_elements[target_elem.tag].text
|
||||||
|
|
||||||
|
def process_files(source_dir, target_dir):
|
||||||
|
"""Process all .nfo files in source_dir and update matching files in target_dir."""
|
||||||
|
source_files = glob.glob(os.path.join(source_dir, "*.nfo"))
|
||||||
|
target_files = glob.glob(os.path.join(target_dir, "*.nfo"))
|
||||||
|
|
||||||
|
for src_file in source_files:
|
||||||
|
src_filename_base = os.path.splitext(os.path.basename(src_file))[0] # Remove .nfo extension
|
||||||
|
matching_targets = [tgt for tgt in target_files if src_filename_base in os.path.splitext(os.path.basename(tgt))[0]]
|
||||||
|
|
||||||
|
if not matching_targets:
|
||||||
|
print(f"No matching target file found for: {src_filename_base}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
source_tree = parse_xml(src_file)
|
||||||
|
if source_tree is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for tgt_file in matching_targets:
|
||||||
|
target_tree = parse_xml(tgt_file)
|
||||||
|
if target_tree is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
update_target_file(source_tree, target_tree)
|
||||||
|
|
||||||
|
# Save the updated target file
|
||||||
|
with open(tgt_file, "wb") as f:
|
||||||
|
target_tree.write(f, encoding="utf-8", xml_declaration=True)
|
||||||
|
|
||||||
|
print(f"Updated: {tgt_file}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Usage: python script.py <source_directory> <target_directory>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
source_directory = sys.argv[1]
|
||||||
|
target_directory = sys.argv[2]
|
||||||
|
|
||||||
|
process_files(source_directory, target_directory)
|
||||||
|
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if mkvpropedit is installed
|
||||||
|
if ! command -v mkvpropedit &> /dev/null; then
|
||||||
|
echo "Error: mkvpropedit not found. Please install mkvtoolnix."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure correct number of arguments
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "Usage: $0 <mkv-file> <track-number>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkv_file="$1"
|
||||||
|
default_track="$2"
|
||||||
|
|
||||||
|
# Ensure the file exists
|
||||||
|
if [[ ! -f "$mkv_file" ]]; then
|
||||||
|
echo "Error: File '$mkv_file' not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get subtitle track IDs
|
||||||
|
subtitle_tracks=$(mkvmerge -i "$mkv_file" | grep 'subtitles' | awk -F ': ' '{print $1}' | awk '{print $3}')
|
||||||
|
|
||||||
|
if [[ -z "$subtitle_tracks" ]]; then
|
||||||
|
echo "No subtitle tracks found in '$mkv_file'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove default and forced flags from all subtitle tracks
|
||||||
|
for track_id in $subtitle_tracks; do
|
||||||
|
echo "Running: mkvpropedit \"$mkv_file\" --edit track:$track_id --set flag-default=0 --set flag-forced=0"
|
||||||
|
mkvpropedit "$mkv_file" --edit track:$track_id --set flag-default=0 --set flag-forced=0
|
||||||
|
done
|
||||||
|
|
||||||
|
# Set the specified track as default
|
||||||
|
echo "Running: mkvpropedit \"$mkv_file\" --edit track:$default_track --set flag-default=1"
|
||||||
|
mkvpropedit "$mkv_file" --edit track:$default_track --set flag-default=1
|
||||||
|
|
||||||
|
echo "Subtitle track $default_track set as default in '$mkv_file'."
|
||||||
|
|
||||||
Loading…
Reference in new issue