Jump to content

New Plugin - Custom Scripting | Emby ScripterX


Anthony Musgrove

Recommended Posts

Anthony Musgrove

Getting closer.

ALL VARS = STARTED 6707 Peach 10 Video e6ffa36f4ab6468699dc107f84e8a2e2 The Big Bang Theory C:\Users\Hunter3DPrinting\AppData\Roaming\Emby-Server\programdata\data\livetv\recordings\The Big Bang Theory\The Big Bang Theory 2022_04_18_21_55_35.ts 19839 %recording.show.id%  %recording.episode.title% 7db878918f368de5a24c9349d19eefbd   18/04/2022 11:55:35 AM +00:00 18/04/2022 12:24:47 PM +00:00 18/04/2022 9:55:35 PM 18/04/2022 10:24:47 PM 0 0 False False True False False False False False False True False True False H3DP-LASERPC 8096 8920 8096 8920 4.7.0.35 Win32NT Microsoft Windows 10.0.19042 1d 21h 30m 18s  4.0.0.1 4 1 0 0 

produced via:

onLiveTvRecordingStart:

STARTED %recording.channel.id% %recording.channel.name% %recording.channel.number% %recording.channel.mediatype% %recording.timer.id% %recording.name% %recording.path% %recording.program.id% %recording.show.id% %recording.episode.number% %recording.episode.title% %recording.series.id% %recording.season.number% %recording.productionyear% %recording.date.start.utc% %recording.date.end.utc% %recording.date.start% %recording.date.end% %recording.prepadsecs% %recording.postpadsecs% %recording.iskids% %recording.islive% %recording.ismanual% %recording.ismovie% %recording.isnew% %recording.isnews% %recording.isprepaddingrequired% %recording.ispostpaddingrequired% %recording.ispremiere% %recording.isprogramseries% %recording.isrepeat% %recording.isseries% %recording.issports% %server.name% %server.port.local.http% %server.port.local.https% %server.port.public.http% %server.port.public.https% %server.version% %server.platform.os% %server.platform.osver% %server.platform.uptime% %scripterx.version% %scripterx.version.major% %scripterx.version.revision% %scripterx.version.minor% %scripterx.version.build%

 

Link to comment
Share on other sites

Anthony Musgrove

and recording ended working correctly, just need to massage in the new token values, I'm releasing this version onto the Catalog now for comment & testing.  It will be restricted to BETA ONLY.

ALL VARS = STARTED 6707 Peach 10 Video e2e926c9d00c4573a66c105e42dd596e The Big Bang Theory C:\Users\Hunter3DPrinting\AppData\Roaming\Emby-Server\programdata\data\livetv\recordings\The Big Bang Theory\The Big Bang Theory 2022_04_18_22_24_47.ts 19840 %recording.show.id%  %recording.episode.title% 7db878918f368de5a24c9349d19eefbd   18/04/2022 12:24:47 PM +00:00 18/04/2022 12:50:50 PM +00:00 18/04/2022 10:24:47 PM 18/04/2022 10:50:50 PM 0 0 False False True False False False False False False True False True False H3DP-LASERPC 8096 8920 8096 8920 4.7.0.35 Win32NT Microsoft Windows 10.0.19042 1d 21h 37m 33s  4.0.0.1 4 1 0 0 
ALL VARS = ENDED 6707 Peach 10 Video e2e926c9d00c4573a66c105e42dd596e The Big Bang Theory C:\Users\Hunter3DPrinting\AppData\Roaming\Emby-Server\programdata\data\livetv\recordings\The Big Bang Theory\The Big Bang Theory 2022_04_18_22_24_47.ts 19840 %recording.show.id%  %recording.episode.title% 7db878918f368de5a24c9349d19eefbd   18/04/2022 12:24:47 PM +00:00 18/04/2022 12:50:50 PM +00:00 18/04/2022 10:24:47 PM 18/04/2022 10:50:50 PM 0 0 False False True False False False False False False True False True False H3DP-LASERPC 8096 8920 8096 8920 4.7.0.35 Win32NT Microsoft Windows 10.0.19042 1d 21h 37m 48s  4.0.0.1 4 1 0 0 

A few things that aren't working (yet) are %recording.show.id%, episode title, etc.  Working through these issues.

Link to comment
Share on other sites

Anthony Musgrove

