2
I have bash script that utilizes the Mac based mdls command in a shell script to generate a metadata report for media files. When the script works the output looks like this:
1) [./test1.mov]
- Duration: 22.03
- Dimensions: 480 X 640 pixels
- Codec: ( "H.264" )
Sometimes I get null in the results for all files in the report:
1) [./test1.mov]
- Duration: (null)
- Dimensions: (null) X (null) pixels
- Codec: ( null )
Here is my script that generates the report:
cd "path_to_folder"
while IFS= read -r -d $'\0' file; do
duration=`mdls -name kMDItemDurationSeconds "$file" | cut -d "=" -f 2 `
duration=`printf "%.2f" $duration;`
pixel_height=`mdls -name kMDItemPixelHeight "$file" | cut -d "=" -f 2`
pixel_width=`mdls -name kMDItemPixelWidth "$file" | cut -d "=" -f 2`
codec=`mdls -name kMDItemCodecs "$file" | cut -d "=" -f 2`
temp="$i) [$file]\n- Duration: $duration\n- Dimensions: $pixel_width X $pixel_height pixels\n- Codec: $codec\n"
metaDataOutput=$metaDataOutput"\n"$temp
i=$((i + 1))
done < <(find . \( -iname \*.m4v -o -iname \*.mov -o -iname \*.m4r -o -iname \*.m4a \) -print0 )
echo -e "\n[Report]\n"$metaDataOutput
Any idea what I might be doing wrong here? Why the nulls?
Interesting edge case: If you make a hard link of a file, then trash one of the filenames, OSX (10.12 for me in this moment) will throw out the spotlight info for the remaining file and leave nulls. – joshfindit – 2019-10-01T19:40:07.957
So you say that sometimes, it just works for all files and then, it doesn't? Or is this only happening to specific files? – slhck – 2012-04-07T18:58:39.670