Skip to content

Commit 51614c7

Browse files
committed
Init
1 parent ca370cb commit 51614c7

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

Diff for: exiffind/__init__.py

Whitespace-only changes.

Diff for: exiffind/main.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import os
2+
import exifread
3+
import argparse
4+
import dateutil.parser as du
5+
6+
def main():
7+
parser = argparse.ArgumentParser(description="Find images by their EXIF data")
8+
parser.add_argument("dir", type=str, help="base dir to search in")
9+
parser.add_argument("--before", type=str, help="date to be digitized before in format YY-MM-DD")
10+
parser.add_argument("--after", type=str, help="date to be digitized after in format YY-MM-DD")
11+
parser.add_argument("--ext", nargs=1, type=str, help="search only for files with $EXT extensions")
12+
parser.add_argument("--orientation", type=str, choices=["Horizontal", "Vertical"])
13+
parser.add_argument("--author", type=str)
14+
parser.add_argument("--software", type=str)
15+
16+
args = dict(parser.parse_args().__dict__)
17+
check(args)
18+
19+
20+
def check(args: dict):
21+
for dir, file in enumerate_files(args.get("dir", "."), args.get("ext", None)):
22+
with open(os.path.join(dir, file), "rb") as f:
23+
tags = exifread.process_file(f, details=False)
24+
if len(tags) is 0:
25+
continue
26+
27+
ok = True
28+
ok &= check_daterange( tags, args.get("before", None), args.get("after", None))
29+
ok &= check_orientation(tags, args.get("orientation", None))
30+
ok &= check_author( tags, args.get("author", None))
31+
ok &= check_software( tags, args.get("software", None))
32+
if ok is True:
33+
print(os.path.join(dir, file))
34+
35+
36+
def check_ext(file: str, exts: list = None):
37+
if exts is None:
38+
return True
39+
for ext in exts:
40+
if ext:
41+
_ext = file[-len(ext):].lower()
42+
if _ext == ext.lower():
43+
return True
44+
return False
45+
46+
47+
def check_daterange(tags, before:str=None, after:str=None):
48+
def _check(dat):
49+
if before is not None:
50+
if dat >= before:
51+
return False
52+
if after is not None:
53+
if dat <= after:
54+
return False
55+
return True
56+
57+
if before is None and after is None:
58+
return True
59+
60+
before = du.parse(before) if before is not None else before
61+
after = du.parse(after) if after is not None else after
62+
63+
date_args = ("EXIF DateTimeDigitized", "EXIF DateTimeOriginal", "Image DateTime")
64+
for arg in date_args:
65+
if arg in tags:
66+
value = str(tags[arg])
67+
if not value:
68+
continue
69+
if value.count(":") > 3:
70+
value = value.replace(":", "-", 2)
71+
value = du.parse(value)
72+
if value and _check(value):
73+
return True
74+
return False
75+
76+
77+
def check_tag(tags: dict, key: str, value: str) -> bool:
78+
if value is None:
79+
return True
80+
if key in tags:
81+
_value = str(tags[key]).lower()
82+
if _value.find(value.lower()) > -1:
83+
return True
84+
return False
85+
86+
87+
def check_orientation(tags, orientation: str = None):
88+
return check_tag(tags, "Image Orientation", orientation)
89+
90+
91+
def check_author(tags, author: str = None):
92+
author_args = ("Image Artist", "Image XPAuthor")
93+
for arg in author_args:
94+
if check_tag(tags, arg, author):
95+
return True
96+
return False
97+
98+
99+
def check_software(tags, software: str = None):
100+
return check_tag(tags, "Image Software", software)
101+
102+
103+
def enumerate_files(dir: str, exts: list = None):
104+
for root, _, files in os.walk(dir):
105+
for file in files:
106+
if check_ext(file, exts):
107+
yield root, file
108+
109+
110+
if __name__ == '__main__':
111+
main()

Diff for: requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exifread
2+
python-dateutil

Diff for: setup.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='exiffind',
5+
version='0.0.1',
6+
packages=['exiffind'],
7+
url='https://github.com/k0rmarun/exiffind',
8+
license='MIT',
9+
author='Kormarun',
10+
author_email='[email protected]',
11+
description='Find images by their exif tags',
12+
13+
entry_points={
14+
"console_scripts": [
15+
"exiffind = exiffind.exiffind:main"
16+
]
17+
},
18+
install_requires=[
19+
"exifread",
20+
"python-dateutil"
21+
],
22+
23+
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
24+
classifiers=[
25+
# How mature is this project? Common values are
26+
# 3 - Alpha
27+
# 4 - Beta
28+
# 5 - Production/Stable
29+
'Development Status :: 3 - Alpha',
30+
31+
# Indicate who your project is intended for
32+
'Environment :: Console',
33+
'Intended Audience :: End Users/Desktop',
34+
'Topic :: Desktop Environment :: File Managers',
35+
'Topic :: Multimedia :: Graphics',
36+
'Topic :: Utilities',
37+
38+
# Pick your license as you wish (should match "license" above)
39+
'License :: OSI Approved :: MIT License',
40+
41+
# Specify the Python versions you support here. In particular, ensure
42+
# that you indicate whether you support Python 2, Python 3 or both.
43+
'Programming Language :: Python :: 3',
44+
'Programming Language :: Python :: 3.3',
45+
'Programming Language :: Python :: 3.4',
46+
'Programming Language :: Python :: 3.5',
47+
]
48+
)

0 commit comments

Comments
 (0)