LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 04-30-2015, 11:26 AM   #1
jlivin25
LQ Newbie
 
Registered: Feb 2012
Posts: 9

Rep: Reputation: Disabled
Smile Determine optical media type (Audio CD, DVD, blu-ray) by using UDEV and scripts


Hello Lovely Ubuntu Folk


I am relatively new to linux having made the switch from Windows to have a headless media centre. So i am running KODIBuntu.


I am trying to achieve an automated ripping system to backup my hard copy media collection. I have loved the concept with linux that 'if you can dream it you can make it happen'.


What i'm aiming to achieve is that a disc is put into the drive and a script rips the content to my drive.


e.g disc inserted -> media type determined -> correct ripping script run


I have used lots of useful web pages through google searches to create scripts that will do the ripping work itself. I have done a bunch of reading and was pointed towards using 'HAL'....I then found that his function had been deprecated and replaced by udev. I did a bunch more reading and found out how to use UDEV and created the folowing rule which i have proved works by linking directly to a ripping script


https://pathar.tl/blog/the-ultimate-...pping-machine/
http://confoundedtech.blogspot.co.uk...and-on-cd.html
http://askubuntu.com/questions/35985...on-of-dvd-disc


https://github.com/littlejeem/CDRip/...iscTypeTest.sh


Code:
Code:
#!/bin/bash
#
set -eu
#
# code below is derived from work by JimVanns, thanks
# https://github.com/jvanns/htpc/blob/master/dsc-trg-q
#
#
###########################################################################
###                        DEFINE VARIABLES HERE                        ###
### $HOME DOES NOT NEED DEFINING AS IT SEEMS TO BE BUILT INTO BASH FROM ###
###   WHAT POSTS I HAVE READ RELATING TO USING WHAT I THINK ARE UDEV    ###
###  ENVIRONMENTAL VARIABLES E.G. $ID_CDROM_MEDIA_CD DO NOT APPEAR TO   ###
###    NEED DEFINING THEMSELVES, ALSO PART OF BASH OR LINUX COMMAND     ###
###                      STRUCTURE CALLED BY BASH?                      ###
###########################################################################
#
MEDIA=
#
##############################################################################
### LEFT IN SO AS TO ALTER AS LITTLE AS POSSIBLE, I HAVE READ THAT DELAYS  ###
###  OFTEN IRON OUT KINKS IN CODE,  PLUS ALSO FOUND IT USEFULL TO ALLOW A  ###
###    SMALL DELAY FOR CD-DRIVE TO DO ITS THING AFTER PUTTING DISK IN      ###
##############################################################################
#
sleep 2
#
mkdir -p $HOME/myscripts/scriptlogs


if [ "$ID_CDROM_MEDIA_BD" = "1" ]
then
        MEDIA=bluray
        (
        echo "$MEDIA" >> $HOME/myscripts/scriptlogs/DiscTypeTest.log
        ) &
if [ "$ID_CDROM_MEDIA_DVD" = "1" ]
then
        MEDIA=dvd
        (
        echo "$MEDIA" >> $HOME/myscripts/scriptlogs/DiscTypeTest.log
        ) &
elif [ "$ID_CDROM_MEDIA_CD" = "1" ]
then
        MEDIA=cdrom
        (
        echo "$MEDIA" >> $HOME/myscripts/scriptlogs/DiscTypeTest.log
        ) &
fi
Thanks in advance

James

Last edited by jlivin25; 04-30-2015 at 11:29 AM. Reason: post not showing all of information posted
 
Old 04-30-2015, 11:31 AM   #2
jlivin25
LQ Newbie
 
Registered: Feb 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
Im sorry don't know why but part of my explanation has been cut from the description:

https://github.com/littlejeem/CDRip/...scInsert.rules


Code:
"
ACTION=="change", SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{vendor}=="TSSTcorp", MODE="0660", GROUP="optical", RUN+="/home/jlivin25/myscripts/DiscTypeTest.sh"
"
I realised that I needed an intermediate script that would do the 'work' to determine what the optical media type is. Further reading led me to believe that I would need to use some kind of 'IF' statement.


IF disc inserted
then
IF audio cd run rip script 1
IF DVD run rip script 2
IF blu-ray run rip script 3
ELSE no cd inserted


I have done some more googling and found some code in various places that uses environmental variables to work. However from further information on google it appears that these variables are not defined until referenced by UDEV?
 
Old 05-15-2015, 04:48 PM   #3
jlivin25
LQ Newbie
 
Registered: Feb 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
solved

Well well well!!

Thanks to advice from blm-ubunet and Keith_Helm on ubuntu forums and ixer on stack exchange I have changed the construction of the 'if' statements to match bits of advice and headless rip is now working thank you.

Udev rule as follows:
Code:
Code:
# ID_CDROM_MEDIA_BD = Bluray
# ID_CDROM_MEDIA_DVD = DVD
# ID_CDROM_MEDIA_CD = CD
ACTION=="change", SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{vendor}=="TSSTcorp", ENV{ID_CDROM}=="?*", MODE="0660", GROUP="optical", RUN+="/usr/local/bin/DiscTypeTest3.sh"
links to script as follows

Code:
Code:
#!/bin/bash
# ID_CDROM_MEDIA_BD = Bluray
# ID_CDROM_MEDIA_DVD = DVD
# ID_CDROM_MEDIA_CD = CD
MEDIA=
if [ $ID_CDROM_MEDIA_DVD = "1" ]
then
        MEDIA=dvd
        (
        echo "$MEDIA" >> "/var/log/DiscTypeTest.log"
        ) &


elif [ $ID_CDROM_MEDIA_CD = "1" ]
then
        MEDIA=cdrom
        (
        echo "$MEDIA" >> "/var/log/DiscTypeTest.log"
        ) &
fi
(set -o posix ; set) > "/var/log/DiscTypeTestVariables.log"
produces the following output in
Code:
/var/log/DiscTypeTest.log
when an audio CD and then a DVD is inserted

Code:
cdrom
cdrom
dvd
dvd
I figure next step for me is to add in the paths to the ripping scripts where the echo commands currently sit. Buy a blu-ray drive and reinsert the blu-ray loop and we are there!

Hope this helps someone

James
 
  


Reply

Tags
ripping, script, udev, variables



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
blu ray player not playing copied dvd's zato no ichi Linux - Newbie 3 12-18-2013 02:02 PM
[SOLVED] Transfering DVD and Blu Ray discs to my Slackware machine lpallard Slackware 101 02-21-2011 10:10 PM
How to enjoy video/audio on ipod, iphone, Gphone? ( Blu-Ray) winterwang Linux - Software 1 08-11-2009 06:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration