How do you get a list of files in a folder
#1
I've search google and this forum for the answer, but found nothing. I apologize in advance if this question has already been answered.

I'm learning python, and am trying to create some add-ons for xbmc. In my settings, there is an option to set the HDHomeRun UPnP folder, which is working correctly. I can successfully get the upnp://[address] from the settings and it returns the correct value.

The question I have is:
how do you retrieve the list of files/streams w/in this folder?

Calling the following method, shown below, brings up the list of streams I want in a dialog, so I'm sure there has to be a way to retrieve this data in python.
xbmcgui.Dialog().browse(1, '', 'video', '.strm')

Thanks in advance,
Gunjan
Reply
#2
give this a shot:
Code:
dirs, files = xbmcvfs.listdir(path)


see: http://mirrors.xbmc.org/docs/python-docs...l#-listdir
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
I tried that already. I wasn't calling it right, so I was hoping that was the reason why it wasn't working. I was only doing the files = xbmcvfs.listdir(path) not "folders, files = ..."

I'll post the code and log for my hello world add-on.

Code:
# Get the HD Homerun UPnP address
url = utils.getSetting('hdhomerun_folder')
utils.log("URL: " + url)

# Parse the files in the hdhomerun folder
folders, files = xbmcvfs.listdir(url)
if files is not None:
utils.log("Parsing the files. Total found: ", len(files))
for file in files:
utils.log(file)

# Ensure it ends w/ 'Cable TV'
if(not url.endswith("Cable TV/")):
url += "Cable TV/"
utils.log("URL Updated: " + url)

# Parse the files in the hdhomerun folder
folders, files = xbmcvfs.listdir(url)
if files is not None:
utils.log("Parsing the files. Total found: ", len(files))
for file in files:
utils.log(file)

Log:
20:25:46 T:860 NOTICE: service.tvguide.hdhomerun: Hello World!!!
20:25:46 T:860 NOTICE: service.tvguide.hdhomerun: URL: upnp://938319DE-1113-38E4-8D72-B0AFFAED2C92/
20:25:51 T:860 ERROR: XFILE::CDirectory::GetDirectory - Error getting upnp://938319DE-1113-38E4-8D72-B0AFFAED2C92/
20:25:51 T:860 NOTICE: service.tvguide.hdhomerun: URL Updated: upnp://938319DE-1113-38E4-8D72-B0AFFAED2C92/Cable TV/
20:25:51 T:860 ERROR: XFILE::CDirectory::GetDirectory - Error getting upnp://938319DE-1113-38E4-8D72-B0AFFAED2C92/Cable TV/
Reply
#4
I read somewhere that xbmcvfs only works with local, SMB, NFS and AFP paths.

Also, it's safer to use
Code:
os.path.join(url, "Cable TV")
instead of
Code:
url += "Cable TV/"
Reply
#5
(2013-03-16, 14:33)Anthirian Wrote: I read somewhere that xbmcvfs only works with local, SMB, NFS and AFP paths.

Also, it's safer to use
Code:
os.path.join(url, "Cable TV")
instead of
Code:
url += "Cable TV/"

Thanks, and that's good to know. I'm still trying learning python. Any tips are helpful.

Does anyone know where the xbmcgui.py scripts are generated in the c code? My background is in c and c++, but just need a starting point.
Reply
#6
Submitted a push request to allow the xbmcvfs.listdir([url]) method to return upnp://[address] files. I hope it gets pushed through.
Reply
#7
It would also be nice to have that functionality in other parts of the module. Maybe if it is merged you could also add that? At the moment I don't need it, but there will eventually be people that want to, especially since Gotham focuses largely on UPnP playback.
Reply
#8
I removed the push request. This has been fixed in a prior code update which is available in the nightly build as of now, but not in the current Frodo release.

I posted my extension for the tv guide addon in this thread.
Reply

Logout Mark Read Team Forum Stats Members Help
How do you get a list of files in a folder1