photein 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/photein +2 -2
- data/lib/photein/image.rb +5 -5
- data/lib/photein/logger.rb +8 -0
- data/lib/photein/media_file.rb +4 -4
- data/lib/photein/version.rb +1 -1
- data/lib/photein/video.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b3bcb770e66b470a49fd5f486560c447e92ba8df6daa33434c45fdd3564a2e7
|
4
|
+
data.tar.gz: 83df115282d7cef28bfd2f32a42643a843726ea40c8eda1de5e7908f1b7f4832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33ceaea508cbe94cc40906364a1094c825c647e0bc7a38a1f9bdc21f1624a63a8b0c7e39351a0dcbc973afd2969af0e5e20615f3404d2b7b2af2f2cc6db1930f
|
7
|
+
data.tar.gz: 798e0351b09bcb1cbe0cae6875b6731cbfeeffb2cba1d2e09bc6b5e9ded21ebf009af302e2c17841e5b6cf2f025e5b1cbcd819787ce645205c3167e6afbb6ba7
|
data/bin/photein
CHANGED
@@ -5,7 +5,7 @@ require 'photein'
|
|
5
5
|
require 'pathname'
|
6
6
|
|
7
7
|
Photein::Config.parse_opts!
|
8
|
-
Photein
|
8
|
+
Photein.logger.open
|
9
9
|
|
10
10
|
# Setup ------------------------------------------------------------------------
|
11
11
|
|
@@ -17,7 +17,7 @@ begin
|
|
17
17
|
raise "#{Photein::Config.dest}: no such directory" unless DEST_DIR.exist?
|
18
18
|
raise "#{Photein::Config.source}: no photos or videos found" if Dir.empty?(SRC_DIR)
|
19
19
|
rescue => e
|
20
|
-
Photein
|
20
|
+
Photein.logger.fatal(e.message)
|
21
21
|
exit 1
|
22
22
|
end
|
23
23
|
|
data/lib/photein/image.rb
CHANGED
@@ -29,7 +29,7 @@ module Photein
|
|
29
29
|
when '.jpg', '.heic'
|
30
30
|
return false if image.dimensions.reduce(&:*) < MAX_RES_WEB
|
31
31
|
|
32
|
-
Photein
|
32
|
+
Photein.logger.info "optimizing #{path}"
|
33
33
|
MiniMagick::Tool::Convert.new do |convert|
|
34
34
|
convert << path
|
35
35
|
convert.colorspace('sRGB')
|
@@ -42,11 +42,11 @@ module Photein
|
|
42
42
|
end unless Photein::Config.dry_run
|
43
43
|
when '.png'
|
44
44
|
FileUtils.cp(path, tempfile, noop: Photein::Config.dry_run)
|
45
|
-
Photein
|
45
|
+
Photein.logger.info "optimizing #{path}"
|
46
46
|
begin
|
47
47
|
Optipng.optimize(tempfile, level: 4) unless Photein::Config.dry_run
|
48
48
|
rescue Errno::ENOENT
|
49
|
-
Photein
|
49
|
+
Photein.logger.error('optipng is required to compress PNG images')
|
50
50
|
raise
|
51
51
|
end
|
52
52
|
end
|
@@ -57,7 +57,7 @@ module Photein
|
|
57
57
|
def image
|
58
58
|
@image ||= MiniMagick::Image.open(path)
|
59
59
|
rescue MiniMagick::Invalid => e
|
60
|
-
Photein
|
60
|
+
Photein.logger.error(<<~MSG) if e.message.match?(/You must have ImageMagick/)
|
61
61
|
ImageMagick is required to manipulate image files
|
62
62
|
MSG
|
63
63
|
raise
|
@@ -66,7 +66,7 @@ module Photein
|
|
66
66
|
def metadata_stamp
|
67
67
|
MiniExiftool.new(path.to_s).date_time_original
|
68
68
|
rescue MiniExiftool::Error => e
|
69
|
-
Photein
|
69
|
+
Photein.logger.error(<<~MSG) if e.message.match?(/exiftool: not found/)
|
70
70
|
exiftool is required to read timestamp metadata
|
71
71
|
MSG
|
72
72
|
raise
|
data/lib/photein/logger.rb
CHANGED
data/lib/photein/media_file.rb
CHANGED
@@ -29,7 +29,7 @@ module Photein
|
|
29
29
|
|
30
30
|
optimize if Photein::Config.optimize_for
|
31
31
|
|
32
|
-
Photein
|
32
|
+
Photein.logger.info(<<~MSG.chomp)
|
33
33
|
#{Photein::Config.keep ? 'copying' : 'moving'} #{path.basename} to #{dest_path}
|
34
34
|
MSG
|
35
35
|
|
@@ -47,7 +47,7 @@ module Photein
|
|
47
47
|
|
48
48
|
def corrupted?(result = false)
|
49
49
|
return result.tap do |r|
|
50
|
-
Photein
|
50
|
+
Photein.logger.error("#{path.basename}: cannot import corrupted file") if r
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -61,7 +61,7 @@ module Photein
|
|
61
61
|
|
62
62
|
if status.success? # Do open files ALWAYS return exit status 0? (I think so.)
|
63
63
|
cmd, pid = out.lines[1]&.split&.first(2)
|
64
|
-
Photein
|
64
|
+
Photein.logger.fatal("skipping #{path}: file in use by #{cmd} (PID #{pid})")
|
65
65
|
return true
|
66
66
|
else
|
67
67
|
return false
|
@@ -119,7 +119,7 @@ module Photein
|
|
119
119
|
when 0 # if no files found, no biggie
|
120
120
|
when 1 # if one file found, WITH OR WITHOUT COUNTER, reset counter to a
|
121
121
|
if Dir[collision_glob].first != collision_glob.sub('*', 'a') # don't try if it's already a lone, correctly-countered file
|
122
|
-
Photein
|
122
|
+
Photein.logger.info('conflicting timestamp found; adding counter to existing file')
|
123
123
|
FileUtils.mv(Dir[collision_glob].first, collision_glob.sub('*', 'a'), noop: Photein::Config.dry_run)
|
124
124
|
end
|
125
125
|
else # TODO: if multiple files found, rectify them?
|
data/lib/photein/version.rb
CHANGED
data/lib/photein/video.rb
CHANGED
@@ -36,7 +36,7 @@ module Photein
|
|
36
36
|
def optimize
|
37
37
|
return if video.bitrate < BITRATE_THRESHOLD[Photein::Config.optimize_for]
|
38
38
|
|
39
|
-
Photein
|
39
|
+
Photein.logger.info("transcoding #{tempfile}")
|
40
40
|
return if Photein::Config.dry_run
|
41
41
|
|
42
42
|
video.transcode(
|
@@ -60,7 +60,7 @@ module Photein
|
|
60
60
|
def video
|
61
61
|
@video ||= FFMPEG::Movie.new(path.to_s)
|
62
62
|
rescue Errno::ENOENT
|
63
|
-
Photein
|
63
|
+
Photein.logger.error('ffmpeg is required to manipulate video files')
|
64
64
|
raise
|
65
65
|
end
|
66
66
|
|
@@ -68,7 +68,7 @@ module Photein
|
|
68
68
|
# video timestamps are typically UTC
|
69
69
|
MediaInfo.from(path.to_s).general.encoded_date&.getlocal
|
70
70
|
rescue MediaInfo::EnvironmentError
|
71
|
-
Photein
|
71
|
+
Photein.logger.error('mediainfo is required to read timestamp metadata')
|
72
72
|
raise
|
73
73
|
end
|
74
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: photein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Lue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mediainfo
|