Exemplo n.º 1
0
def main():

    console.clear()
    #p = photos.pick_image(show_albums=True, include_metadata=True, original=True, raw_data=False, multi=True)
    # Build dictionary filename: index
    fn_index = {}
    for ip in range(photos.get_count()):
        m = photos.get_metadata(ip)
        #print m
        fn = m.get('filename')
        fn_index[fn] = (ip, '')

    # - type = 1: album
    # - subtype = 2: regular album
    result = PHAssetCollection.fetchAssetCollectionsWithType_subtype_options_(
        1, 2, None)
    #print result
    for i in range(result.count()):
        coll = result.objectAtIndex_(i)
        album = str(coll.localizedTitle())
        assets = PHAsset.fetchAssetsInAssetCollection_options_(coll, None)
        for j in range(assets.count()):
            a = assets.objectAtIndex_(j)
            fn = str(a.valueForKey_('filename'))
            tuple = fn_index[fn]
            ip = tuple[0]
            fn_index[fn] = (ip, album)

    # print filename -> album,index
    print(fn_index)
def main():

	console.clear()
	#p = photos.pick_image(show_albums=True, include_metadata=True, original=True, raw_data=False, multi=True)
	# Build dictionary filename: index
	fn_index = {}
	for ip in range(photos.get_count()):
		m = photos.get_metadata(ip)
		#print m
		fn = m.get('filename')
		fn_index[fn] = (ip,'')	

	# - type = 1: album
	# - subtype = 2: regular album
	result = PHAssetCollection.fetchAssetCollectionsWithType_subtype_options_(1,2, None)
	#print result
	for i in range(result.count()):
		coll = result.objectAtIndex_(i)
		album = str(coll.localizedTitle())
		assets = PHAsset.fetchAssetsInAssetCollection_options_(coll, None)
		for j in range(assets.count()):
			a = assets.objectAtIndex_(j)		
			fn = str(a.valueForKey_('filename'))
			tuple = fn_index[fn]
			ip = tuple[0]
			fn_index[fn] = (ip,album)
			
	# print filename -> album,index
	print fn_index
Exemplo n.º 3
0
def get_extension():
	ext = 'jpg'
	photo_meta = photos.get_metadata(-1).keys()
	if '{PNG}' in photo_meta:
		ext = 'png'
	elif '{GIF}' in photo_meta:
		ext = 'gif'
	elif '{TIFF}' and '{Exif}' in photo_meta:
		ext = 'jpg'	
	return ext
Exemplo n.º 4
0
def get_extension():
    ext = 'jpg'
    photo_meta = photos.get_metadata(-1).keys()
    if '{PNG}' in photo_meta:
        ext = 'png'
    elif '{GIF}' in photo_meta:
        ext = 'gif'
    elif '{TIFF}' and '{Exif}' in photo_meta:
        ext = 'jpg'
    return ext
Exemplo n.º 5
0
    def __init__(self, width, height):
        self.frame = (0, 0, width, height)
        self.iwidth = 200.0
        self.iheight = 200.0
        framesize = 10
        iw = self.iwidth - 2 * framesize
        ih = self.iheight - 2 * framesize

        ratio = ih / iw
        self.img = []
        self.imgcount = min(photos.get_count(), 100)
        console.hud_alert(
            "Please wait while {} photos are loading...".format(self.imgcount)
        )
        for i in range(self.imgcount):
            s = photos.get_metadata(i)
            if s["filename"][-3:] == "MOV":  # skip movies
                self.img.append(None)
                continue
            img = ui.Image.from_data(photos.get_image(i, raw_data=True))
            w, h = img.size
            rat = h / w
            x_ratio = 1.0
            y_ratio = 1.0
            x = framesize
            y = framesize

            if ratio < 1:  # landscape canvas
                if rat <= ratio:  # full width
                    y = ((ih - iw * rat) / 2) + framesize
                    y_ratio = iw * rat / ih
                else:  # full height
                    x = ((iw - ih / rat) / 2) + framesize
                    x_ratio = ih / rat / iw
            elif ratio > 1:  # portrait canvas
                if rat > ratio:  # full height
                    x = ((iw - ih / rat) / 2) + framesize
                    x_ratio = ih / rat / iw
                else:  # full width
                    y = ((ih - iw * rat) / 2) + framesize
                    y_ratio = iw * rat / ih
            else:  # cubic canvas
                if rat < 1:  # full width
                    y = ((ih - iw * rat) / 2) + framesize
                    y_ratio = iw * rat / ih
                elif rat > 1:  # full height
                    x = ((iw - ih / rat) / 2) + framesize
                    x_ratio = ih / rat / iw
                else:  # cubic
                    pass  # x_ratio = y_ratio = 1.0
            with ui.ImageContext(self.iwidth, self.iheight) as ctx:
                img.draw(x, y, iw * x_ratio, ih * y_ratio)
                self.img.append(ctx.get_image())
