Jump to content

New Plugin - Custom Scripting | Emby ScripterX


Anthony Musgrove

Recommended Posts

rafinha

Is this still working?

I'm trying to send a post to my endpoint using scripterx by @Anthony Musgrove and I don't get anything.

Look the image attached.

I know I can use the webhooks from emby, but the problem is that emby webhooks, doesn't have an "onMediaItemAdded" option.

Anybody know how to use the post option from scripterx ?

Thanks

Screenshot 2021-05-10 143411.png

Link to comment
Share on other sites

harrv
1 hour ago, rafinha said:

Is this still working?

I'm trying to send a post to my endpoint using scripterx by @Anthony Musgrove and I don't get anything.

Look the image attached.

I know I can use the webhooks from emby, but the problem is that emby webhooks, doesn't have an "onMediaItemAdded" option.

Anybody know how to use the post option from scripterx ?

Thanks

Screenshot 2021-05-10 143411.png

Yes, I see at least one problem, and maybe three.

A web post requires a payload template, and you haven't specified one. The template is a text file that contains whatever you want to be posted to your web hook. It has variables in it that correspond to the data Scripter-X knows how to resolve for the event. Here is what mine looks like for onMediaItemAddedComplete (which is more useful than onMediaItemAdded assuming you want to take some action when something is actually done being added and not just when something new is detected but has not finished adding yet):

{
    "Event": "scripterx.mediaitem.added.complete",
    "item.id": "%item.id%",
    "item.name": "%item.name%",
    "item.originaltitle": "%item.originaltitle%",
    "item.tagline": "%item.tagline%",
    "item.overview": "%item.overview%",
    "item.type": "%item.type%",
    "item.productionyear": "%item.productionyear%",
    "item.isvirtual": "%item.isvirtual%",
    "item.library.type": "%item.library.type%",
    "item.library.name": "%item.library.name%",
    "season.id": "%season.id%",
    "season.name": "%season.name%",
    "season.number": "%season.number%",
    "series.id": "%series.id%",
    "series.name": "%series.name%",
    "episode.number": "%episode.number%",
    "embyServer": {
        "id": "%server.id%",
        "name": "%server.name%",
        "version": "%server.version%",
        "platform": {
            "os": "%server.platform.os%",
            "osVersion": "%server.platform.osver%",
            "upTime": "%server.platform.uptime%"
        }
    },
    "scripterx": {
        "version": {
            "full": "%scripterx.version%",
            "major": "%scripterx.version.major%",
            "minor": "%scripterx.version.minor%",
            "build": "%scripterx.version.build%",
            "revision": "%scripterx.version.revision%"
        }
    }
}

I saved that file as MediaItemAddedComplete.json on my Emby server and then when I configured Scripter-X for that event I specified the full path to that template file in the field immediately below the run field.

image.thumb.png.9af742caa84fd5fc8e755d6deca77e11.png

 

Potential problem #2:

Notice that I don't use a where clause. That's because I want to use this same config for all onMediaItemAddedComplete events. You only need a where clause if you want to filter the events based on something in a variable. For example, if I wanted to have different templates or call a different web hook depending on whether it is a movie or a TV episode being added, I would use a where clause for that.

I see that you have a where clause, and that it doesn't make much sense. I assume you were trying to use it to specify what you want to be posted, but you need to use a payload template for that, as described above.

Potential problem #3:

You specifically mentioned the onMediaItemAdded event, but your screenshot shows that you configured the onPlaybackStart event. I will assume that this isn't a problem and that you are actually configuring both events and happened to post a screenshot of onPlaybackStart rather than onMediaItemAdded.

I hope this helps!

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

  • 2 weeks later...
abegreen

Hi,

I wanted to write a simple python script that will be executed by the scripter-x.

Whole night I was trying to just make it run.

/c notepad.exe is the peek of my accomplishment.

 

Please type me an example of a command to run the .py script.

 

Thank you.

