From 690cd31a4030142475261457a60189bf45b9e857 Mon Sep 17 00:00:00 2001 From: Marco Realacci Date: Thu, 10 Apr 2025 15:28:31 +0200 Subject: [PATCH] add readme --- .idea/vcs.xml | 6 +++ README.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 17 --------- 3 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 README.md diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..80a10de --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ +Sure! Here's a clean and minimal `README.md` for your Immich album downloader project, including setup instructions and the example `systemd` service and timer: + +--- + +```markdown +# Immich Album Downloader + +This Python script downloads all assets (photos/videos) from a specific album in your [Immich](https://github.com/immich-app/immich) instance, using its API. It supports resuming by skipping files that already exist locally. + +## Features + +- Downloads all assets from a specified album +- Uses pagination to handle large albums +- Skips already-downloaded files +- Can be automated with `systemd` services and timers + +## Requirements +You can install dependencies with: + +```bash +pip install requests +``` +or you can use your system's package manager. + +## Environment Variables + +| Variable | Description | +|------------------------|----------------------------------------| +| `IMMICH_API_KEY` | Your Immich API key | +| `IMMICH_INSTANCE_URL` | Immich instance URL (e.g. `https://your-instance/api`) | +| `IMMICH_ALBUM_ID` | The ID of the album to download | +| `IMMICH_DOWNLOAD_PATH` | Directory to save downloaded assets | + +## Usage + +You can run the script manually: + +```bash +python3 main.py +``` + +Or set it up as a `systemd` service for automatic and scheduled execution. + +--- + +## Example: systemd Service + +Create a service file at `/etc/systemd/user/immich-album-downloader.service`: + +```ini +[Unit] +Description=Immich Album Downloader +After=network.target + +[Service] +Type=simple +Environment="IMMICH_ALBUM_ID=my-super-cool-album-id" +Environment="IMMICH_API_KEY=averysecretapikeypleasedonotsteal" +Environment="IMMICH_DOWNLOAD_PATH=/home/marco/wallapers/" +Environment="IMMICH_INSTANCE_URL=https://your-immich.instance/api" +ExecStart=/usr/bin/python3 /opt/immich-album-downloader/main.py +Restart=no + +[Install] +WantedBy=default.target +``` + +Enable and start the service: + +```bash +systemctl --user daemon-reexec +systemctl --user enable --now immich-album-downloader.service +``` + +--- + +## Example: systemd Timer + +To run the download periodically, create `/etc/systemd/user/immich-album-downloader.timer`: + +```ini +[Unit] +Description=Download an Immich album periodically + +[Timer] +OnBootSec=15m +OnUnitActiveSec=6h + +[Install] +WantedBy=timers.target +``` + +Enable the timer: + +```bash +systemctl --user enable --now immich-album-downloader.timer +``` + +This will trigger the album download 15 minutes after boot and then every 6 hours. + +--- \ No newline at end of file diff --git a/main.py b/main.py index 56b4cea..ff69240 100644 --- a/main.py +++ b/main.py @@ -13,23 +13,6 @@ IMMICH_INSTANCE_URL = os.getenv('IMMICH_INSTANCE_URL') ALBUM_ID = os.getenv('IMMICH_ALBUM_ID') DOWNLOAD_PATH = Path(os.getenv('IMMICH_DOWNLOAD_PATH', './downloads')) - -# def get_album_id(): -# """Get album ID by name from Immich API""" -# headers = {'x-api-key': IMMICH_API_KEY} -# response = requests.get( -# f"{IMMICH_INSTANCE_URL}/albums", -# headers=headers, -# params={'albumName': ALBUM_NAME} -# ) -# response.raise_for_status() -# -# for album in response.json(): -# if album['albumName'] == ALBUM_NAME: -# return album['id'] -# raise ValueError(f"Album '{ALBUM_NAME}' not found") - - def get_album_assets(album_id): """Retrieve all assets in album with pagination""" headers = {'x-api-key': IMMICH_API_KEY}