Database update script automation before Kodi starts

Good afternoon
I have an script to update the trailers to use the Invidious plugin instead of Youtube.
I want to run it before Kodi starts (or after it stops).
The script runs a Kodi Database update, so it must be stopped.
I have tried it with a file “.config/autostart.sh” with something:

/usr/bin/systemctl stop kodi
/usr/bin/sqlite3 /storage/.kodi/userdata/Database/MyVideos119.db <<EOF
UPDATE movie SET c19 = REPLACE(c19,‘youtube/?action=play_video&videoid’,‘invidious/?action=video&videoId’);
EOF
/usr/bin/systemctl restart kodi

which resulted in Coreelec not starting anymore, staying on the boot screen.
How could I invoke an automatic script before kodi starts?

autostart.sh is already started BEFORE Kodi is started. So you just need to remove both systemctl lines and leave only sqlite3 line.

And I think you don’t need EOF but instead just something like

/usr/bin/sqlite3 /storage/.kodi/userdata/Database/MyVideos119.db "UPDATE movie SET c19 = REPLACE(c19,‘youtube/?action=play_video&videoid’,‘invidious/?action=video&videoId’);" ".exit"

Thanks Peter.
I have removed the systemctl calls and changed the db-update to one line.
Also I create a copy of the original database beforehands.
Seems to work so far.
Many Thanks again.

1 Like