Jump to content

New Plugin - Custom Scripting | Emby ScripterX


Anthony Musgrove

Recommended Posts

PenkethBoy

Anthony

 

trying out the new global variables and getting a slightly odd result

 

with Session start or end the scripterx.version is not returning the value

 

In my log i see

 

[05/05/2020 18:58:17.859] - EventType: SessionStart User: TimPercy Device: Chrome ScripterX: %scripterx.version%

 

however in the emby log

 

2020-05-05 18:58:18.060 Info Emby ScripterX: onSessionStarted: -EventType "SessionStart" -UserName "TimPercy" -DevName "Chrome" -ScripterVersion "2.2.8.0"

 

the variable does work on things like libscancomplete, scheduled task start/end etc

 

Any insight on why that would be?

 

(the times recorded are interesting as it appears the emby log happens after my script gets the info - i assume this is because you pass the info off to emby to post to the log and it has a queue that need to be worked through)

  • Like 1
Link to comment
Share on other sites

jdotero

Anthony:

 

Bravo on a job well done!  I am very excited to use your plugin.  (This is my second attempt to post, not sure what happened to my first post, but if it should show up twice, excuse the double posting.)

 

Unfortunately I seem to be having a small issue with 'permission denied' errors.

 

First my setup.  I am running Emby on a ReadyNAS which runs Debian (linux).  I am trying to create an event which executes a script to change lighting in my house when a movie starts.  The idea would be to trigger a shell script after an 'OnPlaybackStart' event.  Below is a screen capture of the configuration.  Note I am only passing one variable at the moment for testing, but will eventually pass more variable and use some logic to trigger the lighting for only specific 'ONPlaybackStart' Events.

 

5eb1d2d39c1ef_552020154054.png

 

 

In the Emby server log I see the following error:

 

2020-05-05 13:14:32.577 Error Emby ScripterX: Error executing script '/data/data/scanhouston/scripts/shell/emby/turn_on_movie_mode_emby 5818314e687942c880e7d6ac255562dd': /bin/bash: /data/data/scanhouston/scripts/shell/emby/turn_on_movie_mode_emby: Permission denied

 

I am confident the script exists in that location and I have opened the permissions to 777 (for now) so that everyone can read and execute the script.  Unfortunately the error remains. In the image below, I show the script, where it sits and its permissions.  Am I okay in assuming the plugin uses absolute paths and not some sort or relative path?

 

5eb1d46af0404_552020160111.png

 

Can you suggest anything else I can try?  The error log is not very descriptive and I suspect there is something more going on than a simple permissions error.

 

Thanks for your help!  And great work so far.  :)

 

 

 

  • Like 1
Link to comment
Share on other sites

PenkethBoy

a guess - does the emby user have access to the script with the correct permissions

  • Like 1
Link to comment
Share on other sites

jdotero

