flickrup 1.1.16 → 1.1.17

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
  SHA1:
3
- metadata.gz: ad462e038fa89dfb979d9af1c698b9f87580b71a
4
- data.tar.gz: 54d8cebb44f503918fd6e4c6b85bbacbb57ffd88
3
+ metadata.gz: ece798f51989ffaa6c056bc48e54d9a593ba7248
4
+ data.tar.gz: 7ef6b9643cf597917b614353b4934e9d05ea1d9c
5
5
  SHA512:
6
- metadata.gz: 0f52e164534c066fee0275f7fcb3b5fc4a4cfb66141c079cf03f76d79ce8aab383df89f381c16d3feeb95598f11bac62fdf0adb6c801b1b6f216b008f9aa4f3c
7
- data.tar.gz: 51594d054c856ae00d68c8dc82387fc5fcfcc4353724fca6e32a48384c26a9f385e08c86b6415de90061033f75644e4e8b104bbc91e999583992ca196bf406f4
6
+ metadata.gz: d270ceea438c105e8d28626e61c1c1ee2dac02d05169962809fade8cb1e0e8eeee52c7a64ed8352fb27a702b9189a7f3af06822edd597e697733f4f220cc9683
7
+ data.tar.gz: 540b8c03c5d9a1161ae7347be209fa7bfeb8cb51cdf08e1f0f9649251558a73e9bd11f47767110be12619814a32cd97382e4ba87e7125cebcd9be159c372e142
@@ -0,0 +1,33 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ class Converter
5
+ include Logging
6
+
7
+ def initialize(mappings)
8
+ @mappings = mappings
9
+ @move_dir = Dir.tmpdir
10
+ end
11
+
12
+ def maybe_convert(file)
13
+ mapping = @mappings[File.extname(file)[1..-1].downcase]
14
+
15
+ if mapping then
16
+ to_exec = mapping % {:file => file}
17
+ logger.debug("Running: #{to_exec}")
18
+ result = system(to_exec)
19
+
20
+ if result
21
+ logger.info("Removing converted source file #{file}")
22
+ logger.debug("Moving #{file} to #{@move_dir}")
23
+ FileUtils.mv(file, @move_dir)
24
+ else
25
+ logger.info("Failed to convert source file #{file}")
26
+ end
27
+
28
+ return result
29
+ else
30
+ false
31
+ end
32
+ end
33
+ end
@@ -28,6 +28,6 @@ class TaggedVideo < TaggedFile
28
28
  TYPE
29
29
  end
30
30
 
31
- register_reader(%w(mp4 MP4 mts MTS))
31
+ register_reader(%w(mp4 MP4))
32
32
 
33
33
  end
@@ -8,6 +8,7 @@ require "flickrup/ext/visibility"
8
8
  require "flickrup/ext/sidecar"
9
9
  require "flickrup/archiver"
10
10
  require "flickrup/ext/associated_files"
11
+ require 'flickrup/converter'
11
12
 
12
13
  class Processor
13
14
  include Logging
@@ -15,6 +16,7 @@ class Processor
15
16
  def initialize(config)
16
17
  @MAX_DATE = Time.at(2130578470)
17
18
  @config = config
19
+ @converter = Converter.new(config[:convert_files])
18
20
  end
19
21
 
20
22
  def paused
@@ -30,6 +32,19 @@ class Processor
30
32
  return 0
31
33
  end
32
34
 
35
+ converted_count = all_files.select{ |x|
36
+ if File.exist? x
37
+ @converter.maybe_convert(x)
38
+ else
39
+ false
40
+ end
41
+ }.length
42
+
43
+ if converted_count > 0
44
+ logger.info("Converted #{converted_count} files, reprocessing")
45
+ return true
46
+ end
47
+
33
48
  # some files may have been removed by now: https://bitbucket.org/jgilbert/flickrup/issue/1
34
49
  files = all_files.map { |x|
35
50
  if File.exist? x
@@ -81,7 +96,7 @@ class Processor
81
96
 
82
97
  logger.info("Processed #{tagged.length} valid files")
83
98
 
84
- tagged.length
99
+ false
85
100
  end
86
101
 
87
102
  private
@@ -53,7 +53,7 @@ class SlowListener
53
53
  #ignore, processing thread will reschedule
54
54
  logger.info("Scheduling queued")
55
55
  when IDLE
56
- schedule_internal
56
+ schedule_internal @wait
57
57
  end
58
58
  end
59
59
 
@@ -71,6 +71,7 @@ class SlowListener
71
71
  @processing.set PROCESSING
72
72
 
73
73
  files = Dir["#{@config[:watch_dir]}/*.*"]
74
+ reprocess = false
74
75
 
75
76
  old, new = files.partition { |x| Time.now > File.mtime(x) + @wait }
76
77
 
@@ -81,25 +82,27 @@ class SlowListener
81
82
 
82
83
  unless old.empty?
83
84
  logger.info("Found #{old.length} stable files")
84
- @processor.run(old)
85
+ reprocess = @processor.run(old)
85
86
  end
86
87
 
87
88
  @processing.compare_and_swap(PROCESSING, IDLE)
88
89
 
89
- if @processing.get == SCHEDULED
90
+ if reprocess
91
+ schedule_internal 1
92
+ elsif @processing.get == SCHEDULED
90
93
  logger.info("Rescheduling...")
91
- schedule_internal
94
+ schedule_internal @wait
92
95
  end
93
96
  end
94
97
 
95
- def schedule_internal
98
+ def schedule_internal(secs)
96
99
  if @scheduler.jobs.empty?
97
- logger.info("Scheduling processing for #@wait sec")
98
- @scheduler.in @wait do
100
+ logger.info("Scheduling processing for #{secs} sec")
101
+ @scheduler.in secs do
99
102
  do_upload
100
103
  end
101
104
  else
102
- logger.info("Already scheduled")
105
+ logger.info('Already scheduled')
103
106
  end
104
107
  end
105
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickrup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.16
4
+ version: 1.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gilbert
@@ -130,6 +130,7 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - lib/flickrup/archiver.rb
133
+ - lib/flickrup/converter.rb
133
134
  - lib/flickrup/ext/associated_files.rb
134
135
  - lib/flickrup/ext/machine_tags.rb
135
136
  - lib/flickrup/ext/prefixed_extension.rb