Writing a Swift code to check movie file's attributes

Started by Anuj, June 14, 2019, 11:27:30 PM

Previous topic - Next topic

Anuj

Hi

I am a super newbie with exiftool and files.I am trying to write a small utility to clean up some files on my Mac. I know I can use some external tool to solve my problem, but I want to attempt to write my own small custom tool.

I am trying to write a small code in Swift, on Mac to parse my video files and check what's the original creation date. Here is my swift code:

import Cocoa
var filePath = "some movie file"
let fileManager = FileManager.default
if let attributes = try? fileManager.attributesOfItem(atPath: filePath) {
    for (_,value) in attributes.enumerated() {
        print("\(value.key.rawValue)   =   \(value.value)")
    }
}

Here is what I am getting
NSFileType   =   NSFileTypeRegular
NSFileCreationDate   =   1970-01-01 00:00:00 +0000
NSFileHFSCreatorCode   =   0
NSFileExtensionHidden   =   0
NSFilePosixPermissions   =   493
NSFileModificationDate   =   2007-04-17 19:51:06 +0000
NSFileSystemFileNumber   =   5885740
NSFileGroupOwnerAccountID   =   20
NSFileGroupOwnerAccountName   =   staff
NSFileOwnerAccountID   =   502
NSFileReferenceCount   =   1
NSFileExtendedAttributes   =   {
    "com.apple.quarantine" = <30303832 3b353938 66376461 623b5068 6f746f73 3b>;
}
NSFileSize   =   72081686
NSFileHFSTypeCode   =   0
NSFileOwnerAccountName   =   TestUser
NSFileSystemNumber   =   16777220


exiftool gives me lot more details. Can someone suggest me how I can get those details by writing code in Swift?

Hayo Baan

I don't think I understand your question, but are you really asking how to write a Swift program that gives you all file details exiftool gives you? So basically how to rewrite exiftool in Swift? While doable, it's a job of months if not longer... And to be able to have all flexibility is even harder as Perl allows a lot of things easily that are very hard in other languages (like Swift).
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Quote from: Anuj on June 14, 2019, 11:27:30 PM
I am trying to write a small code in Swift, on Mac to parse my video files

The code you wrote isn't parsing the file.  It is just getting the Finder attributes for a file.  You have to actually parse the file to get the information that ExifTool returns.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).