Skip to content

Commit 28313ad

Browse files
fix: preserve original video creation date
Signed-off-by: Alex Zhukov <aleksandr.a.zhukov@gmail.com>
1 parent 7b12241 commit 28313ad

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

Sushitrain/PhotoBackup.swift

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -617,39 +617,31 @@ enum PhotoSyncProgress {
617617

618618
DispatchQueue.main.async { self.progress = .exportingVideos(index: idx, total: videoCount, current: nil) }
619619

620-
_ = await withCheckedContinuation { resolve in
621-
Log.info("Exporting video \(asset.originalFilename)")
622-
let options = PHVideoRequestOptions()
623-
options.version = .current
624-
options.deliveryMode = .highQualityFormat
625-
626-
PHImageManager.default().requestExportSession(
627-
forVideo: asset, options: options, exportPreset: AVAssetExportPresetPassthrough
628-
) { exportSession, info in
629-
if let es = exportSession {
630-
es.outputURL = fileURL
631-
632-
es.exportAsynchronously {
633-
Log.info("Done exporting video \(asset.originalFilename)")
634-
resolve.resume(returning: true)
635-
}
620+
do {
621+
try await withCheckedThrowingContinuation { resolve in
622+
Log.info("Copying original video resource for \(asset.originalFilename)")
623+
624+
guard let resource = asset.primaryResource else {
625+
Log.warn("No primary resource for video \(asset.originalFilename)")
626+
resolve.resume()
627+
return
636628
}
637-
else {
638-
Log.info("Could not start export setting for \(asset.originalFilename): \(String(describing: info))")
639-
resolve.resume(returning: false)
629+
630+
PHAssetResourceManager.default().writeData(for: resource, toFile: fileURL, options: nil) { error in
631+
if let error = error {
632+
Log.warn("Failed to save original video for \(asset.originalFilename): \(error.localizedDescription)")
633+
resolve.resume(throwing: error)
634+
}
635+
else {
636+
Log.info("Copied original video resource for \(asset.originalFilename)")
637+
resolve.resume()
638+
}
640639
}
641640
}
642641
}
643-
644-
if let cd = asset.creationDate {
645-
do {
646-
try FileManager.default.setAttributes(
647-
[FileAttributeKey.creationDate: cd, FileAttributeKey.modificationDate: cd],
648-
ofItemAtPath: fileURL.path(percentEncoded: false))
649-
}
650-
catch {
651-
Log.warn("Could not set creation time of file: \(fileURL) \(error.localizedDescription)")
652-
}
642+
catch {
643+
Log.warn("Failed to save original video for \(asset.originalFilename): \(error.localizedDescription)")
644+
continue
653645
}
654646

655647
selectPaths.append(selectPath)

0 commit comments

Comments
 (0)