Jump to content

New Plugin - Custom Scripting | Emby ScripterX


Anthony Musgrove

Recommended Posts

Spaceboy
1 hour ago, Arly (Sprinkles) said:

New user for this plugin.

Am I able to use this to run a batch script off of a task in Emby?

yes. i'm using it to initiate comskip following the start of a recording

Link to comment
Share on other sites

  • 4 weeks later...
paddy75

Hi,
i'm new to this plugin and have a question if it is possible.
Running Emby on QNAP inside docker

When a new item is added to one of my  libraries (test for example) the folowing should happen:
1. Add all actors additionally to Tags
2. Add all studios additionally to Genres

is this possible and when yes, how? What script must be used here?

Edited by paddy75
Link to comment
Share on other sites

On 8/14/2022 at 10:38 AM, paddy75 said:

Hi,
i'm new to this plugin and have a question if it is possible.
Running Emby on QNAP inside docker

When a new item is added to one of my  libraries (test for example) the folowing should happen:
1. Add all actors additionally to Tags
2. Add all studios additionally to Genres

is this possible and when yes, how? What script must be used here?

Sure, it's possible. But it's not a "plug and play" sort of task, it's a coding task. You'll need to be comfortable with some programming language (like python, for example) or some advanced scripting language.

Basically your steps will be:

  1. Set up Scripter-X to trigger your script on the media-item-added-complete event. That event won't include all of the details you seem to need, so just have it pass in the library name and the item id to your script.
  2. In your script, you will need to look at the library name and decide if the item that was added is one you want to take that action on or not. (Like, is the library the item was added to your "test" library.) If it is, continue to step 3. If not, exit.
  3. The next step is to collect the studio(s) associated with the Emby media item. You can do that in one of at least two ways: (a) you can use the Emby API or (b) you can read it out of the .nfo file for the item that Emby creates, assuming you've configured your library to store .nfo files. Most any programming language or advanced scripting language is capable of either of those tasks, but will require some coding skill. If you use the Emby API you can get the documentation for it at the link at the bottom of your Emby server dashboard. If you go the .nfo file route, you'll probably want to use an XML parser library.
  4. Once you have the list of studios, you'll apply them as genres for the media item. (I'm not sure why you'd want to do that, but it's your project so I don't need to.) Again, you can do that either through the Emby API, or by manipulating the .nfo file and then getting Emby to rescan the directory containing the .nfo file. You can trigger Emby to do that scan via an API call, or you can wait until the next scheduled scan (which you control the schedule of) or if your library is configured to detect file system changes, it might do that automatically.
  5. Repeat steps 3 and 4, but this time with actors -> tags.
  6. Profit ;)

Hopefully that gives you a high-level outline that you can follow to do what you're asking for, or at least give you an idea of whether you are capable of doing it or not. If not, depending on how important this is to you and the resources you have available, maybe you could hire someone to write that script/program for you.

In any case, Scripter-X will only help you with step 1. (Now that I think about it, Scripter-X can also do step 2 if you set the right conditions.) It's simply a way to trigger your script/program and supply the library name and item id. It doesn't provide a way to automatically do steps 3-5. Also, to be complete in my answer, I think Scripter-X is probably the best tool to use for step 1, but it's not the only way. Another way to get that event "trigger" you need to perform the rest of the actions would be to write your own Emby plugin (using one of the .NET languages) and tie into the Emby events that way. I think a plugin also has some direct methods you can use to read and set values such as genres, tags, and the associated actors and studios, rather than going through the API, but I'm not sure. Anyway, just wanted to say there are multiple ways to get there, but none of them are a cake walk, and what you want isn't obviously useful to a larger group of Emby server admins, so you're unlikely to get it unless you do it yourself.

Good luck,

harrv

Edited by harrv
Added some clarification to some of the steps.
Link to comment
Share on other sites

  • 2 weeks later...
DesnLee

Hi,

I created a Telegram bot and a webhook to send new item add completion notifications and tested it successfully in Postman.

But when I use it in Scripture-X it doesn't work, I'm tried logging the request  with console.log and I found that the request header I receive is "Content-type : application/x-www-form-urlencoded", even though I provided a JSON template. I guess that's why my bot can't parse the request body, right?

 

