media-workflow 0.2.0__tar.gz
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.
- media_workflow-0.2.0/LICENSE +201 -0
- media_workflow-0.2.0/PKG-INFO +254 -0
- media_workflow-0.2.0/README.md +240 -0
- media_workflow-0.2.0/pyproject.toml +27 -0
- media_workflow-0.2.0/setup.cfg +4 -0
- media_workflow-0.2.0/src/media_workflow/__init__.py +27 -0
- media_workflow-0.2.0/src/media_workflow/__main__.py +4 -0
- media_workflow-0.2.0/src/media_workflow/cli.py +232 -0
- media_workflow-0.2.0/src/media_workflow/duplicates.py +339 -0
- media_workflow-0.2.0/src/media_workflow/fix_times.py +176 -0
- media_workflow-0.2.0/src/media_workflow/importer.py +730 -0
- media_workflow-0.2.0/src/media_workflow.egg-info/PKG-INFO +254 -0
- media_workflow-0.2.0/src/media_workflow.egg-info/SOURCES.txt +18 -0
- media_workflow-0.2.0/src/media_workflow.egg-info/dependency_links.txt +1 -0
- media_workflow-0.2.0/src/media_workflow.egg-info/entry_points.txt +2 -0
- media_workflow-0.2.0/src/media_workflow.egg-info/requires.txt +4 -0
- media_workflow-0.2.0/src/media_workflow.egg-info/top_level.txt +1 -0
- media_workflow-0.2.0/tests/test_cli.py +242 -0
- media_workflow-0.2.0/tests/test_duplicates.py +149 -0
- media_workflow-0.2.0/tests/test_importer.py +753 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: media-workflow
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Import, organize, and de-duplicate photo collections.
|
|
5
|
+
Author: media-workflow contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: Pillow>=10.0
|
|
11
|
+
Provides-Extra: test
|
|
12
|
+
Requires-Dist: pytest>=8.0; extra == "test"
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# media-workflow
|
|
16
|
+
|
|
17
|
+
Tools for importing camera photos and videos into a date-based archive and
|
|
18
|
+
cleaning up duplicate copies.
|
|
19
|
+
|
|
20
|
+
The repository started as a small collection of shell/Python scripts. It is now
|
|
21
|
+
a Python package with a single CLI and a test suite that builds fake JPEGs with
|
|
22
|
+
EXIF metadata to verify the import rules.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
Install the published package as a standalone CLI tool with `uv`:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
uv tool install media-workflow
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or install it into the current environment with pip:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pip install media-workflow
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For development from a checkout:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pip install -e .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For development and tests:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pip install -e '.[test]'
|
|
48
|
+
pytest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or, with `uv`:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
uv run --extra test pytest
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The package depends on [Pillow](https://python-pillow.org/) for reading image
|
|
58
|
+
metadata. Videos are read with a small built-in ISO-BMFF metadata reader, so
|
|
59
|
+
no additional runtime dependency is needed. The optional `fix-times` command
|
|
60
|
+
also needs `exiftool` on `PATH` to rewrite EXIF dates without re-encoding JPEGs.
|
|
61
|
+
|
|
62
|
+
## Import photos and videos
|
|
63
|
+
|
|
64
|
+
The import command is a Python port of the original `import.sh` exiftool
|
|
65
|
+
command. It requires `Make`, `Model`, and a timestamp in each photo or video
|
|
66
|
+
and moves it into a `YYYY/MM` archive tree:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
media-workflow import ../photos_incoming --destination .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The resulting name is:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
YYYYMMDD_HHMMSS[.SubSecTimeOriginal]_Make_Model.<FileTypeExtension>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For example:
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
photos_incoming/IMG_0001.JPG
|
|
82
|
+
-> 2024/07/20240715_123456.123_Canon_EOS-5D.jpg
|
|
83
|
+
|
|
84
|
+
photos_incoming/PXL_20250809_194948618.TS.mp4
|
|
85
|
+
-> 2025/08/20250809_194948.618_Google_Pixel-6.mp4
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Rules preserved from exiftool, plus the video extensions:
|
|
89
|
+
|
|
90
|
+
| Detail | Behaviour |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| Required metadata | Photos without `Make`, `Model`, or `DateTimeOriginal` are skipped. Videos require make, model, and a timestamp. |
|
|
93
|
+
| Date tree | Files go to `<destination>/<year>/<month>/`. |
|
|
94
|
+
| Photo timestamp | `DateTimeOriginal` is formatted as `YYYYMMDD_HHMMSS`. |
|
|
95
|
+
| Video timestamp | A valid `_YYYYMMDD_HHMMSS[mmm]` filename segment wins; otherwise the Apple `com.apple.quicktime.creationdate` key, then the `©day` tag, then QuickTime `CreateDate` (`mvhd`). |
|
|
96
|
+
| Subseconds | Photo `SubSecTimeOriginal`, video filename milliseconds, or an Apple creation-date fraction are appended as `.123`. |
|
|
97
|
+
| Make/model | Photos use EXIF; videos prefer Android `com.android.*` metadata and fall back to Apple QuickTime metadata. |
|
|
98
|
+
| Extension | Photos use exiftool's `FileTypeExtension`; videos use the lowercased file suffix. |
|
|
99
|
+
| Video containers | `.mp4`, `.mov`, `.m4v`, and `.3gp` are recognized by content, not suffix alone. |
|
|
100
|
+
| Google Photos `.TS` | Top Shot markers are dropped from archive names. |
|
|
101
|
+
| Other video containers | MKV, AVI, WebM, MPEG-TS, and similar formats are skipped. |
|
|
102
|
+
| Collisions | Existing names get `_1`, `_2`, ... before the extension. |
|
|
103
|
+
| Already imported | A file already at its computed destination is left unchanged. |
|
|
104
|
+
| File data | Bytes and modification time are preserved (it is a move/rename). |
|
|
105
|
+
|
|
106
|
+
By default only files directly in `SOURCE` are imported, matching `exiftool`
|
|
107
|
+
without `-r`. Use `--recursive` (or `-r`) to include subdirectories. Use
|
|
108
|
+
`--dry-run` (`-n`) to see what would happen without creating directories or
|
|
109
|
+
moving files.
|
|
110
|
+
|
|
111
|
+
Videos are new to the importer, so run the first archive with `--dry-run` to
|
|
112
|
+
review destinations. `fix-times` remains JPEG-only.
|
|
113
|
+
|
|
114
|
+
The destination defaults to the current directory, which matches running the
|
|
115
|
+
original script from the archive root with `SOURCE=../photos_incoming`.
|
|
116
|
+
|
|
117
|
+
## Defaults from environment
|
|
118
|
+
|
|
119
|
+
The commands accept two optional environment variables as defaults:
|
|
120
|
+
|
|
121
|
+
| Variable | Used by | CLI argument |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| `MEDIA_WORKFLOW_SOURCE` | `import` only | `SOURCE` (the incoming media folder) |
|
|
124
|
+
| `MEDIA_WORKFLOW_ROOT` | `import`, `duplicates`, `fix-times` | archive/library root: `--destination` and `ROOT` |
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
export MEDIA_WORKFLOW_ROOT="$HOME/photos/library"
|
|
128
|
+
export MEDIA_WORKFLOW_SOURCE="$HOME/photos/incoming"
|
|
129
|
+
|
|
130
|
+
media-workflow import # env source -> env archive root
|
|
131
|
+
media-workflow duplicates # scans the env archive root
|
|
132
|
+
media-workflow fix-times # fixes and re-imports the env archive root
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Explicit command-line values always win, then the environment, then the
|
|
136
|
+
built-in default:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
explicit argument > environment variable > built-in default
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
An empty environment variable is treated as unset. When a required source or
|
|
143
|
+
root cannot be resolved, the command exits with an error that names the
|
|
144
|
+
relevant variable.
|
|
145
|
+
|
|
146
|
+
### Python API
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from media_workflow import import_images
|
|
150
|
+
|
|
151
|
+
results = import_images("../photos_incoming", destination=".", recursive=True)
|
|
152
|
+
for result in results:
|
|
153
|
+
print(result.status, result.source, "->", result.destination)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Each result has one of the statuses `moved`, `would_move`, `unchanged`,
|
|
157
|
+
`skipped`, or `failed`.
|
|
158
|
+
|
|
159
|
+
## Remove duplicates
|
|
160
|
+
|
|
161
|
+
The duplicate finder is dry-run by default:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
media-workflow duplicates ~/Pictures
|
|
165
|
+
media-workflow duplicates ~/Pictures --apply
|
|
166
|
+
media-workflow duplicates ~/Pictures --apply --trash
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- `--apply` actually deletes/moves files.
|
|
170
|
+
- `--trash` moves duplicates into a mirrored `.dtrash` tree instead of deleting.
|
|
171
|
+
- `--fuzzy` also matches JPEG re-exports that differ in resolution or quality.
|
|
172
|
+
- `--threshold BITS` controls the dHash Hamming distance (default 6/64).
|
|
173
|
+
- `--verbose` logs near matches that were considered but not flagged.
|
|
174
|
+
|
|
175
|
+
Exact SHA-256 duplicates are detected for JPEGs and for `.mp4`, `.mov`, `.m4v`,
|
|
176
|
+
and `.3gp` video copies. Fuzzy matching stays JPEG-only because perceptual
|
|
177
|
+
comparison requires decoding image pixels. Video candidates still participate
|
|
178
|
+
in exact-hash cleanup when `--fuzzy` is enabled, without image-readability
|
|
179
|
+
warnings.
|
|
180
|
+
|
|
181
|
+
Fuzzy matching uses a perceptual dHash gate followed by a pixel-difference
|
|
182
|
+
check, and differing extended-XMP digests veto a match.
|
|
183
|
+
|
|
184
|
+
## Fix timestamps and re-import
|
|
185
|
+
|
|
186
|
+
The `fix-times` command is a port of `fix_times.sh`:
|
|
187
|
+
|
|
188
|
+
```sh
|
|
189
|
+
media-workflow fix-times 2025/09_fix --destination .
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
It adds one hour to all EXIF dates (configurable with `--hours`) and then
|
|
193
|
+
re-imports the JPEGs using the import naming rules, without
|
|
194
|
+
`SubSecTimeOriginal` (matching the original script). Date shifting requires
|
|
195
|
+
`exiftool`. Videos are not processed by `fix-times`.
|
|
196
|
+
|
|
197
|
+
## Publishing to PyPI
|
|
198
|
+
|
|
199
|
+
Build and publish with uv:
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
uv build --no-sources
|
|
203
|
+
uv publish
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`uv publish` reads the PyPI token from `UV_PUBLISH_TOKEN` or accepts `--token`.
|
|
207
|
+
Tagged releases are published automatically by the GitLab pipeline:
|
|
208
|
+
|
|
209
|
+
```sh
|
|
210
|
+
git tag -a v0.1.0 -m v0.1.0
|
|
211
|
+
git push origin v0.1.0
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
The `publish` job runs only for tags matching `vX.Y.Z` (including common
|
|
215
|
+
pre-release suffixes), checks the built wheel and source distribution, and then
|
|
216
|
+
runs:
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
uv publish --check-url https://pypi.org/simple/
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Before releasing:
|
|
223
|
+
|
|
224
|
+
1. Add a masked, protected CI/CD variable named `UV_PUBLISH_TOKEN` containing a
|
|
225
|
+
PyPI API token for the `media-workflow` project.
|
|
226
|
+
2. Optionally protect the `pypi` environment so releases require approval.
|
|
227
|
+
3. Update the version in `pyproject.toml` (for example with
|
|
228
|
+
`uv version 0.1.0`) and push the matching tag.
|
|
229
|
+
|
|
230
|
+
Trusted publishing for self-managed GitLab is available as a PyPI beta but
|
|
231
|
+
requires onboarding by PyPI staff, so this pipeline uses `UV_PUBLISH_TOKEN`. If
|
|
232
|
+
the instance is onboarded later, or the project moves to gitlab.com/GitHub,
|
|
233
|
+
trusted publishing can replace the token.
|
|
234
|
+
|
|
235
|
+
## Layout
|
|
236
|
+
|
|
237
|
+
```text
|
|
238
|
+
.gitlab-ci.yml # test and PyPI release pipeline
|
|
239
|
+
src/media_workflow/
|
|
240
|
+
importer.py # Python import port and naming rules
|
|
241
|
+
duplicates.py # duplicate finder
|
|
242
|
+
fix_times.py # timestamp shifting + re-import
|
|
243
|
+
cli.py # `media-workflow` entry point
|
|
244
|
+
tests/
|
|
245
|
+
conftest.py # fixtures that create fake images with EXIF data
|
|
246
|
+
test_importer.py
|
|
247
|
+
test_duplicates.py
|
|
248
|
+
test_cli.py
|
|
249
|
+
smoke_test.py # checks the built wheel/sdist
|
|
250
|
+
legacy/
|
|
251
|
+
import.sh # original scripts, kept for reference
|
|
252
|
+
fix_times.sh
|
|
253
|
+
duplicates.py
|
|
254
|
+
```
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# media-workflow
|
|
2
|
+
|
|
3
|
+
Tools for importing camera photos and videos into a date-based archive and
|
|
4
|
+
cleaning up duplicate copies.
|
|
5
|
+
|
|
6
|
+
The repository started as a small collection of shell/Python scripts. It is now
|
|
7
|
+
a Python package with a single CLI and a test suite that builds fake JPEGs with
|
|
8
|
+
EXIF metadata to verify the import rules.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Install the published package as a standalone CLI tool with `uv`:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
uv tool install media-workflow
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or install it into the current environment with pip:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pip install media-workflow
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For development from a checkout:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pip install -e .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For development and tests:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
pip install -e '.[test]'
|
|
34
|
+
pytest
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or, with `uv`:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
uv run --extra test pytest
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The package depends on [Pillow](https://python-pillow.org/) for reading image
|
|
44
|
+
metadata. Videos are read with a small built-in ISO-BMFF metadata reader, so
|
|
45
|
+
no additional runtime dependency is needed. The optional `fix-times` command
|
|
46
|
+
also needs `exiftool` on `PATH` to rewrite EXIF dates without re-encoding JPEGs.
|
|
47
|
+
|
|
48
|
+
## Import photos and videos
|
|
49
|
+
|
|
50
|
+
The import command is a Python port of the original `import.sh` exiftool
|
|
51
|
+
command. It requires `Make`, `Model`, and a timestamp in each photo or video
|
|
52
|
+
and moves it into a `YYYY/MM` archive tree:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
media-workflow import ../photos_incoming --destination .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The resulting name is:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
YYYYMMDD_HHMMSS[.SubSecTimeOriginal]_Make_Model.<FileTypeExtension>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For example:
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
photos_incoming/IMG_0001.JPG
|
|
68
|
+
-> 2024/07/20240715_123456.123_Canon_EOS-5D.jpg
|
|
69
|
+
|
|
70
|
+
photos_incoming/PXL_20250809_194948618.TS.mp4
|
|
71
|
+
-> 2025/08/20250809_194948.618_Google_Pixel-6.mp4
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Rules preserved from exiftool, plus the video extensions:
|
|
75
|
+
|
|
76
|
+
| Detail | Behaviour |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| Required metadata | Photos without `Make`, `Model`, or `DateTimeOriginal` are skipped. Videos require make, model, and a timestamp. |
|
|
79
|
+
| Date tree | Files go to `<destination>/<year>/<month>/`. |
|
|
80
|
+
| Photo timestamp | `DateTimeOriginal` is formatted as `YYYYMMDD_HHMMSS`. |
|
|
81
|
+
| Video timestamp | A valid `_YYYYMMDD_HHMMSS[mmm]` filename segment wins; otherwise the Apple `com.apple.quicktime.creationdate` key, then the `©day` tag, then QuickTime `CreateDate` (`mvhd`). |
|
|
82
|
+
| Subseconds | Photo `SubSecTimeOriginal`, video filename milliseconds, or an Apple creation-date fraction are appended as `.123`. |
|
|
83
|
+
| Make/model | Photos use EXIF; videos prefer Android `com.android.*` metadata and fall back to Apple QuickTime metadata. |
|
|
84
|
+
| Extension | Photos use exiftool's `FileTypeExtension`; videos use the lowercased file suffix. |
|
|
85
|
+
| Video containers | `.mp4`, `.mov`, `.m4v`, and `.3gp` are recognized by content, not suffix alone. |
|
|
86
|
+
| Google Photos `.TS` | Top Shot markers are dropped from archive names. |
|
|
87
|
+
| Other video containers | MKV, AVI, WebM, MPEG-TS, and similar formats are skipped. |
|
|
88
|
+
| Collisions | Existing names get `_1`, `_2`, ... before the extension. |
|
|
89
|
+
| Already imported | A file already at its computed destination is left unchanged. |
|
|
90
|
+
| File data | Bytes and modification time are preserved (it is a move/rename). |
|
|
91
|
+
|
|
92
|
+
By default only files directly in `SOURCE` are imported, matching `exiftool`
|
|
93
|
+
without `-r`. Use `--recursive` (or `-r`) to include subdirectories. Use
|
|
94
|
+
`--dry-run` (`-n`) to see what would happen without creating directories or
|
|
95
|
+
moving files.
|
|
96
|
+
|
|
97
|
+
Videos are new to the importer, so run the first archive with `--dry-run` to
|
|
98
|
+
review destinations. `fix-times` remains JPEG-only.
|
|
99
|
+
|
|
100
|
+
The destination defaults to the current directory, which matches running the
|
|
101
|
+
original script from the archive root with `SOURCE=../photos_incoming`.
|
|
102
|
+
|
|
103
|
+
## Defaults from environment
|
|
104
|
+
|
|
105
|
+
The commands accept two optional environment variables as defaults:
|
|
106
|
+
|
|
107
|
+
| Variable | Used by | CLI argument |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `MEDIA_WORKFLOW_SOURCE` | `import` only | `SOURCE` (the incoming media folder) |
|
|
110
|
+
| `MEDIA_WORKFLOW_ROOT` | `import`, `duplicates`, `fix-times` | archive/library root: `--destination` and `ROOT` |
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
export MEDIA_WORKFLOW_ROOT="$HOME/photos/library"
|
|
114
|
+
export MEDIA_WORKFLOW_SOURCE="$HOME/photos/incoming"
|
|
115
|
+
|
|
116
|
+
media-workflow import # env source -> env archive root
|
|
117
|
+
media-workflow duplicates # scans the env archive root
|
|
118
|
+
media-workflow fix-times # fixes and re-imports the env archive root
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Explicit command-line values always win, then the environment, then the
|
|
122
|
+
built-in default:
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
explicit argument > environment variable > built-in default
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
An empty environment variable is treated as unset. When a required source or
|
|
129
|
+
root cannot be resolved, the command exits with an error that names the
|
|
130
|
+
relevant variable.
|
|
131
|
+
|
|
132
|
+
### Python API
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from media_workflow import import_images
|
|
136
|
+
|
|
137
|
+
results = import_images("../photos_incoming", destination=".", recursive=True)
|
|
138
|
+
for result in results:
|
|
139
|
+
print(result.status, result.source, "->", result.destination)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Each result has one of the statuses `moved`, `would_move`, `unchanged`,
|
|
143
|
+
`skipped`, or `failed`.
|
|
144
|
+
|
|
145
|
+
## Remove duplicates
|
|
146
|
+
|
|
147
|
+
The duplicate finder is dry-run by default:
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
media-workflow duplicates ~/Pictures
|
|
151
|
+
media-workflow duplicates ~/Pictures --apply
|
|
152
|
+
media-workflow duplicates ~/Pictures --apply --trash
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- `--apply` actually deletes/moves files.
|
|
156
|
+
- `--trash` moves duplicates into a mirrored `.dtrash` tree instead of deleting.
|
|
157
|
+
- `--fuzzy` also matches JPEG re-exports that differ in resolution or quality.
|
|
158
|
+
- `--threshold BITS` controls the dHash Hamming distance (default 6/64).
|
|
159
|
+
- `--verbose` logs near matches that were considered but not flagged.
|
|
160
|
+
|
|
161
|
+
Exact SHA-256 duplicates are detected for JPEGs and for `.mp4`, `.mov`, `.m4v`,
|
|
162
|
+
and `.3gp` video copies. Fuzzy matching stays JPEG-only because perceptual
|
|
163
|
+
comparison requires decoding image pixels. Video candidates still participate
|
|
164
|
+
in exact-hash cleanup when `--fuzzy` is enabled, without image-readability
|
|
165
|
+
warnings.
|
|
166
|
+
|
|
167
|
+
Fuzzy matching uses a perceptual dHash gate followed by a pixel-difference
|
|
168
|
+
check, and differing extended-XMP digests veto a match.
|
|
169
|
+
|
|
170
|
+
## Fix timestamps and re-import
|
|
171
|
+
|
|
172
|
+
The `fix-times` command is a port of `fix_times.sh`:
|
|
173
|
+
|
|
174
|
+
```sh
|
|
175
|
+
media-workflow fix-times 2025/09_fix --destination .
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
It adds one hour to all EXIF dates (configurable with `--hours`) and then
|
|
179
|
+
re-imports the JPEGs using the import naming rules, without
|
|
180
|
+
`SubSecTimeOriginal` (matching the original script). Date shifting requires
|
|
181
|
+
`exiftool`. Videos are not processed by `fix-times`.
|
|
182
|
+
|
|
183
|
+
## Publishing to PyPI
|
|
184
|
+
|
|
185
|
+
Build and publish with uv:
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
uv build --no-sources
|
|
189
|
+
uv publish
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`uv publish` reads the PyPI token from `UV_PUBLISH_TOKEN` or accepts `--token`.
|
|
193
|
+
Tagged releases are published automatically by the GitLab pipeline:
|
|
194
|
+
|
|
195
|
+
```sh
|
|
196
|
+
git tag -a v0.1.0 -m v0.1.0
|
|
197
|
+
git push origin v0.1.0
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The `publish` job runs only for tags matching `vX.Y.Z` (including common
|
|
201
|
+
pre-release suffixes), checks the built wheel and source distribution, and then
|
|
202
|
+
runs:
|
|
203
|
+
|
|
204
|
+
```sh
|
|
205
|
+
uv publish --check-url https://pypi.org/simple/
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Before releasing:
|
|
209
|
+
|
|
210
|
+
1. Add a masked, protected CI/CD variable named `UV_PUBLISH_TOKEN` containing a
|
|
211
|
+
PyPI API token for the `media-workflow` project.
|
|
212
|
+
2. Optionally protect the `pypi` environment so releases require approval.
|
|
213
|
+
3. Update the version in `pyproject.toml` (for example with
|
|
214
|
+
`uv version 0.1.0`) and push the matching tag.
|
|
215
|
+
|
|
216
|
+
Trusted publishing for self-managed GitLab is available as a PyPI beta but
|
|
217
|
+
requires onboarding by PyPI staff, so this pipeline uses `UV_PUBLISH_TOKEN`. If
|
|
218
|
+
the instance is onboarded later, or the project moves to gitlab.com/GitHub,
|
|
219
|
+
trusted publishing can replace the token.
|
|
220
|
+
|
|
221
|
+
## Layout
|
|
222
|
+
|
|
223
|
+
```text
|
|
224
|
+
.gitlab-ci.yml # test and PyPI release pipeline
|
|
225
|
+
src/media_workflow/
|
|
226
|
+
importer.py # Python import port and naming rules
|
|
227
|
+
duplicates.py # duplicate finder
|
|
228
|
+
fix_times.py # timestamp shifting + re-import
|
|
229
|
+
cli.py # `media-workflow` entry point
|
|
230
|
+
tests/
|
|
231
|
+
conftest.py # fixtures that create fake images with EXIF data
|
|
232
|
+
test_importer.py
|
|
233
|
+
test_duplicates.py
|
|
234
|
+
test_cli.py
|
|
235
|
+
smoke_test.py # checks the built wheel/sdist
|
|
236
|
+
legacy/
|
|
237
|
+
import.sh # original scripts, kept for reference
|
|
238
|
+
fix_times.sh
|
|
239
|
+
duplicates.py
|
|
240
|
+
```
|