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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8005c4c7e035db2675a5f6cdcc0a0567b53aec6117b279d1242c4dae8d671758
4
- data.tar.gz: 9d3ddc4eaf083903e45eaa55de9c93bd97c2201777bc676ee815436b427c0641
3
+ metadata.gz: 7b3bcb770e66b470a49fd5f486560c447e92ba8df6daa33434c45fdd3564a2e7
4
+ data.tar.gz: 83df115282d7cef28bfd2f32a42643a843726ea40c8eda1de5e7908f1b7f4832
5
5
  SHA512:
6
- metadata.gz: 683fd6aa36b788f9e985210e7ae2fc97474b3d155afa04db1d8e1a87c1892b68d9a262e93798b0b3449b83285809e6035c3a82bb4955f1dd3f02f01768173a4f
7
- data.tar.gz: 74cfbc6831fb2fbdb88a09dd0d3412ceac70ddc62379bf37e3bc800e442433b9b13d112bdff358cf04276b5ed6d59dc8804ef0fef757d223dcb466ebc726a627
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::Logger.open
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::Logger.fatal(e.message)
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::Logger.info "optimizing #{path}"
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::Logger.info "optimizing #{path}"
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::Logger.error('optipng is required to compress PNG images')
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::Logger.error(<<~MSG) if e.message.match?(/You must have ImageMagick/)
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::Logger.error(<<~MSG) if e.message.match?(/exiftool: not found/)
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
@@ -4,6 +4,14 @@ require 'logger'
4
4
  require 'singleton'
5
5
 
6
6
  module Photein
7
+ class << self
8
+ attr_writer :logger
9
+
10
+ def logger
11
+ @logger ||= Photein::Logger
12
+ end
13
+ end
14
+
7
15
  class Logger
8
16
  include Singleton
9
17
 
@@ -29,7 +29,7 @@ module Photein
29
29
 
30
30
  optimize if Photein::Config.optimize_for
31
31
 
32
- Photein::Logger.info(<<~MSG.chomp)
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::Logger.error("#{path.basename}: cannot import corrupted file") if r
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::Logger.fatal("skipping #{path}: file in use by #{cmd} (PID #{pid})")
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::Logger.info('conflicting timestamp found; adding counter to existing file')
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?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Photein
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
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::Logger.info("transcoding #{tempfile}")
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::Logger.error('ffmpeg is required to manipulate video files')
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::Logger.error('mediainfo is required to read timestamp metadata')
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.8
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-06 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mediainfo