Jump to content


Photo

New Plugin - Custom Scripting | Emby ScripterX


  • Please log in to reply
294 replies to this topic

#281 ginjaninja OFFLINE  

ginjaninja

    Advanced Member

  • Members
  • 1851 posts
  • Local time: 01:23 PM
  • Locationuk

Posted 27 May 2020 - 08:35 AM

Hi Anthony,

 

has something changed in the last few versions with ScripterX aggregating tv remove events 'onmediaitemremoved'?

 

When i remove a single episode, its logged as an episode removal

 

but if i remove a season, i only see a season remove event...i thought i used to see the season and all the episode remove events, but i may be imagining it.

 

not necessarily a problem, but just wanted to check if the behaviour is newish / intentional.



#282 PenkethBoy OFFLINE  

PenkethBoy

    Advanced Member

  • Members
  • 4299 posts
  • Local time: 01:23 PM
  • LocationWarrington,UK

Posted 27 May 2020 - 12:45 PM

i see the same when removing an album it only has a remove album event - this is not new always been like this from my experience

 

this is an emby thing i suspect

 

i.e. it only notifies the top level item not all the sub items being removed



#283 ginjaninja OFFLINE  

ginjaninja

    Advanced Member

  • Members
  • 1851 posts
  • Local time: 01:23 PM
  • Locationuk

Posted 27 May 2020 - 12:52 PM

i see the same when removing an album it only has a remove album event - this is not new always been like this from my experience

 

this is an emby thing i suspect

 

i.e. it only notifies the top level item not all the sub items being removed

thanks for confirming



#284 spaceman07 OFFLINE  

spaceman07

    Member

  • Members
  • 18 posts
  • Local time: 01:23 PM

Posted 27 May 2020 - 10:41 PM

hello.. sorry if this has been asked before.. can i use python scripting with the plugin?



#285 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted 28 May 2020 - 06:54 AM

hello.. sorry if this has been asked before.. can i use python scripting with the plugin?

 

Thats okay, and absolutely you can!  In the interpreter, just place the path to your python executable.  The script should just specify the path to your python script - then the same, parameters are simply passed to your script, conditions are checked (if any are configured) before it submits to python :)



#286 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted 28 May 2020 - 06:54 AM

Hi Anthony,

 

has something changed in the last few versions with ScripterX aggregating tv remove events 'onmediaitemremoved'?

 

When i remove a single episode, its logged as an episode removal

 

but if i remove a season, i only see a season remove event...i thought i used to see the season and all the episode remove events, but i may be imagining it.

 

not necessarily a problem, but just wanted to check if the behaviour is newish / intentional.

 

I'll check these out mate :) I'll have to add them to Github Issues so I can keep track :)



#287 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted 28 May 2020 - 06:56 AM

The packages interface is coming together nicely, and is almost ready for a new release.

 

Packages will have much more power to script with too, for example, exposing things such as Item Finder, User management etc, all from your javascript code.

 

It's going to really shape the future direction of the Packages side of Scripter X

 

:) thank you all you're all awesome!

 

5ecf98d611cae_packagesinterface.png



#288 ginjaninja OFFLINE  

ginjaninja

    Advanced Member

  • Members
  • 1851 posts
  • Local time: 01:23 PM
  • Locationuk

Posted 28 May 2020 - 08:54 AM

Dont know if any one else would find this useful,

a power shell logger which logs all parameters dynamically as you change ScripterX parameters.

ie anything you add to ScripterX parameters gets added to the log.

(i got bored of keeping the two in sync during development/testing)

#Generic ScripterX logger
[CmdletBinding()]
param(
  [parameter(ValueFromRemainingArguments=$true)]
  $allscripterxparams
)

$LogCSV = "$PSScriptRoot\Log.CSV"
#$true/$false - clears the log if the ScripterX parameters are different to log, otherwise new paramters will be truncated
$clearlogonheaderchange=$true

$logparams = [Ordered]@{}
#add some of your own parameters if you wish
$now = (Get-Date)
$logparams['DateTime'] = $Now

#Enumerate parameters into key/value pairs.
$allscripterxparams | ForEach-Object {
  if ($_ -match '^-') {
    #New parameter
    $lastvar = $_ -replace '^-'
    $logparams[$lastvar] = $null
  }
  else {
    #Value
    $logparams[$lastvar] = $_
  }
}

<#
#can still enumerate the parameter keys/values if you wish to code more functionality
foreach($key in $logparams.keys) {Write-Host = "$key, $($logparams[$key])"}
#$logparams.Username
#>

#Remove parameters if you dont want them logged
#$logparams.remove('id')

#Clear log if log headers do not match ScripterX parameters
if ((test-path $logcsv) -and ($clearlogonheaderchange)) {
  $currentlog = import-csv -Path $LogCSV
  $csvheaders = $currentlog[0].psobject.properties.name
  #convert to strings so like objects can match
  $csvheaders = $csvheaders -join ","
  $currentparams=$logparams.Keys -join ","
  if ($csvheaders -ne $currentparams) {Clear-Content $logcsv} 
}

#Convert to psobject for ExportCSV
New-Object PSObject -property $logparams | Export-Csv -Path  $LogCSV -Append -NoTypeInformation -Force


  • Anthony.Musgrove likes this

#289 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted 29 May 2020 - 03:49 AM

Emby Scripter-X version 3.0 (up on the catalog now!)

 

5ed0b938393f4_EmbyScripterX_v300Logo.png

 

The major change in this version is -- Packages -- !

 

This gives you the opportunity to develop packages for Scripter X for others to install and use.   And very soon, there will be a Packages catalog available that you'll be able to search for, and install community packages, straight from your Emby Administration Console.

 

A package is written in Javascript.   A Package requires 3 things - 1)  a PackageInfo.json file, 2) a Package.js file, and 3) both these files zipped up together in a .ZIP file.

 

PackageInfo.json provides vital information about your package to ScripterX.  It's format is as follows :-

{
    "Id":            "scripterx.package.example",
    "Name":         "Example Package",
    "Description":    "An example package for the ScripterX package system.",
    "Author":        "Anthony Musgrove",
    "Email":        "anthony@emby-scripterx.info"
}

Package.js is the javascript file for your package - where all your code exists.    This is the fun bit.

 

Some important things to know about your script:

 

When your package is initialised by ScripterX (on installation, and on server startup), a function in your Package.js is executed.  It is called _package_init():

function _package_init() {
//do something here on package startup
}

- Your script can subscribe to ANY of the ScripterX events, by adding a function with the name _EventName, for example, if you wish to subscribe your package to the onAuthenticationFailed event, you'd simply enter:

function _onAuthenticationFailed(context)
{
//do something here when someone fails to authenticate to emby.
}

*** Note, the parameter for these functions is context, which is the context of the event call.  It contains all the information regarding token values, etc, that you have full access to.   For example, to get the username of the attempted failed authentication, you could use :-

function _onAuthenticationFailed(context)
{
var attempted_username = context.Token("%username%").value;
}

Same goes for any of the other events, events being:

onAuthenticationFailed, onAuthenticationSuccess, onLibraryScanComplete, onMediaItemAdded, onMediaItemRemoved, onMediaItemUpdated,
onPlaybackStart, onPlaybackStopped, onScheduledTask, onSessionEnded, onSessionStarted, onCameraImageUploaded, onLiveTVRecordingStart,
onLiveTVRecordingEnded, onScheduledTaskStart, onScheduledTaskEnded, onMediaItemAddedComplete, onPlaybackProgress

To log output from your package to the Emby server log, you can utilise the ScripterX.Log functions, they are :-

ScripterX.Log.Info("Add an Info log entry to emby server log.");
ScripterX.Log.Error("Add an Error log entry to emby server log.");

If you need timers, ScripterX has timers.   You can simply create, delete, start, restart or stop a timer by using the following Timers commands :

 

Create a timer that only elapses once, but can be restarted manually after its elapsed, by using .createOnce:

ScripterX.Timers.createOnce("myTimer", 5000, "tmrMyTimer_Elapsed", null); 

or, create a timer that elapses every interval, without having to be restarted, by using .createRepeating:

ScripterX.Timers.createRepeating("myRepeatingTimer", 10000, "tmrMyRepeatingTimer_Elapsed", null);

When your timer elapses, it will call the function set in as your callback.  For example, when my timer elapses, it will call the following function:

function tmrMyTimer_Elapsed(timer_name, timer_interval, objects)
{
//do something here when my timer elapses, the timer's name is given here too.
//timer name is needed to start, stop, restart, delete etc.
} 

ScripterX supports webhook posts right from your javascript, you can perform a webhook post by using the ScripterX.Web functions, for example, in my _onPlaybackStart function, I want to post to a webhook every time someone starts playing a movie or TV show on my server, I can do this by:

function _onPlaybackStart(context)
{
    /* Send a webhook when (someone) plays (something) */
    var api_url = "https://myapi.url.com";
    
    var playback_info = {};
    
    playback_info.itemId = context.Token("%item.id%").value;
    playback_info.itemName = context.Token("%item.name%").value;
    
    playback_info.userName = context.Token("%username%").value;
    playback_info.deviceName = context.Token("%device.name%").value;

    playback_info.serverName = context.Token("%server.name%").value;
    
    playback_info.memo = playback_info.userName + " is playing " + playback_info.itemName + " on device " + playback_info.deviceName + " from server " + playback_info.serverName;
    
    ScripterX.Web.Post(api_url, JSON.stringify(playback_info));
} 

- Once you've created your Package zip file for distribution, you can install it on your Emby server by using the Emby Scripter-X package installer interface, as shown below:

 

5ed0bded47053_sxPackagesInterface.png

 

 

While you're testing your package, you don't have to keep uninstalling and reinstalling your package to test and debug.  Simply install your package ONCE, then navigate to your Emby data directory, find ScripterX, then find Packages, then find the folder labelled with your package's assigned installationId.  Inside this directory, you'll notice Package.js.  Make changes directly to this file, then go back into your Emby administration panel and click the 'Reload' icon next to your package listed in your 'Installed Packages' panel.  The reload icon is next to the uninstall/delete icon.   If you wish to uninstall a package, simply click the trashbin, then confirm by clicking 'Really Uninstall?' 

 

 

There is MUCH, MUCH more to come, but for now this will get people going.   There are other function groups that I am going to implement including Library searching and Item manipulation, User manipulation and searching, among many, many other functionality. 

 

Please enjoy, and as always, any comments, feedback, suggestions are MUCH MUCH appreciated.


Edited by Anthony.Musgrove, 29 May 2020 - 03:51 AM.

  • Spaceboy likes this

#290 PenkethBoy OFFLINE  

PenkethBoy

    Advanced Member

  • Members
  • 4299 posts
  • Local time: 01:23 PM
  • LocationWarrington,UK

Posted 29 May 2020 - 06:49 AM

Hi Anthony

 

looks interesting :)

 

can you please look at resolving the outstanding issues on github before you add more functionality

 

so we dont have errors/issues in the core of the plugin thats stopping me using it for somethings i want to try and test

 

Thanks



#291 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted 31 May 2020 - 09:42 PM

Hi Anthony

looks interesting :)

can you please look at resolving the outstanding issues on github before you add more functionality

so we dont have errors/issues in the core of the plugin thats stopping me using it for somethings i want to try and test

Thanks


Absolutely mate thank you for the feedback :) ive added a changelog in the plugin interface its self to make it easier to track the issues once they've been implemented or resolved too :)
  • PenkethBoy likes this

#292 reneboulard OFFLINE  

reneboulard

    Advanced Member

  • Members
  • 38 posts
  • Local time: 08:23 AM

Posted Today, 06:10 AM

I been playing around with the plugin, it is most interesting and powerfull.

 

I use emby as a PVR.  My media library are shows and movies been recorded over the last few years.

 

I process the recording with a postprocessing script.  However some of the action must be done by hand since emby just send the path of the file to the postprocessing script.

 

I process the recordings differently if the are Movies, Series, News, Kids or Sports.

 

I could use the  "onLiveTVRecordingEnded" call of Emby-ScripterX to acheive better result, if additionnal information was available to my script.  Those information are available in Emby EPG and could be passed as parameters, they are :

IsMovie, IsSeries, IsNews, IsKids and IsSports.

 

Is it possible to add those to the "onLiveTVRecordingEnded" call.

 

This is the way I process recording :

Movies - I run comskip, cut commercial and run Hanbrake.

Series - I run Handbrake

News and Sports - I do nothing since they are erased after been watched

Kids movies and Series are moved to separate libraries.

Handbrake setting are different for Movies, Series and Kids

 

Thank you for your help



#293 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted Today, 06:36 AM

I been playing around with the plugin, it is most interesting and powerfull.

 

I use emby as a PVR.  My media library are shows and movies been recorded over the last few years.

 

I process the recording with a postprocessing script.  However some of the action must be done by hand since emby just send the path of the file to the postprocessing script.

 

I process the recordings differently if the are Movies, Series, News, Kids or Sports.

 

I could use the  "onLiveTVRecordingEnded" call of Emby-ScripterX to acheive better result, if additionnal information was available to my script.  Those information are available in Emby EPG and could be passed as parameters, they are :

IsMovie, IsSeries, IsNews, IsKids and IsSports.

 

Is it possible to add those to the "onLiveTVRecordingEnded" call.

 

This is the way I process recording :

Movies - I run comskip, cut commercial and run Hanbrake.

Series - I run Handbrake

News and Sports - I do nothing since they are erased after been watched

Kids movies and Series are moved to separate libraries.

Handbrake setting are different for Movies, Series and Kids

 

Thank you for your help

 

 

Absolutely mate, I will add these this evening!  I'm just finishing up the new Email Notifications plugin, and then I'll release a new version with all these included!, I'll reply to this thread once I've released it! 



#294 Anthony.Musgrove ONLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 237 posts
  • Local time: 10:23 PM
  • LocationNewcastle, NSW, Australia

Posted Today, 07:36 AM

@reneboulard Thank you so much for your feedback by the way, it is so very much appreciated as is everyone's feedback!
 
I've added the requested tokens for you to Live TV recordings, just update to the latest version in the Emby Catalog v3.0.2

 

5ed639b5c5878_addednewtokens.png



#295 reneboulard OFFLINE  

reneboulard

    Advanced Member

  • Members
  • 38 posts
  • Local time: 08:23 AM

Posted Today, 07:43 AM

Absolutely mate, I will add these this evening!  I'm just finishing up the new Email Notifications plugin, and then I'll release a new version with all these included!, I'll reply to this thread once I've released it!


Thank you, will look forward to the added feature and make use of it.
I will be able to have much simplier postprocessing script and reduce manual processing of media file.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users