*** Added a new piece of functionality.   The interpreter dropdown now includes /bin/sh (just for cosmetic purposes), but also:  sendmessage:sessionid.

 

What does sendmessage:sessionid do?  Allows you in the driver seat to send on-screen notifications to people using your media server when certain conditions are met - and all the variables and conditions are available to do so.  My example below, onPlaybackStart, I want to tell my family member or media server user to enjoy the episode of a show they have chosen to watch.     In my example, I obviously would check to make sure its a TV show.  If its a movie, I'd have a different action that would say 'Hi there, please enjoy the movie' etc..

When using sendmessage:sessionid, the 'Run' (or 'script') box is the recipient of the notification, in this case, %session.id% which is the session.id of the session responsible for triggering this action, and 'Parameters' is simply the message I want to show on screen, with all the variables usable available for that particular action, for example %username%, %device.name%, etcetera.


This will be available in 4.0.0.2

 

image.png.526a2dffb014a609dbb688652095fbe7.png

 

image.png.6f77f6884c59045ae29d5b5b154f3a7d.png

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

Anthony Musgrove

4.0.0.2 now up on catalog, available for Emby 4.7+ Beta only, under 'Beta'

 

image.png.6bfccf4c70f22ec0d1010fd30f12d79f.png

Link to comment
Share on other sites

Anthony Musgrove

As of 4.0.0.3, and as per GitHub request #57:

image.png.0d63ad36d06770278348e725711f531b.png

So for example, using WEB:GET, the URL to 'get' is stored in the 'script' field, and now supports tokens being used, ie  https://myurl.com/?action=play&userid=%user.id%&itemid=%item.id% for example, will produce something like  https://myurl.com/?action=play&userid=anthony&itemid=6992  

This is at the request of @fkueyu on GitHub

 

Link to comment
Share on other sites

Anthony Musgrove

If you're using the current version (4.0.0.3) on beta, can you please give some feedback on how things are going so far with LiveTV?  I'd like to continue adding functionality and ensuring the functionality required is working well, but I'm not sure which direction to take until I get some feedback.

Thanks guys ❤️ ! 

Link to comment
Share on other sites

Anthony Musgrove

Also please note - the wiki is coming together again nicely; Just finished adding the Packages wiki section, and includes an example package zip file:

https://wiki.emby-scripterx.com/doku.php?id=packages

I'm going to work on the Package uploader/installer until I get a bit more feedback from the community re LiveTV

❤️ 

Link to comment
Share on other sites

Anthony Musgrove

Question; how do I get the responsible tuner for the RecordingStarted event from the Argument object provided?

I need what I used to have access to with ChannelInfo.

Thank you.

image.png.a7546cd9e3dbaad4463198fd1cea0757.png

Link to comment
Share on other sites

Anthony Musgrove
33 minutes ago, Anthony Musgrove said:

Question; how do I get the responsible tuner for the RecordingStarted event from the Argument object provided?

I need what I used to have access to with ChannelInfo.

Thank you.

image.png.a7546cd9e3dbaad4463198fd1cea0757.png

 

Primarily so I can get this information:  TunerHostId, TunerChannelId which is NOT included in LiveTVChannel!

 

image.png.6b1c1886ff92cf33fd6f080db32b734d.png

Link to comment
Share on other sites

Anthony Musgrove

Tried looking at Parent, TopParent, 

2022-04-21 02:32:14.464 Info Emby ScripterX: CHANNEL LOADED AND HAS TOP PARENT, TOP Parent = Live TV, Type=MediaBrowser.Controller.Entities.UserView
2022-04-21 02:32:14.464 Info Emby ScripterX: DEBUG, LOADED CHANNEL WITH NAME: SBS ONE
Edited by Anthony Musgrove
Link to comment
Share on other sites

Anthony Musgrove

I honestly forgot how fun this plugin has been to develop and maintain, I'm so glad I've revisited this.  I just wrote a really quick package to do telegram notifications (via a custom telegram bot that you can create).

Inspired by @darkside40's plugin, I thought I'd show just how simple it is to integrate things like Telegram and other third party services with ScripterX just by writing a simple package.

It's in no way complete - but it works.  Easy to add to/modify.. and gives the ultimate flexibility of subscribing to ANY ScripterX supported events - including a better way to execute onMediaAddedComplete (this won't spam your bot every time you add something, it will only notify once its correctly and completely added).

