Friday, September 30, 2016

Sync media from PC to Plex Server on Nvidia Shield Android TV

I have a Windows 10 PC where I download, edit, and generally keep all of my media (photos, music, videos, tv shows, movies, etc.). I could run Plex Media Server on this PC, but why when I've got an efficient Android device that is always on and could do it just as well, or better?
I have an Nvidia Shield Android TV device with Plex Media Server connected to my living room TV. The issue is getting all my media onto the Shield, and then syncing any subsequent changes. I found the best method is to use a PowerShell script referencing Robocopy. However, there are some key points I've noticed in my experience that I'd like to share.

The first step to using Robocopy with the Shield is enabling Plex Media Server and the network access to the Shield's storage (an SMB or Samba share). See https://shield.nvidia.com/blog/how-to-setup-plex-media-server. The access provided by these credentials is limited. For example, you can't delete a directory if there are files in it. You can only delete empty directories. Another example is that if you instruct Robocopy to overwrite a changed file, the timestamp doesn't change on the Shield, so Robocopy will continue to overwrite the file every time you run the PowerShell script.
Now let's get into the script:
# Mirror music
$MusicSource = 'D:\YourUserName\Music\'
$MusicDestination = '\\SHIELD\internal\Music\'
Robocopy $MusicSource $MusicDestination /xo /mir /MT /fft /timfix /eta 
# Mirror photos
$PhotosSource1 = 'D:\YourUserName\Pictures\'
$PhotosDestination1 = '\\SHIELD\internal\Pictures\'
Robocopy $PhotosSource1 $PhotosDestination1 /xo /mir /MT /fft /timfix /eta

# Mirror tv
$tvSource = 'D:\YourUserName\Videos\tv'
$tvDestination = '\\SHIELD\internal\TV Shows'
Robocopy $tvSource $tvDestination /xo /mir /MT /fft /timfix /eta
 I've defined variables for the source and destination folders.
"/xo" means it will only copy newer files, so anything that you've added since the last sync will get copied over. As mentioned above, if you changed a file on the source, you'll need to delete it on the destination manually so that it can get the new timestamp and avoid being synced over each subsequent time.
"/fft" adds some flexibility for timestamps when copying files from Windows to an Android device.
"/MT" allows Robocopy to copy eight files at a time, reducing the time it takes.
"/mir" means Robocopy will delete files on the destination if they were deleted on the source.
"/timfix" is supposed to fix timestamps, but I couldn't get this to actually work. I think there may be permission issues on the Shield.
Hope you find this useful! I do.

No comments:

Post a Comment