YANO's digital garage

Copyright ©YANO All rights reserved. https://www.bravotouring.com/~yano/

Last-modified: 2024-04-08 (月)


[一語一絵/IT系]

eyefiserver2 / 2013-05-15 (水)

昨年のEye-Fi導入から1年弱。ようやくGT110b@ubuntu 10.04へ直接アップロードできるようになったので、おさらい。

まずは[External]eyefiserver2-DEV.tar.gzをダウンロードして展開する。buildは不要。

yano@GT110b:~/software$ wget https://eyefiserver2.googlecode.com/files/eyefiserver2-DEV.tar.gz
yano@GT110b:~/software$ mkdir eyefiserver2
yano@GT110b:~/software$ cd eyefiserver2
yano@GT110b:~/software/eyefiserver2$ tar xvf ../eyefiserver2-DEV.tar.gz
yano@GT110b:~/software/eyefiserver2$ sudo cp -pr usr/local/bin/eyefiserver.py /usr/local/bin/
yano@GT110b:~/software/eyefiserver2$ sudo cp -pr etc/eyefiserver.conf /etc/
続いて[External]Pythonのライブラリパッケージも導入する。
yano@GT110b:~$ sudo apt-get install python-pyexiv2 python-dateutil python-tz python-parsedatetime python-configglue
手元の環境で不足しているのはこれだけのようだったが、場合によってはもっと不足しているかもしれないので、その場合は
yano@GT110b:~$ fgrep import /usr/local/bin/eyefiserver.py
の結果を参考に。

/usr/local/bin/eyefiserver.py/etc/eyefiserver.confは以下のように修正。upload_dirにタイムスタンプを含めた場合にうまく転送されなかった為に一旦temp_dirへ転送するようにしたのと、timezoneを設定できるように改修した。
yano@GT110b:~$ diff -bc ~/software/eyefiserver2/usr/local/bin/eyefiserver.py /usr/local/bin/eyefiserver.py
*** /home/yano/software/eyefiserver2/usr/local/bin/eyefiserver.py       2012-06-28 13:16:46.000000000 +0900
--- /usr/local/bin/eyefiserver.py       2013-05-16 15:35:42.000000000 +0900
***************
*** 566,572 ****
      eyeFiLogger.debug("Using file_mode " + file_mode)
      eyeFiLogger.debug("Using dir_mode " + dir_mode)

!     tempDir = os.path.dirname(self.server.config.get('EyeFiServer','upload_dir'))


      imageTarPath = os.path.join(tempDir, imageTarfileName)
--- 566,574 ----
      eyeFiLogger.debug("Using file_mode " + file_mode)
      eyeFiLogger.debug("Using dir_mode " + dir_mode)

!     tempDir = os.path.dirname(self.server.config.get('EyeFiServer','temp_dir'))
!     if not os.path.isdir(tempDir):
!       os.makedirs(tempDir)


      imageTarPath = os.path.join(tempDir, imageTarfileName)
***************
*** 586,593 ****
      imageTarfile = tarfile.open(imageTarPath)

      for member in imageTarfile.getmembers():
!       #timezone = self.server.config.getint('EyeFiServer','timezone')
!       timezone = -7
        imageDate = datetime.fromtimestamp(member.mtime) - timedelta(hours=timezone)
        uploadDir = imageDate.strftime(self.server.config.get('EyeFiServer','upload_dir'))
        eyeFiLogger.debug("Creating folder " + uploadDir)
--- 588,595 ----
      imageTarfile = tarfile.open(imageTarPath)

      for member in imageTarfile.getmembers():
!       timezone = self.server.config.getint('EyeFiServer','timezone')
!       # timezone = -7
        imageDate = datetime.fromtimestamp(member.mtime) - timedelta(hours=timezone)
        uploadDir = imageDate.strftime(self.server.config.get('EyeFiServer','upload_dir'))
        eyeFiLogger.debug("Creating folder " + uploadDir)
***************
*** 616,625 ****
      try:
          import pyexiv2

