星期三, 8月 04, 2010

XMP and Cell ID

去年就看到這篇文章:Cell ID Photo PC Tool 0.3,想試試看了。因為是c#寫的,照理來說,Linux 上的 mono 應該可以用才對,哪知道卻發現他用了 System.Windows.Media.Imaging 這個 mono 沒實作的類別庫。

沒辦法,於是就想說用 python 寫一個好了,當作練習。

首先遇到的問題就是 cell id 怎麼取得,原本以為是在 exif 裏面,用了 PIL 去撈,卻沒撈到。胡亂找了一陣,才知道這是放在 XMP metadata 裏面,得用 XML toolkit sdk 來撈才行,python 也是有 binding:Python XMP toolkit,只是得另外裝,ubuntu 沒有包進去。

是故,得先裝 libexempi3 (sudo apt-get install libexempi3),再下載 Python XMP toolkit,解開後,執行 sudo python setup.py install 來安裝。這樣就大功告成了。

程式很簡單,簡單到爆:
#!/usr/bin/env python
import sys
from libxmp import file_to_dict

CELL_NS="http://developer.sonyericsson.com/cell/1.0/"
if __name__ == '__main__':
xmp = file_to_dict( sys.argv[1] )
for prop_name, prop_value, prop_options in xmp[CELL_NS]:
print prop_name, prop_value


就這樣就可以把 Cell ID 相關的資訊都撈出來了。

沒有留言: