-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multiple export profile support with new Airtable profile (#21)
- Loading branch information
Showing
33 changed files
with
541 additions
and
376 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
Sources/MarkersExtractor/Export/Components/CSV Export Utils.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// CSV Export Utils.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
import OrderedCollections | ||
import CodableCSV | ||
|
||
extension ExportProfile { | ||
static func csvWiteManifest( | ||
csvPath: URL, | ||
_ preparedMarkers: [PreparedMarker], | ||
payload: Payload | ||
) throws { | ||
let rows = csvDictsToRows(preparedMarkers) | ||
let csvData = try CSVWriter.encode(rows: rows, into: Data.self) | ||
try csvData.write(to: csvPath) | ||
} | ||
|
||
public static func csvDoneFileContent(csvPath: URL) throws -> Data { | ||
let content = ["csvPath": csvPath.path] | ||
|
||
let encoder = JSONEncoder() | ||
encoder.outputFormatting = [.prettyPrinted] | ||
return try encoder.encode(content) | ||
} | ||
|
||
// MARK: Helpers | ||
|
||
private static func csvDictsToRows( | ||
_ preparedMarkers: [PreparedMarker] | ||
) -> [[String]] { | ||
let dicts = preparedMarkers.map { manifestFields(for: $0) } | ||
guard !dicts.isEmpty else { return [] } | ||
|
||
// header | ||
var result = [Array(dicts[0].keys.map { $0.name })] | ||
|
||
// marker rows | ||
result += dicts.map { row in | ||
Array(row.values) | ||
} | ||
|
||
return result | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Sources/MarkersExtractor/Export/Components/CSVExportPayload.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// AirtableExportProfile Payload.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
|
||
public struct CSVExportPayload: ExportPayload { | ||
let csvPath: URL | ||
|
||
init(projectName: String, outputPath: URL) { | ||
let csvName = "\(projectName).csv" | ||
csvPath = outputPath.appendingPathComponent(csvName) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Sources/MarkersExtractor/Export/Components/EmptyExportIcon.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// EmptyExportIcon.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
|
||
/// `ExportIcon` prototype that can be used when a profile does not use marker icons. | ||
public struct EmptyExportIcon: ExportIcon { | ||
public var resource: EmbeddedResource = .notion_marker_png // ignore | ||
|
||
public var fileName: String = "empty.png" | ||
|
||
public let data: Data = Data() | ||
|
||
public init(_ type: MarkerType) { } | ||
} |
42 changes: 20 additions & 22 deletions
42
...files/notion/CSVExportProfile Field.swift → ...port/Components/StandardExportField.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Sources/MarkersExtractor/Export/Components/StandardExportMarker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// StandardExportMarker.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
import OrderedCollections | ||
|
||
/// A marker with its contents prepared as flat String values in a standard format suitable for | ||
/// various different export profiles. | ||
public struct StandardExportMarker: ExportMarker { | ||
public typealias Field = StandardExportField | ||
public typealias Icon = NotionExportProfile.Icon | ||
|
||
public let id: String | ||
public let name: String | ||
public let type: String | ||
public let checked: String | ||
public let status: String | ||
public let notes: String | ||
public let position: String | ||
public let clipName: String | ||
public let clipDuration: String | ||
public let audioRoles: String | ||
public let videoRoles: String | ||
public let eventName: String | ||
public let projectName: String | ||
public let libraryName: String | ||
public let icon: Icon | ||
public let imageFileName: String | ||
|
||
public init( | ||
_ marker: Marker, | ||
idMode: MarkerIDMode, | ||
imageFormat: MarkerImageFormat, | ||
isSingleFrame: Bool | ||
) { | ||
id = marker.id(idMode) | ||
name = marker.name | ||
type = marker.type.name | ||
checked = String(marker.isChecked()) | ||
status = NotionExportProfile.Status(marker.type).rawValue | ||
notes = marker.notes | ||
position = marker.positionTimecodeString() | ||
clipName = marker.parentInfo.clipName | ||
clipDuration = marker.parentInfo.clipDurationTimecodeString | ||
videoRoles = marker.roles.flattenedString() | ||
audioRoles = marker.roles.flattenedString() | ||
eventName = marker.parentInfo.eventName | ||
projectName = marker.parentInfo.projectName | ||
libraryName = marker.parentInfo.libraryName | ||
icon = Icon(marker.type) | ||
imageFileName = isSingleFrame | ||
? "marker-placeholder.\(imageFormat)" | ||
: "\(marker.id(pathSafe: idMode)).\(imageFormat)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// ExportIcon.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol ExportIcon: Equatable, Hashable { | ||
var resource: EmbeddedResource { get } | ||
var fileName: String { get } | ||
var data: Data { get } | ||
init(_ type: MarkerType) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.