Remember guys, with ScripterX, the sky is TRULY the limit.

Note:  For more information about Pacakges, it's all now on the Wiki:  https://wiki.emby-scripterx.com/doku.php?id=packages

 

tg_package_javascript.png

tgnotification_package_installed.png

scripterxbot.jpg

ScripterXTelegramNotificationPackage.zip

Edited by Anthony Musgrove
added wiki url
Link to comment
Share on other sites


Hello. Thanks for the plugin. I'm trying to install the Telegram notification package but when I click the install button nothing happens. Emby 4.6.7.0 and ScripterX 3.0.5.5.

Thanks in advance.

  • Like 1
Link to comment
Share on other sites

Anthony Musgrove
1 hour ago, kirkj said:


Hello. Thanks for the plugin. I'm trying to install the Telegram notification package but when I click the install button nothing happens. Emby 4.6.7.0 and ScripterX 3.0.5.5.

Thanks in advance.

 

G'day @kirkj!  Thank you for your feedback mate.  The Package Installer in 3.0.5.5 doesn't work due to synchronous calls in the backend; which I've fixed in v4.0.0.5 however 4.0.0.5 requires Emby Server Beta 4.7.35+ and above, I'll be releasing 4.0.0.5 up onto the catalog sometime in the next 24 hours, just have to finalise a couple of loose ends and test.

 

Thanks again mate, I'll let you know as soon as everything is ready :) 

  • Thanks 1
Link to comment
Share on other sites

Anthony Musgrove
16 hours ago, Anthony Musgrove said:

 

G'day @kirkj!  Thank you for your feedback mate.  The Package Installer in 3.0.5.5 doesn't work due to synchronous calls in the backend; which I've fixed in v4.0.0.5 however 4.0.0.5 requires Emby Server Beta 4.7.35+ and above, I'll be releasing 4.0.0.5 up onto the catalog sometime in the next 24 hours, just have to finalise a couple of loose ends and test.

 

Thanks again mate, I'll let you know as soon as everything is ready :) 

4.0.0.5 BETA is now on the Catalog.  Package installer works, after package is installed you'll have to reload the package list page, until I finish the 'Installation Pending' status/code.

 

Link to comment
Share on other sites

Anthony Musgrove

& 4.0.0.6 is now released as Beta - Package Configuration Interface saving functionality now working correctly again - was due to synchronous functions in backend being disallowed, so now when you write a package, and create the appropriate Configuration interface, Configuration XML etc, Reading & Saving works again.  (Nice!)

 

Link to comment
Share on other sites

Anthony Musgrove

And the magic begins.... very simple Package example subscribing to playback start, playback ended, demonstrating context data, and sending it off to Telegram to show on my phone.  And it's really that easy.

Please use this package zip file instead of the one in the above post, because this has the two event subscription examples in it.

 

code.png

example on phone.jpg

PackageInterfaceExample.png

ScripterXTelegramNotificationPackage.zip

  • Thanks 1
Link to comment
Share on other sites

Anthony Musgrove

Also note - once you've installed an instance of a  package, the files can be edited if you have access to the server filesystem.  They're stored in your emby data folder.  On my windows dev laptop, they're stored at:

C:\Users\Hunter3DPrinting\AppData\Roaming\Emby-Server\programdata\data\ScripterX\Packages\{package-instance-id}

eg:

image.png.4e9452e308e5e683c0b54412f048f369.png

 

Inside this folder is your package files:

image.png.3d8e4b7f613ce4457d6f397a39fa6de7.png

 

Make changes to your Package.js, then hit the 'reload button' (little circle) next to the package listing in your Emby dashboard:

image.png.4365fb1aae5028eed06e99081329b861.png

 

And don't forget, any configuration/settings that you've setup for your Package's config interface can be accessed by hitting the 'cog button' next to the package listing in your Emby Dashboard:

image.png.90f41c1d20c611b6a87f44523eecfa4a.png

 

 

Once you click the Cog, it will turn into a 'Save' icon, where you can save any changes to your package instances configuration:

 

image.png.0ee286e7b6bb537e330802beb1c95e81.png

 

and note that these text boxes here in my example package were defined and created by creating a PackageConfig.html with the contents:

