If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Execute Javascript using PYV8

pimylifeuppimylifeup Posts: 14Members ✭✭

Is it possible to execute a .js in the Channel Plugin using PYV8 or alike.

I have a local .js file in the channel and I would like to use it from within the channel python code

Answers

  • czukowskiczukowski Posts: 131Members ✭✭✭

    I've had some degree of success with js2py, but it was to execute Javascript from web pages. You may use just about any Python code if you place it under Libraries/Shared subdirectory and set PlexPluginCodePolicy to Elevated in the channel's Info.plist, it will not be a subject of sandbox restrictions.

    You could also consider rewriting your JavaScript to Python or running it in Node server, could be easier and/or more convenient in the end...

  • TwoureTwoure Posts: 583Members ✭✭✭
    edited March 8

    I used to use PyExecJS before switching to js2py. Here's what was in my Libraries/Shared at the time I was using PyExecJS. I was finding users who were having issues with PyExecJS v1.4.0 so gave them a fall back method for v1.1.0.


    Edit: here is an example of how I was testing on import
    Contents/Services/URL/KissVideo/ServiceCode.pys#L14...L19

  • pimylifeuppimylifeup Posts: 14Members ✭✭
    edited March 8

    @czukowski said:
    I've had some degree of success with js2py, but it was to execute Javascript from web pages. You may use just about any Python code if you place it under Libraries/Shared subdirectory and set PlexPluginCodePolicy to Elevated in the channel's Info.plist, it will not be a subject of sandbox restrictions.

    You could also consider rewriting your JavaScript to Python or running it in Node server, could be easier and/or more convenient in the end...

    Sounds good.
    Could I use pysqlite by downloading and putting it in the Libararies/Shared folder and then import it in my init_py.

    Could you possibly maybe share a snippet of how I might achieve that.

    My issue is that "sqlite3" import is restricted on most OS where PMS runs. Windows and Mac are exceptions, last time I checked.

    I would like to either import sql.js or a python equivalent that will let me run some commands on a db.

    My expertise is only in js and not python, what would you recommend I use

    Thank you for your time

  • czukowskiczukowski Posts: 131Members ✭✭✭

    @pimylifeup if all you need is to access sqlite database, I think you should explore options how to do it in Python, because it is likely that by executing JavaScript you still would not achieve your goal. Even though you can run JavaScript code from Python, it doesn't necessarily have the functions to connect to the database.

    That said, including libraries from Libararies/Shared should not have any restrictions. Using the code is really easy, like this:

    import js2py
    

    If you have troubles using sqlite3 extension on some platforms, it could be that it's missing from Plex on those OSes. You could try to bundle it to your channel as well.

  • pimylifeuppimylifeup Posts: 14Members ✭✭

    @czukowski said:
    @pimylifeup if all you need is to access sqlite database, I think you should explore options how to do it in Python, because it is likely that by executing JavaScript you still would not achieve your goal. Even though you can run JavaScript code from Python, it doesn't necessarily have the functions to connect to the database.

    That said, including libraries from Libararies/Shared should not have any restrictions. Using the code is really easy, like this:

    import js2py
    

    If you have troubles using sqlite3 extension on some platforms, it could be that it's missing from Plex on those OSes. You could try to bundle it to your channel as well.

    @czukowski said:
    @pimylifeup if all you need is to access sqlite database, I think you should explore options how to do it in Python, because it is likely that by executing JavaScript you still would not achieve your goal. Even though you can run JavaScript code from Python, it doesn't necessarily have the functions to connect to the database.

    That said, including libraries from Libararies/Shared should not have any restrictions. Using the code is really easy, like this:

    import js2py
    

    If you have troubles using sqlite3 extension on some platforms, it could be that it's missing from Plex on those OSes. You could try to bundle it to your channel as well.

    Thank you for your time and advise, I think my best bet would be to bundle the sqlite library in my channel.

  • pimylifeuppimylifeup Posts: 14Members ✭✭

    @Twoure said:
    I used to use PyExecJS before switching to js2py. Here's what was in my Libraries/Shared at the time I was using PyExecJS. I was finding users who were having issues with PyExecJS v1.4.0 so gave them a fall back method for v1.1.0.


    Edit: here is an example of how I was testing on import
    Contents/Services/URL/KissVideo/ServiceCode.pys#L14...L19

    Thank you for sharing your coed.
    I will try my best to understand it (I am more of a js dev).

    My issue is that "sqlite3" import is restricted on most OS where PMS runs. Windows and Mac are exceptions, last time I checked.

    I would like to either import sql.js or a python equivalent that will let me run some commands on a db.

    My expertise is only in js and not python, what would you recommend I use

    Thank you for your time

Sign In or Register to comment.