예제 #1
0
def __get_albums(type, subtype):
    # Helper function: constructs dictionary with user / smart albums
    # Sort albums in ascending order, based on their localized title
    PHAssetCollection = ObjCClass("PHAssetCollection")
    NSSortDescriptor = ObjCClass("NSSortDescriptor")
    PHFetchOptions = ObjCClass("PHFetchOptions")
    fetchOptions = PHFetchOptions.alloc().init().autorelease()
    fetchOptions.sortDescriptors = [
        NSSortDescriptor.sortDescriptorWithKey_ascending_(
            "localizedTitle", True)
    ]
    # Fetch the albums with the specified type and return a list of their unique identifiers
    result = PHAssetCollection.fetchAssetCollectionsWithType_subtype_options_(
        type, subtype, fetchOptions)
    albums = dict()
    for index in range(result.count()):
        # Get each PHAssetCollection object and save (key,value) = (title,identifier)
        collection = result.objectAtIndex_(index)
        if type == __SMART_ALBUM:
            albums[__localized_smart_album_title(
                collection.assetCollectionSubtype())] = str(
                    collection.localIdentifier())
        else:
            albums[str(collection.localizedTitle())] = str(
                collection.localIdentifier())
    # Return the dictionary with titles and identifiers
    return albums
예제 #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)