MediaImporter / DEVELOPMENT.md
Newer Older
02f71bb 8 months ago History
280 lines | 10.786kb
Bogdan Timofte authored 8 months ago
1
# Development Guide
2

            
3
## 1. Objectives
4

            
5
The Media Importer project aims to provide a robust, efficient solution for organizing media files by date with proper timezone handling and conflict - **Naming Convention**: `{s/f}_{YYYYMMDD_HHMMSS}_{TestName}.md` format where:
6
  - `s` = success, `f` = failure
7
  - Followed by timestamp and test name (spaces converted to underscores)esolution.
8

            
9
Key objectives:
10
- Reliable EXIF/metadata extraction and date parsing
11
- Proper UTC time conversion for QuickTime/Apple media files
12
- Flexible organization patterns (year/month/day/hour)
13
- Safe file operations with dry-run capabilities
14
- Cross-platform compatibility (macOS/Linux)
15

            
16
## 2. Guide
17

            
18
### Development Workflow
19

            
20
When making changes to the project, follow this structured approach:
21

            
22
### Changelog Entries Format
23

            
24
All changelog entries should follow this format:
25

            
26
```
27
- Date time
28
- Bug/Feature description
29
- Changes made
30
```
31

            
32
Example:
33
```
34
- 2025-09-07 10:30
35
- Fixed data loss issue when processing already-sorted folders
36
- Added exclusion patterns for sorted/organized/processed folders
37
- Added --include-sorted flag to override exclusions when needed
38
```
39

            
40
### File Move Confirmation
41

            
42
Every file move operation should be confirmed:
43
- After moving a file, the script must check that the file exists at the destination.
44
- If the file is not present at the destination after the move operation, the script should immediately stop and report an error.
45
- This ensures data integrity and prevents silent data loss.
46

            
47
### Destination Inside Source Handling
48

            
49
- Given the script's purpose, the destination folder may be inside the source folder.
50
- In this case, all files within the destination folder must be excluded from scanning and processing.
51
- For extra safety: before processing any file, if its path matches (or is inside) the destination path, the script must report an error and stop immediately.
52
- This prevents accidental re-processing or moving of files that have already been sorted, ensuring data integrity.
53

            
54
### Testing
55

            
56
Testing is essential to ensure the script's reliability and data safety. The following methodology should be used:
57

            
58
#### Test Environment Setup
59
- The `samples` directory contains a variety of media files for testing.
60
- Create a dedicated working directory named `test` for each test run.
61
- Copy selected files from `samples` into the `test` directory to simulate real-world scenarios.
62
- Perform import operations using the script, targeting the `test` directory as the source and a subdirectory (e.g., `test/sorted`) as the destination.
63

            
64
#### Test Execution and Documentation
65
- Before and after each import operation, run `find` on both the source and destination directories to capture the file structure:
66
  - Example: `find ./test > test/source_before.txt`
67
  - Example: `find ./test/sorted > test/dest_before.txt`
68
- Log all results, including script output and directory listings, into a dedicated log file for each test.
69

            
70
#### Test Report Format
71
Each test must generate a comprehensive Markdown report in `test/test_report.md` with the following structure:
72

            
73
```markdown
74
# Test Report: [Test Name/Scenario]
75

            
76
## Test Information
77
- **Date**: $(date)
78
- **Scenario**: [Brief description of what is being tested]
79
- **Objective**: [What specific functionality/behavior is being verified]
80
- **Files Used**: [List of test files and their characteristics]
81

            
82
## Pre-Test State
83
### Source Directory Structure
84
\`\`\`
85
[Contents of source_before.txt]
86
\`\`\`
87

            
88
### Destination Directory Structure
89
\`\`\`
90
[Contents of dest_before.txt]
91
\`\`\`
92

            
93
## Test Execution
94
### Command Used
95
\`\`\`bash
96
[Exact command executed]
97
\`\`\`
98

            
99
### Script Output
100
\`\`\`
101
[Full script output from import_log.txt]
102
\`\`\`
103

            
104
## Post-Test State
105
### Source Directory Structure
106
\`\`\`
107
[Contents of source_after.txt]
108
\`\`\`
109

            
110
### Destination Directory Structure
111
\`\`\`
112
[Contents of dest_after.txt]
113
\`\`\`
114

            
115
## Analysis and Verification
116
### Expected Results
117
- [List what should happen]
118

            
119
### Actual Results
120
- [List what actually happened]
121

            
122
### Issues Found
123
- [Any problems, errors, or unexpected behavior]
124
- [Include error messages, incorrect file placements, etc.]
125

            
126
### Protections Verified
127
- [ ] Destination exclusion working
128
- [ ] Move confirmation functional
129
- [ ] No data loss detected
130
- [ ] UTC conversion correct (for QuickTime files)
131
- [ ] Unimportable files handling (if applicable)
132

            
133
## Corrective Actions
134
### Issues Identified
135
- [Detailed description of problems found]
136

            
137
### Fixes Applied
138
- [Code changes made]
139
- [Configuration adjustments]
140
- [Process improvements]
141

            
142
### Re-test Results
143
- [Results after applying fixes]
144

            
145
## Conclusion
146
### Test Result
147
- [ ] PASSED
148
- [ ] FAILED
149
- [ ] PARTIAL (with notes)
150

            
151
### Notes
152
[Any additional observations, recommendations, or follow-up actions needed]
153

            
154
### Files Generated
155
- `test/source_before.txt` - Pre-test source structure
156
- `test/dest_before.txt` - Pre-test destination structure
157
- `test/source_after.txt` - Post-test source structure
158
- `test/dest_after.txt` - Post-test destination structure
159
- `test/import_log.txt` - Full script execution log
160
- `test/test_report.md` - This report
161
```
162

            
163
#### Automated Test Runner
164
A comprehensive test runner script (`test_runner.sh`) is available to automate the testing process:
165

            
166
```bash
167
./test_runner.sh
168
```
169

            
170
The script provides:
171
- **Pre-configured test scenarios** for common use cases
172
- **Automatic report generation** in Markdown format
173
- **State capture** before and after test execution
174
- **Protection verification** with checkboxes
175
- **Custom test support** for specific scenarios
176

            
177
#### Test Categories
178
The test runner provides the following pre-configured test scenarios:
179

            
180
1. **Basic Functionality Test**: Tests processing of files with valid EXIF data to verify correct sorting and organization
181
2. **Unimportable Files Test**: Tests handling of files without EXIF data in both root and subfolders, without --collect-unimportable flag
182
3. **Mixed Content Test**: Tests processing of sortable and unimportable files in separate folders to verify cleanup behavior
183
4. **Safety Protections Test**: Tests destination exclusion and move confirmation mechanisms to prevent data loss
184
5. **UTC Conversion Test**: Tests UTC timestamp conversion for QuickTime/Apple EXIF data
185
6. **Subdirectory Processing Test**: Tests processing of files in nested subdirectories to ensure recursive file discovery
186
7. **Custom Test**: Allows user-defined test scenarios with custom file sets and commands
187

            
188
#### Test Result Persistence
189
The test runner includes automatic result persistence:
190

            
191
- **Archival Location**: Test results are saved as individual Markdown files in `test_reports/` directory
192
- **Naming Convention**: `{TestName}_{YYYYMMDD_HHMMSS}.md` format for easy identification
193
- **Contents Preserved**: Single self-contained Markdown file with:
194
  - Complete test information and directory structures
