How to 'filter' directory items ?
#1
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
Reply
#2
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")


Image
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


Reply
#3
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.
Reply
#4
(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...
Image
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


Reply
#5
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
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
How to 'filter' directory items ?00