SQL in a Plex windows plug-in

I am interested in porting the Game Launcher Revised plug-in to windows ( or eventually generalizing it for cross platform use.) However it depends on sql (specifically sqlite3) which is only available to MacOS plex installs. I found this post about adding 3rd party Python Modules but I must admit I am still a little in the dark. Before I dive deeper into any one path I am hoping someone might be able to help me with a few questions:

  1. Is there any sort of SQL functionality available to plugins through the current Plug-in framework included with Plex?
  2. If I understand correctly, Plex uses some SQL solution to store the media database. Is this consistent across platforms?

    2a. Is there a way to leverage this?
  3. Barring any sort of consistent cross platform Plex approved SQL for plug-ins, what needs to go into the plug-in’s shared folder to add something like sqlite3? Every search I do for installing the module is either a reference to apt-get or a windows executable, neither of which really help me with weaving the module into Plex.



    Thank you so much for your time and to everyone who has helped make Plex so great.


Just want to draw your attention to this...

http://forum.xbmc.org/showthread.php?tid=146711

http://forums.plexapp.com/index.php/topic/56457-integrating-libretro-into-plex/

Now that the source code for PHT is available I imagine this could be integrated and gamelauncher would seem to provide a suitable library for launching roms. (I realise this answers none of your questions, just want to get it on the radar of the Plex community!)

I think it would end up being very challenging to get this to work cross platform. OSX PMS uses OSXes supplied version of python – and version wise that means it can vary depending on which OSX version is being used and not all of them include sqlite3 by default. Also don’t forget that there is a Linux PMS. If you want to get it working for just windows (or have windows use it’s own lib) you’ll have to figure out which python version is being bundled and make sure to include appropriate libs. That also means that whenever they update windows PMS there’s a possibility of the plugin breaking. Good luck with it, but without built-in sqlite3 included I think you’re going to get frustrated trying to keep things running if you can even get it that far.

what does the plugin use sqlite for? maybe you can get away with something more basic?

It uses sqlite for storing all of the metadata it pulls down for the games and also uses lookups of the database to populate the menus when the user selects by platform, genre, release date, publisher etc. So if I understand correctly, very similar usage to how Plex is using its sql database for media metadata storage and organization. Perhaps there is a way to cache it all to local files, but that feels like hammering a nail with a shoe.

Yep I’d have to agree that trying to do all of that in flat file of some sort and making it work within the channel does feel like hammering a nail with a shoe. You could try and hack something up for yourself and get it working and go from there, but I dunno if it’s something you’d want to try and upkeep for the long haul. I’d say try getting sqlite working in your windows and if nothing else it can be your own private games channel if it’s too complicated to get it working for the masses.

it would be nice if the plex framework allowed you to have your own set of tables in the plex db.



sounds like getting sqlite is your best bet.

Since Plex already runs on Python 2.7 for the plugins, it has built in Sqlite 3 support.

But it looks Sqlite 3 is not allowed to be used. This is being accomplished by the use of RestrictedPython.

At least I get following error, if I try to access the module sqlite3 with "import sqlite3":

  File "/share/MD0_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 345, in __import__
    raise e
ImportError: No module named _sqlite3

In sandbox.py I find:

from RestrictedPython.Guards import safe_builtins...

# Set up the default builtins
    standard_builtins = dict(safe_builtins)
    standard_builtins['__import__'] = self.__import__   

But how RestrictedPython gets its information about no Sqlite 3 is allowed, I don't quite understand. That thing is really complicated to look at.

So I would also like to know, is that intentional? If so why?

How can I circumvent it for my lone installation here?

Maybe you will allow this with one of the future builds of Plex Media Server?

Plex channels have to run on Python 2.5, for osx.

Oh, well Plex itself runs with Phyton 2.7 on my QNAP, so this is not the case for all distribution platforms?

Then back to the question: How can I circumvent it for my lone installation here?

Anyone knows how to tell that RestrictedPython to allow the module sqlite3?

For different platforms it's different versions of python.  Some are bundled in versions (windows, possibly linux), OSX uses the OSes built-in python.

I _think_ that running escalated might allow you to do what you want.  In your channels .plist file try to add the following (requires a PMS restart to pick up this change as well):

PlexPluginCodePolicy
Elevated

They package their own Python on Linux as well it seems.


Using elevated code policy is a good suggestion, also I’ve noticed that code under Libraries/Shared is less restricted.

Bump.

Anyone have any success getting past this error on Windows:

ImportError: No module named _sqlite3

I have cygwin installed with sqlite3/pysqlite.

Thanks,
Lee

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.