Kodi Community Forum
How to 'filter' directory items ? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: How to 'filter' directory items ? (/showthread.php?tid=134198)



How to 'filter' directory items ? - Swifty - 2012-06-17

Hey all,

I'm new to python and i'm trying to write my first xbmc addon.
I've got most of the addon working, but there is one bit I'm stuck with;

I'd like to get a directory (from an NFS share) and list the largest 3 files in that directory - I can list the directory fine in XBMC, but I'm struggling to work out how to 'filter' out the stuff I don't want.
I found some sample python which gets the largest file in a directory but it's working at an OS level, so it knows nothing about the NFS:// path I give it (which XBMC seems to handle just fine, thanks to Memphiz!)

Could anyone with some python experience point me in the right direction?

Thanks


RE: How to 'filter' directory items ? - giftie - 2012-06-17

Best way would to use JSON RPC:

Code:
json_query = '{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "%s", "media": "%s", "properties": ["size"]}, "id": 1}' % ( dir_name , media_type )
json_response = xbmc.executeJSONRPC( json_query )

the dir_name = the folder you want to look in
media_type = can limit the type of file return("video", "music", "pictures", "files", "programs")





RE: How to 'filter' directory items ? - Swifty - 2012-06-17

Thanks very much, there is no way I would have come up with that Smile

I've just tried it out and it's coming back with an error;

22:35:15 T:5356 DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "nfs://192.168.1.251/Media/Videos/Misc", "media": "files", "properties": ["size"]}, "id": 1}
22:35:15 T:5356 DEBUG: JSONRPC: Calling files.getdirectory
22:35:15 T:5356 DEBUG: JSONRPC: Value does not match any of the enum values in type
22:35:15 T:5356 DEBUG: JSONRPC: Array element at index 0 does not match in type properties

I'm not sure what to make of that.. I just found the json wiki pages and it seems to have all the correct parameters for Eden.


RE: How to 'filter' directory items ? - giftie - 2012-06-17

(2012-06-17, 23:33)Swifty Wrote: Thanks very much, there is no way I would have come up with that Smile

I've just tried it out and it's coming back with an error;

22:35:15 T:5356 DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "nfs://192.168.1.251/Media/Videos/Misc", "media": "files", "properties": ["size"]}, "id": 1}
22:35:15 T:5356 DEBUG: JSONRPC: Calling files.getdirectory
22:35:15 T:5356 DEBUG: JSONRPC: Value does not match any of the enum values in type
22:35:15 T:5356 DEBUG: JSONRPC: Array element at index 0 does not match in type properties

I'm not sure what to make of that.. I just found the json wiki pages and it seems to have all the correct parameters for Eden.

looks like the size property is not available in Eden, It is in the nightlies though...


RE: How to 'filter' directory items ? - Swifty - 2012-06-18

Thanks giftie, it's working ok on the latest nightly Smile

What's the best way of parsing those results from the json query so that I only get the largest 3 filenames and urls?

I'm struggling to figure out how to select the various properties from the results and shove them into an array or something I can use later