Exemplo n.º 6
0
def select_photos():
    console.clear()
    back = MyView(frame=(0, 0, 500, 500))
    back.present('sheet')
    todels = photos.pick_image(include_metadata=True,
                               original=True,
                               raw_data=False,
                               multi=True)

    # todels = list of tuples
    # [(image,metadata),(image,metadata),...]

    # Build dictionary filename: index
    fn_index = {}
    for ip in range(photos.get_count()):
        m = photos.get_metadata(ip)
        fn = m.get('filename')
        fn_index[fn] = ip
        # that could be a problem if two photos have the same filename, what happens if you download the same file (fi from Dropbox) more than once.

    # pick_image seems to display "camera roll" which seems to be all photos in sequence like
    # - type = 2: smartalbum
    # - subtype = 209: smartalbumlibrary
    result = PHAssetCollection.fetchAssetCollectionsWithType_subtype_options_(
        2, 209, None)
    coll = result.firstObject()
    assets = PHAsset.fetchAssetsInAssetCollection_options_(coll, None)

    # create array of assets to be deleted
    a_del = []
    for todel in todels:
        fn = todel[1].get('filename')
        ia = fn_index[fn]  # file name -> index
        a = assets.objectAtIndex_(ia)

        resources = PHAssetResource.assetResourcesForAsset(a)
        filename = resources[0].originalFilename

        a_del.append(a)

    lib = PHPhotoLibrary.sharedPhotoLibrary()

    def change_block():
        # standard delete will ask a confirmation by specifying the number of photos to be deleted but by showing only one
        req = PHAssetChangeRequest.deleteAssets_(a_del)

    def perform_changes():
        lib.performChangesAndWait_error_(change_block, None)

    t = threading.Thread(target=perform_changes)
    t.start()
    t.join()
Exemplo n.º 7
0
 def __init__(self, width, height):
     self.frame = (0,0,width,height)
     self.iwidth = 200.0
     self.iheight = 200.0
     framesize = 10
     iw = self.iwidth - 2 * framesize
     ih = self.iheight - 2 * framesize
     
     ratio = ih / iw
     self.img = []
     self.imgcount = min(photos.get_count(), 100)
     console.hud_alert('Please wait while {} photos are loading...'.format(self.imgcount))
     for i in xrange(self.imgcount):
         s = photos.get_metadata(i)
         if s['filename'][-3:] == 'MOV':     #skip movies
             self.img.append(None)
             continue
         img = ui.Image.from_data(photos.get_image(i,raw_data=True))
         w, h = img.size
         rat = h / w
         x_ratio = 1.0
         y_ratio = 1.0
         x = framesize
         y = framesize
         
         if ratio < 1:      #landscape canvas
             if rat <= ratio:     #full width
                 y = ((ih - iw * rat) / 2) + framesize
                 y_ratio = iw * rat / ih
             else:                #full height
                 x = ((iw - ih / rat) / 2) + framesize
                 x_ratio = ih / rat / iw
         elif ratio > 1:    #portrait canvas
             if rat > ratio:      #full height
                 x = ((iw - ih / rat) / 2) + framesize
                 x_ratio = ih / rat / iw
             else:                #full width
                 y = ((ih - iw * rat) / 2) + framesize
                 y_ratio = iw * rat / ih
         else:              #cubic canvas
             if rat < 1:          #full width
                 y = ((ih - iw * rat) / 2) + framesize
                 y_ratio = iw * rat / ih
             elif rat > 1:        #full height
                 x = ((iw - ih / rat) / 2) + framesize
                 x_ratio = ih / rat / iw
             else:                #cubic
                 pass             #x_ratio = y_ratio = 1.0
         with ui.ImageContext(self.iwidth, self.iheight) as ctx:
             img.draw(x,y,iw * x_ratio,ih * y_ratio)
             self.img.append(ctx.get_image())
Exemplo n.º 8
0
# https://gist.github.com/omz/8838751

# Shows the location of the last photo in the canera roll in the Maps app.
# (thanks to @HyShai for pointing out that the latitude/longitude refs are necessary)

import photos
import webbrowser

meta = photos.get_metadata(-1)
gps = meta.get('{GPS}')
if gps:
    latitude = str(gps.get('Latitude', 0.0)) + gps.get('LatitudeRef', '')
    longitude = str(gps.get('Longitude', 0.0)) + gps.get('LongitudeRef', '')
    maps_url = 'safari-http://maps.apple.com/?ll=%f,%f' % (latitude, longitude)
    webbrowser.open(maps_url)
else:
    print 'Last photo has no location metadata.'
Exemplo n.º 9
0
# https://gist.github.com/omz/8838751

# Shows the location of the last photo in the canera roll in the Maps app.
# (thanks to @HyShai for pointing out that the latitude/longitude refs are necessary)

import photos
import webbrowser

meta = photos.get_metadata(-1)
gps = meta.get('{GPS}')
if gps:
	latitude = str(gps.get('Latitude', 0.0)) + gps.get('LatitudeRef', '')
	longitude =str(gps.get('Longitude', 0.0)) + gps.get('LongitudeRef', '')
	maps_url = 'safari-http://maps.apple.com/?ll=%f,%f' % (latitude, longitude)
	webbrowser.open(maps_url)
else:
	print 'Last photo has no location metadata.'
Exemplo n.º 10
0
    console.clear()
    back = MyView(frame=(0, 0, 500, 500))
    back.present('sheet')
    todels = photos.pick_image(include_metadata=True,
                               original=True,
                               raw_data=False,
                               multi=True)


# todels = list of tuples
# [(image,metadata),(image,metadata),...]

# Build dictionary filename: index
fn_index = {}
for ip in range(photos.get_count()):
    m = photos.get_metadata(ip)
    fn = m.get('filename')
    fn_index[fn] = ip
    # that could be a problem if two photos have the same filename, what happens if you download the same file (fi from Dropbox) more than once.

# pick_image seems to display "camera roll" which seems to be all photos in sequence like
# - type = 2: smartalbum
# - subtype = 209: smartalbumlibrary
result = PHAssetCollection.fetchAssetCollectionsWithType_subtype_options_(
    2, 209, None)
coll = result.firstObject()
assets = PHAsset.fetchAssetsInAssetCollection_options_(coll, None)

# create array of assets to be deleted
a_del = []
for todel in todels:
Exemplo n.º 11
0
def get_index(filename):
    c = photos.get_count()
    for i in range(c):
        m = photos.get_metadata(i)
        if m.get('filename') == filename:
            return i
    #print result
    for i in range(result.count()):
        coll = result.objectAtIndex_(i)
        album = str(coll.localizedTitle())
        assets = PHAsset.fetchAssetsInAssetCollection_options_(coll, None)
        for j in range(assets.count()):
            a = assets.objectAtIndex_(j)
            fn = str(a.valueForKey_('filename'))
            tuple = fn_index[fn]
            ip = tuple[0]
            fn_index[fn] = (ip, album)

    # print filename -> album,index
    print fn_index


main()

# --------------------

fn_index = {
    photos.get_metadata(i)['filename']: (i, '')
    for i in range(photos.get_count())
}

# --------------------

NSBundle.bundleWithPath_('/System/Library/Frameworks/Photos.framework').load()

# --------------------
def get_img_index(filename):
    c = photos.get_count()
    for i in range(c):
        m = photos.get_metadata(i)
        if m.get('filename') == filename:
            return i