Path Substitution Strategy

I’m planning on moving media files from several mounted volumes to something else TBD (probably one large volume on a NAS). I read this ([HowTo] Repairing File Paths with Path Substitution). It explains that:

If you’re going to use path substitution it is important that you DO NOT update your source paths, or add new ones that point to the new location. If you want to do that, do not use path substitution.

So to clarify then, I would use the old source forever more? (even though the old source is the LAN name of a Mac no longer in use?) And any media added thereafter would be added to the database with a path in reference to the old source?

Is there another way? Substituting all database entries with a new partial path, then changing the source to the new one?

Yes

If you know how to manually edit a database then sure, have at it. I’m not going to suggest such a thing and nobody here is going to provide any support for that not going well.

You always have the option of just dumping everything and starting over. I’m of the opinion that this is stupid and unnecessary in this kind of situation. Path substitution works fine and is just a matter of adding a couple lines to one xml files. Kodi doesn’t look any different when you do this so why worry yourself about how the file paths are stored in the database?

ok thank you very much. so, then:

• how do you browse the new source – from the root – if you don’t / can’t add it as a source?

• can you have multiple path substitutions set in advanced settings? for instance, right now i have a single source, “nfs://192.168.0.n”, and all the paths look like:

nfs://192.168.0.202/Volumes/VolumeA/Video [VolumeA]/path (where there are multiple volumes A,B,C etc.)

now as I want everything on one volume:

nfs://192.168.0.202/Volumes/NewBigVolume/Video [Volume A]/path
nfs://192.168.0.202/Volumes/NewBigVolume/Video [Volume B]/path
etc.

so it would have to be a different from/to for each volume, as far as i can figure here.

Your sources.xml has paths that then get used for browsing in videos>files mode as well as what gets used by the scraper. When you scrape content into your library full file paths get stored in your database pointing to the content. When you use path substitution when Kodi prepares to call up a file path it looks for a matching substitution and simply changes the file path it using according to what you told it to do. You can think of it like a find and replace function in a word processor.

Kodi will look and act exactly the same. Your not making a new source or touching the existing source at all. That is kind of the point. If you made a new source, or edited an existing source, that has your existing content then Kodi will then add all of that media into your library a new duplicates of the old. At this point you would have been better off removing everything and starting over. If you decide to add an additional source that has content that isn’t in your existing sources then you can choose to add it using the actual file path or the old one that is path subbed. It really doesn’t matter much since Kodi will end up in the same place. My personal preference would be to use the same main file path always though as if you end up having to change a file path agin in the future because your subnet changed or something I would rather just modify my existing path sub rather than have to remember that I used multiple base addresses and account for them.

My guide literally has an example of a multiple path sub advancedsetting.xml. If you take write down a full UNC path to a video file in your current location and then manually remove the part you listed as “from” and swap in the part you put into “to” then you have a new UNC path. If this path is valid and where your files got moved to then your golden. I don’t say this to be flippant. It may be easier to visualize what your doing if you actually write down example file paths and run the text swap to see the effect.

from: nfs://192.168.0.202/Volumes/VolumeA/
to: nfs://192.168.0.202/Volumes/NewBigVolume/
from: nfs://192.168.0.202/Volumes/VolumeB/
to: nfs://192.168.0.202/Volumes/NewBigVolume/

Transforms these (I added brackets to highlight the substituted part)…
[nfs://192.168.0.202/Volumes/VolumeA/] [Video/movies/test/test.mkv]
[nfs://192.168.0.202/Volumes/VolumeB/] [Video/movies/test2/test2.mkv]

To these paths…
[nfs://192.168.0.202/Volumes/NewBigVolume/] [Video/movies/test/test.mkv][nfs://192.168.0.202/Volumes/NewBigVolume/] [Video/movies/test2/test2.mkv]

ie you moved from two old subfolders to a new “movies” folder which has both moves in it.

EDIT: DON’T do the part that I lined out above. I had overlooked the fact that the original source paths would then see all the media that was now in the same folder so it would add a bunch of duplicates. If you want so combine content from more than one location that has been scraped into a new combined folder a new library would be the correct option.

1 Like

Just as an FYI, I tried this once because I’m on the Kodi dev team and I Knew It Would Work.

It didn’t. I updated the database, then I deleted the old source and added the new one. And then Kodi scanned everything again and I had two copies of every video file. I nuked the entire database and rescanned everything.

Don’t do this. Seriously. Just don’t.

2 Likes

I misspoke in my earlier post about being able to do an easy path sub combining two folders into one. Don’t do that, it doesn’t work without a full library rebuild. But in the situation being questions where one has two different sources on smaller drives that they want to move to a larger drive the quick and easy (easy-ish depending on your skill level) way would be as follows.

Sample original setup
nfs://192.168.0.202/Volumes/VolumeA/Video/Movies/
nfs://192.168.0.202/Volumes/VolumeB/Video/Movies/

You move these folders on the source to…
nfs://192.168.0.202/Volumes/NewVolume/Video/MoviesA/
nfs://192.168.0.202/Volumes/NewVolume/Video/MoviesB/

You add an advancedsettings.xml file that looks like this…

<?xml version="1.0" encoding="utf-8"?>
<advancedsettings>
	<pathsubstitution>
		<substitute>
			<from>nfs://192.168.0.202/Volumes/VolumeA/Video/Movies</from>
			<to>nfs://192.168.0.202/Volumes/NewVolume/Video/MoviesA/</to>
		</substitute>
		<substitute>
			<from>nfs://192.168.0.202/Volumes/VolumeB/Video/Movies</from>
			<to>nfs://192.168.0.202/Volumes/NewVolume/Video/MoviesB/</to>
		</substitute>
	</pathsubstitution>
</advancedsettings>

And at this point Kodi will look and act exactly as it did before.

On a not really related, but almost touched on topic, if you want your sources in Videos>Files to show as being all in one place you can actually do this without it impacting scraping. If you add a different source for each path then they will show up separately. You can instead add more than one path to a single source and Kodi will show them as if they are all in the same folder. You can do this in the UI but I think it may be a bit easier just manually editing sources.xml. In the above example we might have a sources.xml that looks like the following (it is going to have more stuff in it but I omitted it here to make the post smaller)…

<sources>
    <video>
        <default pathversion="1"></default>
        <source>
            <name>Movies A</name>
            <path pathversion="1">nfs://192.168.0.202/Volumes/VolumeA/Video/Movies</path>
            <allowsharing>true</allowsharing>
        </source>
        <source>
            <name>Movies B</name>
            <path pathversion="1">nfs://192.168.0.202/Volumes/VolumeB/Video/Movies</path>
            <allowsharing>true</allowsharing>
        </source>
    </video>
</sources>

The preseeding would show up as two sources titled “Movies A” and “Movies B”. If you modified it like the following…

<sources>
    <video>
        <default pathversion="1"></default>
        <source>
            <name>Movies combined</name>
            <path pathversion="1">nfs://192.168.0.202/Volumes/VolumeA/Video/Movies</path>
            <path pathversion="1">nfs://192.168.0.202/Volumes/VolumeB/Video/Movies</path>
            <allowsharing>true</allowsharing>
        </source>
    </video>
</sources>

This would show up in Kodi as a single source titled “Movies Combined” and when you navigated into it everything in both folders would be intermixed as if they were the same source. As long as you don’t change the file paths then scraping will not be affected.

1 Like

Thank you so much for the detailed update. i will study this all closely soon when i actually begin the migration.

1 Like