Jump to content


Photo

Script to create Per User Recently Watched Playlists


  • Please log in to reply
6 replies to this topic

#1 ginjaninja ONLINE  

ginjaninja

    Advanced Member

  • Members
  • 1831 posts
  • Local time: 07:33 PM
  • Locationuk

Posted 20 May 2020 - 02:23 PM

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.

 

 

Attached File  Playlist v0.0.0.2beta.zip   105.88KB   1 downloads

Attached File  Playlist v0.0.0.1.zip   123.86KB   4 downloads

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, 24 May 2020 - 06:43 AM.

  • Spaceboy, neik and Anthony.Musgrove like this

#2 mastrmind11 ONLINE  

mastrmind11

    Advanced Member

  • Members
  • 3134 posts
  • Local time: 02:33 PM
  • LocationLong Island, NY

Posted 20 May 2020 - 03:17 PM

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



#3 Spaceboy ONLINE  

Spaceboy

    Advanced Member

  • Members
  • 4769 posts
  • Local time: 07:33 PM

Posted 21 May 2020 - 06:23 AM

Nice, I’ll give this a go

#4 Anthony.Musgrove OFFLINE  

Anthony.Musgrove

    Advanced Member

  • Members
  • 215 posts
  • Local time: 04:33 AM
  • LocationNewcastle, NSW, Australia

Posted 22 May 2020 - 10:27 PM

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



#5 Spaceboy ONLINE  

Spaceboy

    Advanced Member

  • Members
  • 4769 posts
  • Local time: 07:33 PM

Posted 23 May 2020 - 09:22 AM

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



#6 ginjaninja ONLINE  

ginjaninja

    Advanced Member

  • Members
  • 1831 posts
  • Local time: 07:33 PM
  • Locationuk

Posted 23 May 2020 - 11:17 AM

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, 23 May 2020 - 11:18 AM.


#7 ginjaninja ONLINE  

ginjaninja

    Advanced Member

  • Members
  • 1831 posts
  • Local time: 07:33 PM
  • Locationuk

Posted 23 May 2020 - 05:37 PM

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, 24 May 2020 - 06:49 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users