Hi guys,
Just got my first Pi for XBMC media center and wanted to see if its possible to auto copy content on a USB Key to a main HD connected to the Pi when the USB key is auto mounted.
The idea is that when I build one for family i can provide new content on the USB key and when they connect the USB it will copy the content to the main HD. Even better if i can prompt a library update after the copy in XBMC.
I had a quick search around and couldn't find anything pre written. I thought for sure i'm not the only one with tech challenged family that update media centers in the same way.
Not even sure what programming language to use. The Pi is running Xbian. Easy to change this if it makes the process achievable
Thanks,
Mike
Are you talking system updates or simple media files?
(26th Sep, 2014 02:00 PM)f1vefour Wrote: [ -> ]Are you talking system updates or simple media files?
Just media files. Just want to make it as easy as giving family a USB key to connect and it will copy the new content and update XBMC library.
One of the guys on the XBMC forum posted a possible solution I just need to test it.
http://forum.xbmc.org/showthread.php?tid=205060&pid=1800362#pid1800362
Do you happen to know how i can install Rsync on the Xbian distro? Part of the solution above require Rsync.
Thanks for the response
Mike
Sure can, it's what I was going to suggest.
sudo apt-get install rsync
(26th Sep, 2014 03:05 PM)f1vefour Wrote: [ -> ]Sure can, it's what I was going to suggest.
sudo apt-get install rsync
Excellent.
Let everyone know if i can get it working.
Thanks,
I can't seem to get the xbmc-send to work
xbmc-send --action="UpdateLibrary(video)"
Has anyone here used the xbmc-send command with xbian?
Thanks,
Mike
You can use curl also, but yes I have used it before.
Anyone know of timeouts on udev rules?
I have the rule working and the copy starts but stops at about 77-80mb. So I was thinking the udev rule runs the script and then times out.
udev rule:ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdb1", RUN+="/storage/script/usbcopy.sh"
Script:
#!/bin/sh
/storage/.xbmc/addons/network.backup.rsync/bin/rsync -a -v --ignore-existing /media/USB/NewMovies/* /media/mainhd/
/usr/bin/xbmc-send --action="UpdateLibrary(video)"
/usr/bin/xbmc-send --action="Notification(All Done, You may safely remove the drive)"
From WinSCP I can see the file start and progress and then stop at about the 77mb-80mb.
Any ideas
thanks,
Mike
Just to mention that running the script manually completes the copy. I just fails to complete when executed from the udev rule.
Since the size of the file is different each time i was thinking udev may have a time out.
Thanks,
Mike
@
mjbrown
timeout on udev rules makes perfect sense. otherwise udevtrigger could block booting of system.
to check if this is problem, make your usbcopy.sh just wrapper to launch another - real copy script as spawned process. so in usbcopy.sh called from udev rull do just
Code:
/run/my/real/copy.sh &
this way copy process will start as another process and usbcopy.sh rule will return to udev immediately.
another approach and maybe more suitable would be to re-use xbians usbmount implementation (auto usb storage mounter).
it itself is called by a udev rule, spawned, and mounts your drive. it is already designed to provide "hooks" for user to easy inject the mount and umount events. all you need is to copy your scrtipt into /etc/usbmount/mount.d . all scripts here are started after disk is mounted. you don't need any conf files changes / updates.
it even provides some internal info to the scripts, like UM_MOUNTPOINT is actual dir where the disk is mounted, and others ...
UM_DEVICE - filename of the device node
UM_MOUNTPOINT - mointpoint
UM_FILESYSTEM - filesystem type
UM_MOUNTOPTIONS - mount options that have been passed to the mount command
UM_VENDOR - vendor of the device (empty if unknown)
UM_MODEL - model name of the device (empty if unknown)
some basic doc is at /usr/share/doc/usbmount/README.gz . but again, just put the script into relevant hook folder and you are done.
I mentioned you could update the library with curl but I never gave an example.
Code:
curl -H "Content-Type: application/json" -u user:pword -d "{\"jsonrpc\":\"2.0\",\"method\":\"VideoLibrary.Scan\",\"id\":\"scan\"}" http://127.0.0.1:8686/jsonrpc