Skip to content

Instantly share code, notes, and snippets.

@dahool
Last active February 9, 2025 14:28
Show Gist options
  • Save dahool/7cdd66d17b1b26c885c298f0c324d88c to your computer and use it in GitHub Desktop.
Save dahool/7cdd66d17b1b26c885c298f0c324d88c to your computer and use it in GitHub Desktop.

Revisions

  1. dahool revised this gist Feb 9, 2025. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions heic_dup_keeper.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    #!/usr/bin/python3
    import requests
    import os
    import json
    from datetime import datetime

    API_KEY = '<YOUR_API_KEY>'
    BASE_URL = 'http://localhost:2283/api' # IMMICH URL
  2. dahool created this gist Feb 9, 2025.
    66 changes: 66 additions & 0 deletions heic_dup_keeper.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    #!/usr/bin/python3
    import requests
    import os
    import json
    from datetime import datetime

    API_KEY = '<YOUR_API_KEY>'
    BASE_URL = 'http://localhost:2283/api' # IMMICH URL

    HEADERS = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'x-api-key': API_KEY
    }

    def do_get(url):
    response = requests.get(f'{BASE_URL}/{url}', headers=HEADERS)
    return response.json()

    def delete_assets(asset_list):
    ids = list(map(lambda item: item['id'], asset_list))

    payload = json.dumps({
    "force": False,
    "ids": ids
    })

    requests.request("DELETE", f'{BASE_URL}/assets', headers=HEADERS, data=payload)

    print(f'Removed {len(ids)} assets')

    def list_dups():

    print('Retrieving duplicates list...')

    response = do_get('duplicates')

    remove_assets_list = []

    for dupItem in response:
    heic_file = False
    temp_asset = []
    for asset in dupItem['assets']:
    if 'image/heic' != asset['originalMimeType']:
    temp_asset.append(asset)
    else:
    heic_file = True
    if heic_file and temp_asset: remove_assets_list.extend(temp_asset)

    if remove_assets_list:
    print('Review the following list and confirm to remove:\n')
    for item in remove_assets_list:
    print(item['originalFileName'])
    user_input = input('\nProceed? (y/n)')
    if user_input.lower() in ('y','yes'):
    delete_assets(remove_assets_list)
    else:
    print('Cancelled.')
    else:
    print('No duplicates found.')

    def main():
    list_dups()

    if __name__ == "__main__":
    main()