Skip to content

Instantly share code, notes, and snippets.

@pkulak

pkulak/camera_dl.rb

Last active Mar 9, 2017
Embed
What would you like to do?
A simple script to get the files off your Olympus camera.
#!/usr/bin/env ruby
require 'open-uri'
require 'time'
require 'json'
class Runner
def initialize
@base = "http://192.168.0.10/DCIM/100OLYMP"
# Replace this with wherever you'd like your photos to live.
@home = File.join(Dir.home, "/Google Drive/Photo Sync/Negatives/#{DateTime.now.year}/#{DateTime.now.strftime("%m")}")
@config = File.join(Dir.home, "/.imported_photos")
unless Dir.exist?(@home)
Dir.mkdir(@home)
end
if File.exist?(@config)
@seen = JSON.parse(IO.read(@config))
else
@seen = []
end
end
def run
page = open(@base).read
last_ext = ""
page.split("\n").each do |line|
next unless line.start_with?("wlansd[")
file = line[11...-3].split(",")[1]
if @seen.include?(file)
puts "skipping file #{file}"
next
end
`curl #{@base}/#{file} > "#{@home}/#{file}"`
@seen << file
end
File.open(@config, 'w') {|file| file.write(@seen.to_json)}
end
end
Runner.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment