Kodi Community Forum
Solved Copying a file from smb share at startup (autoexec.py) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: Solved Copying a file from smb share at startup (autoexec.py) (/showthread.php?tid=372745)



Copying a file from smb share at startup (autoexec.py) - beeswax - 2023-03-27

Does anyone know how to achieve the problem outlined in the title?  I came up with the below:

python:
import xbmcvfs
from shutil import copy
source = "smb://192.168.0.3/tv01/Movies_MultiFormat.xsp"
target = xbmcvfs.translatePath('special://home/userdata/playlists/video/')
copy(source, target)

but it seems the python environment isn't smb capable because I get this exception in the log:

[Errno 2] No such file or directory: 'smb://192.168.0.3/tv01/Movies_MultiFormat.xsp' 

Why do I want to do this?  I have a smart playlist which I regenerate a few times a day via a scheduled task.  This playlist is used to keep track of which movies are available in multiple resolutions e.g. 1080p, 4k.  This playlist can then be used, in combination with a few others, to make sure that devices show only one version of these movies - the version that they are capable of playing.  While I had only Nvidia Shield devices, I got around this by getting my scheduled script to copy the files to the Kodi device (Shield has an SMB server).  Now I have devices which don't have an smb server (e.g. Firesticks) and now I need a way to have each Kodi client pull this playlist from a central location.  autoexec.py seemed like the obvious solution but I'm stuck on getting it to speak smb.

Any pointers would be greatly appreciated!


RE: Copying a file from smb share at startup (autoexec.py) - izprtxqkft - 2023-03-27

use the copy function from xbmcvfs instead, it is smb:// friendly

https://romanvm.github.io/Kodistubs/_autosummary/xbmcvfs.html


RE: Copying a file from smb share at startup (autoexec.py) - beeswax - 2023-03-27

Thank you!  Got it working thanks to your advice.  I've re-arranged things on my server so that the share it's pulling from is more sensibly named.  Also turned out my target path was incorrect so fixed that too.  Working code:

python:
import xbmcvfs
source = "smb://username:[email protected]/KodiFiles/Playlists/video/Movies_MultiFormat.xsp"
target = xbmcvfs.translatePath('special://profile/playlists/video/Movies_MultiFormat.xsp')
xbmcvfs.copy(source, target)