[Release] PDST - DVR & Sports Tools

This is a set of python tools for helping with/improving Plex DVR handling of Sporting events.

One of my lockdown coping mechanisms has been getting into watching way more sports than I used to.

At about the same time I moved from YouTubeTV to using Plex DVR to record/watch a lot of these sports,
but I found the experience…lacking in a number of areas.

I’ve been working on a set of tools to try to improve what I can, and I wanted to share what I’ve
got with the rest of the Plex community!

pdst - DVR & Sports Tools

The main feature I initially created this for is generation of episode thumbnails for recorded sporting events featuring team logos (such as you might find in YouTubeTV or ESPN):

It also supports exporting EPG metadata to a format useable by mjarends’ Extended Personal Media Shows Agent as well as moving/renaming files in an intelligent way.

Some more examples of how I’m currently using it:

NBA Playoffs recordings default appearance:

After:

Tour de France recordings before:

After

International competitions:


(I’m still figuring out what looks best for national flag thumbnails)

Changelog

v1.2.0 - 2020-10-01

  • Improved the team name to logo matching process
  • Image generator now by default checks for BG colors being too similar and tries to use another color

v1.1.0 - 2020-09-21

  • ‘move’ command now properly ensures no timestamp conflicts with other media
  • Fixed ‘fillLogo’ background style centering
  • Added filename hinting support for stroke
  • Added ‘overrideShow’ support to sport-level config as well as sub-matches
  • Added support for mjarends’ ‘genres’ in metadata export
  • Use ConfigParser for reading metadata files
3 Likes

This looks awesome! Just wanted to give a heads up that I recently made some updates to the Extended Personal Media Shows scanner/metadata agent. See the following for more details: [REL] Extended Personal Media Shows Agent

If you have some time it would be helpful to have someone else test before I release the latest version.

I actually just saw that - I’ll take a look and should be able to integrate the updates as well.

This is awesome! I download and record a lot of rugby and have the problem of seeing the score displayed on the banners and thumbnails!!

I’m having problems parsing the Rugby files and was hoping to get some help from you. I download the matches (so don’t use Plex DVR to record them) but they all come down with a pretty consistent file naming scheme but when I run pdst analyze, the team names are not located.

Here’s an example:

steve@MediaServer:~/pdst$ pdst analyze -v /PlexMedia/Rugby_Downloads/
Processing directory: /PlexMedia/Rugby_Downloads/
Analyzing /PlexMedia/Rugby_Downloads/RU.2020.Mitre.10.Cup.R02.Tasman.v.Northland.540p.x264.mp4
---- RU.2020.Mitre.10.Cup.R02.Tasman.v.Northland.540p.x264.mp4 ----
Mitre 10 Cup: None
steve@MediaServer:~/pdst$ 

And my config.json file looks like this:

{
    "sports": [
    {
        "name": "Mitre 10 Cup",
        "imageRoot": "/PlexMedia/Media/Images/Mitre10Cup",
        "matches": ["Mitre"]
    }
    ],
    "imageRoot": "/PlexMedia/Media/Images",
    "thumbnailSize": [600, 340],
    "fallbackColor": "#111",
    "videoExtensions": ["mkv", "ts", "mp4"],
    "imageExtensions": ["png", "jpg", "jpeg"],
    "createdImageExtension": "png",
    "plexLibrary": "/var/lib/plexmediaserver",
    "moveTarget": "/PlexMedia/Media/Sports",
    "umask": "002"
}

So clearly it’s picking up that it’s a Mitre 10 Cup game, but it’s not able to work out the teams. Any ideas on how to get that working?

Ah, a man of taste and culture! :stuck_out_tongue_winking_eye:

So, you’ve found a shortcoming in the current version because at the moment it relies a lot on Plex DVR’s pretty standard naming conventions, which is basically <show> - <timestamp> - <episode name>.<ext> I look explicitly for those separators (dash - with spaces around it) to then look for team names. Since that example filename doesn’t have the exact separator I look for, it doesn’t know how to pull out the team names.

In the short term, a fix would be to rename the file(s) to have that separator, so for example RU.2020.Mitre.10.Cup.R02.Tasman.v.Northland.540p.x264.mp4 could become RU.2020.Mitre.10.Cup.R02 - Tasman.v.Northland - 540p.x264.mp4 (or whatever - the important bit is having only the team names somewhere in the filename either by themselves at the end of the filename or with another separator before any additional info like the res and encoding) Once it can analyze just Tasman.v.Northland it should detect that it is Tasman vs. Northland.

The better long term solution will be me adding the ability to support more varied filename structures.

I’ll start looking at adding that to the tool so filenames other than the Plex DVR format will work better.

Brilliant - I’ll try that out. While I was waiting I was trying to get the NFL games I HAD recorded with Plex DVR to work but am having an issue with the Metadata apparently… Any ideas where I messed up?

