Autoplay CD with shell script not working

I tweaked this nifty nugget from sideshowbob for the Nanosound CD plugin, but can’t get the autoplay. I think it’s because of a longer delay for Volumio CD items to become available. Running the playcd.sh script works and plays the CD. Could anybody help me with this? ta

/home/volumio/playcd.sh

#!/bin/bash
sleep 5m
curl localhost:3000/api/v1/v1/browse?uri=audiocd | jq  '.navigation.lists[0].items' > myjson.txt
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=clearQueue
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/addToQueue --data "$(cat myjson.txt)"
# curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=volume&volume=50
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=play

/etc/udev/rules.d/99-local.rules

KERNEL=="sr[0-9]", ACTION=="change", ENV{ID_CDROM_MEDIA}=="1", ENV{ID_CDROM_MEDIA_STATE}!="blank", RUN+="/home/volumio/playcd.sh &"

Got this to work finally!

Just create a helper script file
/home/volumio/udev-playcd.sh (don’t forget to chmod +x it!)

#!/bin/bash
echo /home/volumio/playcd.sh | at now

/etc/udev/rules.d/99-local.rules

KERNEL=="sr[0-9]", ACTION=="change", ENV{ID_CDROM_MEDIA}=="1", ENV{ID_CDROM_MEDIA_STATE}!="blank", RUN+="/home/volumio/udev-playcd.sh &"

Then your /home/volumio/playcd.sh is…

#!/bin/bash
curl localhost:3000/api/v1/v1/browse?uri=audiocd | jq  '.navigation.lists[0].items' > myjson.txt
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/addToQueue --data "$(cat myjson.txt)"
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=volume&volume=50
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/commands/?cmd=play&N=1
eject -x 4 /dev/cdrom

The eject command is optional—prevents my CD drive overspinning noisily; credit nanomesher

Autoplay CD in Volumio is probably not an easy task; if it were, it would have been implemented by the developers.

The CD launching script by @sideshowbob, modified by @mettamyron, works reliably when called from the console or IR remote. However, in my device, it didn’t work as autoplay when inserting the disc.

After many attempts, I managed to solve this problem by 90%. That is, autoplay starts in most cases, but sometimes it doesn’t start (usually after system reboot). Then I use the remote.

How to do it:

Create file /home/volumio/playcd.sh
(ownership volumio, don’t forget chmod +x it)

Content of file:

#!/bin/bash
volumio clear
curl localhost:3000/api/v1/v1/browse?uri=audiocd | jq  '.navigation.lists[0].items' > /home/volumio/myjson.txt
curl -i --header "Content-Type: application/json" localhost:3000/api/v1/addToQueue --data "$(cat /home/volumio/myjson.txt)"
eject -x 4 /dev/cdrom
volumio play

It is necessary to first run the script from the console to create the file ⁠ /home/volumio/myjson.txt ⁠ with ownership volumio.

Section of the lircrc file:

begin
         prog = irexec
         button = KEY_YOUR__KEY
         config = /home/volumio/playcd.sh
         repeat = 0
      end

Create a helper script file /usr/loca/bin/udev-playcd.sh with ownership root, change ownership and permissions

sudo chown volumio:volumio /usr/local/bin/udev-playcd.sh
chmod +x /usr/local/bin/udev-playcd.sh

Contents of the file:

#!/bin/bash
/home/volumio/playcd.sh | at now 

Install package at

Create file /etc/udev/rules.d/99-local.rules

Contents of the file:

KERNEL=="sr[0-9]", ACTION=="change", ENV{ID_CDROM_MEDIA}=="1", ENV{ID_CDROM_MEDIA_STATE}!="blank", RUN+="/bin/bash -c '/usr/local/bin/udev-playcd.sh &'"

Enjoy!