-
-
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.
- Loading branch information
Showing
10 changed files
with
242 additions
and
23 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
Sources/MarkersExtractor/Export/Manifest/Delimited Text 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,31 @@ | ||
// | ||
// Delimited Text Export Utils.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import CodableCSV | ||
import Foundation | ||
import OrderedCollections | ||
|
||
extension ExportProfile { | ||
func dictsToRows( | ||
_ preparedMarkers: [PreparedMarker], | ||
noMedia: Bool | ||
) -> [[String]] { | ||
let dicts = preparedMarkers.map { | ||
tableManifestFields(for: $0, noMedia: noMedia) | ||
} | ||
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 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sources/MarkersExtractor/Export/Manifest/TSV 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,28 @@ | ||
// | ||
// TSV Export Utils.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
import OrderedCollections | ||
import TextFileKit | ||
|
||
extension ExportProfile { | ||
func tsvWriteManifest( | ||
tsvPath: URL, | ||
noMedia: Bool, | ||
_ preparedMarkers: [PreparedMarker] | ||
) throws { | ||
let rows = dictsToRows(preparedMarkers, noMedia: noMedia) | ||
|
||
guard let tsvData = TextFile.TSV(table: rows).rawText.data(using: .utf8) | ||
else { | ||
throw MarkersExtractorError.extraction(.fileWrite( | ||
"Could not encode TSV file." | ||
)) | ||
} | ||
|
||
try tsvData.write(to: tsvPath) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Sources/MarkersExtractor/Export/Payload/TSVExportPayload.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 @@ | ||
// | ||
// TSVExportPayload.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
|
||
public struct TSVExportPayload: ExportPayload { | ||
let tsvPath: URL | ||
|
||
init(projectName: String, outputURL: URL) { | ||
let tsvName = "\(projectName).tsv" | ||
tsvPath = outputURL.appendingPathComponent(tsvName) | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
Sources/MarkersExtractor/Export/Profile/TSV/TSVProfile Export.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,108 @@ | ||
// | ||
// TSVProfile Export.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import AVFoundation | ||
import Foundation | ||
import Logging | ||
import OrderedCollections | ||
import TextFileKit | ||
import TimecodeKit | ||
|
||
extension TSVProfile { | ||
public func prepareMarkers( | ||
markers: [Marker], | ||
idMode: MarkerIDMode, | ||
tcStringFormat: Timecode.StringFormat, | ||
payload: Payload, | ||
mediaInfo: ExportMarkerMediaInfo? | ||
) -> [PreparedMarker] { | ||
markers.map { | ||
PreparedMarker( | ||
$0, | ||
idMode: idMode, | ||
mediaInfo: mediaInfo, tcStringFormat: tcStringFormat | ||
) | ||
} | ||
} | ||
|
||
public func writeManifests( | ||
_ preparedMarkers: [PreparedMarker], | ||
payload: Payload, | ||
noMedia: Bool | ||
) throws { | ||
try tsvWriteManifest( | ||
tsvPath: payload.tsvPath, | ||
noMedia: noMedia, | ||
preparedMarkers | ||
) | ||
} | ||
|
||
public func resultFileContent(payload: Payload) throws -> ExportResult.ResultDictionary { | ||
[ | ||
.tsvManifestPath: .url(payload.tsvPath) | ||
] | ||
} | ||
|
||
public func tableManifestFields( | ||
for marker: PreparedMarker, | ||
noMedia: Bool | ||
) -> OrderedDictionary<ExportField, String> { | ||
var dict: OrderedDictionary<ExportField, String> = [:] | ||
|
||
dict[.id] = marker.id | ||
dict[.name] = marker.name | ||
dict[.type] = marker.type | ||
dict[.checked] = marker.checked | ||
dict[.status] = marker.status | ||
dict[.notes] = marker.notes | ||
dict[.position] = marker.position | ||
dict[.clipType] = marker.clipType | ||
dict[.clipName] = marker.clipName | ||
dict[.clipDuration] = marker.clipDuration | ||
dict[.videoRole] = marker.videoRole | ||
dict[.audioRole] = marker.audioRole.flat | ||
dict[.eventName] = marker.eventName | ||
dict[.projectName] = marker.projectName | ||
dict[.libraryName] = marker.libraryName | ||
// no iconImage | ||
|
||
if !noMedia { | ||
dict[.imageFileName] = marker.imageFileName | ||
} | ||
|
||
return dict | ||
} | ||
|
||
public func nestedManifestFields( | ||
for marker: PreparedMarker, | ||
noMedia: Bool | ||
) -> OrderedDictionary<ExportField, ExportFieldValue> { | ||
var dict: OrderedDictionary<ExportField, ExportFieldValue> = [:] | ||
|
||
dict[.id] = .string(marker.id) | ||
dict[.name] = .string(marker.name) | ||
dict[.type] = .string(marker.type) | ||
dict[.checked] = .string(marker.checked) | ||
dict[.status] = .string(marker.status) | ||
dict[.notes] = .string(marker.notes) | ||
dict[.position] = .string(marker.position) | ||
dict[.clipType] = .string(marker.clipType) | ||
dict[.clipName] = .string(marker.clipName) | ||
dict[.clipDuration] = .string(marker.clipDuration) | ||
dict[.videoRole] = .string(marker.videoRole) | ||
dict[.audioRole] = .array(marker.audioRole.array) | ||
dict[.eventName] = .string(marker.eventName) | ||
dict[.projectName] = .string(marker.projectName) | ||
dict[.libraryName] = .string(marker.libraryName) | ||
// no iconImage | ||
|
||
if !noMedia { | ||
dict[.imageFileName] = .string(marker.imageFileName) | ||
} | ||
|
||
return dict | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Sources/MarkersExtractor/Export/Profile/TSV/TSVProfile.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,26 @@ | ||
// | ||
// TSVProfile.swift | ||
// MarkersExtractor • https://github.com/TheAcharya/MarkersExtractor | ||
// Licensed under MIT License | ||
// | ||
|
||
import Foundation | ||
import Logging | ||
|
||
public class TSVProfile: NSObject, ProgressReporting, ExportProfile { | ||
// ExportProfile | ||
public typealias Payload = TSVExportPayload | ||
public typealias Icon = EmptyExportIcon | ||
public typealias PreparedMarker = StandardExportMarker | ||
public static let profile: ExportProfileFormat = .tsv | ||
public static let isMediaCapable: Bool = false | ||
public var logger: Logger? | ||
|
||
// ProgressReporting | ||
public let progress: Progress | ||
|
||
public required init(logger: Logger? = nil) { | ||
self.logger = logger | ||
progress = Self.defaultProgress | ||
} | ||
} |
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