I have a music directory on a debian computer, which from time to time gets too big files in it. To help me with eventual deleting of these files, I've installed mediainfo and made a script, that should go through all the files with in music directory using that command.
I'm trying to utilize the duration parameter to define what needs to deleted or not. The example input is:
mediainfo --Inform="General;%Duration%" /home/administrator/music/Example\ Full\ OST.mp4
7838987
Output returns duration as milliseconds. Please note, that if files have any spaces in them, mediainfo marks a backslash in front of them. I've taken this into account in my script:
#!/bin/bash
for i in /home/administrator/music/*
do
# Changing i to readable form for mediainfo
i=$(echo $i | sed -r 's/[ ^]+/\\&/g')
echo $i
# Go Through files, storing the output to mediadur variable
mediadur=$(mediainfo --Inform="General;%Duration%" $i);
echo $mediadur;
done
echo outputs are:
/home/administrator/music/Example\ Full\ OST.mp4
The mediadur echo output doesn't show anything. But when I copy the first echo output to the first example, it shows same output.
However, if the directory has any media that doesn't have space in its filename, the script works fine. The output of the script:
/home/administrator/music/546721638279.mp3
83017
This problem has left me very puzzled. Any help is appreciated.