image.thumb.png.94410a18b43c2f0c6706430c85abda56.png

Link to comment
Share on other sites

  • 4 weeks later...
abegreen

Hello to the best dev on the forum.

I was just wondering... Is it possible to integrate an option "run script" into context menu?

Like I select a video or multiple videos and on right click, context menu shows option to run script and expands to a list of scripts.

IT would be useful to move files, create screenshots if missing, rewrite nfo if not correct, upload hardcoded meta or subtitles, possibilities are endless.

 

Thank you.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

On 9/21/2022 at 3:25 PM, abegreen said:

Hello to the best dev on the forum.

I was just wondering... Is it possible to integrate an option "run script" into context menu?

Like I select a video or multiple videos and on right click, context menu shows option to run script and expands to a list of scripts.

IT would be useful to move files, create screenshots if missing, rewrite nfo if not correct, upload hardcoded meta or subtitles, possibilities are endless.

 

Thank you.

This would really be useful!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
ados8000

Just discovering this amazing plugin!

Has anyone been able to get the sendmessage:sessionid working for onPlaybackStart, only can get it working on onPlaybackStopped.

Thought it was a timing issue so used playback percentages to make it wait longer but it doesn't work at all.

Really hoping to get his working as on content end is too late for example, notifying a user they are watching TV episode mid-way or the second movie in a series having not watched the first.

I'm guessing based on the way Emby doesn't show the notification function until stream is playing there is no way to have it send a notification on sign in or landing page?

Current on version 4.0.0.7

Edited by ados8000
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
ginjaninja

Hi @Anthony Musgrove does your ScripterX / Package environment support calling a plugin's schedule task or even a function in another plugin? im learning plugins and looking to migrate all my external Powershell scripts into Emby plugins; but to do so i still need to be able to call them from ScripterX events. I appreciate an external script could use the api to call a scheduled task but that sort of defeats the point of trying to make an accessible "100% within emby" solution. thanks.

edit: i think that was a silly question, i think i can get a plugin to subscribe to the event directly itself. will try that first.

Edited by ginjaninja
Link to comment
Share on other sites

mickle026

You can send an url using web-get with a hook, so the above is really easy. Use the IService to execute the request (or call your function) from within your c#

Define an IService route

in your plugins class
  
  class WhateverPlugin: IService
    {
       

[Route("/MyPlugin/RunMeFunction", "GET", Summary = "")]
        public class RunThisInsteadOfPowershell // dont return anything :IReturn<object>
        {
        }
  

 

        public Get(RunThisInsteadOfPowershell)
        {
 				# Call to run the task
				RunTask();
		}

}

 

You would then web hook a web:get to the emby url

http://myurl:8096/emby/MyPlugin/RunMeFunction

 

 

 

 

 

Edited by mickle026
  • Thanks 1
Link to comment
Share on other sites

MarkusMail

Hi! Unfortunately I only speak German!
I would like to send notifications to ioBroker.
With the ioBroker adapter simple-api
What am I doing wrong ?

Thanks for the plugin!

Hallo! Leider spreche ich nur Deutsch!
Ich möchte gerne Benachrichtigungen an ioBroker senden.
Und zwar mit dem ioBroker Adapter  simple-api
Was mache ich falsch ?

get.png

sss).png

get2.png.28e62d32ad241e0af2c36b254fe13b28.png

Edited by MarkusMail
Link to comment
Share on other sites

  • 1 month later...
MarkusMail

Fixed, I prefer to use a webhook in PHP that's easier!

Hat sich erledigt, ich verwende lieber einen Webhook in PHP das ist einfacher!

Link to comment
Share on other sites

jdotero

Hi Anthony!  Fantastic job on the plugin.  I recently noticed that one of my OnPlayBackStart Actions that is supposed to trigger a bash script stopped working.  I don't know when it stopped but it was some time ago.  Perhaps an upgrade broke something and I didn't read the change logs very well.  Any how, the bash script takes some input variables (as shown in the screen capture that is attached) and then performs some logic to determine whether or not it should dim the lighting in the media room.   As stated, this no longer seems to work.  Oddly, when looking through all the logs, even with the debugging turned on, I see no reference to ScripterX trying to run the bash script.  It is almost like it doesn't see the OnPlayBackStart item.  I have tried deleting it and recreating it.  No luck.  The bash script is 755 so all users can run it,  but again, I don't even think ScripterX is trying to run it.  I even tried adding a simple "touch file" command so that a text file should be generated every time it runs.  On the command line, from the machine with the emby server, the script runs and touches the file as expected.  But through EmbyScripter X it does not.  Another reason I don't think the script is even being called. Any suggestions to what I can try next?  Hopefully you see something obvious in the attached screenshot.  Again great job on this!  Wish I had your skills. 

scripterx_screenshot.png

  • Thanks 1
Link to comment
Share on other sites

  • 5 weeks later...
dmdyxx

Error logs when using the Scripter X plug-in

The same error occurred in both the docker version and the official native installation package testing    And has also been tried in version 4.7, with the same error

@dmdyxx

