Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
L
Logbook-json-exif-merge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian
Logbook-json-exif-merge
Commits
d0634084
Commit
d0634084
authored
2 years ago
by
Sebastian
Browse files
Options
Downloads
Patches
Plain Diff
Add PhotoExif Converter
#4
parent
fa08d2c1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/convert_photoexif_csv.py
+39
-46
39 additions, 46 deletions
scripts/convert_photoexif_csv.py
with
39 additions
and
46 deletions
scripts/convert_photoexif_csv.py
+
39
−
46
View file @
d0634084
from
datetime
import
datetime
import
math
import
json
import
csv
import
sys
import
os
import
re
from
fractions
import
Fraction
version
=
"
logbook_json_exif_merge v0.1
"
def
get_
logbookjson
_filename
(
filepath
):
def
get_
photoexifcsv
_filename
(
filepath
):
for
x
in
os
.
listdir
(
filepath
):
if
x
.
endswith
(
"
json
"
):
json_file
=
x
return
(
json_file
)
if
x
.
endswith
(
"
csv
"
):
csv_file
=
x
return
(
csv_file
)
def
load_logbookjson
(
json_file
):
with
open
(
json_file
,
"
r
"
)
as
file
:
logbook_json
=
json
.
load
(
file
)
shots
=
logbook_json
.
pop
(
"
shots
"
)
for
shot
in
shots
:
shot
.
update
(
logbook_json
)
def
load_photoexifcsv
(
csv_file
):
with
open
(
csv_file
,
newline
=
''
)
as
file
:
photoexif_csv
=
csv
.
DictReader
(
file
)
shots
=
list
(
photoexif_csv
)
return
(
shots
)
...
...
@@ -37,12 +34,17 @@ def fnumber_to_FNumber(fnumber):
return
(
fnumber
)
def
date_to_DateTimeOriginal
(
date_str
):
exif_date
=
datetime
.
strptime
(
date_str
,
"
%
Y-%m-%dT
%H:%M
:%SZ
"
).
strftime
(
"
%Y:%m:%d %H:%M:%S
"
)
exif_date
=
datetime
.
strptime
(
date_str
,
"
%
d/%m/%Y
%H:%M
"
).
strftime
(
"
%Y:%m:%d %H:%M:%S
"
)
return
(
exif_date
)
def
exposure_time_to_ExposureTime
(
time
):
return
(
time
)
try
:
float_time
=
float
(
sum
(
Fraction
(
s
)
for
s
in
time
.
replace
(
"
s
"
,
""
).
split
()))
return
(
float_time
)
except
ValueError
:
return
(
0
)
def
focal_length_to_FocalLength
(
focal_length
):
return
(
focal_length
)
...
...
@@ -103,30 +105,28 @@ def find_filename(shot_number,file_dict):
return
(
filename
)
return
(
"
null
"
)
def
convert_
logbook
_to_json
(
shots
):
def
convert_
photoexifcsv
_to_json
(
shots
):
exif_shots
=
[]
file_dict
=
load_file_dict
(
path
)
for
shot
in
shots
:
exif_shot
=
{}
datetimeoriginal
=
date_to_DateTimeOriginal
(
shot
.
pop
(
"
date
"
))
exposure_time
=
exposure_time_to_ExposureTime
(
shot
.
pop
(
"
exposure_time
"
))
fnumber
=
fnumber_to_FNumber
(
shot
.
pop
(
"
fnumber
"
))
focal_length
=
focal_length_to_FocalLength
(
shot
.
pop
(
"
focal_length
"
))
latitude
=
lat_dec_to_lat_dms
(
shot
.
pop
(
"
latitude
"
))
longitude
=
lon_dec_to_lon_dms
(
shot
.
pop
(
"
longitude
"
))
make
=
shot
.
pop
(
"
camera_make
"
)
model
=
shot
.
pop
(
"
camera_model
"
)
film_name
=
shot
.
pop
(
"
film name
"
)
notes
=
str
(
shot
.
pop
(
"
notes
"
))
iso
=
box_iso_to_iso
(
shot
.
pop
(
"
box_iso
"
))
isospeed
=
shot_iso_to_isospeed
(
shot
.
pop
(
"
shot_iso
"
))
focallengthin35mmformat
=
focal_length_to_FocalLengthIn35mmFormat
(
focal_length
,
shot
[
"
film_format
"
])
imagenumber
=
shot
.
pop
(
"
shot_number
"
)
lensmake
=
shot
.
pop
(
"
lens_make
"
)
lensmodel
=
shot
.
pop
(
"
lens_model
"
)
reelname
=
shot
.
pop
(
"
roll_name
"
)
imageuniqueid
=
str
(
reelname
)
+
"
_
"
+
str
(
imagenumber
)
usercomment
=
"
roll_notes:
"
+
str
(
shot
.
pop
(
"
roll_notes
"
))
+
"
\n
dev_notes:
"
+
str
(
shot
.
pop
(
"
dev_notes
"
))
+
"
\n
load_date:
"
+
shot
.
pop
(
"
load_date
"
)
+
"
\n
unload_date:
"
+
shot
.
pop
(
"
unload_date
"
)
datetimeoriginal
=
date_to_DateTimeOriginal
(
shot
.
pop
(
"
Date
"
))
exposure_time
=
exposure_time_to_ExposureTime
(
shot
.
pop
(
"
Speed
"
))
fnumber
=
fnumber_to_FNumber
(
shot
.
pop
(
"
Aperture
"
))
focal_length
=
focal_length_to_FocalLength
(
shot
.
pop
(
"
Focal
"
))
latitude
=
lat_dec_to_lat_dms
(
float
(
shot
.
pop
(
"
Latitude
"
)))
longitude
=
lon_dec_to_lon_dms
(
float
(
shot
.
pop
(
"
Longitude
"
)))
camera
=
shot
.
pop
(
"
Camera
"
)
make
=
camera
.
split
(
maxsplit
=
1
)[
0
]
try
:
model
=
camera
.
split
(
maxsplit
=
1
)[
1
]
except
:
model
=
"
unkown
"
film_name
=
shot
.
pop
(
"
Film type
"
)
notes
=
str
(
shot
.
pop
(
"
Comment
"
))
iso
=
box_iso_to_iso
(
shot
.
pop
(
"
ASA value
"
))
imagenumber
=
shot
.
pop
(
"
Number
"
)
lensmodel
=
shot
.
pop
(
"
Lens
"
)
documentname
=
film_name
exif_shot
[
"
DateTimeOriginal
"
]
=
datetimeoriginal
...
...
@@ -139,21 +139,15 @@ def convert_logbook_to_json(shots):
exif_shot
[
"
GPSLongitudeRef
"
]
=
longitude
exif_shot
[
"
Make
"
]
=
make
exif_shot
[
"
Model
"
]
=
model
exif_shot
[
"
LensMake
"
]
=
lensmake
exif_shot
[
"
LensModel
"
]
=
lensmodel
exif_shot
[
"
Notes
"
]
=
notes
exif_shot
[
"
Description
"
]
=
film_name
exif_shot
[
"
ReelName
"
]
=
reelname
exif_shot
[
"
ISO
"
]
=
iso
exif_shot
[
"
ISOSpeed
"
]
=
isospeed
exif_shot
[
"
SensitivityType
"
]
=
3
# for "ISO Speed"
exif_shot
[
"
ImageUniqueId
"
]
=
imageuniqueid
exif_shot
[
"
FileSource
"
]
=
1
# for "FilmScanner"
exif_shot
[
"
FocalLengthIn35mmFormat
"
]
=
focallengthin35mmformat
exif_shot
[
"
ImageNumber
"
]
=
imagenumber
exif_shot
[
"
SourceFile
"
]
=
"
./
"
+
str
(
file_dict
.
get
(
str
(
int
(
imagenumber
))))
exif_shot
[
"
Software
"
]
=
version
exif_shot
[
"
UserComment
"
]
=
usercomment
exif_shot
[
"
SpectralSensitivity
"
]
=
film_name
exif_shot
[
"
DocumentName
"
]
=
documentname
...
...
@@ -164,11 +158,10 @@ def convert_logbook_to_json(shots):
def
main
():
json_file
=
get_logbookjson_filename
(
path
)
shots
=
load_logbookjson
(
path
+
"
/
"
+
json_file
)
exif_shots
=
convert_logbook_to_json
(
shots
)
json_output_filename
=
"
converted
"
+
json_file
print
(
json_output_filename
)
csv_file
=
get_photoexifcsv_filename
(
path
)
print
(
csv_file
)
shots
=
load_photoexifcsv
(
path
+
"
/
"
+
csv_file
)
exif_shots
=
convert_photoexifcsv_to_json
(
shots
)
with
open
(
str
(
path
+
"
/
"
+
"
converted.json
"
),
"
w
"
)
as
file
:
json
.
dump
(
exif_shots
,
file
,
indent
=
2
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment