Jump to content
ginjaninja

Script to create Per User Recently Watched Playlists

Recommended Posts

ginjaninja
Posted (edited)

Goal
Automatically manage a 'curated' recently watched episode playlist, which works on Roku, in a similar vein to Plex's recently watched ribbon.
Last time i tested smart playlist and playback reporting plugins, their recently watched playlist's content was not visible on my Roku.

Design
Only 'real' watches are added to the playlist. Real are ones where there is start event on an unplayed item followed by a stop event on a played item.
-re-watching something already watched wont add an item to playlist.
-Marking a item played wont add item.
Most recent watched earliest in list.
Duplicates are not added to playlist.
Image for playlist based on the most recent watched four episodes.
per user functionality is provided by a ScripterX user condition and different instances of the script/name of playlist in the config.
should work for movies too.

Installation
Extract files to same directory
Install Powershell
Install Scripter X plugin by @@Anthony.Musgrove
set scripterX parameters
Interpreter: pwsh.exe
Script File:
-File "A:\Example\LogPlayback.ps1"
Parameters:
-EventType "onPlaybackStart" -Type "%item.type%" -Id "%item.id%" -Name "%item.name%" -Username "%username%" -Device "%device.name%" -userid "%user.id%"
Parameters:
-EventType "onPlaybackStopped" -Type "%item.type%" -Id "%item.id%" -Name "%item.name%" -Username "%username%" -Device "%device.name%" -userid "%user.id%"
Conditions: item.type equals episode.

Logplayback.ps1 is intended to be called via Scripter X plugin to create log
Process.ps1 is intended to be launched by logplayback.ps1.
Config.psd1 contains your api info, playlist config and local datetime config.

 

Changes

v0.0.0.2beta - not compatable with old csvs and a new config option is required.

New - New config option DateTimeFormat - match your Datetime format in (new) log to this option.

New - Process.ps1 is now launched automatically by the logger on the onplaybackstopped event, so no need to schedule process.ps1. Ensures the playlist is only a few seconds behind real life.

 

 

Playlist v0.0.0.2beta.zip

Playlist v0.0.0.1.zip

Caveats
might need latest Powershell and a relaxed Powershell execution policy.
tested on Windows but should be agnostic.
a bit alpha - learning classes, methods, constructors, functions.
issues/suggestions welcome.

5eca340ab702d_ScripterXConfig.jpg

Edited by ginjaninja
  • Like 3

Share this post


Link to post
Share on other sites
mastrmind11

you guys and your Powershell....  nicely done, dude!

Share this post


Link to post
Share on other sites
Spaceboy

Nice, I’ll give this a go

Share this post


Link to post
Share on other sites
Anthony Musgrove

I'm absolutely loving these scripts you're putting together mate.  I am so so glad that this is all coming together :) 

Share this post


Link to post
Share on other sites
Spaceboy

well i'm set up. I'll check back in tomorrow after i've watched some stuff tonight and the process script runs overnight

Share this post


Link to post
Share on other sites
ginjaninja
Posted (edited)

well i'm set up. I'll check back in tomorrow after i've watched some stuff tonight and the process script runs overnight

 

interested to see how you get on

If you run into problems i would try watching some old stuff manually to create a log "Queue,csv", and run the process script manually from pwsh, so you can see the output.

 

in order for process.ps1 to register a 'watch', the id needs to have a start event on an unplayed item and a stop event with a played item in the log. so a bit of tweaking required if testing on previously "played=true" content.

Added to playlist...

"onPlaybackStart","False"

"onPlaybackStopped","True"

Not added to playlist...

"onPlaybackStart","True"

"onPlaybackStopped","True"

"DateTime","Type","ID","Name","Username","Userid","Device","EventType","Played","Processed","Valid","Matched"
"23 May 2020 15:59:21","Episode","321997","The Return","User1","6cc6d0fa039849af8147592f5da46188","Chrome","onPlaybackStart","False","No","",""
"23 May 2020 15:59:22","Episode","321997","The Return","User1","6cc6d0fa039849af8147592f5da46188","Chrome","onPlaybackStopped","True","No","",""
Edited by ginjaninja

Share this post


Link to post
Share on other sites
ginjaninja
Posted (edited)

have notice a bug, if unprocessed rows remain in queue.csv when it is processed, the date format is changed and the script failss on subsequent runs...will need to fix that, although if running in middle of night you probably wont see this issue.

need to find a way to force a date format on powershells export-csv...ie keep it the same

 

edit

have not been able to find a way to control the datetime format internally in memory or on export or really understand how this works across regional cultures and i suspect the script may fail in other cultures.... so for now  have added a datetimeformat config option, so user can match the format in their logs in their local region (logging uses the default format)..

 

e.g my logging/default datetime format is

"24/05/2020 11:29:33","Episode","322312","What's the Matter with Tony Slattery?","user1","6cc6d0fa039849af8147592f5da46188","Chrome","onPlaybackStart","False","No","",""

so i have set my datetimeformat option in config to match (case and separators matter)

DateTimeFormat="dd/MM/yyyy HH:mm:ss"

hopefully this will make it reliable.

 

updated to v0.0.0.2

Edited by ginjaninja

Share this post


Link to post
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...