photo-helper 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15c0871a007b14b316dea045d05cb6b1aa45138d
4
- data.tar.gz: b1f3f2c3a80c62ab196d40509872cbb523f7ccfc
3
+ metadata.gz: 72ceb15c03d99b057c67256c085549136c8ba316
4
+ data.tar.gz: 03e82ca1efe158858eab5c189705275a071215d1
5
5
  SHA512:
6
- metadata.gz: a90878d857cf0d91f67adad0e28fd31cb4d17397ee42bd98ae8f3ce6c6e2d02ecd1b8c5379b670fae7c7a3ff3d6a482f91c83f13c441609e166caff1032ea182
7
- data.tar.gz: bb0bf7405842d936da3daba1af3defb8705a0960335ff97b3d16b28489a8dfe35db11ccd379e24c7d22c7b0c332a0c59b8d35111089dc010afef61a8eab3a127
6
+ metadata.gz: 1f06f55c4a414864ba7436950322ce7538c2bff225b5cf3243d8c4a87ec67dd0d5a6f622a3331407530a89a54f4d5626ff9ca030a3032b4448b50d16c0d1ab07
7
+ data.tar.gz: f4dbfa2de0930a5a3dc361b1dfabe4759fc15f919c00bdce35338bda1c77162e03781703adf472d9655c85d6c83b139838db2badefc93eb7d7006105f2eca888
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- photo-helper (0.2.9)
4
+ photo-helper (0.2.10)
5
5
  ejson
6
6
  mimemagic
7
7
  mini_magick
@@ -9,6 +9,6 @@ class FileHelper
9
9
 
10
10
  def self.is_jpeg?(path)
11
11
  extension = File.extname(path)
12
- ['.jpeg', '.jpg'].include? extension.downcase
12
+ JPEG_EXTENSIONS.include? extension.downcase
13
13
  end
14
14
  end
@@ -1,11 +1,35 @@
1
1
  class ImageHelper
2
2
  IMAGE_CLASS_REGEX = %r{xmp:Label="(.+)"}
3
+ RATING_REGEX = %r{xmp:Rating="(.+)"}
3
4
 
4
- def self.color_class(image)
5
+ def self.xmp(image)
5
6
  xmp = File.join(File.dirname(image), File.basename(image, ".*") + ".XMP")
6
7
  return unless File.exists?(xmp)
7
- contents = File.read(xmp)
8
+ File.read(xmp)
9
+ end
10
+
11
+ def self.color_class(image)
12
+ contents = xmp(image)
8
13
  matches = contents.match(IMAGE_CLASS_REGEX)
9
- matches[1] if matches
14
+ matches[1] if matches
15
+ end
16
+
17
+ def self.contains_color_class?(image, values)
18
+ values = [values] unless values.is_a? Array
19
+ values.include? color_class(image)
20
+ end
21
+
22
+ def self.rating(image)
23
+ contents = xmp(image)
24
+ matches = contents.match(RATING_REGEX)
25
+ matches[1] if matches
26
+ end
27
+
28
+ def self.is_select?(image)
29
+ contains_color_class?(image, SELECT_COLOR_TAGS)
30
+ end
31
+
32
+ def self.is_5_star?(image)
33
+ rating(image) == '5'
10
34
  end
11
35
  end
@@ -0,0 +1,84 @@
1
+ require "helpers/smugmug_api"
2
+ require "helpers/image_helper"
3
+ require "helpers/file_helper"
4
+
5
+ class SmugmugHelper
6
+ attr_accessor :smugmug_api
7
+
8
+ # to figure out what to delete, read all xmp files, loop through uploaded files and check xmp file
9
+
10
+ PATH_REGEX = %r{^.+Pictures\/.+\/(\d{4})\/(\d{2})_.+\/[^_]+_([^\/]+)}
11
+
12
+ def initialize(search_path)
13
+ @search_path = search_path
14
+ @smugmug = SmugmugAPI.new
15
+ end
16
+
17
+ def parse_path
18
+ if matches = "#{@search_path}/".to_s.match(PATH_REGEX)
19
+ @year = matches[1]
20
+ @month = Date::MONTHNAMES[matches[2].to_i].capitalize
21
+ @location = matches[3].split("_").map(&:capitalize).join(' ')
22
+ end
23
+ end
24
+
25
+ def album_name
26
+ parse_path
27
+ if @year && @month && @location
28
+ folder = "#{@month} #{@year}"
29
+ album_name_short = "#{@location} #{@month} #{@year}"
30
+ File.join(@year, @month, album_name_short)
31
+ else
32
+ puts 'Unable to determine album from path'
33
+ end
34
+ end
35
+
36
+ def image_list
37
+ # todo: exclude exported path
38
+ Dir["#{@search_path}/**/*.{#{IMAGE_EXTENSIONS.join(",")}}"].reject{ |p| FileHelper.ingore_file?(p) }
39
+ end
40
+
41
+ def merge_exported(images = image_list)
42
+ exported = Dir["#{@search_path}/**/{Exported,exported}/*.{#{IMAGE_EXTENSIONS.join(",")}}"]
43
+ exported_basenames = exported.map{ |p| File.basename(p, ".*") }
44
+ images = images.reject { |p| exported_basenames.include? File.basename(p, ".*") }
45
+ images.concat(exported)
46
+ end
47
+
48
+ def upload(album_name, pictures, reject_trash = true)
49
+ album = @smugmug.get_or_create_album(album_name, album_url: @location&.downcase)
50
+ puts "#{album[:web_uri]}\n"
51
+
52
+ # remove uploaded pictures
53
+ uploaded = @smugmug.image_list(album[:id])
54
+
55
+ pictures = pictures.reject do |p|
56
+ if reject_trash
57
+ return true if ImageHelper.color_class(p) == "Trash"
58
+ end
59
+ uploaded.include? File.basename(p)
60
+ end
61
+
62
+ puts "Uploading #{pictures.count} jpegs"
63
+
64
+ @smugmug.upload_images(pictures, album[:id], workers: 8)
65
+ end
66
+
67
+ def upload_dl
68
+ @album_name = album_name
69
+ @album_name = File.join("dl", @album_name)
70
+
71
+ puts "Uploading all images to album #{@album_name}"
72
+ upload(@album_name, image_list)
73
+ end
74
+
75
+ def upload_select
76
+ @album_name = album_name
77
+ pictures = image_list
78
+ pictures = pictures.select{ |p| ImageHelper.is_select?(p)}
79
+ pictures = merge_exported(pictures)
80
+
81
+ puts "Uploading selects to album #{@album_name}"
82
+ upload(@album_name, pictures)
83
+ end
84
+ end
data/lib/helpers/trash.rb CHANGED
@@ -16,7 +16,7 @@ class File
16
16
  FileUtils.mv(filename,"/Volumes/#{$1}/.Trashes/501/")
17
17
  else
18
18
  # Main drive, move to ~/.Trash/
19
- FileUtils.mv(filename,self.expand_path("~/.Trash/"))
19
+ FileUtils.mv(filename,self.expand_path("~/.Trash"))
20
20
  end
21
21
  # when /^Microsoft Windows/
22
22
  # raise NotImplementedError, ""
@@ -1,4 +1,5 @@
1
1
  require 'helpers/trash'
2
+ require 'helpers/file_helper'
2
3
 
3
4
  module PhotoHelper
4
5
  class Delete < Thor
@@ -28,9 +29,13 @@ module PhotoHelper
28
29
  end
29
30
 
30
31
  files.each do |file|
31
- raw_file_name = File.basename(file.to_s, JPEG_EXTENSION) + RAW_EXTENSION
32
- next unless File.exist? File.join(search_path, raw_file_name)
33
-
32
+ has_raw = false
33
+ RAW_EXTENSIONS.each do |extension|
34
+ raw_file_name = "#{File.basename(file.to_s, '.*')}.#{extension}"
35
+ has_raw = true if File.exist? File.join(File.dirname(file.to_s), raw_file_name)
36
+ end
37
+ next unless has_raw
38
+ next if FileHelper.ingore_file?(file)
34
39
  puts file
35
40
 
36
41
  if options[:hard]
@@ -1,49 +1,30 @@
1
- require 'helpers/smugmug_api'
1
+ require 'helpers/smugmug'
2
2
  require 'date'
