Best way to modify existing TV show episode metadata (title, summary, etc) from the command line

Server Version#: 4.145.1
Player Version#: (various)

( I hope I’m posting this to the run area – my apologies if I’m not. )

I was wondering (1) if it’s possible to change metadata for an existing TV show episode, and if so, (2) what’s the best way to do this from the command line…?

Background: My Plex server runs on Ubuntu 24.xx. The Plex DVR records “Modern Marvels” (OTA), but the resulting metadata is wrong (if you dig around on the Internet for program information for Modern Marvel episodes, you’ll find that different source have conflicting information).

I played around with both ChatGPT and Google Gemini, and I discovered that if I was them for data (e.g., in a Plex-friend, XML NRO file format), I get the proper information. This led me to creating a Python script to go query Gemini and parse the returned data. So far, so good.

I would like to replace the existing “broken” metadata with the “good” data that I get via my script. I went back to Gemini and asked it to create a Python script to replace the existing metadata (title, summary, etc) for given TV show episode. According to Gemini, I should be able to use the Python “plexapi” library, but I spent hours trying to create a script that successfully changes the data, but alas, I was not successful – the test script successfully pulls the (incorrect) metadata from the local Plex server, and I use some calls that Gemini suggested in order to update the information (and no errors are generated), but the next time I pull the data, I still get the old, broken data.

I also Googled plexapi, and from what I could gather, plexapi does not have any facility to write metadata to the Plex server database. That caught me off-guard – if it doesn’t have the ability to write metadata, I’m wondering why Gemini (as well as ChatGPT) suggest to use plexapi…? :-?

After more searching, I did see something that looked like metadata could be written to the Plex database using POST operations (via HTML/HTTP like calls) on the server, but the example script I found was different enough from what I’m looking for that I wasn’t sure it really would do what I need.

Thoughts?

advTHANKSance.

Possibly the Sonarr API can help you get there. update_episode_file may do what you want.

https://github.com/devopsarr/sonarr-py/blob/main/docs/EpisodeFileApi.md#update_episode_file

Another potential option might be filebot. Have a look at this topic How about sharing your CLI scripts? - FileBot which gives the ability to embed metadata directly into your media files. You could then enable prefer local metadata within your plex library (only supports mp4 containers). Plex will then pick these up instead of using their crappy consolidated metadata back-end.

BTW… plex has said they will provide external nfo metadata support at some point in the future. However, no design on how this will work, what tags will be used etc… or timeline has been provided.

Hi. I hadn’t heard of Sonarr. It appears to be a separate DVR-like program and isn’t related to Plex. Or am I missing something?

MP4s, huh… I typically use MKVs (I don’t like to have closed captions burned into the video stream which is what MP4s do).

However, the Plex DVR records things to TS file, and I wouldn’t really care if the subtitles were/weren’t included in Modern Marvel episodes.

Here’s a half-baked thought…

  • Create a new (additional) library directory for TV shows that require local metadata (like Modern Marvels would), and configure that special library directory for local data (and any other special tweaks that are required).
  • Write a script that does post-processing on the .ts file – run Handbrake to convert it to a .mp4 file, and also have the script update the embedded data in the newly created .mp4 file.
  • Place the new .mp4 file into the new/special library directory.
  • Remove the original .ts file (yeah, this will break the ability to play the file from the Plex DVR menu, but I rarely do that – I normally watch it from the regular “TV Shows” library menu).
  • Force a rescan of the TV Shows library (or maybe just Modern Marvels – it doesn’t matter since the rescan is pretty fast).

I could play around with this approach to see if it’ll give me the desired results…

This generalization is untrue. MP4 do support “soft” subtitles as well, just like MKV does.

Sonarr, and its cousins Radarr, Lidarr, Readarr are all apps that work with Plex and indexers like Prowlarr to automatically update your libraries by monitoring rss feeds from the indexers to download torrents and usenet nzbs for the movies, tv shows, music or audiobooks you want added to your libraries.

You mentioned you tried the plexapi but weren’t able to get it to update. The sonarr api I referenced seems to have an api call that updates episodes which is why I suggested looking at it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.