195
  - Full script execution output embedded inline (ANSI codes stripped for readability)
196
  - Import log content included directly in the report
197
- **Excluded Files**: No separate files - everything is consolidated in the Markdown report
198
- **Historical Tracking**: Maintains complete test history for debugging and regression testing
199

            
200
#### Cleanup
201
- Review the test report and verify all aspects are documented
202
- Clean up the `test` directory after each test run to ensure a fresh environment for subsequent tests
203
- Archive important test reports in a `test_reports/` directory for future reference
204

            
205
## 3. Changelog
206

            
207
### 2025-09-07 21:15 - Test 2 and 3 Enhancements
208
- Updated Test 2 (Unimportable Files Test) to include files in both root and subfolder
209
- Removed --collect-unimportable flag from Test 2 to test default behavior
210
- Updated Test 3 (Mixed Content Test) to use separate folders for sortable vs unimportable files
211
- Test 3 now verifies that folders with only sortable files are cleaned up while folders with unimportable files are preserved
212
- Updated menu descriptions to reflect the changes
213
- Tests now verify proper handling of unimportable files without collection flag
214

            
215
---
216

            
217
### 2025-09-07 21:25 - Documentation Enhancement
218
- Added comprehensive documentation for --collect-unimportable flag in README.md
219
- Added Example 4 showing how to use --collect-unimportable flag
220
- Updated Features section to mention unimportable files handling
221
- Updated Configuration section to explain default behavior for unimportable files
222
- Added usage example for --collect-unimportable in Basic Usage section
223

            
224
---
225

            
226
### 2025-09-07 21:30 - Git Ignore Enhancement
227
- Added test_reports/ to .gitignore to exclude generated test reports from version control
228
- Test reports are generated files that don't need to be tracked in Git
229
- Prevents large numbers of timestamped report files from cluttering the repository
230
- Added sample/ to .gitignore to exclude test media files from version control
231

            
232
---
233

            
234
### 2025-09-07 20:40 - Source Only Test Addition
235
- Added Test 8: Source Only Test to test runner
236
- Tests processing with only source parameter (creates sorted subdirectory automatically)
237
- Verifies that when no destination is specified, files are sorted into source/sorted/
238
- Updated menu and command line options for new test
239

            
240
---
241

            
242
### 2025-09-07 20:45 - Test 7 Refinement
243
- Updated Test 7 to test --keep-empty-dirs functionality instead of cleanup
244
- Since cleanup is now default behavior, Test 7 now verifies empty directory preservation
245
- Renamed from "Cleanup Empty Directories Test" to "Keep Empty Directories Test"
246
- Updated test scenario to validate --keep-empty-dirs flag behavior
247
- Added command line option "keep-empty-dirs" for test 7
248

            
249
---
250

            
251
### 2025-09-07 19:30 - Test Runner Directory Separation
252
- Adapted test runner to use separate source and destination directories
253
- Changed from test/ as source to test/source/ and test/destination/
254
- Updated all test functions to use proper directory separation
255
- Improved test isolation and clarity
256

            
257
---
258

            
259
### 2025-09-07 19:00 - Default Cleanup Behavior
260
- Made --cleanup-empty-dirs the default behavior (implicit option)
261
- Added --keep-empty-dirs flag to disable cleanup if needed
262
- Updated help text and configuration display to reflect new default
263
- Cleanup now runs automatically unless explicitly disabled
264

            
265
---
266

            
267
### 2025-09-07 18:56 - Cleanup Empty Directories Feature
268
- Added --cleanup-empty-dirs option to remove empty directories from source after processing
269
- Added cleanup_empty_directories() function with safe empty directory detection
270
- Updated final report to show cleanup status
271
- Maintains safety by not removing source root directories
272
- Works correctly with dry-run mode
273

            
274
## 4. Todo
275

            
276
Key areas for future development:
277
- GPS metadata integration for timezone detection
278
- Enhanced duplicate detection
279
- Performance optimizations for large file sets
280
- Additional organization patterns