Skip to content

Commit

Permalink
ci: add actions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecavestro committed May 27, 2024
1 parent b791066 commit 4190482
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 4 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build and Push Docker Image

on:
push:
branches:
- main
tags:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract version number
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/')

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
davidecavestro/gphotos-cdp:dev-main
davidecavestro/gphotos-cdp:${{ github.sha }}
if: github.ref == 'refs/heads/main'

- name: Build and push tagged Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
davidecavestro/gphotos-cdp:${{ env.VERSION }}
davidecavestro/gphotos-cdp:latest
if: startsWith(github.ref, 'refs/tags/')
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ FROM chromedp/headless-shell:latest
RUN apt-get update && apt-get install -y \
exiftool \
curl \
rsync \
locales \
tree \
&& rm -rf /var/lib/apt/lists/*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

COPY --from=build /go/bin/gphotos-cdp /usr/local/bin/
COPY save.sh /usr/local/bin/

Expand Down
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# docker-gphotos-cdp
Container image based on gphotos-cdp and chromedp/headless-shell

A container image based on [gphotos-cdp](https://github.com/perkeep/gphotos-cdp) and [chromedp/headless-shell](https://github.com/chromedp/docker-headless-shell) to download items from Google Photos with their original geo-location attributes.


# Browser profile for auth

Launch the browser with a profile from scratch into an empty folder and complete the authentication.
```bash
google-chrome \
--user-data-dir=/path/to/gphotos/profile_family \
--no-first-run \
--password-store=basic \
--use-mock-keychain \
https://photos.google.com/
```
Close the browser: the folder you chose is enough to open a headless browser and access your photos.

# Compose

Launch the container mounting the profile folder and the directory where you want to

```compose.yml
---
version: "3"
services:
gphoto:
image: davidecavestro/gphotos-cdp:dev-main
# command: -start https://photos.google.com/photo/abcd1234...
working_dir: /download
volumes:
- /etc/localtime:/etc/localtime
- /path/to/gphotos/profile_family:/tmp/gphotos-cdp
- /Volume1/Photos/data_gphotos:/dest
environment:
- DEST_DIR=/dest
restart: no
```

# Crontab

Running `crontab -l` reveals:
```bash
0 20 * * * docker compose --project-name gphotos_family -f /path/to/gphotos/compose.yml up -d
```
23 changes: 20 additions & 3 deletions save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@
FILE=$1
PARENT_DIR=$(dirname $FILE)

pwd

ls -lha $FILE

DEST_DIR='' : "${DEST_DIR:?DEST_DIR is not set}"
[ -d "$DEST_DIR" ] || { echo "DEST_DIR does not exist: $DEST_DIR"; exit 2; }

echo "PARENT_DIR: $PARENT_DIR"
# set file time
exiftool "-DateTimeOriginal>FileModifyDate" $FILE

# move file to proper dir
exiftool '-Directory<DateTimeOriginal' -d '%Y/%Y-%m' $FILE
# move file to proper subdir
exiftool -d "${PARENT_DIR}/%Y/%Y-%m" '-directory<${CreateDate}' '-filename<${filename}' '-DateTimeOriginal>FileModifyDate' $FILE

# move to destination folder
cd $PARENT_DIR
rsync \
-av \
--remove-source-files \
--include='*/' \
--include='20[0-9][0-9]/' --include='20[0-9][0-9]/20[0-9][0-9]-[0-1][0-9]/' \
. $DEST_DIR

rm -rf $PARENT_DIR
#rm -rf $PARENT_DIR

0 comments on commit 4190482

Please sign in to comment.