[update #1]:  I think the 777 permissions rwxrwxrwx would cover this.  Although there appears to be a sticky bit set too.  I tried to sudo to user 'emby' but it has a nologin setting.  Perhaps I can allow that user to log in for a bit, try to run the script and emby and see what happens.

 

 

[update #2]: I think this may be a permissions error.  Need to play with group settings, etc.  Will keep you updated.

 

 

[update #3]:  I am embarrassed to admit this was indeed a permissions error.  I could never get it to work with rwxrwxrwx but finally set it to 750 (rwxrw----) and added emby to the group which had permissions for the shell script.  That seemed to fix the problem.

 

One question -- is the device id a unique, static number for each device that plays the content?  Can I expect a FireTV stick to always have the same device id provided I don't delete the device, or sign out?

Edited by jdotero
  • Like 1
Link to comment
Share on other sites

Anthony Musgrove

Thank you so much for the input mate.

 

Have you tried renaming your script to have a .sh extension, and chmod +x yourscriptfile.sh .. I'm very curious this one too :)

Edited by Anthony.Musgrove
Link to comment
Share on other sites

Anthony Musgrove

Anthony

 

trying out the new global variables and getting a slightly odd result

 

with Session start or end the scripterx.version is not returning the value

 

In my log i see

 

[05/05/2020 18:58:17.859] - EventType: SessionStart User: TimPercy Device: Chrome ScripterX: %scripterx.version%

 

however in the emby log

 

2020-05-05 18:58:18.060 Info Emby ScripterX: onSessionStarted: -EventType "SessionStart" -UserName "TimPercy" -DevName "Chrome" -ScripterVersion "2.2.8.0"

 

the variable does work on things like libscancomplete, scheduled task start/end etc

 

Any insight on why that would be?

 

(the times recorded are interesting as it appears the emby log happens after my script gets the info - i assume this is because you pass the info off to emby to post to the log and it has a queue that need to be worked through)

That's a very interesting one mate ill have a look into it, but definitely if it shows in the emby log it should definitely be being passed to the command line :)

  • Like 1
Link to comment
Share on other sites

ginjaninja

something to be aware of.

I was finding my queue processing script was falling over during testing.

this was due to  the object in the queue had since been removed and readded to library on a different ID. (The item in the queue was no longer valid)

 

no problem i thought ....i would just introduce a check that name of id in queue matched name of id in database.

unfortunately %item.name% gets changed, on initial ingestion it is based on file/folder name,

but after a while (by the time i start to process the queue) the databases value for item.name has changed.

 

eg item.name output as  "[2002] Abba greatest hits"  by scripterX ,  later becomes "Abba Greatest hits" when the database is rechecked.

 

now i am sure i can find another way to check that a queue item is still valid (just check path in queue matches path in database would hack it.), but i thought it was worth noting that comparing item.name is still the same is not a valid approach.

Link to comment
Share on other sites

PenkethBoy

Yes this is emby - it names things by the foldername first then looks for the metadata online then renames after it "matches" and as you have found it can delete the first item and recreate it

 

i think the delete and recreate happens when the folder name does not match the metadata - not 100% sure on this as its on my list to check

Link to comment
Share on other sites

ginjaninja

Yes this is emby - it names things by the foldername first then looks for the metadata online then renames after it "matches" and as you have found it can delete the first item and recreate it

 

i think the delete and recreate happens when the folder name does not match the metadata - not 100% sure on this as its on my list to check

 

interested in your findings on this.

another reason for some value in scripterX firing its mediaitemadded events after the mediaitem has been fetched/fully ingested.

Link to comment
Share on other sites

PenkethBoy

i can get it to added then remove with [2002] Abba greatest hits for me it gets changed to Greatest Hits - this is an emby thing and not a scripterx issue

 

its intermittent as removing the album - waiting for emby to clean up and adding it back does not create a remove event - i suspect its because emby remembers some stuff via provider id's and maybe this stops it deleting and readding on the second try

 

i do see it updating the name of the Album without deleting it when added for the second time

 

So you would also need to monitor onitemremoved to make your script more tolerant of this via the ID of the item to match the events - and probably itemupdated as well to catch the "real" name rather than the "folder name"

 

[edit]

 

i have also seen the add/remove for episodes as well when recording livetv - when emby updates the name etc when epg data is not accurate etc

 

So it happens a lot :)

Edited by PenkethBoy
Link to comment
Share on other sites

Anthony Musgrove

Version 2.2.9 is now up on the catalog, and addresses a few issues on Github, one being Enable/Disable.  You'll notice now that each event has a checkbox next to it - this is to enable or disable the event; when the event is disabled, no actions in that event will trigger :)

 

I also repaired the issue where global tokens weren't working for some events.

 

5eb2c8060abc8_Actions_299.png

  • Like 1
Link to comment
Share on other sites

Anthony Musgrove

cool - Thanks Anthony

 

You're welcome mate :) I'm slowly getting through the GitHub Issues list :) :) :) 

Link to comment
Share on other sites

spaceman07

Hello

 

Any chance you can help troubleshoot this running ubuntu 18.0.4 and Emby runnnig in docker?

2020-05-07 16:02:05.347 Error SessionManager: Error in event handler
        *** Error Report ***
        Version: 4.4.2.0
        Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
        Operating system: Unix 4.15.0.91
        64-Bit OS: True
        64-Bit Process: True
        User Interactive: True
        Runtime: file:///system/System.Private.CoreLib.dll
        System.Environment.Version: 3.1.2
        Processor count: 10
        Program data path: /config
        Application directory: /system
        System.ComponentModel.Win32Exception: System.ComponentModel.Win32Exception (2): No such file or directory
           at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
           at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
           at EmbyScripterX.Plugin.execute_action(EmbyScripterXAction nAction, String parameters)
           at EmbyScripterX.EventManagers.ScripterXSessionManager._sessionManager_PlaybackStart(Object sender, PlaybackProgressEventArgs e)
           at MediaBrowser.Common.Events.EventHelper.<>c__DisplayClass1_0`1.<QueueEventIfNotNull>b__0()
        Source: System.Diagnostics.Process
        TargetSite: Boolean ForkAndExecProcess(System.String, System.String[], System.String[], System.String, Boolean, Boolean, Boolean, Boolean, UInt32, UInt32, UInt32[], Int32 ByRef, Int32 ByRef, Int32 ByRef, Boolean, Boolean)

I am using following options:
 

    <EmbyScripterXAction>
      <ActionID>23505b37-4905-4599-bc18-3e0cc4e74e76</ActionID>
      <Enabled>false</Enabled>
      <ActionType>onPlaybackStart</ActionType>
      <Interpreter>/bin/bash</Interpreter>
      <Script>/home/seed/scripts/playback.sh</Script>
      <Parameters>START %username%</Parameters>
    </EmbyScripterXAction>

I have taken the playback.sh from your example file in the github.

Edited by spaceman07
Link to comment
Share on other sites

Anthony Musgrove

Hello

 

Any chance you can help troubleshoot this running ubuntu 18.0.4 and Emby runnnig in docker?

2020-05-07 16:02:05.347 Error SessionManager: Error in event handler
        *** Error Report ***
        Version: 4.4.2.0
        Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
        Operating system: Unix 4.15.0.91
        64-Bit OS: True
        64-Bit Process: True
        User Interactive: True
        Runtime: file:///system/System.Private.CoreLib.dll
        System.Environment.Version: 3.1.2
        Processor count: 10
        Program data path: /config
        Application directory: /system
        System.ComponentModel.Win32Exception: System.ComponentModel.Win32Exception (2): No such file or directory
           at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
           at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
           at EmbyScripterX.Plugin.execute_action(EmbyScripterXAction nAction, String parameters)
           at EmbyScripterX.EventManagers.ScripterXSessionManager._sessionManager_PlaybackStart(Object sender, PlaybackProgressEventArgs e)
           at MediaBrowser.Common.Events.EventHelper.<>c__DisplayClass1_0`1.<QueueEventIfNotNull>b__0()
        Source: System.Diagnostics.Process
        TargetSite: Boolean ForkAndExecProcess(System.String, System.String[], System.String[], System.String, Boolean, Boolean, Boolean, Boolean, UInt32, UInt32, UInt32[], Int32 ByRef, Int32 ByRef, Int32 ByRef, Boolean, Boolean)
