Connecting to smb in xbmc python
#1
okay, i need access to a samba share within a python script. i know this is a topic which has been discussed before -- without really answering the question, otherwise i wouldn't be posting again. rather, it's just demonstrated that there's a broader need for this functionality.

i've read darkie's reply here, but there's no useful description of the existing script or library that he's referring to. darkie or andrew, if either of you are reading this, do you know which script actually contains a working method?

based on other stuff i've seen in python forums (not xbmc-specific forums), i developed a script that temporarily mounts a smb drive using command-line instructions, but when i got it to xbmc i discovered that os.system(command) has been disabled (or...not ported). that makes sense, i suppose, since there isn't a real os running underneath the interpreter, but do we have access to anything like the os.system commands?

here's what i'm actually trying to do:
Quote:cmdcreatedrive = "net use r: \\\\computer\\share"
os.system(cmdcreatedrive)
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#2
hi
it would be wonderfull to connect to a smb share !
maybe if the os.system doesn't work, should the xbmc team develop a way to do it easily

c ya (all those alex ... lol)
Reply
#3
just a thought, not sure it's written like that but i think so. ever tried just opening a file with the correct structure ie:
smb://computername/share/....

i think python is using our virtual file system, if it is just go ahead and connect. don't see why it wouldn't use it.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
y'know, i tried that on my pc machine in my early testing, and it didn't work. i didn't even think of trying it out on the xbox. i'll let you know if it works.

thanks for the suggestion!
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#5
elupus, it's not working quite right. one time out of three, it will play a music file properly if i type out the full samba path of the file. the other two times it locks up the xbox with no meaningful output.

but the real problem is having to type the full filename. no matter how i try, os.listdir() won't work on a smb path of that sort. do you happen to know of any other function for getting a list of the files available at a smb path?
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#6
well, my previous post wasn't entirely accurate. after further testing, it seems that xbmc is able to accurately interpret smb path references, but the python interpreter very much isn't able to.

i can now successfully play media files all the time (unlike what i said before) by passing a samba path and filename to player.play(). however, os.listdir isn't the only function that fails to work with such paths -- i'm equally unable to open files in python. i built a text file containing a list of all the files in my share, and told python to open the file "smb://claighan/media/syndicator.nm" (the text file i'd made) and i get the error "no such file or directory."

would it be possible to add a python function that would set up a temporary drive ("r:"?) and reroute all python path requests through the xbmc virtual file system? maybe?
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#7
does it seems stupid to try to open a socket with the samba share ?
i don't know anything about socket but it looks like taht could be done in taht way..
i'm just telling that to you guys 'cause you are better than i am with python and scripting...
Reply
#8
first of, its not possible to access samba shares / files through python. it will work with xbmc.player().play('smb://') cause it's not python that does the smb handling, but xbmc that does it. play() is only there to tell xbmc to play the file from that path, xbmc will then open that path using the virtual filesystem.

openening a socket to a samba share is possible, but then you would still have to interpret the information correctly (which means you basicly have to port samba to python Smile, not realy an option if you ask me Smile

then again there are some other possibilities. one is redirecting file io from python through the xbmc file system (needs some rewrite of the current xmbc filesystemcode).

another option is to use the python <-> smb code provided by the samba team. but then again you can't do os.open but you would have to use smb.open for example. this gives us another problem cause it could be xbmc can't access the samba shares python can (because xbmc / python-smb uses a slightly different notation).

so redirecting python file io to the xbmc file io would be the best option, but involves some / lot's of work. that is why it isn't supported atm. atm cause i'm still planning to integrate it this way. but as always ( and i think i'm not the only one with this problem) there are so many things todo for xbmc and there is alway's not enough time.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#9
certainly understood, and thank you for the detailed reponse, darkie. after hearing all the points, i entirely agree with your take on the issue. and, as i said, i understand that it'll take a while.

keep us posted, though. this would be a major improvement, given the ways xbmc is generally used.
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#10
thanks a lot darkie !
Reply

Logout Mark Read Team Forum Stats Members Help
Connecting to smb in xbmc python0