Skip to content

Commit

Permalink
Fixed for python >3.10 and pyexiftool
Browse files Browse the repository at this point in the history
  • Loading branch information
mangelajo committed Aug 25, 2024
1 parent 16e98bc commit bf6abee
Show file tree
Hide file tree
Showing 12 changed files with 737 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ output:
```

## Release Notes
### 2024.1.1
* Support for python 3.12, fixed missing files in tests

### 2021.1.4
* PIL image library has been replaced for exiftool so datetime from videos can
be obtained too.
* Files with no creation datetime EXIF or tags are ignored for now.
* Files with no creation datetime EXIF or tags are ignored for now.
15 changes: 12 additions & 3 deletions photosort/exif.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import exiftool
from exiftool.exceptions import ExifToolExecuteError

et = None

Expand All @@ -7,12 +8,20 @@ def start():
"""Starts a background batch exiftool process for quickly processing files
"""
global et
et = exiftool.ExifTool()
et.start()
et = exiftool.ExifToolHelper()


def get_metadata(filename):
global et
if et is None:
start()
return et.get_metadata(filename)
# exiftool.get_metadata returns a list of maps with the
# exif metadata, because now it supports a list of files as input
try:
return et.get_metadata(filename)[0]
except ExifToolExecuteError as e:
print("ExifToolExecutError: %s" % e)
print("args: %s" % e.args)
print("stderr: %s" % e.stderr)
print("stdout: %s" % e.stdout)
raise e
6 changes: 5 additions & 1 deletion photosort/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def _exif_datetime(self):
'EXIF:CreateDate',
'XMP-exif:DateTimeDigitized',
'QuickTime:ContentCreateDate',
'QuickTime:CreationDate'
'QuickTime:CreationDate',
'QuickTime:CreateDate',
'MediaCreateDate',
'TrackCreateDate',
'CreateDate',
]:
try:
exif_datetime_str = exif_data[exif_tag]
Expand Down
1 change: 1 addition & 0 deletions photosort/photosort.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def main():

log_level = logging.INFO
if ns.debug:
print("Debug log level")
log_level = logging.DEBUG
photo_sort = PhotoSort(ns.config, log_level)

Expand Down
Binary file added photosort/test/data/media2/BigBuckBunny.avi
Binary file not shown.
Binary file modified photosort/test/data/media2/mov1.mp4
Binary file not shown.
Binary file modified photosort/test/data/media2/mov1_dup.mp4
Binary file not shown.
Binary file added photosort/test/data/media2/mov_exif.m4v
Binary file not shown.
5 changes: 3 additions & 2 deletions photosort/test/testcases/test_002_exif_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import stat

from photosort.test import test as test_main
from photosort import test
from photosort import media

Expand Down Expand Up @@ -39,7 +40,7 @@ def test_hash_creation(self):
def test_datetime(self):
self.assertEqual(str(self.photo.datetime()), "2013-08-24 13:05:52")
self.assertEqual(str(self.movie.datetime()),
"2020-03-08 21:51:41+01:00")
"2020-06-18 07:50:31")

def test_equal_checking(self):
self.assertTrue(self.photo.is_equal_to(self.img1dup))
Expand Down Expand Up @@ -145,4 +146,4 @@ def test_move_to_existing_directory_pattern_file_fmt(self):


if __name__ == '__main__':
test.test.main()
test_main.main()
4 changes: 2 additions & 2 deletions photosort/test/testcases/test_003_noexif_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class TestMovieMedia(test.TestCase):

def setUp(self):
super().setUp()
self.mov1 = self.get_data_path('media2/mov1.mp4')
self.mov1 = self.get_data_path('media2/BigBuckBunny.avi')
self.movie = media.MediaFile.build_for(self.mov1)

def test_hash_creation(self):
expected_hash = "d41d8cd98f00b204e9800998ecf8427e"
expected_hash = "630569ce2efda22d55d271bfe8ec4428"
self.assertEqual(self.movie.hash(), expected_hash)

# check for hasher non being re-started
Expand Down
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "photosort"
authors = [{name="Miguel Angel Ajo Pelayo", email = "[email protected]"}]
version = "2024.1.0"
description = "Picture inbox simplified"
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"pyaml>=24.7.0",
"pyexiftool>=0.5.6",
]

[project.scripts]
photosort = "photosort.photosort:main"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"pytest>=8.3.2",
"mock>=5.1.0",
"setuptools>=73.0.1",
"twine>=5.1.1",
]
685 changes: 685 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit bf6abee

Please sign in to comment.