Kodi Community Forum

Full Version: How to detect New Media event and how to do Safe Remove?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Kodi team and developers,

Story:
I am working on a service plugin that automatically copies the photos from SD flash to my photo media library in specific folder structure of my preference (YYYY-MM/YYYY-MM-DD/IMGXXX.jpg), skips photos that are already copied, creates preview picture of the month folder, etc.
In my family the photographer is my wife, so the target is to have a seamless way to backup her photos from SD card with as minimum movements as possible.
My ultimate goal is this workflow: my wife inserts the SD card from the camera into the card reader, service plugin detects new media and automatically kicks in the backup process displaying progress bar and once all photos are copied - a dialog is displayed asking her if she wants to Safely Remove the media, she clicks OK - a confirmation is displayed that media is disconnected (Kodi does that already). She removes the SD card and inserts her next SD card. Happy wife - happy life Smile

My initial version is doing most already, except it is polling for the target media folder from settings and kicks in when the list of files is changed and cannot safely remove media.

Questions:
1) How do I detect New Media is connected? i.e. when Kodi displays "New Media Connected" and debug log shows:
INFO: UDisks: Added /media/htpc/3930-6466

I need to detect event and get media path.
Ideally I need cross platform detection, while linux way is minimum.

2) How do I initiate Safely Remove media from plugin?

Thank you for your help!
1) you listen on the dbus like kodi does.
2) you post the udisks command on the dbus

there is no cross platform way. possibly there are some python wrappers hiding the platform details, i dunno.
I would be very intwrested in this! I hope you publish it. :-)
Thanks for the reply, ironic_monkey,

I was hoping Kodi does a notification that I could listen to or at least do JSON polling of media devices to have a cross platform detection.
Kodi already does both detection and ejection cross platform so reinventing the wheel was least preferable.

Torben, if there is an interest - I am happy to publish
it shouldn't be hard to do the announce on the announce bus. but the ejection is a command, not a listen, so that is less straight-forward (dunno if it would be welcome in the json api).
(2015-10-29, 15:02)pavel.kuzub Wrote: [ -> ]Torben, if there is an interest - I am happy to publish

Great! :-)