piwigo-api 0.5.3 → 0.5.4

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: d1f218541e0a4b20b9e6b3656b29d8930864b07131fd0dbd1f9951c96a6fec4a
4
- data.tar.gz: b9857102f2e6b5c8ea8fd746f0de90ed4316d76b3b98d3223a09954e10f9d67e
3
+ metadata.gz: 87356665f4013fd077e465bc8bc455d65521778ecabe929b4d51e77a4f8a48f7
4
+ data.tar.gz: 2febfdf137f95ccca79bdb23565373220e1f553114376b05333c944f2d8caee1
5
5
  SHA512:
6
- metadata.gz: 3b1753972858ddcf68ba352b49f42d7a683aee2d08d6cbcf2b4ba6b3ef795d70d4de33c81aca6c098be0b95126bacdd1f7d8519c310c46eba88a082f37d1789e
7
- data.tar.gz: 41588632e509053b1188d8797db04dc30cfd1ce04bdbdf1e1dc82f4932c11ad995010e146c38219efdec4847156997e1f0d740396bb70bfaed7f187432bd941f
6
+ metadata.gz: fc6d52f44e5d80aea19d572c1bf0c20027c830be07aa6d1d91cccb163be5e65f5fa190c4c7ba4aaf05b8042405c57609f3b8dbdd343285416d9e0a08548750c0
7
+ data.tar.gz: 50b9ffe518dda064dbbad1c56a43cbfc0671bcec6c2eb70c1833bb3d5bf072b22eb750b7e42f7effca9b01dcc346f07fba210d2c045eca498aa371306180912e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ 0.5.4 - 2019-11-26
8
+ - Fix crash in sniff_attributes when the image dosn't contain a valid EXIF data
9
+ - Fix parent albums when syncronizing a folder-tree of albums into Piwigo
10
+
7
11
  0.5.3 - 2019-11-25
8
12
  - Fixed to coverage reports
9
13
  - Only generate coverage reports during CI build
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- piwigo-api (0.5.3)
4
+ piwigo-api (0.5.4)
5
5
  exifr (~> 1.3)
6
6
  http (~> 4.2)
7
7
  logger (~> 1.4)
@@ -21,7 +21,6 @@ GEM
21
21
  domain_name (0.5.20190701)
22
22
  unf (>= 0.0.5, < 1.0.0)
23
23
  exifr (1.3.6)
24
- ffi (1.11.3)
25
24
  ffi (1.11.3-x64-mingw32)
26
25
  ffi-compiler (1.0.1)
27
26
  ffi (>= 1.0.0)
@@ -0,0 +1,21 @@
1
+ ## Syncronize a Directory with Piwigo
2
+
3
+ To syncronize a folder-tree of im ages with Piwigo:
4
+
5
+ ```ruby
6
+ require 'piwigo/session'
7
+ require 'piwigo/folder_sync'
8
+
9
+ folder = ARGV[0]
10
+ puts "Processing #{folder}"
11
+ session = Piwigo::Session.login('10.100.230.78', 'Adrian', 'mypassword', https: false)
12
+ unless session.nil?
13
+ Piwigo::FolderSync.synchronize(session, folder)
14
+ end
15
+ ```
16
+
17
+ Call the script with the directory to syncronize. Eg:
18
+
19
+ ```ruby
20
+ ruby main.rb //DISKSTATION/photos/
21
+ ```
@@ -3,6 +3,10 @@
3
3
  Upload a single image if it doesn't already exist. Image is not associated with any Albums. The image will named apple-pie-bars
4
4
 
