예제 #1
0
def __get_asset_count(album, media_type):
    PHAsset = ObjCClass("PHAsset")
    NSPredicate = ObjCClass("NSPredicate")
    PHFetchOptions = ObjCClass("PHFetchOptions")
    fetchOptions = PHFetchOptions.alloc().init().autorelease()
    fetchOptions.predicate = NSPredicate.predicateWithFormat_("mediaType==" +
                                                              str(media_type))
    assets = PHAsset.fetchAssetsInAssetCollection_options_(album, fetchOptions)
    return assets.count()
예제 #2
0
def __get_album_dates(album):
    PHAsset = ObjCClass("PHAsset")
    NSSortDescriptor = ObjCClass("NSSortDescriptor")
    PHFetchOptions = ObjCClass("PHFetchOptions")
    fetchOptions = PHFetchOptions.alloc().init().autorelease()
    fetchOptions.sortDescriptors = [
        NSSortDescriptor.sortDescriptorWithKey_ascending_(
            "creationDate", True)
    ]
    result = PHAsset.fetchAssetsInAssetCollection_options_(album, fetchOptions)
    if result.count() != 0:
        start_date = result.firstObject().creationDate()
        end_date = result.lastObject().creationDate()
        return (start_date, end_date)
    else:
        return (None, None)