If you have items that seem to have been stuck forever in Plex’s “Recently Added” lists, editing the Plex database directly is the surest way to correct the problems. We’re going to use a combination of tools to determine what the problem is, and to correct it:
A MySQLite database editor:
An Epoch Unix Timestamp converter:
https://www.epochconverter.com/
Windows Terminal (from the Microsoft Store) or the Command Prompt
The most likely reason for something to be perpetually in a Recently Added list is the value that was used for the “date added” is in the future. To determine if that’s the case for you, we’re going to take a look at the XML for a movie or TV Show. From the Plex webpage, click on one of the problem items in “Home – Recently Added”, and then click on the three dots near the thumbnail for the item:
From there we want “Get Info”, and then “View XML”. View XML gives us a look at what’s stored in the database for that media item:
In particular, let’s look at “addedAt=”, which will be in Unix Epoch Time format. Copy the number and paste it into the Epoch calculator referenced earlier in this post. Does this time make sense? In my case all of my problem items had dates well into the future. If this item needs fixing you’ll want to jot a number or two down, including “key=”, “parentKey=”, and “grandparentKey=” for tv shows — and you only need the numerical portion. For movies, “key=” is all you need.
Next let’s open the MySQLite browser you installed earlier, and click on “Open Database”. Browse to:
%USERPROFILE%\AppData\Local\Plex Media Server\Plug-in Support\Databases
and open:
com.plexapp.plugins.library.db
Click on “Execute SQL” and let’s try a few queries. We’re not going to change anything through this interface, we’re just going to look at the data and test our logic for any changes we want to make. Don’t save any changes when you exit this application! The opened database should look like this:
and like this in “Execute SQL”:
The most basic query we’ll use is:
select * from metadata_items
Copy and paste the into the SQL box, press the Play icon, and you should get a full list of your database:
Let’s say from earlier analysis of the XML data that an episode with an ID # (from key=) of 6137 is the one we need to fix. We can now execute a more limited query of:
select * from metadata_items
where id = 6137
Press the play icon and the result should be just the episode we want to modify.
Now would be a good time to close Plex Media Server, by right clicking on its icon in the System Tray and clicking close. You might also want to make a backup of the database file we opened, if you haven’t already done so.
Since Plex no longer allows certain types of operations through a generic MySQLite browser. We’ll keep the DB browser open so we can check our work, but we’ll need a Command Prompt window open as well to execute commands using Plex’s included MySQL binary. I’ll be using Windows Terminal to open a command prompt, but you can also just run “cmd” from the Windows search box.
We’ll be issuing commands from the command prompt in the following fashion:
"Plex SQLite.exe" "com.plexapp.plugins.library.db" "MySQLite commands"
We’ll be putting in the full path for the exe and db files though. Let’s try the same command we executed in the DB browser looking for just the one problem video:
"C:\Program Files (x86)\Plex\Plex Media Server\Plex SQLite.exe" "%USERPROFILE%\AppData\Local\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db" "select * from metadata_items where id = 6137"
The result is not as easy to follow as the DB browser output, but at least we know everything is working properly from the command line. The easiest way to update a record that has an “addedAt” in the future, is to change that date to match the “originallyAvailableAt” date. The syntax, using our same example file, would be:
"C:\Program Files (x86)\Plex\Plex Media Server\Plex SQLite.exe" "%USERPROFILE%\AppData\Local\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db" "update metadata_items set added_at = originally_available_at where id = 6137"
Execute that, using your own “id=” of course, and if it’s successful you’ll just get a new command prompt. However, you can go back to the DB Browser window, and do a query on that same record to see that the added_at value has changed to match the originally_available_at value.
Using these same commands, you can also change entire seasons at the same time, using the “parent_id=” variable instead of “id=”, and the appropriate number from an XML search. For now though, restart Plex Media Server, and you should see that your troublesome “Recently Added” item is no longer stubbornly at the front of the list!
If you have a large number of items that need to be modified, you should be able to use:
"C:\Program Files (x86)\Plex\Plex Media Server\Plex SQLite.exe" "%USERPROFILE%\AppData\Local\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db" "update metadata_items set added_at = originally_available_at where added_at >= date('now')"
Always a good idea to test in the DB browser first though, and you would check this would only impact the records you want to modify by using the following in the DB Browser first:
select * from metadata_items
where added_at >= date('now')
If the desired records are shown in the browser, you can execute the command line update with confidence.
Thanks for your help guys…this is working fine
Thank you!
Running an update statement isn’t possible without first removing the two triggers fts4_metadata_titles_before_update_icu
and
fts4_metadata_titles_after_update_icu.
After removing the triggers you can run the update statement.
The Plex database has triggers that prevent editing tables.
If you don’t remove the triggers, you’ll get this error when trying to execute an update:
Execution finished with errors.
Result: unknown tokenizer: collating
Thanks for the feedback. I’m guessing you missed the part of the post where I’m using Plex’s custom version of SQLite.exe to actually modify the database. This eliminates the need to remove and re-add triggers — which would be required using any generic tools. Any SQLite browser can be used to view the data, then “Plex SQLite.exe” to make changes.
then put the triggers back:
CREATE TRIGGER fts4_metadata_titles_before_update_icu BEFORE UPDATE ON metadata_items BEGIN DELETE FROM fts4_metadata_titles_icu WHERE docid=old.rowid; END
CREATE TRIGGER fts4_metadata_titles_after_update_icu AFTER UPDATE ON metadata_items BEGIN INSERT INTO fts4_metadata_titles_icu(docid, title, title_sort, original_title) VALUES(new.rowid, new.title, new.title_sort, new.original_title); END
As above, this is not required when using Plex’s included SQLite.exe tool.
I recently had three movies stuck in recently added. Upon closer inspection of all date attributes on the .mkv, .sub & .idx for each movie, discovered that the modified date was set to 2097. Using a file attribute editor to set modified date to a date in the past might be all that is need to resolve the “stuck” issue. They won’t disappear from the list immediately but should now age as normal.
There might be some other situations that can be fixed as you describe, but for this particular issue the “added_at” date is stored in the Plex database — not in the file attributes.
For what it’s worth, I had a TV season with 25 episodes saved as added in 2097 and I simply fixed it by using the Plex SQLite command tool and the following query:
“update metadata_items set added_at=1693447571 where added_at > 4000000000”
The entire TV season in question vanished from Recently Added right away.
Oh and now I see you did the same in the bottom of the article .. 🙂
You should move it to the top as TL;DR for the numnumbs such as me ..