Thanks to @DFox for making this script and instructions
A simple script and a process to automatically keep my Media Center’s recorded TV, MCE Buddy converted files, and those files on my Surface RT all in sync, including when I’ve watched it on my Surface.
There are two files required that you can download from here:
The script and process is simple, but I figure I’d describe all of the details below.
In summary, on the target device you need to import the Windows Scheduled task “Sync TV” and the “PurgeWatchedTV” script. I exported this Sync TV job. Let me know how I can send you these two text files.
High Level Workflow:
I have my Media Center computer (PC name is “MediaCenter”) recording TV to the location “Recorded TV”. MCE Buddy converts these files (to mp4 in my case) into a folder called “Converted TV” on that same PC. On my Surface RT every time I logon it copies the delta of files from Converted TV to the SD card folder “TV” and removes any that have been removed from Converted TV. When I am away from home and after I have watched a show on my Surface, I move that file to a folder called “Watched TV” on the SD. When I come home and logon to my Surface it deletes the files from Watched TV, Converted TV, and Recorded TV with the Sync TV scheduled task and “PurgeWatchedTV” script.
- MCE Buddy file rename must include " ;" and then the original file name. I think the script also assumes no files on the root; i.e. it needs to have subfolders for the show names and Movies. For example, mine is:
%ismovie%<Movies\%showname% ;%originalfilename%,%showname%\S%season%##E%episode%## - %airyear%_%airmonth%_%airday% - %episodename% ;%originalfilename%>
- MCE Buddy configured to keep files in sync.
- Shares setup for Homegroup on the hosting PC for Recorded TV and Converted TV. In my case \\MediaCenter\Recorded TV and \\MediaCenter\Converted TV.
- A folder on the tablet/laptop that contains the folder for the TV files, the script file, and a dedicated subfolder called “Watched TV”. In my case I have D:\TV and then D:\TV\Watched TV and D:\TV\TV.
- Scheduled Task called “Sync TV” configured on the tablet/laptop.
“Sync TV” Scheduled Task details:
Runs PurgeWatchedTV script. This script deletes any files in the Converted TV share that exist on the local D:\Watched TV folder, along with any empty folders. It then deletes the corresponding original .wtv file in the Recorded TV share.
Runs robocopy mirror command between \\MediaCenter\Converted TV and D:\TV\TV.
The PurgeWatchedTV script also deletes any orphaned files between the Recorded TV and Watched TV. Sometimes this would happen for me if I happen to delete a show on my Media Center while the file is converting. In that case MCE Buddy doesn’t automatically remove the converted file. This script will check for any files where if it exists in Converted TV but not in Recorded TV it will delete it from Recorded TV.
The scheduled task is configured to only runs when it is on the home network. If this is not set then whenever you connect to a network while you are away it will attempt to run Sync TV. The problem would be that the robocopy command will attempt to retry on its own and never time out. I want it to behave that way on my home network, but not run at all while I am away. Fortunately this is a setting within Windows Scheduled Tasks.
- The Media Center PC name and share. If they are different than what I have above you will need to modify the PurgeWatchedTV script with your share paths, as well as the path in the robocopy command in the Sync TV task.
- The converted TV file format. If it is not mp4 then you will need to modify the PurgeWatchedTV FileExtension variable.
- The target device’s local storage path. If different then again modify the robocopy command and PurgeWatchedTV.
- Specify the type of OS in the Sync TV task during import. I’m not sure if this makes a difference, but good practice in any case.
- The user name that runs the task in Sync TV. When you import the task you need to specify the user name on the first screen. It should be you, assuming you have administrator rights on your own device.
- Your home network name in Sync TV task. When importing the task, under conditions specify the name of the home network you connect your device to. In my case my home network is the same as my WiFi.
- The Sync TV task runs only at logon. No problem for me because every night I power my Surface off. You could customize or add other scheduled tasks, like to run during a specified schedule or on wakeup, but I haven’t testing it. Also note the other potential limitations below with other types of tasks.
- The network needs to be fully initialized. Because the Scheduled Task is specified to only run on a particular network by design, the device needs to be fully connected to that network. The issue arises when my Surface boots up it takes about a second to connect to the WiFi. If the logon process happens prior to the connection then Sync TV doesn’t run. I have to enter a pin to logon (Exchange policy) so this is not a problem for me because by the time I unlock and enter my pin it has connected to Wifi. There are settings in Windows that you can require a network connection prior to logging on. I have successfully configured this using group policies on a corporate domain, but I couldn’t manage to get this to work with local policies on my Surface. I didn’t troubleshoot too much because my setup works fine, but you might want to look into this if you have automatic logon or have the scheduled task on a time schedule.
- Obviously during the copy process it needs a persistent network connection. However it doesn’t appear that Windows RT considers the command prompt copy as active and eventually the network goes to sleep. This interrupts the robocopy and it just sits there and waits for the network to come back. That’s the other reason I have the task to run on logon because that is usually when I am planning on using it, giving it enough time to finish the copies. This is also why with the default config a Scheduled Task at a specified time probably doesn’t work because the network won’t be active. You could probably configure the network to stay active but then you would have a battery performance hit. You could also probably get fancy and have the scheduled task wake the network up, run the task, then put it back to sleep if it was sleeping prior to the job, but again I haven’t bothered because it’s not needed for my usage.
- I’ve only tested this on Windows RT but it should work on Windows 7 and 8.
- Viewing and managing these video files doesn’t work well using the Windows 8 Video app: it’s not organized into folders, it truncates the file names, and you can’t manage the files to move them into the Watched TV folder. And viewing them using the Desktop Windows Explorer is a bit clunky (in RT 8.0). Therefore, I use this app “My Explorer”, and set a favorite to the D:\TV\TV folder:
Get My Explorer - Microsoft Store
- I literally typed this script using Notepad on the touch screen on my Surface, so I didn’t bother with much exception handling and it’s not that optimized, but since it runs on the local LAN the script runs fast enough other than the actual copy.