2023-03-31 14:37:43.421 Error App: Error in ItemRemoved event handler
	*** Error Report ***
	Version: 4.8.0.27
	Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
	Operating system: Linux version 5.10.60-qnap (root@U16BuildServer118) (x86_64-QNAP-linux-gnu-gcc (toolchain config: [gcc-4.9.2 binutils-2.25 glibc-2.21]) 4.9.2, GNU ld
	Framework: .NET 6.0.13
	OS/Process: x64/x64
	Runtime: system/System.Private.CoreLib.dll
	Processor count: 2
	Data path: /config
	Application path: /system
	System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.
	
	File name: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
	   at EmbyScripterX.Core.ScripterXEventContext.getTemplate_substituteTokens(String template_contents, Boolean jsonSafe)
	   at EmbyScripterX.Core.ScripterXEventContext.ProcessWeb(String method)
	   at EmbyScripterX.Core.ScripterXEventContext.Process(EmbyScripterXAction withAction)
	   at EmbyScripterX.EventManagers.ScripterXLibraryManager._libraryManager_ItemRemoved(Object sender, ItemChangeEventArgs e)
	   at Emby.Server.Implementations.Library.LibraryManager.ReportItemRemoved(BaseItem item, BaseItem parent)
	Source: EmbyScripterX
	TargetSite: System.String getTemplate_substituteTokens(System.String, Boolean)

 

The following is the program configuration

 

I want to know what this error means or what the solution is. thank you

 

 

 

1H`3$}VTHT(%PJZM5)UBR%O.png

_OZ5L%NUGW}HP{$EQXJA06G.png

Link to comment
Share on other sites

  • 2 months later...
Anthony Musgrove

Thank you so much for all the wonderful feedback guys :) 

Just awaiting emby dev team in regard to plans moving forward for this plugin.  I'd love to continue developing it; and quite possibly get some more developers interested to kick it back into gear.

 

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
Amanade3

Help... So I was trying to send session id message when playback starts. I managed to do it but i wanted it to display only for music video instead of all my library. any idea how to limit it to only music video? thanks. And one more thing How am i able to display artist of music video... i tried %item.meta.artists% and doesn't work...any idea?

sShot.PNG

Edited by Amanade3
Link to comment
Share on other sites

Amanade3

I think I figured it out on my own. well except the artist name.

And a follow up question. Is it possible to display... up next music video title lets say as playback percentage reaches 95% (if you are playing more than one music video)?

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
griam01

I am looking for some assistance to send a Prowl alert when a LiveTV Recording stops and starts (so I can confirm if it actually attempted to record.  Looking to use the onLiveTVRecordingStart and onLiveTVRecordingEnded and record name of the show, date/time and file size possibly on the Ended.  I have prowl and an api key, but don't know how to put the pieces together.  Any assistance would be appreciated.  Thank you in advance for your time!!!

Link to comment
Share on other sites

rbjtech
6 minutes ago, griam01 said:

I am looking for some assistance to send a Prowl alert when a LiveTV Recording stops and starts (so I can confirm if it actually attempted to record.  Looking to use the onLiveTVRecordingStart and onLiveTVRecordingEnded and record name of the show, date/time and file size possibly on the Ended.  I have prowl and an api key, but don't know how to put the pieces together.  Any assistance would be appreciated.  Thank you in advance for your time!!!

So you'll need to have a play - but in summary, you need to setup an 'action' to do 'something' when it happens - in your case it will be onLiveTVRecordingStart.

You then tell Scripter-X which items you want (items available for that action are listed in the colours) then pass those (as %variables%) into the 'command'.

In my example - I'm passing them into a Windows batch file to do all sorts of stuff - but I've extracted what I do to Notify me as a Alarm in PushOver - listing the details in the Pushover notification - it just sends it via the Pushover API service via curl.  Prowl will likely have something like this - I'm not sure.

But the first step is to get scripter-x to do 'something' on the action - and then build it from there.

image.png.6da56db70d4addadf58ea81498654e7b.png

curl -s \ --form-string "token=(YOURTOKEN)" \ --form-string "user=(YOURUSER)" \ --form-string "sound=alien" \ --form-string "priority=1" \ --form-string "message=EMBY Login Fail USER:%3 IP:%1 EMBYID:%4 PW:%5 DEVICE:%6" \ https://api.pushover.net/1/messages.json

image.png.d8557d0c1a0c5742dcbf0ecb0a29ef25.png

Link to comment
Share on other sites

griam01
2 hours ago, rbjtech said:

So you'll need to have a play - but in summary, you need to setup an 'action' to do 'something' when it happens - in your case it will be onLiveTVRecordingStart.

You then tell Scripter-X which items you want (items available for that action are listed in the colours) then pass those (as %variables%) into the 'command'.

In my example - I'm passing them into a Windows batch file to do all sorts of stuff - but I've extracted what I do to Notify me as a Alarm in PushOver - listing the details in the Pushover notification - it just sends it via the Pushover API service via curl.  Prowl will likely have something like this - I'm not sure.

But the first step is to get scripter-x to do 'something' on the action - and then build it from there.

image.png.6da56db70d4addadf58ea81498654e7b.png

curl -s \ --form-string "token=(YOURTOKEN)" \ --form-string "user=(YOURUSER)" \ --form-string "sound=alien" \ --form-string "priority=1" \ --form-string "message=EMBY Login Fail USER:%3 IP:%1 EMBYID:%4 PW:%5 DEVICE:%6" \ https://api.pushover.net/1/messages.json

image.png.d8557d0c1a0c5742dcbf0ecb0a29ef25.png

Thank you very much for your detailed explanation, it gives me a good starting point!  I appreciate the info.

Link to comment
Share on other sites

harrv
On 6/30/2023 at 8:41 AM, Anthony Musgrove said:

Thank you so much for all the wonderful feedback guys :) 

Just awaiting emby dev team in regard to plans moving forward for this plugin.  I'd love to continue developing it; and quite possibly get some more developers interested to kick it back into gear.

 

If you give it an open source license and put it on GitHub or somewhere a lot of us would probably contribute. It's very useful!

Link to comment
Share on other sites

  • 2 months later...

Error Emby ScripterX: Error adding global server tokens: Object reference not set to an instance of an object

embyserver: 4.8.0.45

ScripterX:4.0.0.8
Background log error, every 10 seconds

 

image.png.6904eeb6bd54754616270f10767d572e.png

Link to comment
Share on other sites

  • 3 weeks later...
Anthony Musgrove

Hey guys, my apologies.  Will get this sorted and release an update very soon 

 

Kindest regards as always,

Anthony

  • Like 1
  • Haha 1
Link to comment
Share on other sites

maegibbons
9 hours ago, Anthony Musgrove said:

Hey guys, my apologies.  Will get this sorted and release an update very soon 

 

Kindest regards as always,

Anthony

Hi Anthony,

That's great news!!

Many thanks

 

Krs

Mark

Link to comment
Share on other sites

Anthony Musgrove

You guys are more than welcome!  

Just an update:  I've opened the source and I'm just reconfiguring the dev environment to continue developing ScripterX.  Will let you know as soon as its releasable!

 

image.thumb.png.ddb81d53a723be31782a28cd88072328.png

  • Like 2
  • Thanks 1
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...