Updating your Plex video source file paths

Today while perusing the forums on the Plex website, I noticed someone inquiring as to how they would go about changing the file paths in Plex for one of the video sources without removing the source and adding it back from the new location.

The reason for wanting to do this is to ensure that your database entry tweaks, fanart settings, etc., are not lost, which is what would happen if you removed the source and it’s library entries.

One of the more interesting parts of the Plex project at the moment is the complete re-build of the database structure and how you work with it.  The existing database structure is fairly poor in it’s design.  There are a lot of cryptic field names, and it is easily corruptible.  The current library system is a hold-over from the old XBMC code base.

Regardless of all of that, the task itself is fairly straightforward and easily accomplished with a little care.

The first thing that you have to note is that this should never be attempted on a live Plex database.  Always do this on a backup.  Secondly, this is not a normal end-user type of operation. And finally, performing such an operation could easily wipe out your data if done improperly.  Also, the steps listed below require a certain amount of “non-average” experience with the Mac OS. If you are not comfortable working at the command line using Terminal, then don’t attempt this.

That being said, here ya go:

1. Make a working copy of the database to test with, never work on the original. The video information database is stored here by default:

/Users/USERNAME/Library/Application Support/Plex/userdata/Database/

2. The name of the video database may vary a little. For instance mine is named:

MyVideos34.db

3. Open the working copy using the built-in SQLite3 installation:

sqlite3 MyVideos34.db

4. At this point you will be presented with the SQLite3 command prompt:

SQLite version 3.6.12
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite>

5. The first thing you should do is to determine what the database has recorded for your current path structure. This information is found in the “path” table in the “strPath” column. So enter the following command and then hit enter:

SELECT strPath FROM path;

6. You should get a lot of output that is similar to the following:

62|/Users/arfore/Pictures/Plexaeon/soundcheck/||||||
 
96|/Volumes/Movies 0001/|movies|imdb.xml||0|0|<settings><setting id="fullcredits" value="false" /><setting id="impawards" value="true" /><setting id="movieposterdb" value="false" /><setting id="trailer" value="true" /><setting id="fanart" value="true" /><setting id="imdbscale" value="512" /><setting id="url" value="akas.imdb.com" /></settings>
 
97|/Volumes/TV Shows 0001/|tvshows|tvdb.xml|A73E600F7EBB57B238351083E2FD8573|0|0|<settings><setting id="fullcredits" value="false" /><setting id="impawards" value="true" /><setting id="movieposterdb" value="false" /><setting id="trailer" value="true" /><setting id="fanart" value="true" /><setting id="imdbscale" value="512" /><setting id="url" value="akas.imdb.com" /></settings>
 
98|/Volumes/TV Shows 0001/Witch Hunter Robin/|||0DBFC8A633052B0CFE252AA91D4283B4|||

It should be plainly obvious, but in case it’s not, each column in the output is delimited by a pipe symbol “|” (no, this is not a lowercase “L” or an uppercase “i”). The first column is an id field. The second column is the path to the file.

7. Now here’ the fun part. Say I have copied all of my TV Show seasons over to my new NAS and I want to change the DB to reflect that.

Below are the two location spots:

OLD LOCATION: /Volumes/TV Shows 0001/

NEW LOCATION: /Volumes/NAS/TV Shows/

8. What you have to do is to execute an update statement using the replace function on the database (and this includes the line about the tvdb data, since that line is used to control the scrapper). Remember that this should never be done on a live db:

UPDATE path SET strPath = REPLACE(strPath, 'OLD LOCATION', 'NEW LOCATION');

Here’s the description of the replace function from the SQLite website:

The replace(X,Y,Z) function returns a string formed by substituting string Z for every occurrance of string Y in string X. The BINARY collating sequence is used for comparisons. If Y is an empty string then return X unchanged. If Z is not initially a string, it is cast to a UTF-8 string prior to processing.

9. Re-run the SELECT statement from step 5 to verify that your change took effect.

10. Quit SQLite:

.quit

Then you will need to quit Plex and backup the unaltered database file and replace it with your newly changed database file. Assuming everything worked your Plex install will now reference your new file structure.

Remember, this is not supported by me or any of the Plex guys. I just was in the same situation and wanted to see if I could figure it out. I successfully did this with no detrimental issues, but your mileage may vary.

4 thoughts on “Updating your Plex video source file paths

  1. Great post… and very helpful. One question (and keep in mind I’m not a database kind of guy): I am consolidating multiple drives onto a Drobo. It doesn’t look like SQLite will allow me to do that. I can successfully change the path of one drive (/Volumes/MOVIE_HD) to the drobo (/Volumes/Drobo/), but not for a second (/Volumes/MOVIE_HD_2/). Is there a way to execute multiple UPDATE statements at the same time? Or am I just missing something very simple? Thanks for your help.

  2. @ steven

    Actually I have run this partciular query several times, each time with a different old location. This was due to having split up my library across multiple external drives.

    In each case the query worked as expected. I have no idea if you can actually run the update commands concurrently or not. I would imagine that to do so would cause data corruption issues, which I imagine is the reason that no one actually developing the core Plex functionality is likely to recommend this particular scenario.

  3. For most cases this solution seems to work rather well, but I’ve run into some issues with simply updating the paths:

    1.) This solution does not work for stacked movies or episodes, as the stacks are not defined in the ‘path’ table, but in the ‘files’ table. You will also have to replace the paths in the ‘files’ table where ‘strFilename’ begins with ‘stack://’

    2.) Plex/Aeon stopped showing Artwork and Thumbnails for TV shows after updating the paths…

  4. thanks for this guide, worked very well for me :-)

    @steven, I had the same problem. the trick to merge into one folder from other folders is:
    first update the OLD paths like:
    /OLDVolume/ folder1/ to /OLDVolume2/folder2/
    /OLDVolume2/folder2/ to /OLDVolume3/folder3/ and finally rename the path of last the new bigger volume
    /OLDVolume3/folder3/ -> /NEWVolume/mergedfolder/.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">