PDA

View Full Version : [SOLVED] Script to determine optical media format?


atavus
22nd January 2010, 09:40 PM
Hi everyone. I need help with some bash scripting that can identify whether a mounted optical disk is a CDDA, DVD, Blu-Disk, etc. I'm running Fedora 12 64bit. Thanks for the help.

atavus
4th February 2010, 07:23 PM
I wouldn't have thought it to be so hard to find this solution, but after weeks of research I have one, and for all those who also need this info, here it is:

#! /bin/bash
## This script looks for an Audio CD, DVD, data or blank optical disc and echos
## a positive reply, it's up to you to do something useful with it.

device="${1:-/dev/sr0}" # Change the device path to match your optical drive
udi=$(hal-find-by-property --key block.device --string $device | \
while read u ; do \
[[ "$(hal-get-property --udi $u --key block.is_volume)" == "true" ]] && \
[[ "$(hal-get-property --udi $u --key volume.is_disc)" == "true" ]] && \
[[ "$(hal-get-property --udi $u --key volume.disc.is_blank)" == "false" ]] && \
echo $u ; \
done)

if [[ "$udi" != "" ]]; then
if [[ "$(hal-get-property --udi $udi --key volume.disc.has_audio)" == "true" ]]; then
echo "Audio CD detected"
elif [[ "$(hal-get-property --udi $udi --key volume.disc.is_videodvd)" == "true" ]]; then
echo "Video DVD detected"
elif [[ "$(hal-get-property --udi $udi --key volume.disc.has_data)" == "true" ]]; then
if [[ "$(hal-get-property --udi $udi --key volume.is_mounted)" == "false" ]]; then
pmount $device
fi
echo "Data disc detected"
fi
fi