Database access from Python script - Printable Version
+- XBMC Community Forum (http://forum.xbmc.org)
+-- Forum: Development (/forumdisplay.php?fid=32)
+--- Forum: Python Add-on Development (/forumdisplay.php?fid=26)
+--- Thread: Database access from Python script (/showthread.php?tid=130603)
Database access from Python script - taalas - 2012-05-03 19:47
I am currently trying to read my way into addon development for XBMC and I got a little confused with the bulk of (partly fresh, partly deprecated) info that is out there. I was hoping that someone could give me some pointers as to where to read next.
I am planning to implement an addon which reacts whenever an item was added to the XBMC library (I guess this should be a Python Script - Service plugin?).
Is it possible to access the xbmc database (read and write) from the Python script? Also, are there event-like structures to trigger the script (I found an OnUpdate somewhere in the documentation).
Also I wasn't able to find some kind of doxygen like API documentation for the Python methods, could someone please point me to a link for this?
(2012-05-03 19:47)taalas Wrote: Also I wasn't able to find some kind of doxygen like API documentation for the Python methods, could someone please point me to a link for this?
Meh, as soon as I posted this I found
So this part of the question is answered I guess
RE: Database access from Python script - Bstrdsmkr - 2012-05-03 20:07
Currently, you can still use the http api which will let you query the db, but that's technically depreciated in Eden (it still works now, but will be removed in Frodo). Team-xbmc has decided to not allow direct sql execution on the db, but rather they want to move everything to the JSONRPC. Currently, not everything is implemented in the JSONRPC, so even though it's technically depreciated, you still need to use the httpapi.
RE: Database access from Python script - taalas - 2012-05-03 20:10
Ah, ok, thanks for clearing this up.
So there is no way of accessing the DB in the current version of the JSON RPC API? The only way (currently) is to use the HTTP API to make changes or query the DB? No built-in functions do this? (I haven't found any)
RE: Database access from Python script - Bstrdsmkr - 2012-05-03 22:52
You CAN, but it's actively discouraged. I don't believe an addon that directly edits the DB would be accepted into the official repo. That being said:
rows is now a list of records of movies released after 2010. If you make any changes (like INSERT or DELETE statements), You need call db.commit() afterward or the changes will be discarded. When you're finished, call db.close() to unlock the db (only one process can access it at a time).
RE: Database access from Python script - jmarshall - 2012-05-04 00:22
You can react on database update events in currently nightlies I think (possibly also in the april snapshot?) via the Monitor class:
In the not-too-distant future you'll have additional information there as well, such as individual events for video added and so on - check the pull req's of Montellese on github.
And yes, please do NOT access the db directly - instead, let's work to get everything you want to be able to do into JSON-RPC so it can be done in a db-agnostic manner.
RE: Database access from Python script - taalas - 2012-05-04 13:42
Thank you both for taking the time to explain the situation. I do understand the reason behind not wanting direct DB access and I would be happy to try out (upcoming) functionality in the JSON-RPC API. That said, could you elaborate on what I would have to do to request additional functionality in the JSON-RPC API?
The script I would like to implement is for a feature I wanted to have in XBMC for a long time:
On library update check video item path -> if similar filename already exists ask user whether to add a new item or "correct" the existing item
I often move lot's of files between share (from a NAS to an unRAID server) and I would love to have path autocorrection (to me this seemed like a feature that would benefit a lot of people, but after having asked in different threads I seem to be one of the few that have this "problem" )