How to stop Kodi from importing Mac resource forks from SMB shares.

I am using Kodi (previously XMBC) on one of my Raspberry Pi as a small media centre. This is serving videos from my old SAN where I store and share my backed up DVD's via SMB. This works great except for one small problem. My Mac. Normally Mac's store a resource fork in another section of a file on a Mac filesystem (MFS, HFS and HFS Plus). It uses this to store metadata about the file. As SMB drives don't support resource forks this is performed using a file that looks like ._filename where filename is the name of the original file. By default Kodi picks this file up at scan time and thinks that it is a video file so it adds the TV-Show or Movie twice with only the one file working. This is annoying as you have to manually delete the wrong entry.

To get around this you can use the advancedsettings.xml file to stop Kodi from picking up these files when it does a scan.

Create or add the advancedsettings.xml with the following:

<advancedsettings>
	<video>
		<excludefromscan> <!-- Regular expressions that if evaluated to true won't be added to library. -->
			<regexp>[-\._ ](sample|trailer)[-\._ ]</regexp>
			<regexp>[-\._ ](sample|trailer)[-\._ ]</regexp>
			<regexp>\/\._</regexp>
		</excludefromscan>
		<excludetvshowsfromscan>
			<regexp>\/\._</regexp>
		</excludetvshowsfromscan>
		<excludefromlisting>
            <!-- Regular expressions that if evaluated to true won't be displayed in Files View -->
			<regexp>[-\._ ](sample|trailer)[-\._ ]</regexp>
			<!-- <regexp>/\._</regexp> -->
		</excludefromlisting>
	</video>
</advancedsettings>

After this add your libraries. This will stop Kodi from pickup up anything that starts with ._ and also the word sample or trailer (for good measure).

If you do this after you have added your files to your library then you will still have to delete the entries manually but at least it won't add any new ones.