forked from cvpe/Pythonista-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IdentifyAlbumOfPhotos.py
47 lines (41 loc) · 1.24 KB
/
IdentifyAlbumOfPhotos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!python2
# coding: utf-8
from __future__ import absolute_import
from __future__ import print_function
import ui
import photos
import console
from objc_util import *
from six.moves import range
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')
print(fn)
fn_index[fn] = (ip,'')
#return
# - 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()