I am relatively new to linux having made the switch from Windows to have a headless media centre. 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
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?
My usual approach is to constuct a line of code, run in terminal and if i get what i want then i put all the lines together in a shell script?
The code i am working on a the moment is below. I though that logically if i could get the script to output what it thinks is in the drive to a file /log that half the battle would be won and i could just substitute this for the script locations that would do the corresponding ripping task ... any ideas folks about why this is not working as i want?
I have used these pages to get information from:
- https://pathar.tl/blog/the-ultimate-automated-ripping-machine/
- https://askubuntu.com/questions/359855/how-to-detect-insertion-of-dvd-disc
here is my 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