piwigo-api 0.5.1 → 0.5.3
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 +4 -4
- data/.rubocop.yaml +1 -1
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +15 -2
- data/Rakefile +4 -1
- data/lib/piwigo/albums.rb +4 -0
- data/lib/piwigo/folder_sync.rb +36 -18
- data/lib/piwigo/image_uploader.rb +45 -17
- data/lib/piwigo/images.rb +0 -1
- data/lib/piwigo/version.rb +1 -1
- data/piwigo-api.gemspec +4 -1
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1f218541e0a4b20b9e6b3656b29d8930864b07131fd0dbd1f9951c96a6fec4a
|
4
|
+
data.tar.gz: b9857102f2e6b5c8ea8fd746f0de90ed4316d76b3b98d3223a09954e10f9d67e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b1753972858ddcf68ba352b49f42d7a683aee2d08d6cbcf2b4ba6b3ef795d70d4de33c81aca6c098be0b95126bacdd1f7d8519c310c46eba88a082f37d1789e
|
7
|
+
data.tar.gz: 41588632e509053b1188d8797db04dc30cfd1ce04bdbdf1e1dc82f4932c11ad995010e146c38219efdec4847156997e1f0d740396bb70bfaed7f187432bd941f
|
data/.rubocop.yaml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,14 @@ 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.3 - 2019-11-25
|
8
|
+
- Fixed to coverage reports
|
9
|
+
- Only generate coverage reports during CI build
|
10
|
+
- codecov.io seems to be ignoring some test files in the coverage report
|
11
|
+
- Use EXIF data to pull out the original image date when uploading to Piwigo
|
12
|
+
|
7
13
|
0.5.1 - 2019-11-23
|
8
|
-
- Fixed image.lookup
|
14
|
+
- Fixed minor bug in image.lookup
|
9
15
|
|
10
16
|
0.5.0 - 2019-11-23
|
11
17
|
- Added a directory of example scripts
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
piwigo-api (0.5.
|
4
|
+
piwigo-api (0.5.3)
|
5
|
+
exifr (~> 1.3)
|
5
6
|
http (~> 4.2)
|
6
7
|
logger (~> 1.4)
|
7
8
|
|
@@ -10,6 +11,8 @@ GEM
|
|
10
11
|
specs:
|
11
12
|
addressable (2.7.0)
|
12
13
|
public_suffix (>= 2.0.2, < 5.0)
|
14
|
+
ansi (1.5.0)
|
15
|
+
builder (3.2.3)
|
13
16
|
codecov (0.1.16)
|
14
17
|
json
|
15
18
|
simplecov
|
@@ -17,7 +20,9 @@ GEM
|
|
17
20
|
docile (1.3.2)
|
18
21
|
domain_name (0.5.20190701)
|
19
22
|
unf (>= 0.0.5, < 1.0.0)
|
20
|
-
|
23
|
+
exifr (1.3.6)
|
24
|
+
ffi (1.11.3)
|
25
|
+
ffi (1.11.3-x64-mingw32)
|
21
26
|
ffi-compiler (1.0.1)
|
22
27
|
ffi (>= 1.0.0)
|
23
28
|
rake
|
@@ -34,8 +39,14 @@ GEM
|
|
34
39
|
json (2.2.0)
|
35
40
|
logger (1.4.1)
|
36
41
|
minitest (5.13.0)
|
42
|
+
minitest-reporters (1.4.2)
|
43
|
+
ansi
|
44
|
+
builder
|
45
|
+
minitest (>= 5.0)
|
46
|
+
ruby-progressbar
|
37
47
|
public_suffix (4.0.1)
|
38
48
|
rake (10.5.0)
|
49
|
+
ruby-progressbar (1.10.1)
|
39
50
|
simplecov (0.17.1)
|
40
51
|
docile (~> 1.1)
|
41
52
|
json (>= 1.8, < 3)
|
@@ -54,8 +65,10 @@ DEPENDENCIES
|
|
54
65
|
bundler (~> 2.0)
|
55
66
|
codecov (>= 0.1.10)
|
56
67
|
minitest (~> 5.0)
|
68
|
+
minitest-reporters (~> 1.4)
|
57
69
|
piwigo-api!
|
58
70
|
rake (~> 10.0)
|
71
|
+
simplecov (~> 0.17)
|
59
72
|
|
60
73
|
BUNDLED WITH
|
61
74
|
2.0.2
|
data/Rakefile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
+
require 'minitest'
|
3
4
|
|
4
5
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << 'test'
|
6
6
|
t.libs << 'lib'
|
7
|
+
t.libs << 'test'
|
7
8
|
t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
t.pattern = 'test/**test.rb'
|
10
|
+
t.verbose = true
|
8
11
|
end
|
9
12
|
|
10
13
|
task default: :test
|
data/lib/piwigo/albums.rb
CHANGED
data/lib/piwigo/folder_sync.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'find'
|
3
|
+
require 'exifr/jpeg'
|
3
4
|
require_relative 'albums'
|
4
5
|
require_relative 'image_uploader'
|
5
6
|
|
@@ -32,27 +33,44 @@ module Piwigo
|
|
32
33
|
def synchronize(directory)
|
33
34
|
@logger.info "Processing Directory: #{directory}"
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
Dir.entries(directory).reject { |entry| entry =~ /^.{1,2}$/ }.each do |directory_entry|
|
37
|
+
item_to_process = File.join directory, directory_entry
|
37
38
|
|
38
|
-
if
|
39
|
-
|
40
|
-
@current_album = Piwigo::Albums::lookup(@session, File.basename(directory_entry))
|
41
|
-
if @current_album.nil?
|
42
|
-
album = Piwigo::Albums::Album.new(hash: { 'name' => File.basename(directory_entry),
|
43
|
-
'id_uppercat' => @parent_album.nil? ? nil : @parent_album.id })
|
44
|
-
@current_album = Piwigo::Albums.add @session, album
|
45
|
-
end
|
46
|
-
|
47
|
-
synchronize directory_entry
|
39
|
+
if File.directory? item_to_process
|
40
|
+
process_directory item_to_process
|
48
41
|
else
|
49
|
-
|
50
|
-
image = Piwigo::Images::lookup(@session, directory_entry)
|
51
|
-
if image.nil?
|
52
|
-
Piwigo::Images::ImageUploader.new(logger: @logger).upload(@session, directory_entry, File.basename(directory_entry))
|
53
|
-
end
|
42
|
+
process_file item_to_process
|
54
43
|
end
|
55
44
|
end
|
56
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
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))
|
54
|
+
|
55
|
+
if @current_album.nil?
|
56
|
+
# Album doesn't exist, create one
|
57
|
+
new_album = { 'name' => File.basename(directory_entry),
|
58
|
+
'id_uppercat' => @parent_album.nil? ? nil : @parent_album.id }
|
59
|
+
album = Piwigo::Albums::Album.new(hash: new_album)
|
60
|
+
@current_album = Piwigo::Albums.add @session, album
|
61
|
+
end
|
62
|
+
|
63
|
+
# Recursively process all of the entries in this album
|
64
|
+
@logger.info "Recursing into #{directory_entry}"
|
65
|
+
synchronize directory_entry
|
66
|
+
end
|
67
|
+
|
68
|
+
def process_file(directory_entry)
|
69
|
+
@logger.info "Processing Image: '#{directory_entry}' in album '#{@current_album}'"
|
70
|
+
image = Piwigo::Images.lookup(@session, directory_entry)
|
71
|
+
return unless image.nil?
|
72
|
+
|
73
|
+
Piwigo::Images::ImageUploader.new(logger: @logger).upload(@session, directory_entry, File.basename(directory_entry), album: @current_album)
|
74
|
+
end
|
57
75
|
end
|
58
|
-
end
|
76
|
+
end
|
@@ -30,7 +30,7 @@ module Piwigo
|
|
30
30
|
# @param [<Type>] name of the image
|
31
31
|
#
|
32
32
|
# @return [Boolean] True if successful
|
33
|
-
def upload(session, filename, name)
|
33
|
+
def upload(session, filename, name, album: null)
|
34
34
|
@session = session
|
35
35
|
raise 'Invalid session' if @session.uri.nil?
|
36
36
|
|
@@ -48,7 +48,8 @@ module Piwigo
|
|
48
48
|
addChunk(chunk, original_sum, chunk_num)
|
49
49
|
chunk_num += 1
|
50
50
|
end
|
51
|
-
|
51
|
+
attributes = sniff_attributes(filename, album: album)
|
52
|
+
add(original_sum, filename, name, attributes: attributes)
|
52
53
|
end
|
53
54
|
|
54
55
|
private
|
@@ -90,17 +91,20 @@ module Piwigo
|
|
90
91
|
# @param [<Type>] original_sum - md5sum that makes the photo unique
|
91
92
|
# @param [<Type>] original_filename
|
92
93
|
# @param [<Type>] name
|
93
|
-
# @param [
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
94
|
+
# @param [Hash] attributes - attributes to include with image add. Include:
|
95
|
+
# author
|
96
|
+
# level - 0 (—-), 1 (Contacts), 2 (Friends), 4 (Family), 8 (Admins)
|
97
|
+
# date_creation - formatted as 2009-03-26
|
98
|
+
# comment -
|
99
|
+
# categories - list of category identifiers where you want the photo to be shown. Optionaly, you can set a rank inside the each category.
|
100
|
+
# Example : '19,3;16,0;134' will associate the photo to category 19 at rank 3, to category 16 at rank 0 (first position) and
|
101
|
+
# to category 134 with an automatic rank (last position).
|
102
|
+
# image_id - give an image_id if you want to update an existing photo
|
101
103
|
#
|
102
104
|
# @return [Boolean] True if successful
|
103
|
-
def add(original_sum, original_filename, name,
|
105
|
+
def add(original_sum, original_filename, name, attributes: {})
|
106
|
+
|
107
|
+
# name, author: nil, level: nil, date_creation: nil, comment: nil, categories: nil, image_id: nil
|
104
108
|
|
105
109
|
http = Net::HTTP.new(@session.uri.host, @session.uri.port)
|
106
110
|
request = Net::HTTP::Post.new(@session.uri.request_uri)
|
@@ -111,12 +115,12 @@ module Piwigo
|
|
111
115
|
name: name
|
112
116
|
}
|
113
117
|
|
114
|
-
form[:author] = author
|
115
|
-
form[:level] = level
|
116
|
-
form[:date_creation] = date_creation
|
117
|
-
form[:comment] = comment
|
118
|
-
form[:categories] = categories
|
119
|
-
form[:image_id] = image_id
|
118
|
+
form[:author] = attributes[:author] if attributes.key? :author
|
119
|
+
form[:level] = attributes[:level] if attributes.key? :level
|
120
|
+
form[:date_creation] = attributes[:date_creation] if attributes.key? :date_creation
|
121
|
+
form[:comment] = comment attributes[:comment] if attributes.key? :comment
|
122
|
+
form[:categories] = attributes[:categories] if attributes.key? :categories
|
123
|
+
form[:image_id] = attributes[:image_id] if attributes.key? :image_id
|
120
124
|
request.set_form_data(form)
|
121
125
|
|
122
126
|
request['Cookie'] = [@session.id]
|
@@ -137,6 +141,30 @@ module Piwigo
|
|
137
141
|
@logger.error "Image Add failed: #{e.message}"
|
138
142
|
false
|
139
143
|
end
|
144
|
+
|
145
|
+
def sniff_attributes(filename, album: nil)
|
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
|
161
|
+
end
|
162
|
+
|
163
|
+
attributes[:categories] = album.id unless album.nil?
|
164
|
+
attributes
|
165
|
+
end
|
140
166
|
end
|
167
|
+
|
168
|
+
|
141
169
|
end
|
142
170
|
end
|
data/lib/piwigo/images.rb
CHANGED
data/lib/piwigo/version.rb
CHANGED
data/piwigo-api.gemspec
CHANGED
@@ -30,8 +30,11 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
31
31
|
spec.add_development_dependency 'codecov', '>= 0.1.10'
|
32
32
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
+
spec.add_development_dependency 'minitest-reporters', '~>1.4'
|
33
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
-
|
35
|
+
spec.add_development_dependency 'simplecov', '~> 0.17'
|
36
|
+
|
35
37
|
spec.add_runtime_dependency 'http', '~>4.2'
|
36
38
|
spec.add_runtime_dependency 'logger', '~>1.4'
|
39
|
+
spec.add_runtime_dependency 'exifr', '~>1.3'
|
37
40
|
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.
|
4
|
+
version: 0.5.3
|
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-
|
11
|
+
date: 2019-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.17'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.17'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: http
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +122,20 @@ dependencies:
|
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '1.4'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: exifr
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.3'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.3'
|
97
139
|
description: Piwigo is open source web application to manage your collection of photos,
|
98
140
|
and other medias. Piwigo provides an API for interacting with it. This is a ruby-based
|
99
141
|
client for interacting with a Piwigo instance using the Piwigo API.
|