Automating Ubuntu Screenshots to Google Photos
说明与用途
自动将Ubuntu截图上传到Google Photos,保留准确的捕获时间和时区,且不修改原始文件。
问题
Ubuntu screenshots lack accurate capture timestamps when uploaded to Google Photos, causing incorrect date metadata.
结果
Automated pipeline uploads Ubuntu screenshots to Google Photos with accurate capture timestamps and timezone, preserving original files and preventing manual uploads.
工作流
- Create project directory and virtualenv
- Install required Python packages
- Set up Google Cloud OAuth credentials and store client_secret.json
- Run auth.py to obtain and store token.json
- Configure inotify to watch ~/Pictures/GooglePhotos/upload/ for new PNGs
- On new file, use GNU stat to read birth time
- Embed DateTimeOriginal and timezone into PNG via Pillow
- Upload image bytes to Google Photos API (upload token + batchCreate)
- Move uploaded file to ~/Pictures/GooglePhotos/uploaded/
证据
The original screenshot is never modified.
Google Photos uses a two‑step upload process: Image bytes → POST /v1/uploads → Upload token → POST /v1/mediaItems:batchCreate → Google Photos media item
- 记录日期: 2026-09-20T08:16:47.987Z