Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpe committed Apr 23, 2016
0 parents commit c0bbd83
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions IdentifyAlbumOfPhotos.py
@@ -0,0 +1,41 @@
# coding: utf-8
import ui
import photos
import console
from objc_util import *

NSBundle.bundleWithPath_('/System/Library/Frameworks/Photos.framework').load()
PHAssetCollection = ObjCClass('PHAssetCollection')
PHAsset = ObjCClass('PHAsset')

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

main()

0 comments on commit c0bbd83

Please sign in to comment.