alvistar / immich-albums

Create immich albums from folder structure
MIT License
38 stars 7 forks source link

Error importing files from NFS with spaces #15

Closed ilopmar closed 3 weeks ago

ilopmar commented 1 month ago

I'm using latest Immich v1.105.1.

I'm trying to create the albums after importing my whole library but the process fails when trying to fetch a photo using the API because the name of the fullpath file is not correct. I'm not 100% sure if the problem is the spaces in paths or the fact that the original files are mounted by NFS in my laptop.

As you can see the folder in local laptop is /home/ivanlm/qFotos/FotosTodas/20080100 - 7 meses Judith but at the end of the log the call to get the first file fails because the spaces are substituted by %20 and that doesn't exist on the database.

HTTP response body: {"message":"Cannot GET /api/assets?originalPath=/data/photos/20080100%20-%207%20meses%20Judith/DSCN2108.JPG","error":"Not Found","statusCode":404}

I've check in the database and using spaces instead of %20 returns the rigth file:

select * from assets
where "originalPath" = '/data/photos/20080100 - 7 meses Judith/DSCN2108.JPG';

a3264825-dc47-4ccb-85d4-e857ab85cc7b,DSCN2108.JPG,97131972-710b-4fe4-b500-ba57dfa8af31,Library Import,IMAGE,/data/photos/20080100 - 7 meses Judith/DSCN2108.JPG,upload/thumbs/97131972-710b-4fe4-b500-ba57dfa8af31/a3/26/a3264825-dc47-4ccb-85d4-e857ab85cc7b-preview.jpeg,2008-01-01 13:08:22.000000 +00:00,2008-01-01 12:08:22.000000 +00:00,false,,upload/thumbs/97131972-710b-4fe4-b500-ba57dfa8af31/a3/26/a3264825-dc47-4ccb-85d4-e857ab85cc7b-thumbnail.webp,"",0x847293779E75D9CE3E9D6EB91AAEEC887487846E,true,,2024-05-17 15:11:09.479325 +00:00,2024-05-17 12:04:31.061676 +00:00,false,DSCN2108.JPG,,0x16180A0D00676780574687D677867898A3974F013A,false,dbdc1495-80cc-4432-9297-60938b41449b,true,,2008-01-01 13:08:22.000000 +00:00,

This is the execution log:

Processing folder: /home/ivanlm/qFotos/FotosTodas/20080100 - 7 meses Judith

Album 20080100 - 7 meses Judith does not exist
searching for: /data/photos/20080100 - 7 meses Judith/DSCN2108.JPG
Traceback (most recent call last):
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/bin/im", line 6, in <module>
    sys.exit(cli())
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/ivanlm/TEMP/immich-albums/src/immich_albums/im.py", line 191, in cli
    immich_albums.create_albums_from_folder(
  File "/home/ivanlm/TEMP/immich-albums/src/immich_albums/im.py", line 152, in create_albums_from_folder
    self.create_albums_from_folder(path, original_path, replace_path, True, dry_run,
  File "/home/ivanlm/TEMP/immich-albums/src/immich_albums/im.py", line 148, in create_albums_from_folder
    self.create_album_from_folder(path, original_path, replace_path, dry_run, skip_existing=skip_existing)
  File "/home/ivanlm/TEMP/immich-albums/src/immich_albums/im.py", line 115, in create_album_from_folder
    assets_ids = self.get_assets_in_folder(path, original_path, replace_path)
  File "/home/ivanlm/TEMP/immich-albums/src/immich_albums/im.py", line 92, in get_assets_in_folder
    asset_id = self.get_asset_by_original_path(replaced_path)
  File "/home/ivanlm/TEMP/immich-albums/src/immich_albums/im.py", line 44, in get_asset_by_original_path
    assets = api_instance.search_assets(original_path=original_path)
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/api/asset_api.py", line 3806, in search_assets
    return self.search_assets_with_http_info(checksum, city, country, created_after, created_before, device_asset_id, device_id, encoded_video_path, id, is_archived, is_encoded, is_external, is_favorite, is_motion, is_offline, is_read_only, is_visible, lens_model, library_id, make, model, order, original_file_name, original_path, page, resize_path, size, state, taken_after, taken_before, trashed_after, trashed_before, type, updated_after, updated_before, webp_path, with_deleted, with_exif, with_people, with_stacked, **kwargs)  # noqa: E501
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/api/asset_api.py", line 4158, in search_assets_with_http_info
    return self.api_client.call_api(
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/api_client.py", line 409, in call_api
    return self.__call_api(resource_path, method,
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/api_client.py", line 221, in __call_api
    raise e
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/api_client.py", line 211, in __call_api
    response_data = self.request(
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/api_client.py", line 435, in request
    return self.rest_client.get_request(url,
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/rest.py", line 242, in get_request
    return self.request("GET", url,
  File "/home/ivanlm/.cache/pypoetry/virtualenvs/immich-albums-fF0xvNUT-py3.10/lib/python3.10/site-packages/openapi_client/rest.py", line 231, in request
    raise NotFoundException(http_resp=r)
openapi_client.exceptions.NotFoundException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'X-Powered-By': 'Express', 'x-immich-cid': 'v31rkpqp', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '146', 'ETag': '"92-0Yq+GPlPhZr57TDlVkUTy3gHQcg"', 'Date': 'Fri, 17 May 2024 19:24:51 GMT', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=5'})
HTTP response body: {"message":"Cannot GET /api/assets?originalPath=/data/photos/20080100%20-%207%20meses%20Judith/DSCN2108.JPG","error":"Not Found","statusCode":404}

Thanks for your tool and support.

alvistar commented 3 weeks ago

Is this still an issue? I made some tests importing files with spaces and I can't reproduce it.

ilopmar commented 3 weeks ago

Thanks for the reply. I didn't test this anymore. At the end I built a custom bash script to create the albums myself.

Closing this.