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
How to 'filter' directory items ?
Swifty
Fan Posts: 482 Joined: Nov 2008 Reputation: 1 |
2012-06-17 20:56
Post: #1
|
| find quote |
giftie
Skilled Python Coder Posts: 2,037 Joined: Mar 2010 Reputation: 35 |
2012-06-17 21:56
Post: #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 )the dir_name = the folder you want to look in media_type = can limit the type of file return("video", "music", "pictures", "files", "programs") ![]() 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 |
| find quote |
Swifty
Fan Posts: 482 Joined: Nov 2008 Reputation: 1 |
2012-06-17 23:33
Post: #3
Thanks very much, there is no way I would have come up with that
![]() 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. |
| find quote |
giftie
Skilled Python Coder Posts: 2,037 Joined: Mar 2010 Reputation: 35 |
2012-06-17 23:49
Post: #4
(2012-06-17 23:33)Swifty Wrote: Thanks very much, there is no way I would have come up with that looks like the size property is not available in Eden, It is in the nightlies though... ![]() 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 |
| find quote |
Swifty
Fan Posts: 482 Joined: Nov 2008 Reputation: 1 |
2012-06-18 10:41
Post: #5
Thanks giftie, it's working ok on the latest nightly
![]() 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 |
| find quote |


![[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]](http://www.mediafire.com/conv/e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e4d2fe70f903275f93e5e4c076g.jpg)

Search
Help