/// <summary> /// generate a playlist /// </summary> /// <param name="control">control file to use to find the destinationRoot, and playlist format</param> /// <param name="copyToDestination">true to copy the playlist to the destination, false to write it locally</param> public void GeneratePlaylist(IReadOnlyControlFile control, bool copyToDestination) { var allDestFiles = control.GetPodcasts().SelectMany( podcast => FileFinder.GetFiles(Path.Combine(control.GetDestinationRoot(), podcast.Folder), podcast.Pattern.Value)); IPlaylist p = PlaylistFactory.CreatePlaylist(control.GetPlaylistFormat(), control.GetPlaylistFileName()); string pathSeparator = PathUtilities.GetPathSeparator().ToString(); foreach (IFileInfo thisFile in allDestFiles) { string thisRelativeFile = thisFile.FullName; string absRoot = PathUtilities.GetFullPath(control.GetDestinationRoot()); if (thisRelativeFile.StartsWith(absRoot, StringComparison.Ordinal)) { thisRelativeFile = thisRelativeFile.Substring(absRoot.Length); } thisRelativeFile = thisRelativeFile.Replace(pathSeparator, control.GetPlaylistPathSeparator()); p.AddTrack("." + thisRelativeFile); } var tempFile = PathUtilities.GetTempFileName(); OnStatusUpdate(string.Format(CultureInfo.InvariantCulture, "Generating Playlist with {0} items", p.NumberOfTracks)); p.SaveFile(tempFile); var destPlaylist = copyToDestination ? Path.Combine(control.GetDestinationRoot(), control.GetPlaylistFileName()) : control.GetPlaylistFileName(); OnStatusUpdate(string.Format(CultureInfo.InvariantCulture, "Writing playlist to {0}", destPlaylist)); FileUtilities.FileCopy(tempFile, destPlaylist, true); }
/// <summary> /// synchronise podcast media files /// </summary> /// <param name="controlFile">control file to use to control the process</param> /// <param name="whatIf">true to generate the status messages but not to actually perform the file copy / deletes</param> public void Synchronize(IReadOnlyControlFile controlFile, bool whatIf) { var filesToCopy = new List <FileSyncItem>(); foreach (PodcastInfo podcast in controlFile.GetPodcasts()) { string podcastSourcePath = Path.Combine(controlFile.GetSourceRoot(), podcast.Folder); string podcastDestinationPath = Path.Combine(controlFile.GetDestinationRoot(), podcast.Folder); IList <IFileInfo> podcastSourceFiles = FileFinder.GetFiles( podcastSourcePath, podcast.Pattern.Value, podcast.MaximumNumberOfFiles.Value, podcast.SortField.Value, podcast.AscendingSort.Value); FileRemover.RemoveUnwantedFiles(podcastSourceFiles, podcastDestinationPath, podcast.Pattern.Value, whatIf); IEnumerable <FileSyncItem> podcastSyncItems = podcastSourceFiles.Select(p => new FileSyncItem { Source = p }); filesToCopy.AddRange(podcastSyncItems); } FileCopier.CopyFilesToTarget( filesToCopy, controlFile.GetSourceRoot(), controlFile.GetDestinationRoot(), controlFile.GetFreeSpaceToLeaveOnDestination(), whatIf); foreach (PodcastInfo podcast in controlFile.GetPodcasts()) { if (podcast.DeleteEmptyFolder.Value) { string podcastDestinationPath = Path.Combine(controlFile.GetDestinationRoot(), podcast.Folder); FolderRemover.RemoveFolderIfEmpty(podcastDestinationPath, whatIf); } } }
/// <summary> /// generate a playlist for the files in the destination folder /// </summary> /// <param name="control">control file to use to find the destinationRoot, and playlist format</param> /// <param name="copyToDestination">true to copy the playlist to the destination, false to write it locally</param> public void GeneratePlaylist(IReadOnlyControlFile control, bool copyToDestination) { GeneratePlaylist(control, control.GetDestinationRoot(), copyToDestination); }