From aaa7d5ab1b6814a6730fa6282cbc83421c23f43f Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Fri, 30 Dec 2022 00:15:41 -0800 Subject: [PATCH] Default done file renamed to done.json; content is JSON (#2) --- .../MarkersExtractor/MarkersExtractor Settings.swift | 2 +- Sources/MarkersExtractor/MarkersExtractor.swift | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/MarkersExtractor/MarkersExtractor Settings.swift b/Sources/MarkersExtractor/MarkersExtractor Settings.swift index bd73e00..8b0689f 100644 --- a/Sources/MarkersExtractor/MarkersExtractor Settings.swift +++ b/Sources/MarkersExtractor/MarkersExtractor Settings.swift @@ -29,7 +29,7 @@ extension MarkersExtractor { public static func mediaSearchPaths(from fcpxml: FCPXMLFile) -> [URL] { [fcpxml.defaultMediaSearchPath].compactMap { $0 } } - public static let doneFilename = "done.txt" + public static let doneFilename = "done.json" } public enum Validation { diff --git a/Sources/MarkersExtractor/MarkersExtractor.swift b/Sources/MarkersExtractor/MarkersExtractor.swift index fee7249..3e48bc3 100644 --- a/Sources/MarkersExtractor/MarkersExtractor.swift +++ b/Sources/MarkersExtractor/MarkersExtractor.swift @@ -92,7 +92,8 @@ extension MarkersExtractor { if s.createDoneFile { logger.info("Creating \(s.doneFilename.quoted) done file at \(outputPath.path.quoted).") - try saveDoneFile(at: outputPath, fileName: s.doneFilename, content: csvPath.path) + let doneFileContent = ["csvPath": csvPath.path] + try saveDoneFile(at: outputPath, fileName: s.doneFilename, content: doneFileContent) } logger.info("Done!") @@ -178,11 +179,15 @@ extension MarkersExtractor { // MARK: - Done File extension MarkersExtractor { - private func saveDoneFile(at outputPath: URL, fileName: String, content: String) throws { + private func saveDoneFile(at outputPath: URL, fileName: String, content: E) throws { let doneFile = outputPath.appendingPathComponent(fileName) do { - try content.write(to: doneFile, atomically: true, encoding: .utf8) + let encoder = JSONEncoder() + encoder.outputFormatting = [.prettyPrinted] + + let data = try encoder.encode(content) + try data.write(to: doneFile) } catch { throw MarkersExtractorError.runtimeError( "Failed to create done file \(doneFile.path.quoted): \(error.localizedDescription)"