6 Commits

Author SHA1 Message Date
bcaeba5ea6 Update README.md 2025-01-06 19:54:31 +03:00
9248a9a84d Update README.md, refactoring 2025-01-06 18:15:22 +03:00
f0a8abb380 Update README.md 2025-01-06 15:18:06 +03:00
fb1ab2f8b5 Update README.md 2025-01-04 22:50:22 +03:00
bdd3eee69f Update README.md 2025-01-04 19:39:59 +03:00
8e315ff557 Update README.md 2025-01-04 19:37:23 +03:00
3 changed files with 104 additions and 78 deletions

160
README.md
View File

@@ -1,111 +1,129 @@
[![Go](https://github.com/derfenix/photocatalog/actions/workflows/go.yml/badge.svg)](https://github.com/derfenix/photocatalog/actions/workflows/go.yml)
# Effortless Photo Organizer # Effortless Photo Organizer
Just copy/hardlink photos (or video, or any other files) from one place to [![Go](https://github.com/derfenix/photocatalog/actions/workflows/go.yml/badge.svg)](https://github.com/derfenix/photocatalog/actions/workflows/go.yml)
another, separating them in sub-directories like `$ROOT/year/month/day/`.
### TL;DR A simple tool to organize your photos, videos, or other files by copying or hardlinking them into a date-based directory structure like `$ROOT/year/month/day/`.
I use a smartphone along with Syncthing to seamlessly sync all my photos to my PC without any manual effort. However, there's a catch: I can't keep all my photos in the synced folder indefinitely. If I clear my phone's memory, the photos on my PC get deleted as well. To avoid this, I need to remember to copy the files to another location before cleaning up my phone. ## TL;DR
Simply dumping all my photos into one folder isn't a solution either — finding anything later would be a nightmare, and a folder with thousands of unsorted photos is far from ideal. I use a smartphone and Syncthing to automatically sync my photos to my PC. However, if I clean up my phone's memory, the synced photos on my PC are deleted as well.
Dumping everything into one folder wasn't an option — finding anything later would be a nightmare.
To address these issues, I created this tool in just one evening. Its primary purpose is to copy (or create hardlinks for) files from one location to another, while organizing them into a simple, date-based directory structure. To avoid this, I needed a solution to back up and organize my photos without manual effort. So, I built this tool in one evening to solve the problem. It has worked flawlessly for me and might help you too. If you encounter any issues, feel free to open a ticket — I'll do my best to assist.
This tool was built for personal use and has been serving me well for quite some time without any problems. However, if you encounter any issues, feel free to report them — Id be happy to help. ## Installation
Install the tool via `go`:
## Installing
```bash ```bash
go install github.com/derfenix/photocatalog/v2@latest go install github.com/derfenix/photocatalog/v2@latest
``` ```
Optionally you could copy created binary from the GO's bin path to
system or user $PATH, e.g. /usr/local/bin/. Optionally, copy the binary to a directory in your system or user's `$PATH` (e.g., `/usr/local/bin`):
```bash ```bash
sudo cp ${GOPATH}/bin/photocatalog /usr/local/bin/photocatalog sudo cp ${GOPATH}/bin/photocatalog /usr/local/bin/photocatalog
``` ```
## Migrating from v0.* ## Organization Modes
TODO The tool supports the following organization modes:
## Organization modes - **copy** — Copies files to the target directory. If the filesystem supports it, uses Copy-on-Write (COW) for efficiency (via FICLONE ioctl call).
- **hardlink** — Creates hardlinks to the source files, saving disk space. Ideal if the source and target are on the same partition, though file permissions remain linked to the original.
- **move** — Moves files from the source to the target directory.
- **symlink** — Creates symbolic links at the target pointing to the source files.
Next organization modes supported: ## Supported Formats
- **copy** — copy files to target root. Make COW (using syscall) if FS supports it. - **JPEG and TIFF files** with valid EXIF metadata.
- **hardlink** — create hardlink to the source file instead of copying. - Files named in the format `yyyymmdd_HHMMSS.ext` (optionally with suffixes after the timestamp) (e.g., `20230101_123456.jpg`). This format is common in Android cameras and other devices.
The best choice if source and target are in same partition for compatibility
and resource usage, but we can't chmod target files, because of original file mode will
be changed too.
- **move** — moves original files to new place.
- **symlink** — create a symlink at the target for the source files.
## Supported formats If a file lacks EXIF data, the tool falls back to parsing the filename.
At this moment supported jpeg and tiff files with filled exif data and any other
files but with names matching pattern `yyymmdd_HHMMSS.ext` with optional suffixes after a timestamp.
Such names format applied by the Android's camera software (I guess all cams
use this format, fix me if I'm wrong).
Jpeg/Tiff files without modification date if exif will be fallen back to the name parsing. Currently, the timestamp format is not customizable. Let me know if support for additional formats is required.
No able to change names format without modifying source code for now. Just because
I have reasons to believe that this format is the most popular for the application use cases.
But let me know if you need different timestamp formats support.
## Usage ## Usage
### One-shot
#### Copy files Arguments
```bash ```
photocalog -mode copy -target ./photos/ -source ./sync/photos/ -dir-mode string
Mode bits for directories can be created while syncing (default "0777")
-file-mode string
Mode bits for files created while syncing (not applicable for hardlink mode) (default "0644")
-mode string
Organazing mode (default "hardlink")
-overwrite
Overwrite existing files
-skip-full-sync
Skip full sync at startup
-source string
Source directory
-target string
Target directory
-watch
Watch for changes in the source directory (default true)
``` ```
#### Create hardlinks `-skip-full-sync` and `-watch` are not compatible.
```bash
photocalog -mode hardlink -target ./photos/ -source ./sync/photos/ `-source` and `-target` are required.
```
or
```bash ## Examples
photocalog -target ./photos/ -source ./sync/photos/*
### One-Time Run
#### Copy Files
```shell
photocatalog -mode copy -target ./photos/ -source ./sync/photos/
``` ```
### Watch mode #### Create Hardlinks
#### Copy files ```shell
```bash photocatalog -mode hardlink -target ./photos/ -source ./sync/photos/
photocalog -mode copy -target ./photos -watch -source ./sync/photos/
``` ```
#### Create hardlinks ### Watch Mode
```bash
photocalog -mode hardlink -target ./photos/ -watch -source ./sync/photos/ Enable continuous monitoring of a source directory:
```
or #### Copy Files
```bash ```shell
photocalog -target ./photos/ -watch -source ./sync/photos/ photocatalog -mode copy -target ./photos -watch -source ./sync/photos/
``` ```
## Install and run monitor service #### Create Hardlinks
```shell
photocatalog -mode hardlink -target ./photos/ -watch -source ./sync/photos/
```
### Systemd ## Running as a Service
```bash
### Systemd Setup
Install and configure the service:
```shell
sh ./init/install_service.sh systemd sh ./init/install_service.sh systemd
``` ```
This command will install unit file, create stub for its config and open
editor to allow you edit configuration. Config file stored at
`$HOME/.config/photocatalog`.
Then enable and start service This will:
```bash
1. Install a systemd unit file.
2. Create a configuration stub at `$HOME/.config/photocatalog`.
3. Open the config file for editing.
Enable and start the service:
```shell
systemctl --user enable --now photocatalog systemctl --user enable --now photocatalog
``` ```
That's all. Now, if any file will be placed in directory, specified as `MONITOR`
in config file, this file will be copied or hardlinked into the target dir Now, files added to the monitored directory (`MONITOR` in the config) will automatically be organized into the target directory under the corresponding subdirectories.
under corresponding sub-dir.
## FAQ ## FAQ
### Why this tool was created if there is awesome XXX tool? ### Why did you create this tool when awesome tool XXX already exists?
I had two good reasons: Two reasons:
1. I wish 1. I wanted to.
2. I can 2. I could.

View File

@@ -180,7 +180,9 @@ func (o *Organizer) FullSync(ctx context.Context) error {
} }
if err := o.processFile(path); err != nil { if err := o.processFile(path); err != nil {
return err log.Printf("Process file `%s` failed: %s", path, err.Error())
return nil
} }
return nil return nil
@@ -203,7 +205,7 @@ func (o *Organizer) getMetaForPath(fp string) (metadata.Metadata, error) {
meta, err := o.getMetadata(fp, file) meta, err := o.getMetadata(fp, file)
if err != nil { if err != nil {
return metadata.Metadata{}, fmt.Errorf("get metadata: %w", err) return metadata.Metadata{}, fmt.Errorf("get metadatas: %w", err)
} }
return meta, nil return meta, nil

16
main.go
View File

@@ -41,13 +41,15 @@ func loadCfg() application.Config {
flag.BoolVar(&cfg.Watch, "watch", true, "Watch for changes in the source directory") flag.BoolVar(&cfg.Watch, "watch", true, "Watch for changes in the source directory")
flag.BoolVar(&cfg.SkipFullSync, "skip-full-sync", false, "Skip full sync at startup") flag.BoolVar(&cfg.SkipFullSync, "skip-full-sync", false, "Skip full sync at startup")
var dirMode string var (
var fileMode string dirMode string
fileMode string
mode string
)
flag.StringVar(&dirMode, "dir-mode", "0777", "Mode bits for directories can be created while syncing") flag.StringVar(&dirMode, "dir-mode", "0777", "Mode bits for directories can be created while syncing")
flag.StringVar(&fileMode, "file-mode", "0644", "Mode bits for files created while syncing (not applicable for hardlink mode)") flag.StringVar(&fileMode, "file-mode", "0644", "Mode bits for files created while syncing (not applicable for hardlink mode)")
flag.StringVar(&mode, "mode", "hardlink", "Organizing mode")
var mode string
flag.StringVar(&mode, "mode", "hardlink", "Mode")
flag.Parse() flag.Parse()
@@ -57,11 +59,15 @@ func loadCfg() application.Config {
cfg.DirMode, err = strconv.ParseUint(dirMode, 8, 32) cfg.DirMode, err = strconv.ParseUint(dirMode, 8, 32)
if err != nil { if err != nil {
log.Println("Parse -dir-mode failed:", err)
cfg.DirMode = 0o777 cfg.DirMode = 0o777
} }
cfg.FileMode, err = strconv.ParseUint(fileMode, 8, 32) cfg.FileMode, err = strconv.ParseUint(fileMode, 8, 32)
if err != nil { if err != nil {
log.Println("Parse -file-mode failed:", err)
cfg.DirMode = 0o644 cfg.DirMode = 0o644
} }