Bot Token: <INPUT TYPE="TEXT" NAME="BOTTOKEN" VALUE="%BOTTOKEN%"><BR/>
Chat ID: <INPUT TYPE="TEXT" NAME="CHATID" VALUE="%CHATID%"><BR/>

 

Which coincide with my PackageConfig.xml:

<?xml version="1.0"?>
<PackageConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Settings>
    <Setting>
      <Id>BOTTOKEN</Id>
      <Value>[hidden for security purposes]</Value>
    </Setting>
    <Setting>
      <Id>CHATID</Id>
      <Value>[hidden for security purposes]</Value>
    </Setting>
  </Settings>
</PackageConfiguration>

 

and these configuration values are accessed in my Package script (Package.js) via:

	telegram_bot_token = ScripterX.Config.Get("BOTTOKEN").StringValue();
	telegram_chat_id = ScripterX.Config.Get("CHATID").StringValue();

 

Nice and easy, I've tried to make it as easy as possible such that I can give even the more novice of end users the ability to create their own scripts etc.

 

My simple sendNotification function is just a javascript function that does the following:- 

function sendNotification(notification_msg)
{
	var submit_notification_url = telegram_api_url + telegram_bot_token + "/sendmessage?chat_id=" + telegram_chat_id + "&text=" + notification_msg;
	ScripterX.Web.Post(submit_notification_url, null);
}

 

Which is activated by two ScripterX subscription methods in my Package.js, onPlaybackStart, onPlaybackEnded:

 

function _onPlaybackStart(context)
{
	sendNotification("User " +  context.Token("%username%").value + " has started playing " +  context.Token("%item.name%").value + " on your media server.");
}

function _onPlaybackStopped(context)
{
	sendNotification("User " +  context.Token("%username%").value + " has stopped playing " +  context.Token("%item.name%").value + " on your media server.");
}

 

And there are a bunch more available subscription methods, which you can see on the wiki: https://wiki.emby-scripterx.com/doku.php?id=packages

 

I hope this kinda explains a bit more about packages, but there are also other cool things packages can do like extend the Emby API, etc.  It's all basically there on the wiki, but working on getting better documentation together.  I'm excited to see what creations people can make with ScripterX!

Warmest regards,

Anthony M

  • Thanks 1
Link to comment
Share on other sites

Anthony Musgrove

Sneak preview of the Online Package Catalog search functionality :)

 

image.png.a8bc1742bf1af79b7e9747954d2c1c26.png

Link to comment
Share on other sites

On 4/21/2022 at 2:43 PM, Anthony Musgrove said:

 

G'day @kirkj!  Thank you for your feedback mate.  The Package Installer in 3.0.5.5 doesn't work due to synchronous calls in the backend; which I've fixed in v4.0.0.5 however 4.0.0.5 requires Emby Server Beta 4.7.35+ and above, I'll be releasing 4.0.0.5 up onto the catalog sometime in the next 24 hours, just have to finalise a couple of loose ends and test.

 

Thanks again mate, I'll let you know as soon as everything is ready :) 

Hi @Anthony Musgrove.

I ended up implementing a Python script for the notifications. Your plugin is pretty cool and works great. Since Emby sends an added media event for each version of a movie, and also when you add an entire series it notifies you once for each episode, I needed to come up with a way to group this information together and create a more polished notification message. And I still send the image along 😀.
Thank you for the work.

  • Thanks 1
Link to comment
Share on other sites

Anthony Musgrove
50 minutes ago, kirkj said:

Hi @Anthony Musgrove.

I ended up implementing a Python script for the notifications. Your plugin is pretty cool and works great. Since Emby sends an added media event for each version of a movie, and also when you add an entire series it notifies you once for each episode, I needed to come up with a way to group this information together and create a more polished notification message. And I still send the image along 😀.
Thank you for the work.

You're more than welcome mate.  I'm glad this plugin can be useful for so many people.  I personally really love having this plugin on my servers so that if I need to customise something quickly, I can, without having to write any software, just simple scripts etc.

 

The package online catalog is coming together nicely too :)

 

image.png.7a0bdae620ba9da97e21042750785be5.png

Link to comment
Share on other sites

Anthony Musgrove
4 hours ago, kirkj said:

Hi @Anthony Musgrove.

