Skip to content

Instantly share code, notes, and snippets.

@fourlastor
Forked from rock3r/grabdng.py
Last active March 20, 2016 13:39
Show Gist options
  • Save fourlastor/9d5c40e9755efe4df576 to your computer and use it in GitHub Desktop.
Save fourlastor/9d5c40e9755efe4df576 to your computer and use it in GitHub Desktop.
Grabs all DNG files from the connected Android device's camera roll
#!/usr/bin/python
import argparse, os, subprocess
# Grab the script directory to use as default
current_directory = os.path.dirname(os.path.abspath(__file__))
def parse_cli_arguments():
parser = argparse.ArgumentParser(description = 'Grabs all DNG files from the connected Android device\'s camera roll.')
parser.add_argument('--output-path', type = str, help = 'The path to download the DNGs to. Default: {script_path}/raw',
default = os.path.join(current_directory, 'raw'))
parser.add_argument('-o', '--overwrite', help = 'If set, overwrites any existing file. Default: don\'t overwrite')
return parser.parse_args()
args = parse_cli_arguments()
print "Listing files on your device..."
result = subprocess.check_output(['adb', 'shell', 'ls', '/sdcard/DCIM/Camera/'])
print "Downloading DNGs..."
output_path = args.output_path
if not os.path.exists(output_path):
os.makedirs(output_path)
overwrite = args.overwrite
only_dng = lambda el: el.endswith('.dng')
for filename in filter(only_dng, result.split("\n")):
source_path = "/sdcard/DCIM/Camera/{filename}".format(filename = filename)
dest_path = os.path.join(output_path, line)
if overwrite or not os.path.exists(dest_path):
subprocess.call(['adb', 'pull', source_path, dest_path])
print "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment