Is this out-dated? I ran the scripts, and I can play moved media files in Plex, but when Plex scan it deletes the old entries and adds them anew.
In my case, I got a new hard drive and moved my .mp4 files to it (didn’t see I was supposed to copy and not move until now)
Scripts:
insert into section_locations
select 19 as id, library_section_id, 'G:\Movies' as root_path, available, scanned_at, created_at, updated_at
from section_locations
where root_path = 'F:\Movies';
UPDATE metadata_items
SET guid= replace(guid, 'F:\Movies\', 'G:\Movies\')
where guid like '%F:\Movies\%.mp4';
UPDATE media_parts
SET file= replace(file, 'F:\Movies\', 'G:\Movies\')
where file like '%F:\Movies\%.mp4';
UPDATE media_streams
SET url= replace(url, 'F:\Movies\', 'G:\Movies\')
where media_item_id in (select media_item_id from media_parts where file like 'G:\Movies\%.mp4');
Yeah, that was the issue…it’s working now. Cheers!
Script:
insert into section_locations
select (select seq from sqlite_sequence where name = 'section_locations') as id, library_section_id, 'G:\Movies' as root_path, available, scanned_at, created_at, updated_at
from section_locations
where root_path = 'F:\Movies';
update sqlite_sequence
set seq = seq + 1
where name = 'section_locations';
UPDATE metadata_items
SET guid= replace(guid, 'F:\Movies\', 'G:\Movies\')
where guid like 'F:\Movies\%.mp4';
UPDATE media_parts
SET file= replace(file, 'F:\Movies\', 'G:\Movies\')
where file like 'F:\Movies\%.mp4';
UPDATE media_streams
SET url= replace(url, 'F:\Movies\', 'G:\Movies\')
where media_item_id in (select media_item_id from media_parts where file like 'G:\Movies\%.mp4');
update media_items
set section_location_id = (select id from section_locations where root_path = 'G:\Movies')
where id in (select media_item_id from media_parts where file like 'G:\Movies\%.mp4');
if you want to move media to an other location and you want to keep your items in PMS library intact (with all of your manually edited metadata) follow these steps:
create an empty new folder where you will migrate your media
add that newly created folder to the library (after you’re done it will automatically scan that empty folder)
move (do not copy!) media to that new folder
scan
done
the trick is that you can move around media files among those folders as long the folders are indexed in the library and you respect folders-subfolders structure.
i’m not sure why this method is not an official plex method, it works flawlessly.
thanks, using the methods above, I was able to go into the metadata section, find the creation and added dates and then I was able to back date a few movies that I did not want showing up on the main page as newish movies.
steps
Downloaded the SQL viewer in the post , shutdown the plex server, open the database, found the metadata section and movie names, found the added date, modified the added date, modified the creation date as well just to make sure some code somewhere did not object to one being before the other???. wrote the database, opened the server, checked in the browser and sure enough the movies jumped further back in time. Wha la. I can now go add all those old embarrassing movies with them showing up in library (sharing with parents) as just added.
Will wait a day or two before doing the rest to make sure the over night updates dont just move them right back.
Thank you @DavidIrwin that totally worked for moving one of my libraries to a new different drive and keeping the ‘watched’ data for my managed users! So glad i landed on this before i tried the Plex Support ‘mode media content to a new location’. Thank you so much, manually putting each file as ‘watched’ would’ve been a real pain!
I can now confirm the steps outlined by @levander in post number 43 about adding the empty directory to the library that you are planning to move your media to first, then moving (not copy) the files to the new directory then scanning the library… Worked like a charm and easier than editing the database… Thank you!!!
I had a similar need. I wanted to merge libraries. The actual location of the media was staying the same. I used sqlite browser. I looked at the table ‘library_locations’ to find Library B had an id of 21. I wanted to move a folder ‘/mnt/tv/animated’ to Library A which had an id 2.
What it was:
Library A (library_section_id = 2)
/mnt/tv/normal
Library B (library_section_id = 21)
/mnt/tv/animated
What I wanted:
Library A (library_section_id = 2)
/mnt/tv/normal
/mnt/tv/animated
Library B (library_section_id = 21)
Stopped plex. Backed up the db file. Updated the following tables. Started plex. All the metadata and watched state was still correct.
UPDATE section_locations
SET library_section_id = 2
WHERE
library_section_id = 21
UPDATE directories
SET library_section_id = 2
WHERE
library_section_id = 21
UPDATE media_items
SET library_section_id = 2
WHERE
library_section_id = 21
UPDATE metadata_item_views
SET library_section_id = 2
WHERE
library_section_id = 21
UPDATE metadata_items
SET library_section_id = 2
WHERE
library_section_id = 21
Do the steps in post #43 only work if you keep the original directory in the library? In my case I’ll be changing from two old external drives to one new external drive, and removing those external drives from my system. Would this method still work for me?
All three drives will have to be attached to start and as long as your operating system doesn’t change the path to your external drives when you remove the old ones… If it does, it doesn’t make it imposable but much more difficult…
Once you are done with the steps outlined you can remove the old, now empty original directory, from your Library. Then you may delete or remove the directory or drive from your system…