4

On a headless Linux server (latest fedora if this is of interest), how can I detect that the inserted optical disk is an audio disk, as opposed to a data disk or a video DVD? There is no desktop environment installed, and I would prefer not to install one.

What I can see is that mounting fails, but I guess that could also be the case for a corrupt data disk:

[root@server ~]# mount /dev/sr0 /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0: can't read superblock
[root@server ~]# echo $?
32

Any suggestions?

2 Answers 2

4

A way to achieve this is to use the cdparanoia command line tool. In Ubuntu Linux you can install it through

sudo apt install cdparanoia

then run

cdparanoia -Q

Where "-Q" stands for "query". If there's no audio disc in the drive, you'll get

cdparanoia III release 10.2 (September 11, 2008)
004: Unable to read table of contents header
Unable to open disc.  Is there an audio CD in the drive?

Otherwise it'd look like...

Table of contents (audio tracks only): track        length             begin        copy pre ch
===========================================================
  1.     8315 [01:50.65]        0 [00:00.00]    no   no  2
  2.    12830 [02:51.05]     8315 [01:50.65]    no   no  2
  3.    15642 [03:28.42]    21145 [04:41.70]    no   no  2
  4.    16238 [03:36.38]    36787 [08:10.37]    no   no  2
1
  • If you want to use it in a script, redirect stdout and stderr to /dev/null, and use the return value - 0 (success) if there's a disk, or non-zero (failure) otherwise. Apr 28, 2016 at 16:06
3

How can I detect if an inserted optical disk is an audio disk?

#!/bin/bash
checkforaudio=`gvfs-info -f cdda://sr0/ | grep "filesystem::type: cdda"`
if [ "$checkforaudio" == "  filesystem::type: cdda" ]; then
    vlc cdda:///dev/sr0
    else
        checkfordvd=`find /media/*/ -name "VIDEO_TS" | grep "VIDEO_TS"`
        if [ ${checkfordvd:(-8)} == "VIDEO_TS" ]; then
            vlc dvd:///dev/sr0
            else
            pcmanfm
        fi
fi
exit 0

Source http://ubuntuforums.org/showthread.php?t=1911452

1
  • I actually knew the source, but was under the false impression that gvfs-info requires gnome, as it its part of the gnome project. It turns out that gvfs-client (the package containing gvfs-info in fedora) installs without the rest of gnome, so yours is certainly a great answer. However, sind I will need cdparanoia anyway in my project (plus it is much smaller), I will accept the other answer.
    – Isaac
    Apr 28, 2016 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .