Open & Get File Size in Linux
#1
Hi,

I'm trying to write a script to search subtitle and need to open and get file size, hash.
I'm having trouble opening file over SMB network.

XBMC can play the file fine.
smb:\\hostname\folder\video.avi

The below code run in windows fine:
ftotallen, SubHash = xbmc.subHashAndFileSize(fpath) (this is to get file size and hash).
or I can get file size by ftotallen = os.stat(fpath).st_size
f = open(fpath, "rb" (file open)

fpath = \\hostname\folder\video.avi

But it doesn't work in Linux:
_ xbmc.subHashAndFileSize is not supported.
_ os.stat(fpath).st_size cannot open file over smb:\\
_ open(fpath, "rb") doesnt seem to work either.

Have anyone seen this problem before?

I did search for the last few days, but could not find anything useful.

Thank you very much in advance.
Reply
#2
Which version of XBMC are you trying to run this on?

I have a hunch it is Eden. The problem is that SMB is a virtual file system in XBMC and the Python OS module can't directly access the VFS. The Python Module xbmcvfs was introduced in Eden that provided access to VFS(copy, rename, delete, exists, etc) In Frodo this module has been extended to include File, which allows reading and writing to the VFS.
Also subHasAndFileSize has been removed from the xbmc module in Frodo

Using xbmcvfs(in Frodo, Nightlies)
Code:
fpath = 'smb:////hostname//folder//video.sub'

f = xbmcvfs.File( fpath )  # essentially the equivalent to the open command
ftotallen = f.size()     # get you the size, in bytes I believe
f.close()

You'll see that the smb:// is used as part of the file name, this is because using just the '//' is a Windows only method.

To do this in Eden, you will need to copy the file to a local folder then use the method that you have.
Code:
xbmcvfs.copy( sourcefile, destinationfile )

then do you code on the destination file.
then delete the destination file
Code:
xbmcvfs.delete( destinationfile )

Reply
#3
Thank you very much giftie.

I tried the xbmcvfs library and it worked!

My version is 12 from the git. So it's Frodo, that's why the subHasAndFileSize doesn't work.

Again, thanks for your help,
Reply

Logout Mark Read Team Forum Stats Members Help
Open & Get File Size in Linux0