I ended up implementing a Python script for the notifications. Your plugin is pretty cool and works great. Since Emby sends an added media event for each version of a movie, and also when you add an entire series it notifies you once for each episode, I needed to come up with a way to group this information together and create a more polished notification message. And I still send the image along 😀.
Thank you for the work.

By the way mate, the method you use to collate all these events together, I'd be very interested in getting this sort of logic somehow of ScripterX.  It's been an ongoing todo since the early days of the plugin :)❤️ 

Link to comment
Share on other sites

harrv

Hi @Anthony Musgrove,

It's great to see you making improvements to your plugin again! I have a suggestion for one. I've worked around this already (by doing some pre-processing at the receiving end before parsing the JSON), but it would probably be useful to others.

If I use your plugin to send a webhook, and I need the payload to be JSON, I can create the template and Scripter-X inserts values, but the values it inserts are not JSON encoded/safe, so at the receiving end, if the webhook processor tries to parse the resulting JSON payload, will fail.

An example is any variable that holds a \ character (such as a Windows or UNC path) or a " character (possible in movie or episode descriptions, etc). Those characters have to be escaped in JSON, so they'd need to be \\ or \"

It would be great to be able to mark a particular webhook as needing to have JSON encoded values and have you automatically encode the strings with whatever JSON library you use before you insert them into the template.

If this had been a feature of Scripter-X it would have saved me a lot of time I spent working around this issue.

Thanks for considering it.

Link to comment
Share on other sites

Anthony Musgrove
2 hours ago, harrv said:

Hi @Anthony Musgrove,

It's great to see you making improvements to your plugin again! I have a suggestion for one. I've worked around this already (by doing some pre-processing at the receiving end before parsing the JSON), but it would probably be useful to others.

If I use your plugin to send a webhook, and I need the payload to be JSON, I can create the template and Scripter-X inserts values, but the values it inserts are not JSON encoded/safe, so at the receiving end, if the webhook processor tries to parse the resulting JSON payload, will fail.

An example is any variable that holds a \ character (such as a Windows or UNC path) or a " character (possible in movie or episode descriptions, etc). Those characters have to be escaped in JSON, so they'd need to be \\ or \"

It would be great to be able to mark a particular webhook as needing to have JSON encoded values and have you automatically encode the strings with whatever JSON library you use before you insert them into the template.

If this had been a feature of Scripter-X it would have saved me a lot of time I spent working around this issue.

Thanks for considering it.

Hey mate,  

Thank you so much for the feedback I really appreciate it.  It's my pleasure to get back into this plugin and get more features and fixes in place.   I'm so sorry to hear that you've had to spend copious amounts of time for working around this one.  It's something I definitely should have thought of when writing the WEB module.

I've added it to the GitHub issue list, and I'm going to check it out right now - it should be a fairly simple one to fix on my side

GitHub ISSUE: https://github.com/AnthonyMusgrove/Emby-ScripterX/issues/63

Warmest regards,

Anthony

  • Thanks 1
Link to comment
Share on other sites

Anthony Musgrove

@harrv  Thank you again mate, I've just rectified this issue and released version 4.0.0.7 on the official catalog, under BETA version, and requires Emby Server Beta 4.7.35+ Minimum.  

 

ChangeLog for 4.0.0.7:

4.0.0.7
General

  • When sending JSON payload with WEB:POST the template provided defines the format and the tokens required for the variables to be sent, however the variables were not being subsidised in a JSON-Safe escaped format.  This has now been rectified, and token values are now supplemented using a JSON-safe escaped format.  This addresses https://github.com/AnthonyMusgrove/Emby-ScripterX/issues/63

Packages

  • Online Package Catalog in implementation stages, allows search functionality however there is currently no download or installation functionality from Online catalog - this will be released very soon.
Edited by Anthony Musgrove
Changed formatting
  • Thanks 1
Link to comment
Share on other sites

13 hours ago, Anthony Musgrove said:

By the way mate, the method you use to collate all these events together, I'd be very interested in getting this sort of logic somehow of ScripterX.  It's been an ongoing todo since the early days of the plugin :)❤️ 

To perform the grouping I record the notifications in a sqlite database. In this bank I save the item_id, the season_id and a field that informs if that item has already been notified.

This is the script that your plugin runs in onMediaItemAddedComplete (save-notification.py). The other script runs on a cron schedule. It reads the database and handles notifications. I forward the attached scripts.

save-notification.py telegram-notifications.py

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...