Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for -use-full-path-album-name to be able to use the full path to the file as album name/title #444

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/files/localassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (la *LocalAssetBrowser) assetFromFile(fsys fs.FS, name string) (*browser.Lo
if fsys, ok := fsys.(fshelper.NameFS); ok {
fullPath = filepath.Join(fsys.Name(), name)
}

a.Metadata.DateTaken = metadata.TakeTimeFromPath(fullPath)

i, err := fs.Stat(fsys, name)
Expand Down
15 changes: 14 additions & 1 deletion cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type UpCmd struct {
GooglePhotos bool // For reading Google Photos takeout files
Delete bool // Delete original file after import
CreateAlbumAfterFolder bool // Create albums for assets based on the parent folder or a given name
UseFullPathAsAlbumName bool // Create albums for assets based on the full path to the asset
AlbumNamePathSeparator string // Determines how multiple (sub) folders, if any, will be joined
ImportIntoAlbum string // All assets will be added to this album
PartnerAlbum string // Partner's assets will be added to this album
Import bool // Import instead of upload
Expand Down Expand Up @@ -119,6 +121,14 @@ func newCommand(ctx context.Context, common *cmd.SharedFlags, args []string, fsO
"create-album-folder",
" folder import only: Create albums for assets based on the parent folder",
myflag.BoolFlagFn(&app.CreateAlbumAfterFolder, false))
cmd.BoolFunc(
"use-full-path-album-name",
" folder import only: Use the full path towards the asset for determining the Album name",
myflag.BoolFlagFn(&app.UseFullPathAsAlbumName, false))
cmd.StringVar(&app.AlbumNamePathSeparator,
"album-name-path-separator",
" ",
" when use-full-path-album-name = true, determines how multiple (sub) folders, if any, will be joined")
cmd.BoolFunc(
"google-photos",
"Import GooglePhotos takeout zip files",
Expand Down Expand Up @@ -565,7 +575,7 @@ func (app *UpCmd) manageAssetAlbum(ctx context.Context, assetID string, a *brows
}
app.Jnl.Record(ctx, fileevent.UploadAddToAlbum, a, a.FileName, "album", album, "reason", "option -create-album-folder")
if !app.DryRun {
err := app.AddToAlbum(ctx, assetID, browser.LocalAlbum{Title: album})
err := app.AddToAlbum(ctx, assetID, browser.LocalAlbum{Title: album, Path: a.FileName})
if err != nil {
app.Jnl.Record(ctx, fileevent.Error, a, a.FileName, "error", err.Error())
}
Expand Down Expand Up @@ -678,6 +688,9 @@ func (app *UpCmd) AddToAlbum(ctx context.Context, id string, album browser.Local
title := album.Title
if (app.GooglePhotos && (title == "" || app.CreateAlbumAfterFolder)) || app.UseFolderAsAlbumName {
title = filepath.Base(album.Path)
} else if !app.GooglePhotos && app.UseFullPathAsAlbumName {
// full path
title = strings.Replace(filepath.Dir(album.Path), "/", app.AlbumNamePathSeparator, -1)
}

l, exist := app.albums[title]
Expand Down
46 changes: 45 additions & 1 deletion cmd/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,51 @@ func TestUpload(t *testing.T) {
},
},
},

{
name: "folder and albums creation using full path",
args: []string{
"-create-album-folder",
"-use-full-path-album-name",
"TEST_DATA/Takeout2",
},
expectedAssets: []string{
"Google Photos/Photos from 2023/PXL_20231006_063528961.jpg",
"Google Photos/Photos from 2023/PXL_20231006_063000139.jpg",
"Google Photos/Sans titre(9)/PXL_20231006_063108407.jpg",
},
expectedAlbums: map[string][]string{
"Google Photos Photos from 2023": {
"Google Photos/Photos from 2023/PXL_20231006_063000139.jpg",
"Google Photos/Photos from 2023/PXL_20231006_063528961.jpg",
},
"Google Photos Sans titre(9)": {
"Google Photos/Sans titre(9)/PXL_20231006_063108407.jpg",
},
},
},
{
name: "folder and albums creation using full path and custom separator",
args: []string{
"-create-album-folder",
"-use-full-path-album-name",
"-album-name-path-separator= & ",
"TEST_DATA/Takeout2",
},
expectedAssets: []string{
"Google Photos/Photos from 2023/PXL_20231006_063528961.jpg",
"Google Photos/Photos from 2023/PXL_20231006_063000139.jpg",
"Google Photos/Sans titre(9)/PXL_20231006_063108407.jpg",
},
expectedAlbums: map[string][]string{
"Google Photos & Photos from 2023": {
"Google Photos/Photos from 2023/PXL_20231006_063000139.jpg",
"Google Photos/Photos from 2023/PXL_20231006_063528961.jpg",
},
"Google Photos & Sans titre(9)": {
"Google Photos/Sans titre(9)/PXL_20231006_063108407.jpg",
},
},
},
// // {
// // name: "google photo, homonyms, keep partner",
// // args: []string{
Expand Down
24 changes: 13 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,19 @@ Use this command for uploading photos and videos from a local directory, a zippe

### Switches and options:

| **Parameter** | **Description** | **Default value** |
| ------------------------------------ | -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `-album="ALBUM NAME"` | Import assets into the Immich album `ALBUM NAME`. | |
| `-dry-run` | Preview all actions as they would be done. | `FALSE` |
| `-create-album-folder` | Generate immich albums after folder names. | `FALSE` |
| `-create-stacks` | Stack jpg/raw or bursts. | `FALSE` |
| `-stack-jpg-raw` | Control the stacking of jpg/raw photos. | `FALSE` |
| `-stack-burst` | Control the stacking bursts. | `FALSE` |
| `-select-types=".ext,.ext,.ext..."` | List of accepted extensions. | |
| `-exclude-types=".ext,.ext,.ext..."` | List of excluded extensions. | |
| `-when-no-date=FILE\|NOW` | When the date of take can't be determined, use the FILE's date or the current time NOW. | `FILE` |
| **Parameter** | **Description** | **Default value** |
|--------------------------------------|-------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| `-album="ALBUM NAME"` | Import assets into the Immich album `ALBUM NAME`. | |
| `-dry-run` | Preview all actions as they would be done. | `FALSE` |
| `-create-album-folder` | Generate immich albums after folder names. | `FALSE` |
| `-use-full-path-album-name` | Use the full path to the file to determine the album name. | `FALSE` |
| `-album-name-path-separator` | Determines how multiple (sub) folders, if any, will be joined | ` ` |
| `-create-stacks` | Stack jpg/raw or bursts. | `FALSE` |
| `-stack-jpg-raw` | Control the stacking of jpg/raw photos. | `FALSE` |
| `-stack-burst` | Control the stacking bursts. | `FALSE` |
| `-select-types=".ext,.ext,.ext..."` | List of accepted extensions. | |
| `-exclude-types=".ext,.ext,.ext..."` | List of excluded extensions. | |
| `-when-no-date=FILE\|NOW` | When the date of take can't be determined, use the FILE's date or the current time NOW. | `FILE` |
| `-exclude-files=pattern` | Ignore files based on a pattern. Case insensitive. Repeat the option for each pattern do you need. | `@eaDir/`<br>`@__thumb/`<br>`SYNOFILE_THUMB_*.*`<br>`Lightroom Catalog/`<br>`thumbnails/` |

### Date selection:
Expand Down