Dropbox 2.0 Swift API:如何获取媒体元数据
Dropbox 2.0 Swift API: how to get Media Metadata
我正在为一个 iOS 项目使用 SwiftyDropbox 库,以递归方式获取文件夹列表,并检查文件是照片还是视频。
client.files.getMetadata(path: fileURL, includeMediaInfo: true).response { response, error in
if let file = response as? Files.FileMetadata {
if file.mediaInfo != nil {
// ??? how to get file.mediaInfo.metadata
// specifically, I need the mediaMetadata
}
}
}
我可以看到 file.mediaInfo(如果它存在,则意味着元数据存在,但文档没有显示如何获取实际元数据本身(具体来说,照片的尺寸或视频的持续时间) .
我可以从 file.mediaInfo 的描述中得到这个(并解析从中返回的字符串),但这是 hacky 并且不是未来安全的。是否有其他方式获取此数据?
这是我想从中获取数据的 class(在 Files.swift 中):
public class MediaMetadata: CustomStringConvertible {
/// Dimension of the photo/video.
public let dimensions : Files.Dimensions?
/// The GPS coordinate of the photo/video.
public let location : Files.GpsCoordinates?
/// The timestamp when the photo/video is taken.
public let timeTaken : NSDate?
public init(dimensions: Files.Dimensions? = nil, location: Files.GpsCoordinates? = nil, timeTaken: NSDate? = nil) {
self.dimensions = dimensions
self.location = location
self.timeTaken = timeTaken
}
public var description : String {
return "\(prepareJSONForSerialization(MediaMetadataSerializer().serialize(self)))"
}
}
这是一个示例:
Dropbox.authorizedClient!.files.getMetadata(path: "/test.jpg", includeMediaInfo: true).response { response, error in
if let result = response as? Files.FileMetadata {
print(result.name)
if result.mediaInfo != nil {
switch result.mediaInfo! as Files.MediaInfo {
case .Pending:
print("Media info is pending...")
case .Metadata(let mediaMetadata):
print(mediaMetadata.dimensions)
print(mediaMetadata.location)
print(mediaMetadata.timeTaken)
}
}
} else {
print(error!)
}
}
我正在为一个 iOS 项目使用 SwiftyDropbox 库,以递归方式获取文件夹列表,并检查文件是照片还是视频。
client.files.getMetadata(path: fileURL, includeMediaInfo: true).response { response, error in
if let file = response as? Files.FileMetadata {
if file.mediaInfo != nil {
// ??? how to get file.mediaInfo.metadata
// specifically, I need the mediaMetadata
}
}
}
我可以看到 file.mediaInfo(如果它存在,则意味着元数据存在,但文档没有显示如何获取实际元数据本身(具体来说,照片的尺寸或视频的持续时间) .
我可以从 file.mediaInfo 的描述中得到这个(并解析从中返回的字符串),但这是 hacky 并且不是未来安全的。是否有其他方式获取此数据?
这是我想从中获取数据的 class(在 Files.swift 中):
public class MediaMetadata: CustomStringConvertible {
/// Dimension of the photo/video.
public let dimensions : Files.Dimensions?
/// The GPS coordinate of the photo/video.
public let location : Files.GpsCoordinates?
/// The timestamp when the photo/video is taken.
public let timeTaken : NSDate?
public init(dimensions: Files.Dimensions? = nil, location: Files.GpsCoordinates? = nil, timeTaken: NSDate? = nil) {
self.dimensions = dimensions
self.location = location
self.timeTaken = timeTaken
}
public var description : String {
return "\(prepareJSONForSerialization(MediaMetadataSerializer().serialize(self)))"
}
}
这是一个示例:
Dropbox.authorizedClient!.files.getMetadata(path: "/test.jpg", includeMediaInfo: true).response { response, error in
if let result = response as? Files.FileMetadata {
print(result.name)
if result.mediaInfo != nil {
switch result.mediaInfo! as Files.MediaInfo {
case .Pending:
print("Media info is pending...")
case .Metadata(let mediaMetadata):
print(mediaMetadata.dimensions)
print(mediaMetadata.location)
print(mediaMetadata.timeTaken)
}
}
} else {
print(error!)
}
}