impd icon indicating copy to clipboard operation
impd copied to clipboard

[Solution-Bash] Automating condense over all files with custom input and output DIRs

Open 825i opened this issue 11 months ago • 4 comments

Hey,

I just want something simple like:

  1. ~/impd/newvideos
  2. ~/impd/newaudio

Where impd takes videos from folder 1 and throws the audio in folder 2, both of which I can have synced automatically.

Unfortunately at the moment it looks like I have to move the file again from immersionpod/whatever because it's in a painful location.

EDIT: Wew lad, I got carried away...

825i avatar Jan 31 '25 01:01 825i

Nevermind, bash to the rescue I guess.

This script takes all files from impd/newvideos and rips the audio into impd/newaudio It doesn't spam the terminal, but still shows which files are done and which is still in progress.

If I do say so myself, it is quite clean. Try it yourself and see.

process.sh

#!/bin/bash

# Check for existing .ogg files
if ls newaudio/*.ogg >/dev/null 2>&1; then
    echo "WARNING: Audio files already exist in newaudio folder!"
    echo "Please remove or move existing .ogg files before running this script."
    echo "Press 'q' to exit..."
    
    while read -r -n1 key; do
        if [[ $key == "q" ]]; then
            echo
            exit 0
        fi
    done
fi

# Initialize counter
count=1

# Count total files
total=$(ls -1 newvideos/* | wc -l)

echo "Starting audio extraction for $total files..."
echo "-------------------------------------------"

# Process each video file
for video in newvideos/*; do
    # Get first 10 chars of filename
    basename=$(basename "$video")
    prefix=${basename:0:10}
    
    # Create output filename
    outfile="newaudio/${prefix}${count}.ogg"
    
    # Show progress (using carriage return to stay on same line)
    printf "\rProcessing file %d of %d: %s -> %s" "$count" "$total" "$basename" "${prefix}${count}.ogg"
    
    # Run impd command with progress output
    impd condense -i "$video" -o "$outfile" 2>&1 | while read -r line; do
        printf "\r\033[K%s" "$line"
    done
    
    # Print completion message for this file
    echo -e "\rDONE $basename"
    
    # Increment counter
    ((count++))
done

echo "-------------------------------------------"
echo "All files processed successfully!"
echo "Press 'q' to exit..."

# Wait for 'q' key
while read -r -n1 key; do
    if [[ $key == "q" ]]; then
        echo
        break
    fi
done

I can test the script now and autorun the script later without the "q" prompt when new video files are detected in newvideos and the files in newaudio are synced to my phone for Antenna pod. Case closed.

825i avatar Jan 31 '25 02:01 825i

It is important to mention that this obviously just runs condense -i etc. on each file and assumes that your video's only/first audio track is a RAW Japanese track. I only download/watch RAWs with no other audio tracks. Though I think the script could be easily customized to do pretty much anything at this point.

825i avatar Jan 31 '25 02:01 825i

The problem here is that likely most people aren't going to use impd the way you specifically designed it. I get why you made it the way you did, but I just don't need all the rotate/archive/etc.

It is designed with mpd and ncmpcpp in mind. Basically, impd assumes that you're going to listen to condensed audio using ncmpcpp and makes it easy to integrate with it. But it's totally fine to use it any other way.

tatsumoto-ren avatar Jan 31 '25 07:01 tatsumoto-ren

So how do I change the output directory?

The config file supports the music_dir setting. However, as I understand it, you need something different. How about we introduce immersionpod_dir instead? Then it would be able to point to any location and won't create additional folders.

tatsumoto-ren avatar Jan 31 '25 07:01 tatsumoto-ren