photo_folder 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,7 @@ class Photo < ActiveRecord::Base
17
17
  File.join(PhotoFolder.source_directory_location,path)
18
18
  end
19
19
 
20
- def update_meta
20
+ def update_info
21
21
  set_exif_data
22
22
  set_last_modified
23
23
  set_guid
@@ -49,6 +49,16 @@ class Photo < ActiveRecord::Base
49
49
  self.last_modified = File.mtime(full_path)
50
50
  end
51
51
 
52
+ def meta_file_path
53
+ File.join(full_path.gsub(/\.(jpg|png)$/,'.json'))
54
+ end
55
+
56
+ def set_meta
57
+ meta_data = File.exists?(meta_file_path) ? File.read(meta_file_path) : nil
58
+ update_attribute :meta, meta_data
59
+ meta_data
60
+ end
61
+
52
62
  def set_exif_data
53
63
  if full_path.match(/\.(png|jpg)$/)
54
64
  if PhotoFolder.mini_exiftool_available?
@@ -74,10 +84,12 @@ class Photo < ActiveRecord::Base
74
84
  end
75
85
  #date,title,lens and tags are special cases
76
86
  if exif[:date].is_a? Time
77
- self.date = exif[:date]
87
+ self.date = exif[:date].to_i
78
88
  else
79
89
  date_match = (exif[:date] || '').match(/([\d]+):([\d]+):([\d]+) ([\d]+):([\d]+):([\d]+)/)
80
- self.date = Time.mktime(date_match[1],date_match[2],date_match[3],date_match[4],date_match[5],date_match[6]) if date_match
90
+ if date_match
91
+ self.date = (Time.mktime(date_match[1],date_match[2],date_match[3],date_match[4],date_match[5],date_match[6])).to_i
92
+ end
81
93
  end
82
94
  self.name = exif[:title] || full_path.split('/').pop.gsub(/\.[a-zA-Z]{1,4}/,'')
83
95
  self.lens = exif[:lens] ? exif[:lens] : nil
@@ -54,6 +54,27 @@ class PhotoCollection < ActiveRecord::Base
54
54
  end
55
55
  end
56
56
 
57
+ def self.cascade_meta_data
58
+ PhotoCollection.find(:all).each do |collection|
59
+ if collection.meta
60
+ collection.descendants.each do |descendant|
61
+ if(descendant.meta)
62
+ collection_meta_as_object = JSON.parse(collection.meta)
63
+ descendant_meta_as_object = JSON.parse(descendant.meta)
64
+ merged_meta = collection_meta_as_object.merge(descendant_meta_as_object)
65
+ descendant.update_attribute :meta, merged_meta.to_json
66
+ else
67
+ descendant.update_attribute :meta, collection.meta
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def descendants
75
+ children.empty? ? [] : children.map(&:descendants).flatten + children
76
+ end
77
+
57
78
  def set_children_parent_id
58
79
  PhotoFolder::all_paths_in_database.select{|path| self.path.underscore.gsub(/\s/,'_') == path.gsub(/\/[^\/]+$/,'').underscore.gsub(/\s/,'_')}.each do |path|
59
80
  Photo.update_all("photo_collection_id = #{self.id}","path = '#{path}'")
@@ -97,8 +118,8 @@ class PhotoCollection < ActiveRecord::Base
97
118
  end
98
119
 
99
120
  def set_meta
100
- meta_data = File.exists?(meta_file_path) ? File.read(meta_file_path) : false
101
- write_attribute :meta, meta_data
121
+ meta_data = File.exists?(meta_file_path) ? File.read(meta_file_path) : nil
122
+ update_attribute :meta, meta_data
102
123
  meta_data
103
124
  end
104
125
 
@@ -52,7 +52,7 @@ module PhotoFolder
52
52
  t.string "guid"
53
53
  t.string "path"
54
54
  t.string "name"
55
- t.datetime "date"
55
+ t.integer "date"
56
56
  t.string "location"
57
57
  t.string "f_stop"
58
58
  t.string "shutter_speed"
@@ -61,6 +61,7 @@ module PhotoFolder
61
61
  t.string "camera"
62
62
  t.string "lens"
63
63
  t.text "caption"
64
+ t.text "meta"
64
65
  t.datetime "last_modified"
65
66
  t.integer "nsfw"
66
67
  t.integer "featured"
@@ -133,11 +134,10 @@ module PhotoFolder
133
134
  PhotoFolder::all_paths_in_filesystem.each do |path_in_filesystem|
134
135
  if !to_add.include?(path_in_filesystem) && !to_remove.include?(path_in_filesystem)
135
136
  entry = Photo.find_by_path(path_in_filesystem)
136
- if entry && File.mtime(entry.full_path) > entry.last_modified
137
+ if entry && File.mtime(entry.full_path) > entry.last_modified || File.exists?(entry.meta_file_path)
137
138
  to_update.push(path_in_filesystem)
138
139
  end
139
140
  elsif to_add.include?(path_in_filesystem)
140
- #cleaned = Photo.clean_filename(path_in_filesystem)
141
141
  entry = Photo.find_by_path(path_in_filesystem)
142
142
  if entry
143
143
  to_update.push(path_in_filesystem)
@@ -197,7 +197,7 @@ module PhotoFolder
197
197
  inner_result[item.id.to_s] = item.attributes.inject(Hash.new) do |attribute_result,key_and_value|
198
198
  key = key_and_value[0]
199
199
  value = key_and_value[1]
200
- attribute_result[key.to_s] = value.to_s
200
+ attribute_result[key.to_s] = value.is_a?(Numeric) ? value : value.to_s
201
201
  attribute_result
202
202
  end
203
203
  inner_result
@@ -247,7 +247,10 @@ module PhotoFolder
247
247
  if photos_to_add.length > 0
248
248
  photos_to_add.each do |path|
249
249
  puts "Adding photo: #{path}"
250
- Photo.create :path => path
250
+ photo = Photo.create :path => path
251
+ if photo.set_meta
252
+ puts "Setting meta data for #{path} from #{photo.meta_file_path}"
253
+ end
251
254
  end
252
255
  else
253
256
  puts "No photos to add."
@@ -257,7 +260,12 @@ module PhotoFolder
257
260
  photos_to_update.each do |path|
258
261
  puts "Updating photo: #{path}"
259
262
  photo = Photo.find_by_path(path)
260
- photo.update_meta if photo
263
+ if photo
264
+ photo.update_info
265
+ if photo.set_meta
266
+ puts "Setting meta data for #{path} from #{photo.meta_file_path}"
267
+ end
268
+ end
261
269
  end
262
270
  else
263
271
  puts "No photos to update."
@@ -319,7 +327,8 @@ module PhotoFolder
319
327
  end
320
328
  end
321
329
  end
322
-
330
+ PhotoCollection.cascade_meta_data
331
+ puts "Cascading meta data."
323
332
  puts "Writing database to #{json_location}"
324
333
  PhotoFolder::write_database_to_file(json_location)
325
334
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "photo_folder"
3
- s.version = "1.0.8"
4
- s.date = "2010-05-11"
3
+ s.version = "1.0.9"
4
+ s.date = "2010-05-27"
5
5
  s.summary = "JavaScript gallery"
6
6
  s.email = "ryan@syntacticx.com"
7
7
  s.homepage = "http://photofolder.org/"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photo_folder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 8
10
- version: 1.0.8
9
+ - 9
10
+ version: 1.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Johnson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-11 00:00:00 -07:00
18
+ date: 2010-05-27 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency