initial commit
This commit is contained in:
commit
cc8779be51
8 changed files with 133 additions and 0 deletions
4
.env.template
Normal file
4
.env.template
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
IMMICH_ALBUM_ID=6999805b-1c70-4881-ba65-785e4ae19654
|
||||||
|
IMMICH_API_KEY=topsecretapykeypleasedontsteal
|
||||||
|
IMMICH_DOWNLOAD_PATH=/home/yourverycoolname/wallpapers
|
||||||
|
IMMICH_INSTANCE_URL=https://your-immich-server/api
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.env
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
10
.idea/immich-album-downloader.iml
generated
Normal file
10
.idea/immich-album-downloader.iml
generated
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.13 (immich-album-downloader)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13 (immich-album-downloader)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (immich-album-downloader)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/immich-album-downloader.iml" filepath="$PROJECT_DIR$/.idea/immich-album-downloader.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
89
main.py
Normal file
89
main.py
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Configure logging
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
IMMICH_API_KEY = os.getenv('IMMICH_API_KEY')
|
||||||
|
IMMICH_INSTANCE_URL = os.getenv('IMMICH_INSTANCE_URL')
|
||||||
|
# ALBUM_NAME = os.getenv('IMMICH_ALBUM_NAME')
|
||||||
|
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}
|
||||||
|
assets = []
|
||||||
|
page = 1
|
||||||
|
|
||||||
|
while True:
|
||||||
|
response = requests.get(
|
||||||
|
f"{IMMICH_INSTANCE_URL}/albums/{album_id}",
|
||||||
|
headers=headers,
|
||||||
|
params={'page': page}
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
assets.extend(response.json()["assets"])
|
||||||
|
total_pages = int(response.headers.get('X-Pagination-Count', 1))
|
||||||
|
if page >= total_pages:
|
||||||
|
break
|
||||||
|
page += 1
|
||||||
|
# break
|
||||||
|
|
||||||
|
return assets
|
||||||
|
|
||||||
|
|
||||||
|
def download_assets(assets):
|
||||||
|
"""Download missing assets to target directory"""
|
||||||
|
DOWNLOAD_PATH.mkdir(parents=True, exist_ok=True)
|
||||||
|
headers = {'x-api-key': IMMICH_API_KEY}
|
||||||
|
|
||||||
|
for asset in assets:
|
||||||
|
filename = f"{asset['originalFileName']}"
|
||||||
|
filepath = DOWNLOAD_PATH / filename
|
||||||
|
|
||||||
|
if not filepath.exists():
|
||||||
|
logging.info(f"Downloading {filename}")
|
||||||
|
response = requests.get(
|
||||||
|
f"{IMMICH_INSTANCE_URL}/assets/{asset['id']}/original",
|
||||||
|
headers=headers,
|
||||||
|
stream=True
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
with open(filepath, 'wb') as f:
|
||||||
|
for chunk in response.iter_content(chunk_size=8192):
|
||||||
|
f.write(chunk)
|
||||||
|
else:
|
||||||
|
logging.debug(f"Skipping existing file {filename}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
assets = get_album_assets(ALBUM_ID)
|
||||||
|
download_assets(assets)
|
||||||
|
logging.info(f"Sync complete. {len(assets)} assets processed")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Sync failed: {str(e)}")
|
||||||
|
raise
|
Loading…
Add table
Add a link
Reference in a new issue