2024-06-21, 06:37 PM
(This post was last modified: 2024-06-21, 06:38 PM by fedonr. Edited 1 time in total.)
I'm not sure how to do it automatically.
I tried this and ran it as cronjob with every reboot
....doesn't work tho
I tried this and ran it as cronjob with every reboot
Code:
#!/bin/bash
# Define directories and language code
SOURCE_DIR="/drive1t/media/movies"
TARGET_DIR="/drive1t/media/himovies"
LANGUAGE="hin"
# Check ffprobe path (modify if necessary)
FFPROBE_PATH="/usr/bin/ffprobe" # Update this if ffprobe is in a different location
# Create the target directory if it doesn't exist
mkdir -p "$TARGET_DIR"
while true; do
# Loop through video files (mp4, mkv)
find "$SOURCE_DIR" -type f \( -name "*.mp4" -o -name "*.mkv" \) | while read -r FILE; do
echo "Processing file: $FILE"
# Extract language using ffprobe (error handling added)
LANG=$("$FFPROBE_PATH" -v error -select_streams a:0 -show_entries stream=codec_type:stream_tags=language:stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$FILE" 2>&1 | grep -oP '(?<=language=)[^,]+' | head -n 1)
# Check for ffprobe errors (optional)
if [[ $? -ne 0 ]]; then
echo "Error extracting language for: $FILE (ffprobe might have failed)"
continue # Skip to the next file if ffprobe has errors
fi
echo "Detected language: $LANG"
# Check if language matches and create symlink if needed
if [ "$LANG" == "$LANGUAGE" ]; then
if [ ! -L "$TARGET_DIR/$(basename "$FILE")" ]; then
ln -s "$FILE" "$TARGET_DIR/$(basename "$FILE")"
echo "Created symlink for: $FILE"
else
echo "Symlink already exists for: $FILE"
fi
fi
done
# Sleep for 10 minutes (600 seconds)
sleep 600
done
....doesn't work tho