Duplicate films following NAS move - different agents?

Long time Plex Pass holder and never needed to post before. I recently moved file storage locations, and followed the usual advice for this. ie. Turn off scanning and trash, add new location with the copied library, allow scanning, remove old location once Plex has resolved the duplicates.

But I found I had lots of duplicates! After a bit of head scratching and investigation I beleive that over the last 10 years various Agents/Scanners have been used across various Plex versions, and I think this has caused Plex not to identify the duplicate.

Here is an example XML for the same title on the different locations.

Old Location

<Video ratingKey=“4” key="/library/metadata/4" guid=“plex://movie/5d77687d7e5fa10020bf080d”

New Location

<Video ratingKey=“12358” key="/library/metadata/12358" guid=“plex://movie/5d77687d7e5fa10020bf080d”

I thought I could clear the metadata via a forced scan to regenerate but it seems it does not refresh or update older titles.

I know I can recreate the library and rescan the lot, but I want to retain the Date Added and Watched stats.

I have read many similar posts, for example Plex detecting same Movie as a duplicate movie in the same library - #3 by thirdgen89gta

Is there anyway to force the library to rescan using a single agent? My thought here is if I force the refresh of all the titles using one agent it woudl replace any older titles scanned with an earlier legacy scanner, then when I move file locations it woudl better identify the duplicate.

Sorry for the long post, I had not expected to get into this level of detail to be honest, I thought Plex woudl be able to manage its own backward compatability.

All help appreciated.

CC

Ok - having read a few similar posts I guessed there would be little response, shame, I was hoping for a bit more support as a Plex supporter.

Anyway, I have a few skills, so last night sat down and and started picking away at the plex database. Will post my steps here for anyone else that feels confident enough and wants to retrace these steps. :slight_smile:

I used SQLiteSpy, and opened up a backup I took of the plex database @%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db

So in my case I wanted to restore the Date Added. Plex failed to identify duplicates in my case becasue of the multiple agents used over the last years. This meant much of my library was all recently added.

I planned to take from the file creation time on my media. The two key tables for this seem to be media_items and metadata_items. media_items contains the film titles with the library identifier etc, and these have a key to link to the apropriate metadata_items if I understood things.

In my case I only wanted to update a library at a time. I found I was able to Select on tables but not update without an error - but found by dropping the triggers first, my updates worked fine, creating the triggers once more afterwards.

Selecting only those metadata_items that relate to a film title we want to update. In this case our library is 3.

Count of rows
SELECT count(*) FROM “metadata_items” a where Exists (Select id from media_items where metadata_item_id=a.id And library_section_id=3)

Details of rows
SELECT id, added_at FROM “metadata_items” a where Exists (Select id from media_items where metadata_item_id=a.id And library_section_id=3)

Dropping Triggers on Metadata_items table

DROP TRIGGER fts4_metadata_titles_after_insert_icu;
DROP TRIGGER fts4_metadata_titles_after_update_icu;
DROP TRIGGER fts4_metadata_titles_before_delete_icu;
DROP TRIGGER fts4_metadata_titles_before_update_icu;

The Related Table Update

Update metadata_items
Set added_at = ( Select created_at From media_items Where metadata_items.id=media_items.metadata_item_id)
where Exists (Select id from media_items where metadata_item_id=metadata_items.id And library_section_id=3);

Creating Triggers on Metadata_items table

CREATE TRIGGER fts4_metadata_titles_after_insert_icu AFTER INSERT 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;
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;
CREATE TRIGGER fts4_metadata_titles_before_delete_icu BEFORE DELETE ON metadata_items BEGIN DELETE FROM fts4_metadata_titles_icu WHERE docid=old.rowid; END;
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;

Good luck hope it helps someone. Maybe Plex will fix the library issue and allow a forced metadata update using a single agent - not sure when backward compatability was dropped.

CC

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