/// <summary> /// Main control flow /// </summary> /// <param name="ip"></param> /// <param name="directory"></param> /// <param name="timeout"></param> public void Run(BlackvueOptions options) { var body = QueryCameraForFileList(options.IPAddress, options.Timeout.Value); var list = GetListOfFilesFromResponse(body); var tempdir = Path.Combine(options.Destination, "_tmp"); var targetdir = Path.Combine(options.Destination, "Record"); CreateDirectories(tempdir, targetdir); ProcessList(list, tempdir, targetdir, options); ProcessBarOption = new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, ForegroundColorDone = ConsoleColor.DarkGreen, BackgroundColor = ConsoleColor.DarkGray, BackgroundCharacter = '\u2593' }; ChildOption = new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow, BackgroundColor = ConsoleColor.DarkGray, ProgressCharacter = '─' }; }
/// <summary> /// For the list, loop through and process it /// </summary> /// <param name="ip"></param> /// <param name="list"></param> /// <param name="tempdir"></param> /// <param name="targetdir"></param> /// <param name="timeout"></param> public void ProcessList(List <BlackVueFile> list, string tempdir, string baseDir, BlackvueOptions options) { var sw = new Stopwatch(); sw.Start(); // The list includes _NF and _NR files. // Loop through and download each, but also try and download .gps and .3gf files foreach (var s in list) { logger.Info($"Processing File: {s.originalName}"); string targetdir = baseDir; if (options.DateFolders) { targetdir = Path.Combine(baseDir, $"{s.dateRecorded.Year}-{s.dateRecorded.Month}-{s.dateRecorded.Day}"); } bool skipDownloadVideo = false; if (options.onlyGPS) { skipDownloadVideo = true; } if (s.videoType == BlackVueFile.VideoType.Normal && options.skipNormal) { skipDownloadVideo = true; } if (s.videoType == BlackVueFile.VideoType.Parking && options.skipParking) { skipDownloadVideo = true; } if (!skipDownloadVideo) { DownloadFile(options.IPAddress, s.originalName, "video", tempdir, targetdir, options.Timeout.Value); } if (s.videoType == BlackVueFile.VideoType.Normal && s.direction == BlackVueFile.Direction.Front) { //download GPS files... // Make filenames for accompanying gps file var gpsfile = s.originalName.Replace("_NF.mp4", "_N.gps"); DownloadFile(options.IPAddress, gpsfile, "gps", tempdir, targetdir, options.Timeout.Value); if (!options.onlyGPS || !skipDownloadVideo) { // Make filenames for accompanying gff file var gffile = s.originalName.Replace("_NF.mp4", "_N.3gf"); DownloadFile(options.IPAddress, gffile, "3gf", tempdir, targetdir, options.Timeout.Value); } } } sw.Stop(); BlackVueDownloaderCopyStats.TotalTime = sw.Elapsed; logger.Info( $"Copied {BlackVueDownloaderCopyStats.Copied}, Ignored {BlackVueDownloaderCopyStats.Ignored}, Errored {BlackVueDownloaderCopyStats.Errored}, TmpDeleted {BlackVueDownloaderCopyStats.TmpDeleted}, TotalTime {BlackVueDownloaderCopyStats.TotalTime}"); logger.Info( $"Downloaded {ByteSize.FromBytes(BlackVueDownloaderCopyStats.TotalDownloaded).ToString()} in {BlackVueDownloaderCopyStats.DownloadingTime}"); }