I am using following options:

    <EmbyScripterXAction>
      <ActionID>23505b37-4905-4599-bc18-3e0cc4e74e76</ActionID>
      <Enabled>false</Enabled>
      <ActionType>onPlaybackStart</ActionType>
      <Interpreter>/bin/bash</Interpreter>
      <Script>/home/seed/scripts/playback.sh</Script>
      <Parameters>START %username%</Parameters>
    </EmbyScripterXAction>
I have taken the playback.sh from your example file in the github.

Hi mate, thank you for your query. The error is referring to /bin/bash being missing, perhaps try /bin/sh :)

Link to comment
Share on other sites

spaceman07

many thanks for that.. i had to also put in a directory where the docker files are mounted so for me /tmp worked.

 

is it possible to grab information if the playback video is being transcoded?

  • Like 1
Link to comment
Share on other sites

Anthony Musgrove

many thanks for that.. i had to also put in a directory where the docker files are mounted so for me /tmp worked.

 

is it possible to grab information if the playback video is being transcoded?

You're very welcome mate! I will add transcoding tokens to the event for you, im planning a new release later this evening and ill include it :)

Link to comment
Share on other sites

spaceman07

that be awesome.. i am hoping to be able to build something where if someone is in a library with 4k and video stream is transcoding then hoping to be able to stop that session.

 

https://github.com/MediaBrowser/Emby/wiki/Playback-Check-ins

 

PlayMethod (string) = 'Transcode'

 

I am hoping to be able to use this.. next will need to work out how to stop a session.. or if you know any scripts or tool that already does it then if you can point me in that direction please.

 

 

Thanks.

  • Like 1
Link to comment
Share on other sites

PenkethBoy

@@spaceman07

 

off top of my head - look at the session end points in swagger - IIRC you can get info on whats being played etc

 

and send commands to the session of user x who is transcoding.....

 

/sessions/{id}/playing/{command} 

 

command includes "stop"

  • Like 1
Link to comment
Share on other sites

Anthony Musgrove

Hey guys,  new version is up now in the catalog; addressing many github issues, case-insensitive variables, etc.  

 

Transcoding is in progress, because it will rely on onPlaybackChange (which isn't implemented yet) :)

 

I hope everyone is going great tonight!

  • Like 1
Link to comment
Share on other sites

PenkethBoy

Anthony

 

are we getting any closer to sorting the item.library.name and item.library.type etc issues  - still present in 2.3

EventType: PlayBackStart Playing: Train Item ID: 87 Item Type: Audio Library Name: %item.library.name% User: TimPercy Library Type: %item.library.type% Device: Chrome ScripterX: 2.3.0.0

dont think either have worked since 1.8.x IIRC

  • Like 1
Link to comment
Share on other sites

Anthony Musgrove

Hey mate, absolutely, please download the latest from the catalog, 2.3.1, changes:

 

- %item.library.name%, %item.library.type% issue resolved
- Added confirmation on delete for actions (theme friendly)
- Remove 'Global Tokens' section in Actions interface (they're listed now for each event)
 
5eb6a9082a4c6_Confirm_Delete.png
Edited by Anthony.Musgrove
Link to comment
Share on other sites

PenkethBoy

Hi Anthony

 

Just testing the item.library.x issue

 

Delete action works

Fine with the global tokens being removed

 

will report back later on item.library.x

Link to comment
Share on other sites

PenkethBoy

Anthony

 

I have updated the closed issue #20 re virtual episodes - as this is not resolved - as getting itemadded events for virtual (future episodes)

 

I included a snippet from my emby log as well - which did not format that well on git - so if you have an issue reading it - let me know

 

Thanks

 

Sorry - forgot this is a variable now!

Edited by PenkethBoy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...