You are not logged in.

#1 2011-01-19 05:50:20

dwidmann
Member
From: Gordonsville, Virginia, US
Registered: 2009-05-27
Posts: 60

How to (automatically) determine optical media type/content?

Is there a scriptable/cli way to determine optical media/content (ie: cd data, cd audio, dvd data, dvd audio, etc) that doesn't involve the now deprecated hal? Not at all interested in a graphical solution, nor one that involves hal as I already know how to do that. I'm just wondering if there's another way, because I've probed around and can't seem to find anything.

I intend to use it to make my cd auto-ripper a bit smarter.


"I refuse to be part of a society that encourages the rampant abuse of its own language." ~ BM

Offline

#2 2011-01-19 08:11:37

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: How to (automatically) determine optical media type/content?

http://www.linuxquestions.org/questions … er-712856/

Quick search not sure if it will help

MrG


Mr Green

Offline

#3 2011-01-19 10:14:50

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: How to (automatically) determine optical media type/content?

You may look into the udevadm info command or udisks --show-info
See the manual for details.

Offline

#4 2011-01-19 11:36:20

dwidmann
Member
From: Gordonsville, Virginia, US
Registered: 2009-05-27
Posts: 60

Re: How to (automatically) determine optical media type/content?

berbae wrote:

You may look into the udevadm info command or udisks --show-info
See the manual for details.

It doesn't offer much(no real way to detect if its a video dvd), and it really isn't all that pretty(not as elegant as hal), but it will work for some things, and that helps a lot smile Thank you.

#!/usr/bin/python2
#isaudiocd.py

from subprocess import check_output, CalledProcessError
import sys
if not len(sys.argv) > 1:
    print('You must supply a device argument to check - ie: /dev/sr0')
    sys.exit(2)
try:
    command = "udisks --show-info %s" % sys.argv[1]
    output = check_output(command, shell=True).decode('utf-8').strip().split('\n')
    audio_line = ''
    for line in output:
        if line.find('num audio tracks') > -1:
            audio_line = line
            break
    if audio_line == '':
        sys.exit(2)
    answer = audio_line.split(':')[1].strip()
    if answer == 1:
        sys.exit(0)
    else:
        sys.exit(1)
except CalledProcessError:
    sys.exit(2)

"I refuse to be part of a society that encourages the rampant abuse of its own language." ~ BM

Offline

#5 2011-01-20 10:39:45

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: How to (automatically) determine optical media type/content?

You can also get the media type of an optical disc.
It's in the drive: part of the output of udisks --shows-info, the line beginning with media:.

For a live CD, I get :

media:                     optical_cd_r

For a DVD  :

media:                     optical_dvd

But using only that command, I don't see a way to know the content of the DVD, data or video. Maybe the filesystem type, but I am not sure about that.

Offline

#6 2011-02-21 05:20:14

dwidmann
Member
From: Gordonsville, Virginia, US
Registered: 2009-05-27
Posts: 60

Re: How to (automatically) determine optical media type/content?

I haven't figured out the DVD one yet, as it's not the real priority of mine, but I have figured out a better way for dealing with the audio disks.

ACTION=="remove", GOTO="cdrom_end"
SUBSYSTEM!="block", GOTO="cdrom_end"
KERNEL!="sr[0-9]*|xvd*", GOTO="cdrom_end"
ENV{DEVTYPE}!="disk", GOTO="cdrom_end"

KERNEL=="sr[0-9]*", ENV{ID_CDROM}="1"
IMPORT{program}="/lib/udev/cdrom_id --export %k"
ACTION=="change", ENV{ID_CDROM_MEDIA_TRACK_COUNT_AUDIO}!="", RUN+="/bin/su - blackwaltz -c '/home/blackwaltz/bin/autorip.sh $env{DEVNAME}'"


LABEL="cdrom_end"


"I refuse to be part of a society that encourages the rampant abuse of its own language." ~ BM

Offline

Board footer

Powered by FluxBB