Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickstarkloff/0b1a4b9615fa5e6d510c62eea2f38429 to your computer and use it in GitHub Desktop.
Save nickstarkloff/0b1a4b9615fa5e6d510c62eea2f38429 to your computer and use it in GitHub Desktop.
Fix incorrect recently added items in Plex

Fix incorrect recently added items in Plex

Sometimes Plex saves a addedAt date in the future, in which case the item will always be stuck in the first position.

With this method you don't have to edit the database directly or shut down the server. You can fix it directly in the browser.

Fix the wrong date value

  1. Open your browser's developer tools
  2. Navigate to the console tab
  3. Adjust the following command and paste it into the console
var plexHost = "https://plex.domain.com"
var plexToken = "XXXXXXXXXXX"

var sectionId = "1"
var itemId = "12345"
// 1 for movie, 4 for episode
var typeId = "4"
// unix timestamp
var addedAtValue = "1672527600"

fetch(
  `${plexHost}/library/sections/${sectionId}/all?type=${typeId}&id=${itemId}&addedAt.value=${addedAtValue}&X-Plex-Token=${plexToken}`,
  {"method": "PUT"}
)

Get Plex token / Get item metadata

Unix timestamp conversion

@cweakland
Copy link

I attempted to do this today, and the web response comes back with:
Promise { : "pending" }
​: "fulfilled"

However, the change does not show up in the database. What am I missing?

@paulkoan
Copy link

paulkoan commented May 2, 2024

However, the change does not show up in the database. What am I missing?

I mistakenly used the media ID from the XML, it worked once I used the right ID, which you can get from the URL when you view XML.

@rjsears
Copy link

rjsears commented Jul 20, 2024

I tried this, but I am getting an error that says:

"Refused to connect to https://x.x.x.x/library...... because it violates the document's security policy."

Any idea how to get around this?

Also, what is the actual itemID out of the XML?

Thanks

@brijazz
Copy link

brijazz commented Mar 9, 2025

@paulkoan I'm having the same issue as @cweakland - which part of the URL (when viewing XML) shows the item ID?

@brijazz
Copy link

brijazz commented Mar 9, 2025

@rjsears Did you manage to find the itemID? My command is running fine in console, but no changes are being reflected in my library, so I'm thinking I'm using the wrong value.

@cweakland
Copy link

@paulkoan I'm having the same issue as @cweakland - which part of the URL (when viewing XML) shows the item ID?

I gave up on this and do this instead, here are my notes:


SSH into the Plex server:

service plexmediaserver stop

See all movies by ID, the newly added ones will be on the bottom:

/usr/lib/plexmediaserver/Plex\ SQLite "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "select id,title from metadata_items where library_section_id = 1 and metadata_type = 1"

Example:

62051|Looney Tunes Mouse Chronicles: The Chuck Jones Collection
62184|Star Wars: The Force Awakens
62234|Once Upon a Deadpool
62245|The Hobbit
62287|Oliver and Company
62333|Inside the Labyrinth

Update a title, be sure to set the time correctly: https://www.epochconverter.com/

Manual time set:
/usr/lib/plexmediaserver/Plex\ SQLite "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" \
"UPDATE metadata_items SET added_at='1700065734' WHERE id = 59384"

Have added_at match originally_available_at:
/usr/lib/plexmediaserver/Plex\ SQLite "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" \
"UPDATE metadata_items SET added_at = originally_available_at WHERE id = 62184"


See all TV shows by ID, the newly added ones will be on the bottom:

/usr/lib/plexmediaserver/Plex\ SQLite "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "select id,title from metadata_items where metadata_type = 4"

/usr/lib/plexmediaserver/Plex\ SQLite "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" \
"UPDATE metadata_items SET added_at = originally_available_at WHERE id = 62447"

@brijazz
Copy link

brijazz commented Mar 9, 2025

Thanks for the quick reply, @cweakland. I was able to get the original instructions to work - I had the item ID correct but had forgotten to change the section ID! Once I did that, everything worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment