<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Tom Moertel's Weblog: Tag images</title>
    <link>http://blog.moertel.com/articles/tag/images?tag=images</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Quality rants on programming theory and stuff geeks like</description>
    <item>
      <title>How to download photos and movies from the Palm Centro to a Linux desktop</title>
      <description>&lt;p&gt;I recently got a Palm Centro smartphone, and so far I love it. Like
most modern cell phones, it has a built-in camera and takes decent
snapshots and even records short movies. It&amp;#8217;s great for
spur-of-the-moment shots when I don&amp;#8217;t have my real camera.  The
trick &amp;#8211; and there&amp;#8217;s always a trick when it comes to cell phones &amp;#8211; is getting
the photos off the camera and onto my computer.&lt;/p&gt;


	&lt;p&gt;To get at my pictures, Sprint would prefer that I sign up for their
ludicrously expensive &amp;#8220;PictureMail&amp;#8221; service.  Leave it to weasely
telecom execs to come up with another way to squeeze money from
teenagers: charge them $5 each month for the &amp;#8220;privilege&amp;#8221; of sharing
their pictures with friends.  This fee, of course, is in addition to the
fee for &amp;#8220;unlimited&amp;#8221; mobile Internet use.  I guess picture bits are
somehow more expensive to move over the air than other kinds of bits.&lt;/p&gt;


	&lt;p&gt;In any case, my next goal after
getting my &lt;a href="http://blog.moertel.com/articles/2007/10/31/how-to-hotsync-the-palm-centro-with-a-fedora-7-linux-desktop-via-usb"&gt;Centro to hotsync with my Linux
workstation&lt;/a&gt; was to figure out how
to download my photos and movies.&lt;/p&gt;


	&lt;p&gt;After a bit of hacking, I figured out that the Centro stores images in
a typical digital-camera-image (DCIM) hierarchy.  For
example, I have a 4-GB microSD card installed in my Centro, and I
store my photos in the &amp;#8220;Palm&amp;#8221; album on it.  This album ends up stored
in the /DCIM/Palm directory on the card.&lt;/p&gt;


	&lt;p&gt;Using the pilot-xfer program
from the &lt;a href="http://www.pilot-link.org/"&gt;pilot-link&lt;/a&gt; project, I was able
to find the directory and its contents.  The trick was to use the
sparsely documented &amp;#8211;D flag to work with the Centro&amp;#8217;s virtual
filesystem.  Here, for example, is how I list the contents of the Palm album:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ pilot-xfer -p usb: -D /DCIM/Palm -l

   Listening for incoming connection on usb:... connected!

   Directory of /DCIM/Palm...
        652 Fri Nov  2 08:17:06 2007  Album.db
     292053 Fri Nov  2 09:04:20 2007  Photo_110207_001.jpg
      78493 Fri Nov  2 08:17:06 2007  Video_110207_001.3g2
         20 Wed Oct 31 12:09:20 2007  Thumbnail.db

   Thank you for using pilot-link.
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Here, you can see that I have one photo and one movie in the album.
(Movies are stored in .3g2 files that contain &lt;span class="caps"&gt;MPEG4&lt;/span&gt; video.)&lt;/p&gt;


	&lt;p&gt;To download the files, I again turned to pilot-xfer, this time using the
&amp;#8211;f (fetch) flag to fetch a list of files.
Here, for example, I&amp;#8217;ll fetch the image from the listing above:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ pilot-xfer -p usb: -D /DCIM/Palm -f Photo_110207_001.jpg

   Listening for incoming connection on usb:... connected!

   Fetching '/DCIM/Palm' ... (292053 bytes)   285 KiB total.

   Thank you for using pilot-link.
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So that&amp;#8217;s the process.  It&amp;#8217;s kind of clunky, so I wrote a small Python
program to automate it.  (I&amp;#8217;m learning Python.  If you&amp;#8217;re a Pythonista, please
consider critiquing my code. I would be especially thankful if you
could point out any helpful idioms that I may have overlooked.)&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s how to use the program:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$ get-pilot-photos.py --help
Usage: get-pilot-photos.py [options]