Fri Oct  9 16:55:09 PDT 2020: /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts
/PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts is a .ts video file!
Converting to /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.mkv
Has metadata file?: /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts : False
Processing /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts
INFO: Did not find a matching media_part entry for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts
NO metadata found in db for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts!
Processing video file: NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts
INFO: Did not find a matching media_part entry for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts
WARNING: NO metadata found in db or metadata file for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts!
Saving NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.png
Moving /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts and associated files...
INFO: Did not find a matching media_part entry for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts
WARNING: NO metadata found in db or metadata file for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts!
NO metadata found for /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts! Not Moving
Fri Oct  9 16:59:55 PDT 2020: /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.png

Yep so that works! But I’m still stuck with missing Metadata! How can I add this manually to the file? And what metadata is it exactly looking for?

steve@MediaServer:/PlexMedia/Rugby_Downloads$ pdst move /PlexMedia/Rugby_Downloads/      
WARNING: NO metadata found in db or metadata file for /PlexMedia/Rugby_Downloads/RU.2020.Mitre.10.Cup.R02 - Tasman.vs.Northland - 540p.x264.mp4!
NO metadata found for /PlexMedia/Rugby_Downloads/RU.2020.Mitre.10.Cup.R02 - Tasman.vs.Northland - 540p.x264.mp4! Not Moving

Did you first run pdst meta-export on the recordings? the actual exporting of metadata to a .metadata file is a separate action and doing that provides a lot more control over the process.

When it needs more info than just the filename, it first checks for a .metadata file first and only if it doesn’t find one will it then try to look in the Plex DB - but that db lookup is much more fragile. Plex has a tendency to completely lose all EPG metadata if a DVR recording is renamed or moved in any way from what I’ve seen - especially since my lookup for the metadata in the db is pretty simple in that it just looks for the filename. As part of my process I run meta-export as soon as a new recording shows up to try and reduce the potential of me messing it up accidentally after the fact.

Actually, something just occurred to me - is the full file path that you are working with the same as what Plex sees? E.g., if you do a ‘Get Info’ in Plex, is the full file path exactly /PlexMedia/Media/Recorded TV/NFL Football (2019)/Season 2020/NFL Football - 2020-10-08 18 29 59 - Tampa Bay Buccaneers at Chicago Bears.ts? Because that is how I try to lookup metadata. If you are running Plex in Docker with a volume mount, and running pdst from another context, chances are those paths won’t match and the metadata lookup will fail. I will need to also look into adding support for potentially modifying the file path pdst uses to lookup the Plex DB metadata to account for those kinds of cases.

If that doesn’t help, you can always just manually create a metadata file. See mjarends’ scanner documentation for the basic underlying structure - though I have added a lot of stuff mjarends’ scanner won’t look at.

Here is an example of what meta-export should get you:

[metadata]
title=Denmark vs. England
summary=Denmark vs. England in League A Matchday 2. From Parken Stadium in Copenhagen.
release=2020-09-08
releaseTime=14:30:00
tags=Sport;Soccer
year=2020

id=18883
library_section_id=9
metadata_type=4
guid=plex://episode/5f46114bd6c4190040d5f383
tags_genre=Sport|Soccer
duration=9000000
user_thumb_url=media://6/8ebeb2051d8e2cfdc99430075ef4d0f543ff9eb.bundle/Contents/Thumbnails/thumb1.jpg
originally_available_at=2020-09-08 08:00:00
added_at=2020-09-08 17:29:22
created_at=2020-09-08 17:29:22
index=-1
hash=8bdef795d1450e75b6621adbf2f6bd4b9c7ff959
parent_id=18696
extra_data=at%3AchannelIdentifier=1128&at%3AmediaGrabBeginsAt=1599589800

[Season]
id=18696
index=2020
hash=6a1a2505f9a42308f4ec55865b98899473311acf
parent_id=18695

[Show]
title=UEFA Nations League
summary=UEFA Nations League action.
id=18695
user_thumb_url=upload://posters/c6e8cb27ee73d0a99d0e3eea368ccf77c02048a1.jpg
index=1
hash=c057c6449828e1ffbdc1e4177a6c8f4f226b23ed
parent_id=None

The first block under [metadata] (before the blank line) is the most important, and if you make changes to the fields there, subsequent runs of pdst move will use those values for creating the filename. Most of the fields are either of limited use or ones I don’t use at all (yet?) but I save them off just in case they might be useful later.

You can also control where pdst move will put the files if you also change/set things under [Season] (important bit is index) and/or [Show] (title). But if you’re manually creating the metadata file chances are you’ve already got the videos where you want them so the actual ‘moving’ part of pdst move is probably less the goal as opposed to the file renaming part.