protected override int Invoke(ProjectInfo project, IngestionIndex index) { var totalDuration = TimeSpan.Zero; var items = index .SelectAll() .Where(item => Tag is null || item.Tag == Tag) .Where(item => !ApplyTimelapseFilters || project.IncludeInTimelapse(item)) .OrderBy(item => item.Tag) .ThenBy(item => item.Timestamp) .Select(item => { item = item.WithFilePath(Path.Combine(project.BasePath ?? ".", item.FilePath)); if (!item.Duration.HasValue) { item = item.WithDurationAndFileSizeByReadingFile(); } return(item); }); foreach (var item in items) { if (item.Duration.HasValue) { totalDuration += item.Duration.Value; } Console.WriteLine(item.FilePath); } Console.WriteLine($"--total-input-duration {totalDuration}"); return(0); }
protected override int Invoke(ProjectInfo project, IngestionIndex index) { InsertItems( index, Ingestion.EnumerateIngestionFiles( project, parseMetadataFromFile: !NoMetadata), DryRun, resetIndex: true); return(0); }
void InsertItems(IngestionIndex index, IEnumerable <IngestionItem> items, bool dryRun, bool resetIndex = false) { int totalItems = 0; TimeSpan totalDuration = default; long totalSize = 0; IEnumerable <IngestionItem> YieldAndLog() { foreach (var item in items) { Log.Information( "[{TotalItems}] {FilePath} {Duration} @ {Timestamp}", ++totalItems, item.FilePath, item.Duration, item.Timestamp); if (item.Duration.HasValue) { totalDuration += item.Duration.Value; } if (item.FileSize.HasValue) { totalSize += item.FileSize.Value; } yield return(item); } } if (dryRun) { var enumerator = YieldAndLog().GetEnumerator(); while (enumerator.MoveNext()) { ; } } else { if (resetIndex) { index.Reset(); } index.Insert(YieldAndLog()); } Log.Information("Count = {TotalItems}", totalItems); Log.Information("Duration = {TotalDuration}", totalDuration); Log.Information("Size = {TotalSize} GB", totalSize / 1024.0 / 1024.0 / 1024.0); }
protected override int Invoke(ProjectInfo project, IngestionIndex index) { int totalItems = 0; TimeSpan totalDuration = default; long totalSize = 0; IEnumerable <IngestionItem> YieldAndLog() { foreach (var item in Ingestion.EnumerateIngestionFiles(project, parseMetadataFromFile: !NoMetadata)) { Log.Information( "[{TotalItems}] {FilePath} {Duration} @ {Timestamp}", ++totalItems, item.FilePath, item.Duration, item.Timestamp); if (item.Duration.HasValue) { totalDuration += item.Duration.Value; } if (item.FileSize.HasValue) { totalSize += item.FileSize.Value; } yield return(item); } } if (DryRun) { var enumerator = YieldAndLog().GetEnumerator(); while (enumerator.MoveNext()) { ; } } else { index.Reset(); index.Insert(YieldAndLog()); } Log.Information("Count = {TotalItems}", totalItems); Log.Information("Duration = {TotalDuration}", totalDuration); Log.Information("Size = {TotalSize} GB", totalSize / 1024.0 / 1024.0 / 1024.0); return(0); }
protected override int Invoke(ProjectInfo project, IngestionIndex index) { FFMpeg.Path = FFMpegPath; project = project.Evaluate(); daemon = Daemon.Create( Path.Combine(project.BasePath ?? ".", "latham.pid"), () => "running"); if ((Stop || Status || Daemonize) && !daemon.IsSupported) { throw new NotSupportedException("Daemon mode is not supported on this system."); } if (Status) { if (daemon.GetExistingProcess() is Process process) { Console.WriteLine("{PID}", process.Id); return(0); } Console.WriteLine("stopped"); return(1); } else if (Stop) { if (daemon.Stop(out var process) && process is object) { Console.WriteLine($"[PID {process.Id}] SIGINT was sent"); } else { Console.WriteLine("Record daemon is not running or unable to find PID for it."); } return(0); }
protected abstract int Invoke(ProjectInfo project, IngestionIndex index);
protected override int Invoke(ProjectInfo project, IngestionIndex index) { index.Insert(Ingestion.EnumerateIngestionFiles(project, InputFiles)); return(0); }
protected override int Invoke(ProjectInfo project, IngestionIndex index) { if (InputFiles.Count > 0) { InsertItems( index, Ingestion.EnumerateIngestionFiles( project, parseMetadataFromFile: !NoMetadata, InputFiles), DryRun); return(0); } project = project.Evaluate(expandPaths: false); if (project.Recordings is null || project.Recordings.Sources.Count == 0) { Console.Error.WriteLine("No recording sources are configured on this project."); return(1); } InsertItems( index, FindNewIngestionItems(), DryRun); IEnumerable <IngestionItem> FindNewIngestionItems() { var newestTimestamp = index.SelectNewestTimestamp(); #nullable disable foreach (var recordingSource in project.Recordings.Sources) #nullable restore { if (!recordingSource.Schedule.HasValue) { continue; } // Unfortunately NCrontab doesn't work with DateTimeOffset, so normalize to UTC. var expectedRecordingTimes = recordingSource .Schedule .Value .GetNextOccurrences( newestTimestamp.UtcDateTime, DateTime.UtcNow); var basePaths = new List <string>(); foreach (var expectedRecordingTime in expectedRecordingTimes) { if (Path.GetDirectoryName( recordingSource.CreateOutputPath( expectedRecordingTime)) is string expectedDirectory) { if (!basePaths.Contains(expectedDirectory)) { basePaths.Add(expectedDirectory); } } } foreach (var ingestion in project.Ingestions) { foreach (var basePath in basePaths) { var adjustedIngestion = new IngestionInfo( Path.GetFileName(ingestion.PathGlob), basePath, ingestion.PathFilter); foreach (var item in Ingestion.EnumerateIngestionFiles( adjustedIngestion, parseMetadataFromFile: !NoMetadata, basePath: ingestion.BasePath)) { yield return(item.WithFilePath(Path.Combine(basePath, item.FilePath))); } } } } }