Options:
  -h, --help            show this help message and exit
  -s SRCDIR, --srcdir=SRCDIR
                        VFS dir on Palm device from which to fetch images
  -d DESTDIR, --destdir=DESTDIR
                        Where to save the images on your computer
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Both the &amp;#8212;srcdir and &amp;#8212;dstdir options are optional.  If you
omit the first, the program will download photos and movies from the
/DCIM/Palm album.  If you omit the second, the program will save the
downloads to a new, timestamped directory within your home directory.&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s it.  The code is below.&lt;/p&gt;&lt;pre&gt;&lt;code style="font-size: smaller"&gt;#!/usr/bin/env python

# get-pilot-photos.py -
# Download photos and movies from my Palm Centro via pilot-link
#
# Tom Moertel &amp;lt;tom@moertel.com&amp;gt;
# 2007-11-01
#
# Copyright 2007 Thomas G. Moertel
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# See &amp;lt;http://www.gnu.org/licenses/&amp;gt; for more.

import os
import optparse
import re
import subprocess
import time

PILOT_XFER = 'pilot-xfer'
DEFAULT_PALM_IMAGE_DIR = '/DCIM/Palm'

class PhotoImporter(object):

    def __init__(self, src_dir, dest_dir=None):
        self.src_dir = src_dir
        self.dest_dir = dest_dir or self.get_image_dir()

    def run(self):
        print 'Finding images in %s on your Palm device.' % self.src_dir
        print 'Begin hotsync now...'
        images = self.get_image_list()
        if len(images) == 0:
            print 'No images were found.  Done.'
            return
        print 'Found %s images' % len(images)
        print 'Waiting for hotsync to complete...'
        time.sleep(10) # give 1st hotsync time to complete
        print 'Begin another hotsync now...'
        self.fetch_images(images)
        print 'Done.  The images were fetched to the following directory:'
        print self.dest_dir

    def get_image_list(self):
        cmdline = [PILOT_XFER, '-p',  'usb:', '-D', self.src_dir, '-l']
        proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
        listing = proc.stdout.read()
        proc.wait()
        return re.findall(r'\b\S+\.(?:jpg|3g2)\b', listing)

    def fetch_images(self, images):
        cmdline = [PILOT_XFER, '-p',  'usb:', '-D', self.src_dir, '-f'] + images
        subprocess.Popen(cmdline, cwd=self.dest_dir).wait()

    def get_image_dir(self):
        root = os.getenv('HOME') or tempfile.mkdtemp()
        now = time.strftime("%Y-%m-%d--%H.%M.%S", time.localtime())
        dir = os.path.join(root, 'images', 'unsorted-pix', now)
        os.makedirs(dir, mode=0771)
        return dir

def main():
    p = optparse.OptionParser()
    p.add_option('--srcdir', '-s', default=DEFAULT_PALM_IMAGE_DIR,
                 help='VFS dir on Palm device from which to fetch images')
    p.add_option('--destdir', '-d',
                 help='Where to save the images on your computer')
    opts, args = p.parse_args()
    PhotoImporter(opts.srcdir, opts.destdir).run()

if __name__ == '__main__':
    main()
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Fri, 02 Nov 2007 15:32:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:92fcb359-e7e8-41dc-a5b9-86caffcde1f5</guid>
      <author>Tom Moertel</author>
      <link>http://blog.moertel.com/articles/2007/11/02/how-to-download-photos-and-movies-from-the-palm-centro-to-a-linux-desktop</link>
      <category>hacks</category>
      <category>movies</category>
      <category>palm</category>
      <category>centro</category>
      <category>hotsync</category>
      <category>images</category>
      <category>download</category>
      <category>python</category>
      <trackback:ping>http://blog.moertel.com/articles/trackback/616</trackback:ping>
    </item>
  </channel>
</rss>