!         metadata = pyexiv2.ImageMetadata(imagePath)
!         metadata.read()
!         if 'Exif.Image.DateTime' in metadata.exif_keys:
!             d = metadata['Exif.Image.DateTime'].value
              seconds = time.mktime(d.timetuple())
              os.utime(imagePath, (seconds, seconds))
          else:
--- 618,627 ----
      try:
          import pyexiv2

!         exif = pyexiv2.Image(imagePath)
!         exif.readMetadata()
!         if 'Exif.Image.DateTime' in exif.exifKeys():
!             d = exif['Exif.Image.DateTime']
              seconds = time.mktime(d.timetuple())
              os.utime(imagePath, (seconds, seconds))
          else:
yano@GT110b:~$
【5/16追記】ファイルのタイムスタンプを[External]ExifのメタデータExif.Image.DateTimeに合わせる部分を改修。(ubuntu 10.04/Python 2.6環境由来の可能性あり)
yano@GT110b:~$ diff -bc ~/software/eyefiserver2/etc/eyefiserver.conf /etc/
*** /home/yano/software/eyefiserver2/etc/eyefiserver.conf      2012-06-28 13:16:46.000000000 +0900
--- /etc/eyefiserver.conf      2013-05-15 10:17:51.000000000 +0900
***************
*** 14,21 ****
  # or ~/Applications Data/Eye-Fi/Settings.xml on mac
  # search for it and paste it here:

! mac_0:<mac address goes here>
! upload_key_0:<upload key goes here>

  mac_1:<mac address goes here>
  upload_key_1:<upload key goes here>
--- 14,21 ----
  # or ~/Applications Data/Eye-Fi/Settings.xml on mac
  # search for it and paste it here:

! mac_0:001856******
! upload_key_0:66beb2d6f0279e5c********************

  mac_1:<mac address goes here>
  upload_key_1:<upload key goes here>
***************
*** 25,31 ****
  # /home/myblog/pictures/%%Y-%%m-%%d
  # notice the double percent sign to escape % from ini interpolation

! upload_dir:/home/david/Pictures/eye-fi/%%Y-%%m

  # The UID of the user that you want to own the uploaded images
  upload_uid:1000
--- 25,32 ----
  # /home/myblog/pictures/%%Y-%%m-%%d
  # notice the double percent sign to escape % from ini interpolation

! upload_dir:/home/family/10_Digicam%%Y/%%Y%%m%%d/
! temp_dir:/var/tmp/eyefiserver/

  # The UID of the user that you want to own the uploaded images
  upload_uid:1000
***************
*** 35,37 ****
--- 36,40 ----
  upload_file_mode:420
  # The permissions to use for the directories that are created
  upload_dir_mode:509
+
+ timezone:+9
yano@GT110b:~$

1月に移行したUFW(Uncomplicated Firewall)の対応も忘れずに。

[eyefiserver]
title=Eyefi-server
description=Eye-Fi memory cards send pictures from digital cameras to your computer (or any machine on your network) using wifi. I use it to send pictures from my camera to my NAS. Read more about Eye-Fi at http://eye.fi/
ports=59278/tcp
…のような設定ファイル/etc/ufw/applications.d/eyefiserverを作成し、設定を適用したあと、デーモンを起動すればOK。
yano@GT110b:~$ sudo ufw allow eyefiserver
yano@GT110b:~$ sudo ufw enable
yano@GT110b:~$ sudo ufw reload
yano@GT110b:~$ sudo update-rc.d eyefiserver enable S23
yano@GT110b:~$ sudo /etc/init.d/eyefiserver start

うまくアップロードできた場合は、以下のようなログが記録されているはずだ。

yano@GT110b:~$ tail -f /var/log/eyefiserver.log
[05/15/13 01:37AM][do_POST] - POST /api/soap/eyefilm/v1 HTTP/1.1
[05/15/13 01:37AM][do_POST] - Headers received in POST request:
[05/15/13 01:37AM][do_POST] - content-length: 410
[05/15/13 01:37AM][do_POST] - soapaction: "urn:StartSession"
[05/15/13 01:37AM][do_POST] - connection: Keep-Alive
[05/15/13 01:37AM][do_POST] - accept: text/xml, application/soap
[05/15/13 01:37AM][do_POST] - user-agent: Eye-Fi Card/5.0019
[05/15/13 01:37AM][do_POST] - host: api.eye.fi
[05/15/13 01:37AM][do_POST] - Attempting to read 410 bytes of data
[05/15/13 01:37AM][do_POST] - Finished reading 410 bytes of data
[05/15/13 01:37AM][do_POST] - Got StartSession request
[05/15/13 01:37AM][startSession] - Delegating the XML parsing of startSession postData to EyeFiContentHandler()
[05/15/13 01:37AM][startSession] - Extracted elements: {'transfermode': u'514', 'macaddress': u'001856******', 'cnonce': u'919b836432f93e0c3023fb37f2b9dc52', 'transfermodetimestamp': u'1368542908'}
[05/15/13 01:37AM][startSession] - Got MAC address of 001856******
[05/15/13 01:37AM][startSession] - Setting Eye-Fi upload key to 66beb2d6f0279e5c********************
[05/15/13 01:37AM][startSession] - Concatenated credential string (pre MD5): 001856******919b836432f93e0c3023fb37f2b9dc5266beb2d6f0279e5c7349b587e363a294
[05/15/13 01:37AM][do_POST] - StartSession response: <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><StartSessionResponse xmlns="http://localhost/api/soap/eyefilm"><credential>0bca8161a1999bff49c6517de26967e1</credential><snonce>99208c155fc1883579cf0812ec0fe6d2</snonce><transfermode>2</transfermode><transfermodetimestamp>1230268824</transfermodetimestamp><upsyncallowed>false</upsyncallowed></StartSessionResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
[05/15/13 01:37AM][do_POST] - POST /api/soap/eyefilm/v1 HTTP/1.1
[05/15/13 01:37AM][do_POST] - Headers received in POST request:
[05/15/13 01:37AM][do_POST] - content-length: 477
[05/15/13 01:37AM][do_POST] - soapaction: "urn:GetPhotoStatus"
[05/15/13 01:37AM][do_POST] - connection: Keep-Alive
[05/15/13 01:37AM][do_POST] - accept: text/xml, application/soap
[05/15/13 01:37AM][do_POST] - user-agent: Eye-Fi Card/5.0019
[05/15/13 01:37AM][do_POST] - host: api.eye.fi
[05/15/13 01:37AM][do_POST] - Attempting to read 477 bytes of data
[05/15/13 01:37AM][do_POST] - Finished reading 477 bytes of data
[05/15/13 01:37AM][do_POST] - Got GetPhotoStatus request
[05/15/13 01:37AM][do_POST] - GetPhotoStatus response: <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><GetPhotoStatusResponse xmlns="http://localhost/api/soap/eyefilm"><fileid>1</fileid><offset>0</offset></GetPhotoStatusResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
[05/15/13 01:37AM][do_POST] - POST /api/soap/eyefilm/v1/upload HTTP/1.1
[05/15/13 01:37AM][do_POST] - Headers received in POST request:
[05/15/13 01:37AM][do_POST] - content-length: 3758019
[05/15/13 01:37AM][do_POST] - connection: Keep-Alive
[05/15/13 01:37AM][do_POST] - accept: text/xml, application/soap
[05/15/13 01:37AM][do_POST] - user-agent: Eye-Fi Card/5.0019
[05/15/13 01:37AM][do_POST] - host: api.eye.fi
[05/15/13 01:37AM][do_POST] - content-type: multipart/form-data; boundary=---------------------------02468ace13579bdfcafebabef00d
[05/15/13 01:37AM][do_POST] - Attempting to read 3758019 bytes of data
[05/15/13 01:37AM][do_POST] - Finished reading 3758019 bytes of data
[05/15/13 01:37AM][do_POST] - Got upload request
[05/15/13 01:37AM][uploadPhoto] - multipart/form-data; boundary=---------------------------02468ace13579bdfcafebabef00d
[05/15/13 01:37AM][uploadPhoto] - ['multipart/form-data', ' boundary=---------------------------02468ace13579bdfcafebabef00d']
[05/15/13 01:37AM][uploadPhoto] - Extracted boundary: ---------------------------02468ace13579bdfcafebabef00d
[05/15/13 01:37AM][uploadPhoto] - Available multipart/form-data: ['SOAPENVELOPE', 'INTEGRITYDIGEST', 'FILENAME']
[05/15/13 01:37AM][uploadPhoto] - SOAPENVELOPE: <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="EyeFi/SOAP/EyeFilm"><SOAP-ENV:Body><ns1:UploadPhoto><fileid>1</fileid><macaddress>001856******</macaddress><filename>IMG_0188.JPG.tar</filename><filesize>3757056</filesize><filesignature>353100000096030000000000e0110300</filesignature><encryption>none</encryption><flags>4</flags></ns1:UploadPhoto></SOAP-ENV:Body></SOAP-ENV:Envelope>
[05/15/13 01:37AM][uploadPhoto] - Extracted elements: {'macaddress': u'001856******', 'filesignature': u'353100000096030000000000e0110300', 'filename': u'IMG_0188.JPG.tar', 'filesize': u'3757056', 'fileid': u'1'}
[05/15/13 01:37AM][uploadPhoto] - Using uid/gid 1000/1000
[05/15/13 01:37AM][uploadPhoto] - Using file_mode 420
[05/15/13 01:37AM][uploadPhoto] - Using dir_mode 509
[05/15/13 01:37AM][uploadPhoto] - Using timezone 9
[05/15/13 01:37AM][uploadPhoto] - Using tempDir /home/family/10_Digicam2013/20130514
[05/15/13 01:37AM][uploadPhoto] - Generated path /var/tmp/eyefiserver/IMG_0188.JPG.tar
[05/15/13 01:37AM][uploadPhoto] - Opened file /var/tmp/eyefiserver/IMG_0188.JPG.tar for binary writing
[05/15/13 01:37AM][uploadPhoto] - Wrote file /var/tmp/eyefiserver/IMG_0188.JPG.tar
[05/15/13 01:37AM][uploadPhoto] - Closed file /var/tmp/eyefiserver/IMG_0188.JPG.tar
[05/15/13 01:37AM][uploadPhoto] - Extracting TAR file /var/tmp/eyefiserver/IMG_0188.JPG.tar
[05/15/13 01:37AM][uploadPhoto] - Creating folder /home/family/10_Digicam2013/20130515/
[05/15/13 01:37AM][uploadPhoto] - imamgePath /home/family/10_Digicam2013/20130515/IMG_0188.JPG
[05/15/13 01:37AM][uploadPhoto] - Closing TAR file /var/tmp/eyefiserver/IMG_0188.JPG.tar
[05/15/13 01:37AM][uploadPhoto] - Deleting TAR file /var/tmp/eyefiserver/IMG_0188.JPG.tar

次はPQI Air Cardからも直接サーバにアップロードできるようにしないとな。

【参照】
●ガジェットに関するメモ http://gadget-memo.blogspot.jp/
EyeFi ManagerがListenしているPort(Macの場合) 2009年3月30日
●デジモノに埋もれる日々 http://ckworks.jp/blog/
Eye-Fiの写真データはドコを通るか? 「転送経路」を検証する 2008年12月26日
●uchikoshi22.py http://fukuoka-py.g.hatena.ne.jp/uchikoshi22/
Ubuntuのpyexiv2で画像Exif情報を読み取り 2011年9月11日
●Lynx-EyEDの電音鍵盤 新館 http://lynxeyed.hatenablog.com/
PQI Air CardでFTP 2012年10月16日
●ひとりぶろぐ http://hitoriblog.com/
まだハック可能?PQI Air Cardの新ファームウェアV147人柱レポート 2013年2月6日
●ITmedia オルタナティブ・ブログ http://blogs.itmedia.co.jp/
これはいい!PQI Air Cardの2つの不満を解決する方法 2013年4月2日
●eyefiserver2 - A standalone Eye-Fi Server in python, for linux https://code.google.com/p/eyefiserver2/
eyefiserver2-DEV.tar.gz