Link to comment
Share on other sites

abegreen
On 5/25/2021 at 6:56 AM, abegreen said:

Hi,

I wanted to write a simple python script that will be executed by the scripter-x.

Whole night I was trying to just make it run.

/c notepad.exe is the peek of my accomplishment.

 

Please type me an example of a command to run the .py script.

 

Thank you.

/c py e:\embyscripts\script.py

Link to comment
Share on other sites

  • 3 months later...
Anthony Musgrove

Hello my beautiful, wonderful friends.  I'm in the process of reviving the Scripter-X project; Just trying to get the codebase to compile with the new nuget packages!   Shouldn't be long!  ❤️ 

  • Like 1
Link to comment
Share on other sites

Anthony Musgrove
22 hours ago, abegreen said:

Hello there,

Please add action "onMediaLiked".

I'd like to execute script to move liked files to another library.

Thanks.

Hi there abegreen, 

Thank you for your feature suggestion!  I've successfully located the core hooks for the event you've requested, along with a bunch of others.

So when I 'favorite' or 'like' a media item, emby signals UserDataSaved, which gives a tonne of functionality along with some variables that I will tokenize.  The event will be onUserDataSaved.  You'll be able to set a condition where %save.reason% equals 'UpdateUserRating'

Then you'll be able to check a token %is.media.favorited.or.liked% which will be True or False.

I'll finalise the implementation and release it soon.

'Favorite':

2021-09-05 22:12:09.369 Info Emby ScripterX: UserDataSaved > ItemName=SuperTed, SaveReason=UpdateUserRating, Username=anthony, IsFavoriteOrLiked=True

 

'Remove Favorite':

2021-09-05 22:12:08.433 Info Emby ScripterX: UserDataSaved > ItemName=SuperTed, SaveReason=UpdateUserRating, Username=anthony, IsFavoriteOrLiked=False
  • Like 2
Link to comment
Share on other sites

abegreen

Well, hell yes man.

Whenever I make a request that makes perfect sense, developers start laying out some stuck up philosophies and reject. Even users go out of their way to give negative feedbacks.

Only through plugins we can make Emby be something more than just a movie player.

I guess you are one of the rare examples of normal people in this negative community.

Thank you very much.

  • Agree 1
Link to comment
Share on other sites

Anthony Musgrove

So I've implemented this, and it's ready for implementation.

This example below will match your criteria of:   When a user 'likes' or 'favorites' an item of media (any media).

This will be available on the next release. :) 

 

image.thumb.png.20f4d45f456f1ef7b0081f0bd9eabcb9.png

  • Like 2
Link to comment
Share on other sites

Anthony Musgrove

 

v3.0.5.2 is now live on the catalog, please update to this version to gain this new functionality.  Let me know if you come across any issues.   Remember also, when you 'like/favorite' an entire TV series, season, etc (where there is a group of media items within it), you'll get an individual onUserDataSaved call for each episode in that series/season/etc :)❤️ 

image.thumb.png.614db029b7c88b5609ddb7cb6200c9c9.png

Edited by Anthony Musgrove
  • Like 2
Link to comment
Share on other sites

Anthony Musgrove

Note, make sure you update to 3.0.5.1 (urgent bugfix, nuget decided to update Jint to a beta version which caused absolute havoc, all sorted now in 3.0.5.1)

Edited by Anthony Musgrove
Link to comment
Share on other sites

Anthony Musgrove

And finally, update to version 3.0.5.2, boolean datatype is now processed correctly with conditions.  So the following script/yields result:

note: you do not need to send %userdata.is.favorite% to the script, because the condition is set to ONLY process this action when %userdata.is.favorite% is true, therefore only processing this script when a user 'favorite/likes' a media item.   This is just an example, be as creative as you like/need!

image.thumb.png.f5270c65adab81aed2c9a3a965ce48e5.png

 

and my Scripter-X action configuration is as follows :-

image.thumb.png.b19c42b3d711a304a1a1cbb212a7940e.png

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

Anthony Musgrove
On 29/05/2021 at 17:02, abegreen said:

/c py e:\embyscripts\script.py

Place the path to your script in the 'script' text box, so e:\embyscripts\script.py and in the interpreter field specify path to your python interpreter :)

Link to comment
Share on other sites

Anthony Musgrove
On 25/05/2021 at 14:56, abegreen said:

Hi,

I wanted to write a simple python script that will be executed by the scripter-x.

Whole night I was trying to just make it run.

/c notepad.exe is the peek of my accomplishment.

 

Please type me an example of a command to run the .py script.

 

Thank you.

Check out https://wiki.emby-scripterx.com/books/scripting-tutorials/page/media-playback-example-python

 

Link to comment
Share on other sites

Benplace

I want to accomplish one thing.  I am familiar with scripting and can edit some python code but not a python developer.

All I would like to do is (On recording end/complete tag that recording with tag "tag name")  I just want to tag all of my recordings with the tag "Recorded"

Thanks in advance for any help!

Link to comment
Share on other sites

Hello - is there a way to use this tool to get Emby to refresh the recording timers on wake, or on a regular interval? As it stands my HTPC sleeps 14 hrs per day, and when it wakes, all the recording timers are off by 14 hrs, and the only way to update them is to manually restart Emby.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
Anthony Musgrove
On 11/09/2021 at 00:00, sward said:

Hello - is there a way to use this tool to get Emby to refresh the recording timers on wake, or on a regular interval? As it stands my HTPC sleeps 14 hrs per day, and when it wakes, all the recording timers are off by 14 hrs, and the only way to update them is to manually restart Emby.

 

Let me look into this now for you!

Link to comment
Share on other sites

maegibbons
2 hours ago, Anthony Musgrove said:

 

Let me look into this now for you!

Yes.  Emby definately needs to restart when it resumes from waking.  Timers do not work until emby is restarted.  Don't know if this should be done within scripterx or whether @luke needs to code something.

But if it can be done in scripterx - why not!!

Thanks for looking at it

 

Krs

 

Mark

Edited by maegibbons
Link to comment
Share on other sites

  • 3 months later...

Hey I'm having a bit of a time with this. I think my issue is related to Emby being in docker so if anyone else has a similar setup maybe they can offer some insight.

First off. Scripter-x does appear to be triggering correctly. using authsuccess as a testing arena and seeing this in my logs:

2021-12-21 09:13:04.021 Info Emby ScripterX: onAuthenticationSuccess: Chrome

But the actual script isn't running. 

Is there any other more indepth logs I can seek out that might help?

Using Emby in Docker running on Ubuntu 20.04.
Permissions all look correct, same username and rw as anything else Emby deals with. 
I've ssh'd into the docker container and confirmed it can both see the script file, and run it successfully. (it's just a basic echo to file for now).
I'm using my config folder for now, but have also tested it inside my Movies folder too, which has a matching folder path to how it's mounted in docker. 


Nevermind worked it out. Turns out the script needs to use full paths. instead of 
echo "something" > result.log

it needed to be 
echo "something" > /config/scripts/result.log

bah

image.png

Edited by Nebarik
Link to comment
Share on other sites

  • 1 month later...
ALdream40K

@Anthony Musgrove

hi,

 

have you any idea for to change the colour of my stripe led rear my TV by genre (action, adventure...) of the film ? and when is pause? no problem when start or stop playback, the command with web.get works very well.

thank you

Link to comment
Share on other sites

  • 1 month later...
harrv
16 hours ago, ZSZQ said:

"%item.meta.*"

Does this parameter support TVDB?
How is it right?

I've wondered that too. %item.meta.*% and %series.meta.*% don't resolve to anything, so we'd need to know what to put in place of the asterisk, but I've never seen an example or documentation about it. Has anyone gotten it to work? Anthony? Can you give us an example of how to use these?

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