Moving viewstate from outdated version to current version with different agent?

I’ve lately upgraded my NAS from TrueNAS Core to TrueNAS Scale. In TrueNAS Core, Plex used to run in a jail but I was not able to update the NAS itself or the jails for ~2 years because of reasons unrelated to this issue.

The result was that the Plex Server version I last ran on TrueNAS Core was 1.40.x (over 2 years out of date).
I also used XBMC nfo plugins as the agent in Plex which are no longer supported on current versions of the Plex Server (I think). While I can no longer run the outdated Plex Server version, I have retained the config folder as well as the jail folder.

Because of all these changes I’d prefer to start fresh with a docker installation of the current Plex Server version. However I’d like to retain the viewstates if possible. I found this guide that describes how to export and import viewstates and ratings.
I was able to export as described in this resource, however upon inspecting the resulting file I wonder if I’ll be able to import it.

1 line of output (redacted numbers with X):
INSERT INTO metadata_item_settings VALUES(1,1,‘com.plexapp.agents.xbmcnfo://ttX?lang=xn’,NULL,NULL,X,X,X,X,0,NULL,X,NULL,NULL);

com.plexapp.agents.xbmcnfo:// is the part that worries me.

Are viewstates only persistent for the same agent? Or can I install the latest version of Plex Server, use different agents and then still import the viewstates without issues?

Yes.

The only way to migrate viewstate, is when converting a library which uses one of the official Plex “legacy” movie or series agents over to the modern Plex agents.

com.plexapp.agents.xbmcnfo://ttX?lang=xn is the “identity” of the media file.
Plex cannot know the identity of an item that was matched with a 3rd-party agent.
So there is no connection between an item in your old library and what it would be matched to with the official Plex agents. Hence the old view states cannot be assigned to items in libraries which use the official agents.

What would the identification look like for one of the official Plex agents? Does it use arbitrary IDs or (like the xmbc agent) IDs that are based on an “official” ID that uniquely matches a movie/episode (ttX in this example line was an imdb-ID)?

If it’s the latter, might I be able to conform the syntax via regex? All my movies and tv-shows have local .nfos I created in tinyMediaManager and thus have such IDs associated with them (both in the .nfos as well as in the file-/foldernames).

guid=“plex://movie/5d776d1647dd6e001f6efd1f” for movies
guid=“plex://episode/65dd8df0f97685e8c5508c8a” parentGuid=“plex://season/619e00f4aedbcfb09cc0861f” grandparentGuid=“plex://show/5d9c07fe2df347001e3a7d17” for series’ episodes

The Plex media info XML of items matched with the modern agent already contains matching hints like

<Guid id="tmdb://1004864"/>
<Guid id="tvdb://101884"/>

While that may help in many cases, it won’t always.
Particularly when you have mini series within a “movies” type of library (the plex agent will only match them in a series library),
or when you have a series as a separate entity, while it is appearing as a new season of an already existing series in TMDB/TVDB.

If you can devise a way of reading the IMDb, TMDB, or TheTVDB ID from your nfo files, and then put them into the folder names of your movies and series, it would probably the best solution. But it will only help with matching as such. It won’t help with assigning the old view state. The modern Plex agents don’t access nfo files at all.
The syntax for this is
{imdb-tt0114746} (curly brackets!)
{tmdb-60948}
{tvdb-82}
You can use tmdb or imdb in movie libraries,
and tmdb or tvdb in series libraries.

Is there an api that returns the plex guids when queried with an imdb-id or tvdb-id?

It doesn’t have to be perfect but I’d like to retain the majority of the viewstates of the thousands of watched movies from 2017 till a month ago if I can. Losing the viewstates of tv-shows isn’t that important to me (it’s way easier to remember if I’ve already watched a tv-show).

That’s already present in my library (except for the fact that I used square brackets). Please don’t tell me the people at Plex are incapable of writing a regex that matches curly or square brackets (took me literally 5min to come up with this regex that matches all provided examples and returns them cleaned up).

Example movie:
Der Blade Runner (1982) [imdbid-tt0083658] {edition-Final Cut}

Example tv-show:
Blade Runner_ Black Lotus (2021) [tvdbid-356155]

Running grep -o ‘com.plexapp.agents.xbmcnfo://tt’ settings.sql | wc -l

against the settings.sql export returns 3765 watched movies with associated imdb-ids.

Turning:
INSERT INTO metadata_item_settings VALUES(1,1,‘com.plexapp.agents.xbmcnfo://ttX?lang=xn’,NULL,NULL,X,X,X,X,0,NULL,X,NULL,NULL);

Into:
INSERT INTO metadata_item_settings VALUES(1,1,‘guid="plex://movie/X"’,NULL,NULL,X,X,X,X,0,NULL,X,NULL,NULL);

and then importing this in the new installation ought to work, or am I missing something (assuming that imdb-ids can be looked up and translated into plex guids)?