Re: Detect CD Media Type?
> have some method to detect media type? I mean CD, like CD-R, CD-RW..?
Interesting topic.
> I try to use dvd+rw-mediainfo. but it just can detect dvd media, not
> include cd. am I right?
>
> If I am wrong, can some body help me?..thanks very much
To my knowledge dvd+rw-mediainfo is unwilling to detect CD media types :
"non-DVD media mounted, exiting"
For CD types, i grep the output of cdrecord option -atip.
If you use contemporary cdrecord-ProDVD (under the command name cdrecord),
then this shell code might do the trick for DVD and CD.
cdrecord without DVD support will only detect types "CD-R" and "CD-RW".
media_type="unknown-media"
infotext=$(cdrecord dev=$scsi_adr -atip 2>&1)
if echo "$infotext" | \
grep 'book type:.*DVD+RW' >/dev/null 2>&1
then
media_type="DVD+RW"
elif echo "$infotext" | \
grep 'book type:.*DVD-RW' >/dev/null 2>&1
then
media_type="DVD-RW"
elif echo "$infotext" | \
grep 'book type:.*DVD+R' >/dev/null 2>&1
then
media_type="DVD+R"
elif echo "$infotext" | \
grep 'book type:.*DVD-R' >/dev/null 2>&1
then
media_type="DVD-R"
elif echo "$infotext" | \
grep '^ Is erasable' >/dev/null 2>&1
then
media_type="CD-RW"
elif echo "$infotext" | \
grep '^ Is not erasable' >/dev/null 2>&1
then
media_type="CD-R"
fi
echo "Detected media type : $media_type"
I myself use alternatively growisofs , cdrecord or cdrecord-ProDVD .
growisofs is accessed via a wrapper which reacts on cdrecord option -atip
and produces a sparse emulation of cdrecord's -atip output :
infotext=$(dvd+rw-mediainfo "$growisofs_target" 2>&1)
if echo "$infotext" |
grep 'Mounted Media:.*DVD+RW' >/dev/null 2>&1
then
media_type="DVD+RW"
elif echo "$infotext" |
grep 'Mounted Media:.*DVD+R' >/dev/null 2>&1
then
media_type="DVD+R"
elif echo "$infotext" |
grep 'Mounted Media:.*DVD-RW' >/dev/null 2>&1
then
media_type="DVD-RW"
if echo "$infotext" |
grep 'Mounted Media:.*Restricted Overwrite' >/dev/null 2>&1
then
media_type="$media_type (growisofs mode Restricted Overwrite)"
fi
elif echo "$infotext" |
grep 'Mounted Media:.*DVD-R' >/dev/null 2>&1
then
media_type="DVD-R"
elif echo "$infotext" |
grep 'non-DVD media mounted, exiting' >/dev/null 2>&1
then
media_type="growisofs:non-DVD"
fi
echo "book type: $media_type (-atip reply emulated by growisofs_wrapper)"
The following code interprets the output of any of the programs.
Variable cdrecord_prog points either to growisofs_wrapper or to
one of the cdrecord programs.
help_reply=$($cdrecord_prog -help 2>&1)
cdrecord_is_prodvd=0
if echo " $help_reply" | \
grep 'Usage:.*cdrecord-ProDVD.*trackn' >/dev/null 2>&1
then
cdrecord_is_prodvd=1
fi
media_type="scdbackup:unknown-media"
infotext=$($cdrecord_prog dev=$scsi_adr -atip 2>&1)
if echo "$infotext" | \
grep 'book type:.*DVD+RW' >/dev/null 2>&1
then
media_type="DVD+RW"
elif echo "$infotext" | \
grep 'book type:.*DVD-RW' >/dev/null 2>&1
then
media_type="DVD-RW"
if echo "$infotext" |
grep '(growisofs mode Restricted Overwrite)' >/dev/null 2>&1
then
# echo 'Note: DVD-RW in mode "Restricted Overwrite" needs no blanking'
if test "$blanken" = "all" -o "$blanken" = "full" \
-o "$blanken" = "sequential"
then
dummy=dummy
else
growisofs_rov_keep=1
fi
fi
elif echo "$infotext" | \
grep 'book type:.*DVD+R' >/dev/null 2>&1
then
media_type="DVD+R"
elif echo "$infotext" | \
grep 'book type:.*DVD-R' >/dev/null 2>&1
then
media_type="DVD-R"
elif echo "$infotext" | \
grep '^ Is erasable' >/dev/null 2>&1
then
media_type="CD-RW"
elif echo "$infotext" | \
grep '^ Is not erasable' >/dev/null 2>&1
then
media_type="CD-R"
elif echo "$infotext" | \
grep 'growisofs:non-DVD' >/dev/null 2>&1
then
media_type="growisofs:non-DVD"
elif test "$cdrecord_is_prodvd" = "0"
then
media_type="$media_type (not cdrecord-ProDVD ?)"
fi
echo "Detected media type : $media_type"
Well, that is far from elegant but allows me to use quite arbitrary
writer programs and at least detect those media types which are suitable
for the particular program.
I do not know any documents which explain or standardize the output formats of
cdrecord -atip , cdrecord-ProDVD -atip ot dvd+rw-mediainfo. Therefore
the next revision of either program might render this code invalid.
I count on Joerg and Andy not fiddling with these output formats
without a good reason.
Trustworthy documentation about the output of cdrecord -atip respectively
dvd+rw-mediainfo would be highly appreciated, of course. (Yes, i already
did read man cdrecord.)
Have a nice day :)
Thomas
Reply to: