flickrup 0.0.14 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flickrup/ext/machine_tags.rb +5 -5
- data/lib/flickrup/ext/prefixed_extension.rb +2 -2
- data/lib/flickrup/ext/replacement_tags.rb +4 -4
- data/lib/flickrup/ext/tag_sets.rb +3 -3
- data/lib/flickrup/ext/visibility.rb +3 -3
- data/lib/flickrup/processing_context.rb +13 -0
- data/lib/flickrup/processor.rb +4 -4
- data/lib/flickrup/tagged_image.rb +10 -9
- data/lib/flickrup/uploader.rb +11 -7
- metadata +5 -4
@@ -3,9 +3,9 @@ class MachineTags
|
|
3
3
|
@config = config
|
4
4
|
end
|
5
5
|
|
6
|
-
def preupload(
|
6
|
+
def preupload(ctx)
|
7
7
|
|
8
|
-
tags =
|
8
|
+
tags = ctx.image.tags
|
9
9
|
|
10
10
|
remapped = tags.map do |x|
|
11
11
|
x.sub(/^([^:]+):([^:]+)::/,"\\1:\\2=")
|
@@ -14,11 +14,11 @@ class MachineTags
|
|
14
14
|
|
15
15
|
|
16
16
|
unless tags == remapped #write back to file
|
17
|
-
|
18
|
-
|
17
|
+
ctx.image['Keywords'] = remapped
|
18
|
+
ctx.image['Subject'] = remapped #also write Subject XMP tag
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
ctx
|
22
22
|
|
23
23
|
end
|
24
24
|
end
|
@@ -3,23 +3,23 @@ class ReplacementTags
|
|
3
3
|
@config = config
|
4
4
|
end
|
5
5
|
|
6
|
-
def preupload(
|
6
|
+
def preupload(ctx)
|
7
7
|
|
8
8
|
replacements = @config[:tag_replacements]
|
9
9
|
|
10
10
|
if replacements != nil
|
11
11
|
replacements.each do |tag_name, tag_value_replacements|
|
12
|
-
existing =
|
12
|
+
existing = ctx.image[tag_name]
|
13
13
|
|
14
14
|
tag_value_replacements.each do |key, value|
|
15
15
|
if existing == key
|
16
|
-
|
16
|
+
ctx.image[tag_name] = value
|
17
17
|
break
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
ctx
|
24
24
|
end
|
25
25
|
end
|
@@ -7,10 +7,10 @@ class TagSets < PrefixedExtension
|
|
7
7
|
@flickr = context[:flickr_client]
|
8
8
|
end
|
9
9
|
|
10
|
-
def upload(
|
11
|
-
sets = values(:tagsetprefix,
|
10
|
+
def upload(ctx)
|
11
|
+
sets = values(:tagsetprefix, ctx)
|
12
12
|
|
13
|
-
uploaded = @delegate.upload(
|
13
|
+
uploaded = @delegate.upload(ctx)
|
14
14
|
|
15
15
|
sets.each do |set|
|
16
16
|
@flickr.add_to_set(uploaded, set)
|
@@ -8,8 +8,8 @@ class Visibility < PrefixedExtension
|
|
8
8
|
@delegate = delegate
|
9
9
|
end
|
10
10
|
|
11
|
-
def upload(
|
12
|
-
visibility = values(:visibilityprefix,
|
11
|
+
def upload(ctx)
|
12
|
+
visibility = values(:visibilityprefix, ctx)
|
13
13
|
|
14
14
|
config_override = if visibility.length == 0
|
15
15
|
logger.debug("No visibility specified for #{image}.")
|
@@ -21,7 +21,7 @@ class Visibility < PrefixedExtension
|
|
21
21
|
config_for_visibility(visibility[0])
|
22
22
|
end
|
23
23
|
|
24
|
-
@delegate.upload(
|
24
|
+
@delegate.upload(ctx.with_properties(config_override))
|
25
25
|
end
|
26
26
|
|
27
27
|
def config_for_visibility(visibility)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ProcessingContext
|
2
|
+
attr_reader :image
|
3
|
+
attr_reader :upload_properties
|
4
|
+
|
5
|
+
def initialize(image, props = {})
|
6
|
+
@image = image
|
7
|
+
@upload_properties = props
|
8
|
+
end
|
9
|
+
|
10
|
+
def with_properties(props)
|
11
|
+
ProcessingContext.new(self.image, self.upload_properties.merge(props))
|
12
|
+
end
|
13
|
+
end
|
data/lib/flickrup/processor.rb
CHANGED
@@ -39,12 +39,12 @@ class Processor
|
|
39
39
|
sleep 5
|
40
40
|
else
|
41
41
|
tagged.each { |x|
|
42
|
-
logger.debug("Beginning upload for #{x.
|
42
|
+
logger.debug("Beginning upload for #{x.filename}...")
|
43
43
|
x.doUpload(get_preupload_handlers, uploader)
|
44
|
-
logger.debug("Upload complete for #{x.
|
45
|
-
logger.debug("Beginning archive for #{x.
|
44
|
+
logger.debug("Upload complete for #{x.filename}")
|
45
|
+
logger.debug("Beginning archive for #{x.filename}...")
|
46
46
|
x.archive(@config[:archive_dir])
|
47
|
-
logger.debug("Processing complete for #{x.
|
47
|
+
logger.debug("Processing complete for #{x.filename}")
|
48
48
|
}
|
49
49
|
end
|
50
50
|
|
@@ -2,15 +2,16 @@ require 'mini_exiftool'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require "flickrup/logging"
|
4
4
|
require "flickrup/tag_set"
|
5
|
+
require "flickrup/processing_context"
|
5
6
|
|
6
7
|
class TaggedImage
|
7
8
|
include Logging
|
8
9
|
|
9
|
-
attr_reader :
|
10
|
+
attr_reader :filename
|
10
11
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@parsed = MiniExiftool.new
|
12
|
+
def initialize(filename)
|
13
|
+
@filename = filename
|
14
|
+
@parsed = MiniExiftool.new filename
|
14
15
|
end
|
15
16
|
|
16
17
|
def tags
|
@@ -25,8 +26,8 @@ class TaggedImage
|
|
25
26
|
|
26
27
|
def doUpload(preupload_handlers, uploader)
|
27
28
|
|
28
|
-
|
29
|
-
handler.preupload(
|
29
|
+
context = preupload_handlers.reduce(ProcessingContext.new(self)) do |ctx, handler|
|
30
|
+
handler.preupload(ctx)
|
30
31
|
end
|
31
32
|
|
32
33
|
#maybe save afterwards
|
@@ -34,7 +35,7 @@ class TaggedImage
|
|
34
35
|
@parsed.save!
|
35
36
|
end
|
36
37
|
|
37
|
-
uploader.upload(
|
38
|
+
uploader.upload(context)
|
38
39
|
|
39
40
|
#maybe save afterwards
|
40
41
|
if @parsed.changed?
|
@@ -52,8 +53,8 @@ class TaggedImage
|
|
52
53
|
)
|
53
54
|
|
54
55
|
FileUtils.mkdir_p(target_dir)
|
55
|
-
FileUtils.mv(@
|
56
|
-
logger.info("Archived #{File.basename(@
|
56
|
+
FileUtils.mv(@filename, File.join(target_dir, File.basename(@filename)))
|
57
|
+
logger.info("Archived #{File.basename(@filename)} to #{target_dir}")
|
57
58
|
end
|
58
59
|
|
59
60
|
# Returns the value of a tag.
|
data/lib/flickrup/uploader.rb
CHANGED
@@ -14,22 +14,26 @@ class Uploader
|
|
14
14
|
@flickr = flickr_client
|
15
15
|
end
|
16
16
|
|
17
|
-
def upload(
|
17
|
+
def upload(ctx)
|
18
18
|
|
19
|
-
if
|
20
|
-
logger.info("Skipping upload of #{image} as marked as NO_UPLOAD")
|
19
|
+
if ctx.upload_properties[UploaderConstants::NO_UPLOAD]
|
20
|
+
logger.info("Skipping upload of #{ctx.image.filename} as marked as NO_UPLOAD")
|
21
21
|
else
|
22
|
-
logger.debug("Uploading #{image} with tags #{
|
22
|
+
logger.debug("Uploading #{ctx.image.filename} with tags #{ctx.image.tags}")
|
23
23
|
|
24
24
|
begin
|
25
|
-
rv = @flickr.upload_photo(image,
|
26
|
-
logger.debug("Uploaded #{image}")
|
25
|
+
rv = @flickr.upload_photo(ctx.image.filename, prepare_upload_properties(ctx))
|
26
|
+
logger.debug("Uploaded #{ctx.image.filename}")
|
27
27
|
rescue StandardError => err
|
28
|
-
logger.error("Failed to upload #{image}: #{err}")
|
28
|
+
logger.error("Failed to upload #{ctx.image.filename}: #{err}")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
rv
|
33
33
|
end
|
34
34
|
|
35
|
+
def prepare_upload_properties(ctx)
|
36
|
+
{:tags => ctx.image.tags.to_s}.merge(ctx.upload_properties)
|
37
|
+
end
|
38
|
+
|
35
39
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickrup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan Gilbert
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/flickrup/ext/visibility.rb
|
146
146
|
- lib/flickrup/flickr_client.rb
|
147
147
|
- lib/flickrup/logging.rb
|
148
|
+
- lib/flickrup/processing_context.rb
|
148
149
|
- lib/flickrup/processor.rb
|
149
150
|
- lib/flickrup/quick_listener.rb
|
150
151
|
- lib/flickrup/slow_listener.rb
|