3
3
  require 'helpers/image_helper'
4
4
 
5
5
  module PhotoHelper
6
6
  class Smugmug < Thor
7
7
  include Thor::Actions
8
- PATH_REGEX = %r{^.+Pictures\/.+\/(\d{4})\/(\d{2})_.+\/[^_]+_([^\/]+)}
9
8
 
10
9
  map 's' => 'sync'
11
-
12
10
  desc 'sync', "sync folder's non-raw images with smugmug"
13
11
  method_option :folder, aliases: '-f', type: :string, default: '.'
14
12
  method_option :recursive, aliases: '-r', type: :boolean, default: false
15
13
  method_option :dry_run, aliases: '-d', type: :boolean, default: false
16
14
  def sync(folder = nil, album_name = nil)
17
15
  search_path = File.expand_path(folder)
18
- unless album_name
19
- if matches = "#{search_path}/".to_s.match(PATH_REGEX)
20
- year = matches[1]
21
- month = Date::MONTHNAMES[matches[2].to_i].capitalize
22
- location = matches[3].split("_").map(&:capitalize).join(' ')
23
16
 
24
- folder = "#{month} #{year}"
25
- album_name_short = "#{location} #{month} #{year}"
26
- album_name = File.join(year, month, album_name_short)
27
- else
28
- puts 'Unable to determine album from path'
29
- return
30
- end
31
- end
32
- puts "Using album: #{album_name}"
17
+ @smugmug = SmugmugHelper.new(search_path)
33
18
 
34
- @smugmug = SmugmugAPI.new
35
- album = @smugmug.get_or_create_album(album_name, album_url: location&.downcase)
36
- puts "#{album[:web_uri]}\n"
37
- pictures = Dir["#{search_path}/**/*.{#{IMAGE_EXTENSIONS.join(",")}}"]
38
-
39
- # remove uploaded pictures
40
- uploaded = @smugmug.image_list(album[:id])
41
- pictures = pictures.reject { |p| (ImageHelper.color_class(p) == "Trash" or uploaded.include? File.basename(p)) }
42
- puts "Uploading #{pictures.count} jpegs"
43
-
44
- @smugmug.upload_images(pictures, album[:id], workers: 8)
19
+ @smugmug.upload_select
20
+ puts("\n")
21
+ if album_name
22
+ @smugmug.upload(album_name, @smugmug.image_list)
23
+ else
24
+ @smugmug.upload_dl
25
+ end
45
26
  end
46
-
27
+
47
28
  desc 'oauth', "fetch oauth credentials"
48
29
  def oauth()
49
30
  SmugmugAPI.new.request_access_token
@@ -1,3 +1,3 @@
1
1
  module KubeDeploy
2
- VERSION = '0.2.9'.freeze
2
+ VERSION = '0.2.10'.freeze
3
3
  end
data/lib/photo_helper.rb CHANGED
@@ -19,11 +19,13 @@ IMAGE_EXTENSIONS = JPEG_EXTENSIONS.concat([])
19
19
  PHOTOS_ROOT = "/Users/benjamincaldwell/Pictures/Pictures"
20
20
  JPEG_ROOT ="/Users/benjamincaldwell/Pictures/jpegs"
21
21
  IGNORE_FOLDERS = ["instagram", "exported", "edited"]
22
+ SELECT_COLOR_TAGS = ["Winner", "Winner alt", "Superior", "Superior alt"]
22
23
 
23
24
  module PhotoHelper
24
25
  class CLI < Thor
25
26
  map "g" => "generate"
26
27
  map "d" => "delete"
28
+ map "s" => "smugmug"
27
29
 
28
30
  desc "version", "displays installed version"
29
31
  def version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photo-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Caldwell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
11
+ date: 2017-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -216,6 +216,7 @@ files:
216
216
  - lib/helpers/image_helper.rb
217
217
  - lib/helpers/printer.rb
218
218
  - lib/helpers/secrets.rb
219
+ - lib/helpers/smugmug.rb
219
220
  - lib/helpers/smugmug_api.rb
220
221
  - lib/helpers/trash.rb
221
222
  - lib/photo-helper/compress.rb