Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cvpe
committed
Apr 23, 2016
0 parents
commit c0bbd83
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |