r/PleX•
TopSecretSpy

How to change the date on added media so it sorts correctly in recently added.

Tips

I recently had the fun of re-integrating a large amount of media I had deleted locally but had backed up in the cloud back into my Plex, due to expanding my drives and Amazon raising their prices for cloud storage.

I didn't want all of it to clog up the "recently added" list, so I researched how to modify the added date so that media will sort properly in the "recently added" sections. I wanted to share the method, in case anyone else wished to do the same.

So, first off, I use a Synology NAS, but this technique will work for any system where you can get a Linux shell with SQLite3 installed. If using Synology, a tool like PuTtY works fine and SQLite is already installed. If not, Windows Subsystem for Linux (I tested Ubuntu) works as well (as does being on a normal Linux box), as long as you make sure SQLite3 is installed.

(Note if using Synology, you will need to SSH via PuTtY using an account in the administrators group, then use "sudo -i" to switch to root.)

To install sqlite, if necessary:

$> apt-get sqlite3

So, next we need to find where Plex is installed. You may have to find the root yourself, but once you find it, navigate to the following in your terminal (for Synology, it's usually in "/volume1"):

$> cd [Your Plex Root Folder]/Plex/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases

I highly recommend making a backup of the database, just in case, but the change I'm making is low-risk, so I'm going to just assume that someone reading this either did the backup or is comfortable with pressing forward.

Anyway, from here, you can run SQLite on the correct file, via the following command:

$> sqlite3 com.plexapp.plugins.library.db

You should be in the terminal application for SQLite now. From here, we need to use simple SQL commands to modify the DB. If all we want to do is set the dates on all items, we can do that with a single command:

$> UPDATE metadata_items SET added_at = originally_available_at WHERE added_at > '2000-01-01' AND originally_available_at < '2020-01-01';

The upper-case isn't necessary; it's just the customary style used by most SQL programmers. The key is to ensure the proper table (metadata_items), columns (added_at and originally_available_at), and syntax. Single-quotes are important, as is the semicolon at the end. If you wanted to narrow to items added after a specific day, such as only a recently-added batch, you can modify the added date accordingly.

There are, of course, many other ways to narrow down the edit to a much more specific point, but this one will clean up the entire library in one shot, and simplicity is often its own virtue.

Once done, you can exit with the following (the period is important to signify a command in SQLite):

$> .exit

A few more "exit" commands (without the period) and the terminal should quit. If you haven't restarted Plex, it can take a while for the changes to show, but if you stop/start Plex they should show right away.

Note, one common problem I had was that media that Plex was unable to match properly wouldn't have an "originally available" date, and thus wouldn't get edited by this. This was a big problem when importing the reconstructed episodes of the old Doctor Who, as well as "specials" episodes from several series. I found that loading up Plex in a web browser, showing the episodes library by episode instead of by show, and enabling the column in the list for the original date allowed me to find and fix those dozen or so more efficiently than hunting through the DB, but that's because TV episodes don't actually contain the name of the show in the DB entry (there's a separate entry for the show as a whole, apart from its episodes, and that's where the show name is held). Once I had manually edited the episode to add an original date, I was able to use the above to sort them properly.

That's it! It seems challenging (to the non-technical, at least) but it's surprisingly easy. I'd be happy to help with people needing further advice on doing this for themselves (and to help make sure they don't make any larger changes that could mess things up). Examples include looking for specific movies/TV Shows, or singling out a specific library to be updated.

Posted Dec 30, 2017, 1:59 AM UTC · edited

161
Undeadllama27E5-2630v3 | 80GB DDR4 | 155TB FreeNAS | 1000/1000 FTTP•

While this isn't something that usually bugs me enough to go to these lengths (as new stuff usually filters through after a few days or so and drops into the front end of 'Recently Added') it's certainly interesting to know.

As someone who's previously gone hunting within the Plex DB to make changes to other bits I definitely appreciate the effort that you've put into figuring this out for everyone!

1
M4V3TH•

Thank you for this, i lost my database and had to rebuild it. I found it very useful in it getting it looking somewhat back to normal. As said above, after a little bit of time has passed it will never be known by anyone as being in error.

1