Skip to content

Commit

Permalink
make file information initializers failable
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Dec 6, 2017
1 parent af5a42c commit ea9b6a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Binary file not shown.
4 changes: 3 additions & 1 deletion jmc/AlbumFileLocationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ class AlbumFilePathTree: NSObject {
func getNodesForObjects(objects: Set<NSObject>) -> Set<AlbumFilePathNode> {
var nodeSet = Set<AlbumFilePathNode>()
for object in objects {
nodeSet.insert(self.rootNode.getLowestChildWithObject(object: object)!)
if let lowestChild = self.rootNode.getLowestChildWithObject(object: object) {
nodeSet.insert(lowestChild)
}
}
return nodeSet
}
Expand Down
36 changes: 24 additions & 12 deletions jmc/Other Windows/TagEditorWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class TagEditorWindow: NSWindowController, NSTextFieldDelegate, NSWindowDelegate
@IBOutlet weak var locationPathControl: NSPathControl!

func populateFileInfo() {
//todo correct tags if inconsistent
//todo touch the actual file if we have to
let url = NSURL(string: self.currentTrack!.location!)!
self.locationPathControl.url = url as URL

Expand All @@ -537,17 +537,29 @@ class TagEditorWindow: NSWindowController, NSTextFieldDelegate, NSWindowDelegate
flacMDItem?.initForMetadata()
}
let kind = MDItemCopyAttribute(mdItem, kMDItemKind) as? String
kindLabel.stringValue = kind!
let duration = MDItemCopyAttribute(mdItem, kMDItemDurationSeconds) as? Int ?? (Int(flacMDItem!.totalFrames / flacMDItem!.sampleRate!))
durationLabel.stringValue = getTimeAsString(Double(duration))!
let size = MDItemCopyAttribute(mdItem, kMDItemFSSize) as! Int
sizeLabel.stringValue = fileSizeFormatter.string(fromByteCount: Int64(size))
let bitRateCheck = (MDItemCopyAttribute(mdItem, kMDItemAudioBitRate) as? Int ?? (((size ) * 8) / 1000) / duration) / 1000
bitRateLabel.stringValue = bitRateFormatter.string(for: bitRateCheck)!
let sampleRateCheck = MDItemCopyAttribute(mdItem, kMDItemAudioSampleRate) as? Int ?? Int(flacMDItem!.sampleRate!)
sampleRateLabel.stringValue = sampleRateFormatter.string(for: sampleRateCheck)!
let channels = MDItemCopyAttribute(mdItem, kMDItemAudioChannelCount) as? Int ?? Int(flacMDItem!.channels!)
channelsLabel.stringValue = String(describing: channels)
if let kind = kind {
kindLabel.stringValue = kind
}
let duration = MDItemCopyAttribute(mdItem, kMDItemDurationSeconds) as? Int ?? (flacMDItem != nil ? (Int(flacMDItem!.totalFrames / flacMDItem!.sampleRate!)) : nil)
if let duration = duration {
durationLabel.stringValue = getTimeAsString(Double(duration))!
}
let size = MDItemCopyAttribute(mdItem, kMDItemFSSize) as? Int
if let size = size {
sizeLabel.stringValue = fileSizeFormatter.string(fromByteCount: Int64(size))
}
let bitRateCheck = MDItemCopyAttribute(mdItem, kMDItemAudioBitRate) as? Int ?? (size != nil && duration != nil ? ((((size!) * 8) / 1000) / duration!) / 1000 : nil)
if let bitRateCheck = bitRateCheck {
bitRateLabel.stringValue = bitRateFormatter.string(for: bitRateCheck)!
}
let sampleRateCheck = MDItemCopyAttribute(mdItem, kMDItemAudioSampleRate) as? Int ?? (flacMDItem != nil ? Int(flacMDItem!.sampleRate!) : nil)
if let sampleRateCheck = sampleRateCheck {
sampleRateLabel.stringValue = sampleRateFormatter.string(for: sampleRateCheck)!
}
let channels = MDItemCopyAttribute(mdItem, kMDItemAudioChannelCount) as? Int ?? (flacMDItem != nil ? Int(flacMDItem!.channels!) : nil)
if let channels = channels {
channelsLabel.stringValue = String(describing: channels)
}
let encoder = MDItemCopyAttribute(mdItem, kMDItemAudioEncodingApplication) as? String
encoderLabel.stringValue = encoder != nil ? encoder! : "No encoder information available."
let dateModified = MDItemCopyAttribute(mdItem, kMDItemContentModificationDate) as? NSDate
Expand Down

0 comments on commit ea9b6a7

Please sign in to comment.