5
5
  ```ruby
6
+ require 'piwigo/session'
7
+ require 'piwigo/images'
8
+
9
+
6
10
  session = Piwigo::Session.login('10.100.230.78', 'Adrian', 'mypassword', https: false)
7
11
  unless session.nil?
8
12
  filename = 'C:\photos\apple-pie-bars-articleLarge.jpg'
data/lib/piwigo/albums.rb CHANGED
@@ -57,7 +57,11 @@ module Piwigo
57
57
  attr_accessor :tn_url
58
58
 
59
59
  def initialize(hash: nil)
60
- hash&.each { |key, value| send("#{key}=", value) }
60
+ hash&.each do |key, value|
61
+ # Bug: If the encoding is Windows-1252, then Piwigo will blowup when creating the album
62
+ value = value.encode('UTF-8', 'Windows-1252') if value.class == String && value.encoding.to_s == 'Windows-1252'
63
+ send("#{key}=", value)
64
+ end
61
65
  end
62
66
 
63
67
  def to_s
@@ -140,6 +144,7 @@ module Piwigo
140
144
  begin
141
145
  http = Net::HTTP.new(session.uri.host, session.uri.port)
142
146
  request = Net::HTTP::Post.new(session.uri.request_uri)
147
+ logger.info "Encoding: #{album.name} - #{album.name.encoding}"
143
148
  form = {
144
149
  method: 'pwg.categories.add',
145
150
  name: album.name
@@ -155,7 +160,7 @@ module Piwigo
155
160
  if response.code == '200'
156
161
  data = JSON.parse(response.body)
157
162
  album.id = data['result']['id']
158
- logger.info "Album Add succeeded: #{album.id} created."
163
+ logger.info "Album Add succeeded: #{album.name}(#{album.id}) created."
159
164
  album
160
165
  end
161
166
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
@@ -181,7 +186,7 @@ module Piwigo
181
186
  begin
182
187
  http = Net::HTTP.new(session.uri.host, session.uri.port)
183
188
  request = Net::HTTP::Post.new(session.uri.request_uri)
184
- request.body = "method=pwg.categories.delete&category_id=#{id}"
189
+ request.body = "method=pwg.categories.delete&category_id=#{id}"
185
190
  request.body.concat "&photo_deletion_mode=#{photo_deletion_mode}" unless photo_deletion_mode.nil?
186
191
  request.body.concat "&pwg_token=#{session.pwg_token}"
187
192
  request['Cookie'] = [session.id]
@@ -190,7 +195,7 @@ module Piwigo
190
195
  response = http.request(request)
191
196
  if response.code == '200'
192
197
  data = JSON.parse(response.body)
193
- logger.info "Album Delete succeeded: #{data}"
198
+ logger.info "Album Delete succeeded: Album #{id} removed - #{data}"
194
199
  true
195
200
  else
196
201
  p response.code
@@ -31,13 +31,22 @@ module Piwigo
31
31
  #
32
32
  # @param [String] directory - directory to syncronize.
33
33
  def synchronize(directory)
34
- @logger.info "Processing Directory: #{directory}"
34
+ if ['originals', '.picasaoriginals'].include? File.basename(directory.downcase)
35
+ @logger.info "Skipping special directory: #{directory}"
36
+ return
37
+ else
38
+ @logger.info "Processing Directory: #{directory}"
39
+ end
35
40
 
36
41
  Dir.entries(directory).reject { |entry| entry =~ /^.{1,2}$/ }.each do |directory_entry|
37
42
  item_to_process = File.join directory, directory_entry
38
43
 
39
44
  if File.directory? item_to_process
40
- process_directory item_to_process
45
+ @parent_album = ensure_album(File.dirname(item_to_process), nil)
46
+ @current_album = ensure_album(item_to_process, @parent_album)
47
+
48
+ # Recursively process all of the entries in this album
49
+ synchronize item_to_process
41
50
  else
42
51
  process_file item_to_process
43
52
  end
@@ -46,26 +55,28 @@ module Piwigo
46
55
 
47
56
  private
48
57
 
49
- def process_directory(directory_entry)
50
- @logger.info "Processing #{directory_entry}"
51
- @parent_album = @current_album
52
- # Look to see if we have previously created an Album in Piwogo with this name
53
- @current_album = Piwigo::Albums.lookup(@session, File.basename(directory_entry))
58
+ def ensure_album(directory_entry, parent_album)
59
+ album_name = File.basename(directory_entry)
60
+ @logger.info "Ensuring Album #{album_name} exits"
61
+ return if ['/', '\\', ''].include? album_name
62
+
63
+ # Look to see if we have previously created an Album in Piwigo with this name
64
+ album = Piwigo::Albums.lookup(@session, album_name)
54
65
 
55
- if @current_album.nil?
66
+ if album.nil?
56
67
  # Album doesn't exist, create one
57
- new_album = { 'name' => File.basename(directory_entry),
58
- 'id_uppercat' => @parent_album.nil? ? nil : @parent_album.id }
68
+ new_album = { 'name' => album_name,
69
+ 'id_uppercat' => parent_album.nil? ? nil : parent_album.id }
59
70
  album = Piwigo::Albums::Album.new(hash: new_album)
60
- @current_album = Piwigo::Albums.add @session, album
71
+ album = Piwigo::Albums.add @session, album
61
72
  end
62
-
63
- # Recursively process all of the entries in this album
64
- @logger.info "Recursing into #{directory_entry}"
65
- synchronize directory_entry
73
+ album
66
74
  end
67
75
 
68
76
  def process_file(directory_entry)
77
+ # Only attempt to import images
78
+ return unless ['.jpg', '.png', '.gif'].include? File.extname(directory_entry).downcase
79
+
69
80
  @logger.info "Processing Image: '#{directory_entry}' in album '#{@current_album}'"
70
81
  image = Piwigo::Images.lookup(@session, directory_entry)
71
82
  return unless image.nil?
@@ -144,23 +144,31 @@ module Piwigo
144
144
 
145
145
  def sniff_attributes(filename, album: nil)
146
146
  attributes = {}
147
-
148
- info = EXIFR::JPEG.new(filename)
149
- @logger.info "--> GPS: #{info.gps.latitude}, #{info.gps.longitude}"
150
- exif = info.exif.first.to_hash if info.exif?
151
- if exif.nil?
152
- # No EXIF data, use the file ctime as the date_creation
153
- fs = File::Stat.new(filename)
154
- attributes[:date_creation] = fs.ctime.strftime('%Y-%m-%d')
155
- else
156
- # We have EXIF data, pull out the date_time_original for the date_creation
157
- attributes[:date_creation] = exif[:date_time_original].strftime('%Y-%m-%d')
158
- # exif.each do |item|
159
- # @logger.info "--> #{item[0]}: #{item[1]}"
160
- # end
147
+ begin
148
+ info = EXIFR::JPEG.new(filename)
149
+ @logger.info "--> GPS: #{info.gps.latitude}, #{info.gps.longitude}" unless info.gps.nil?
150
+ exif = info.exif.first.to_hash if info.exif?
151
+ if exif.nil?
152
+ # No EXIF data, use the file ctime as the date_creation
153
+ fs = File::Stat.new(filename)
154
+ @logger.info "--> File::Stat: #{fs.inspect}"
155
+ attributes[:date_creation] = fs.ctime.strftime('%Y-%m-%d')
156
+ elsif exif.key?(:date_time_original)
157
+ # We have EXIF data, pull out the date_time_original for the date_creation
158
+ attributes[:date_creation] = exif[:date_time_original].strftime('%Y-%m-%d')
159
+
160
+ # if !exif.key? :date_time_original do
161
+ # exif.each do |item|
162
+ # @logger.info "--> #{item[0]}: #{item[1]}"
163
+ # end
164
+ # end
165
+ end
166
+ rescue EXIFR::MalformedJPEG => e
167
+ @logger.error e.message
161
168
  end
162
169
 
163
170
  attributes[:categories] = album.id unless album.nil?
171
+ @logger.info attributes
164
172
  attributes
165
173
  end
166
174
  end
@@ -1,3 +1,3 @@
1
1
  module Piwigo
2
- VERSION = '0.5.3'.freeze
2
+ VERSION = '0.5.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piwigo-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gilbert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,6 +160,7 @@ files:
160
160
  - bin/console
161
161
  - bin/setup
162
162
  - codecov.yml
163
+ - examples/Syncronize_Folder.md
163
164
  - examples/Upload_Image.md
164
165
  - lib/piwigo.rb
165
166
  - lib/piwigo/albums.rb