flickru 0.0.15 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -7,9 +7,8 @@ Photos are identified by case-insensitive extensions: GIF, JPEG, JPG, PNG, and T
7
7
  Videos are identified by case-insensitive extensions: AVI, MPEG, and MPG.
8
8
 
9
9
  flickru automatically sets the following Flickr metadata:
10
- (1) date taken: if JPEG/TIFF Exif metadata is found, date is
11
- extracted from them, otherwise flickru sets date to the last modification
12
- time.
10
+ (1) date taken: file last-modification time, unless JPEG/TIFF Exif metadatum
11
+ 'date_time_original' is found (Flickr understands it natively).
13
12
  (2) privacy policy: private, visible by friends & family, hidden for public
14
13
  searches
15
14
  (3) safety level: safe
@@ -18,7 +17,9 @@ flickru automatically sets the following Flickr metadata:
18
17
  (5) description: for videos longer than 90s (Flickr's longest allowed duration)
19
18
  but shorter than 500MB (Flickr's maximum permisible size), it will contain
20
19
  an annotation about its large duration.
21
- (6) title, geolocation, and accuracy: extracted from the parent directory name.
20
+ (6) title: extracted from the parent directory name
21
+ (7) geolocation & accuracy: extracted from the parent directory name, unless
22
+ JPEG/TIFF Exif GPS metadata is found (Flickr understands them natively).
22
23
 
23
24
  Before uploading photos, please, make sure that you have correctly named each
24
25
  photos parent directory according to the name format 'TITLE[@LOCATION[#PRECISION]]',
@@ -40,5 +41,5 @@ photoset is arranged by 'date taken' (older first).
40
41
  To see some examples on the directory structure recognised by flickru, please
41
42
  explore the subdirectories under 'var/ts'.
42
43
 
43
- Homepage: http://rubygems.org/gems/flickru
44
- GitHub: http://github.com/jesuspv/flickru
44
+ GitHub : http://github.com/jesuspv/flickru
45
+ RubyGems: http://rubygems.org/gems/flickru
@@ -2,6 +2,7 @@
2
2
  #flickru_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  #$LOAD_PATH.unshift(flickru_dir) unless $LOAD_PATH.include?(flickru_dir)
4
4
 
5
+ # flickru
5
6
  require 'flickru'
6
7
  require 'flickru/version'
7
8
 
@@ -22,6 +23,9 @@ photo_dir = File.expand_path ARGV[0]
22
23
  if photo_dir.nil? or photo_dir.empty?
23
24
  Flickru.usage
24
25
  Flickru.die __LINE__, "missing photo directory"
26
+ elsif not File.directory? photo_dir
27
+ Flickru.usage
28
+ Flickru.die __LINE__, "'#{ARGV[0]}' is not directory"
25
29
  end
26
30
 
27
31
  Flickru.flickru photo_dir
@@ -24,6 +24,11 @@ def Flickru.usage
24
24
  Printer.show "\n#{IO.read(readme)}"
25
25
  end
26
26
 
27
+ def Flickru.die code, message
28
+ Printer.error "error:#{code}: #{message}"
29
+ exit 1
30
+ end
31
+
27
32
  def Flickru.config_filename
28
33
  File.join ENV['HOME'], "." + File.basename(__FILE__, File.extname(__FILE__)) + "rc"
29
34
  end
@@ -89,8 +94,7 @@ def self.flickru photo_dir
89
94
  " and better collection mosaics can be randomised."
90
95
  rescue Exception => e
91
96
  file_line = e.backtrace[0].split(':')
92
- Printer.error "error:#{File.basename file_line[-3]}:#{file_line[-2]}: #{e.message}"
93
- exit 1
97
+ Flickru.die "#{File.basename file_line[-3]}:#{file_line[-2]}", e.message
94
98
  end
95
99
 
96
100
  end # module Flickru
@@ -48,7 +48,7 @@ class File
48
48
 
49
49
  def File.date_taken file
50
50
  attempt = 1
51
- begin
51
+ begin
52
52
  case attempt
53
53
  when 1 then EXIFR::JPEG.new(file).date_time_original.strftime "%y-%m-%d %H:%M:%S"
54
54
  when 2 then EXIFR::TIFF.new(file).date_time_original.strftime "%y-%m-%d %H:%M:%S"
@@ -57,7 +57,31 @@ class File
57
57
  rescue
58
58
  attempt += 1
59
59
  retry
60
- end
60
+ end
61
+ end
62
+
63
+ def File.geotagged? file
64
+ attempt = 1
65
+ begin
66
+ case attempt
67
+ when 1 then
68
+ hash = EXIFR::JPEG.new(file).to_hash
69
+ when 2 then
70
+ hash = EXIFR::TIFF.new(file).to_hash
71
+ else return false
72
+ end
73
+ rescue
74
+ puts $!
75
+ attempt += 1
76
+ retry
77
+ end
78
+
79
+ lat = hash.key? :gps_latitude
80
+ lon = hash.key? :gps_longitude
81
+ lat_ref = hash.key? :gps_latitude_ref
82
+ lon_ref = hash.key? :gps_longitude_ref
83
+
84
+ lat and lon and lat_ref and lon_ref
61
85
  end
62
86
 
63
87
  def File.human_readable_size file_size
@@ -50,12 +50,19 @@ module Flickr
50
50
  end
51
51
 
52
52
  date = File.date_taken photo
53
- if date.nil? then date = File.mtime(photo).strftime "%y-%m-%d %H:%M:%S" end
53
+ if date.nil?
54
+ date = File.mtime(photo).strftime "%y-%m-%d %H:%M:%S"
55
+ exif_has_date = false
56
+ else
57
+ exif_has_date = true
58
+ end
54
59
 
60
+ geotagged = File.geotagged? photo
55
61
  loc = Location.new photo
56
62
  Printer.show "uploading " +
57
- (loc.nil? ? "#{loc.name.black} (no location given)" : loc.to_s) +
58
- " taken on #{date.black}... "
63
+ (geotagged ? "#{loc.name.black} (geotagged)"
64
+ : (loc.nil? ? "#{loc.name.black} (no location given)" : loc.to_s)) \
65
+ + " taken on #{date.black} #{exif_has_date ? "(Exif)" : "(mtime)"}... "
59
66
  begin
60
67
  id = flickr.upload_photo photo, :title => UnicodeUtils.nfkc(loc.name), :is_public => 0,
61
68
  :description => description, :tags => UPLOADING_TAG,
@@ -77,14 +84,16 @@ module Flickr
77
84
  end
78
85
  flickr.photos.setTags :photo_id => id, :tags => ''
79
86
 
80
- flickr.photos.setDates :photo_id => id, :date_taken => date
87
+ if not exif_has_date
88
+ flickr.photos.setDates :photo_id => id, :date_taken => date
89
+ end
81
90
  flickr.photos.setPerms :photo_id => id, :is_public => 0,
82
- :is_friend => 1, :is_family => 1, # again! (mandatory) :P
91
+ :is_friend => 1, :is_family => 1, # again! (mandatory args) :P
83
92
  :perm_comment => 1, :perm_addmeta => 0
84
93
  # TODO permission MAY be configurable
85
- if not loc.nil?
94
+ if not geotagged and not loc.nil?
86
95
  flickr.photos.geo.setLocation :photo_id => id, :lat => loc.latitude,
87
- :lon => loc.longitude, :accuracy => loc.accuracy
96
+ :lon => loc.longitude, :accuracy => loc.accuracy
88
97
  end
89
98
 
90
99
  Printer.success
@@ -5,6 +5,7 @@ require 'colorize'
5
5
  require 'escape'
6
6
  require 'open-uri'
7
7
  # flickru
8
+ require 'flickru/file'
8
9
  require 'flickru/ruby'
9
10
  require 'flickru/string'
10
11
 
@@ -18,12 +19,12 @@ class Location
18
19
  def initialize photo
19
20
  dir = File.basename File.dirname(photo)
20
21
  name, place, accuracy = Location.parse dir
21
- raise RuntimeError, "unnamed location #{dir}" if name.nil?
22
+ raise RuntimeError, "#{dir}, name not provided" if name.nil?
22
23
  @name = name
23
24
  begin
24
- @place = place.nil? ? name : place
25
+ @place = place.nil? ? name : place
25
26
  @latitude, @longitude = Location.locate @place
26
- @accuracy = Location.s_to_accuracy(accuracy ? accuracy : DEFAULT_ACCURACY)
27
+ @accuracy = Location.s_to_accuracy(accuracy ? accuracy : DEFAULT_ACCURACY)
27
28
  rescue RuntimeError
28
29
  raise if place
29
30
  raise RuntimeError, "location #{name} not found" if accuracy
@@ -1,5 +1,5 @@
1
1
  module Flickru
2
2
  unless defined? VERSION
3
- VERSION = "0.0.15"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -11,10 +11,6 @@ describe Flickru do
11
11
  Flickru.flickru "var/ts/tc_accents"
12
12
  end
13
13
 
14
- it "setting date-taken metadata from Exif metadata if existing" do
15
- Flickru.flickru "var/ts/tc_date_taken"
16
- end
17
-
18
14
  it "different accuracies work case-insensitively" do
19
15
  Flickru.flickru "var/ts/tc_accuracies"
20
16
  end
@@ -23,10 +19,18 @@ describe Flickru do
23
19
  Flickru.flickru "var/ts/tc_collections"
24
20
  end
25
21
 
22
+ it "setting date-taken metadata from Exif metadata if existing" do
23
+ Flickru.flickru "var/ts/tc_date_taken"
24
+ end
25
+
26
26
  it "various filetypes available, skipping garbage" do
27
27
  Flickru.flickru "var/ts/tc_filetypes"
28
28
  end
29
29
 
30
+ it "ignoring location if photo is geotagged" do
31
+ Flickru.flickru "var/ts/tc_geotagging"
32
+ end
33
+
30
34
  it "large files work" do
31
35
  Flickru.flickru "var/ts/tc_large_files"
32
36
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: flickru
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.15
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jesus Pardillo
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-08 00:00:00 Z
13
+ date: 2012-01-15 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -121,9 +121,8 @@ description: |
121
121
  Videos are identified by case-insensitive extensions: AVI, MPEG, and MPG.
122
122
 
123
123
  flickru automatically sets the following Flickr metadata:
124
- (1) date taken: if JPEG/TIFF Exif metadata is found, date is
125
- extracted from them, otherwise flickru sets date to the last modification
126
- time.
124
+ (1) date taken: file last-modification time, unless JPEG/TIFF Exif metadatum
125
+ 'date_time_original' is found (Flickr understands it natively).
127
126
  (2) privacy policy: private, visible by friends & family, hidden for public
128
127
  searches
129
128
  (3) safety level: safe
@@ -132,7 +131,9 @@ description: |
132
131
  (5) description: for videos longer than 90s (Flickr's longest allowed duration)
133
132
  but shorter than 500MB (Flickr's maximum permisible size), it will contain
134
133
  an annotation about its large duration.
135
- (6) title, geolocation, and accuracy: extracted from the parent directory name.
134
+ (6) title: extracted from the parent directory name
135
+ (7) geolocation & accuracy: extracted from the parent directory name, unless
136
+ JPEG/TIFF Exif GPS metadata is found (Flickr understands them natively).
136
137
 
137
138
  Before uploading photos, please, make sure that you have correctly named each
138
139
  photos parent directory according to the name format 'TITLE[@LOCATION[#PRECISION]]',
@@ -154,8 +155,8 @@ description: |
154
155
  To see some examples on the directory structure recognised by flickru, please
155
156
  explore the subdirectories under 'var/ts'.
156
157
 
157
- Homepage: http://rubygems.org/gems/flickru
158
- GitHub: http://github.com/jesuspv/flickru
158
+ GitHub : http://github.com/jesuspv/flickru
159
+ RubyGems: http://rubygems.org/gems/flickru
159
160
 
160
161
  email:
161
162
  - dev@jesuspardillo.com
@@ -214,6 +215,8 @@ files:
214
215
  - var/ts/tc_filetypes/Testing Collection/Video/mpg video.mpg
215
216
  - var/ts/tc_filetypes/Testing Collection/dummy.doc
216
217
  - var/ts/tc_filetypes/Testing Collection/dummy.txt
218
+ - var/ts/tc_geotagging/Testing Collection/Chile/geotagged.jpg
219
+ - var/ts/tc_geotagging/Testing Collection/No Location Provided/geotagged.jpg
217
220
  - var/ts/tc_large_files/Testing Collection/Too Large!/80MB-of-zeros.mpg.zip
218
221
  - var/ts/tc_locations/Testing Collection/Quebec#region/Quebec#region.jpg
219
222
  - var/ts/tc_locations/Testing Collection/Troll Face/Troll Face.jpg
@@ -221,7 +224,7 @@ files:
221
224
  - var/ts/tc_locations/Testing Collection/Troll Face@38.356797,-0.474376/Troll Face@38.356797,-0.474376.jpg
222
225
  - var/ts/tc_locations/Testing Collection/Troll Face@Montreal/Troll Face@Montreal.jpg
223
226
  - var/ts/tc_locations/Testing Collection/Troll Face@Quebec#region/Troll Face@Quebec#region.jpg
224
- homepage: http://rubygems.org/gems/flickru
227
+ homepage: http://github.com/jesuspv/flickru
225
228
  licenses: []
226
229
 
227
230
  post_install_message:
@@ -285,6 +288,8 @@ test_files:
285
288
  - var/ts/tc_filetypes/Testing Collection/Video/mpg video.mpg
286
289
  - var/ts/tc_filetypes/Testing Collection/dummy.doc
287
290
  - var/ts/tc_filetypes/Testing Collection/dummy.txt
291
+ - var/ts/tc_geotagging/Testing Collection/Chile/geotagged.jpg
292
+ - var/ts/tc_geotagging/Testing Collection/No Location Provided/geotagged.jpg
288
293
  - var/ts/tc_large_files/Testing Collection/Too Large!/80MB-of-zeros.mpg.zip
289
294
  - var/ts/tc_locations/Testing Collection/Quebec#region/Quebec#region.jpg
290
295
  - var/ts/tc_locations/Testing Collection/Troll Face/Troll Face.jpg