Skip to content

Commit

Permalink
build(config): add browser path config field
Browse files Browse the repository at this point in the history
  • Loading branch information
cecobask committed Dec 25, 2024
1 parent 5bd720c commit 0dcd112
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ITS_IMDB_HEADLESS=true
ITS_IMDB_LISTS=ls000000000,ls111111111
ITS_IMDB_PASSWORD=password123
ITS_IMDB_TRACE=false
ITS_IMDB_BROWSERPATH=
ITS_SYNC_HISTORY=false
ITS_SYNC_MODE=dry-run
ITS_SYNC_RATINGS=false
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: sync
on:
push:
branches:
- main
- browserpath
schedule:
- cron: "0 */12 * * *"
workflow_dispatch:
env:
BROWSER_PATH: ${{ github.workspace }}/chrome-linux64/chrome
ITS_IMDB_BROWSERPATH: ${{ github.workspace }}/chrome-linux/chrome
ITS_IMDB_AUTH: ${{ secrets.IMDB_AUTH }}
ITS_IMDB_EMAIL: ${{ secrets.IMDB_EMAIL }}
ITS_IMDB_PASSWORD: ${{ secrets.IMDB_PASSWORD }}
Expand All @@ -33,12 +33,12 @@ jobs:
uses: actions/checkout@v4
- name: Install Google Chrome
run: |
wget --progress=dot:giga https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-linux64.zip
unzip -qq chrome-linux64.zip
if test -f "$BROWSER_PATH"; then
echo "Google Chrome binary stored at $BROWSER_PATH"
wget --progress=dot:giga https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1321438/chrome-linux.zip
unzip chrome-linux.zip
if test -f "$ITS_IMDB_BROWSERPATH"; then
echo "Google Chrome binary stored at $ITS_IMDB_BROWSERPATH"
else
echo "Google Chrome binary not found at $BROWSER_PATH"
echo "Google Chrome binary not found at $ITS_IMDB_BROWSERPATH"
exit 1
fi
- name: Setup Go
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ RUN apt-get update > /dev/null && \
unzip \
wget > /dev/null && \
rm -rf /var/lib/apt/lists/* && \
wget -q https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-linux64.zip && \
unzip -qq chrome-linux64.zip && \
rm chrome-linux64.zip
ENV BROWSER_PATH=/app/chrome-linux64/chrome
wget -q https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1321438/chrome-linux.zip && \
unzip -qq chrome-linux.zip && \
rm chrome-linux.zip
ENV PATH=$PATH:/app/build
ENTRYPOINT ["its"]
CMD ["sync"]
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ IMDB:
# For local debugging you can set this value to false
# If running via GitHub Actions or other CI the value will always be true
HEADLESS: true
# The location of your preferred web browser
# This browser is going to be used for web scraping by the syncer
# The default value is set to the location of Google Chrome from the Docker image
# For local invocations override the value to match your own browser path
# Alternatively, explicitly set this value to empty string in order to attempt lookup of common browser locations
BROWSERPATH: /app/chrome-linux/chrome
SYNC:
# Sync mode to be used when running the application
# The value must be one of the following:
Expand Down
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type IMDb struct {
Lists *[]string `koanf:"LISTS"`
Trace *bool `koanf:"TRACE"`
Headless *bool `koanf:"HEADLESS"`
BrowserPath *string `koanf:"BROWSERPATH"`
}

type Trakt struct {
Expand Down Expand Up @@ -199,6 +200,9 @@ func (c *Config) applyDefaults() {
if c.IMDb.Headless == nil {
c.IMDb.Headless = pointer(true)
}
if c.IMDb.BrowserPath == nil {
c.IMDb.BrowserPath = pointer("")
}
if c.Sync.History == nil {
c.Sync.History = pointer(false)
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/client/imdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/csv"
"fmt"
"log/slog"
"os"
"slices"
"strconv"
"strings"
Expand All @@ -21,7 +20,6 @@ import (
)

const (
envVarKeyBrowserPath = "BROWSER_PATH"
imdbPathBase = "https://www.imdb.com"
imdbPathExports = "/exports"
imdbPathList = "/list/%s"
Expand All @@ -48,7 +46,7 @@ type imdbConfig struct {
}

func NewIMDbClient(ctx context.Context, conf *appconfig.IMDb, logger *slog.Logger) (IMDbClientInterface, error) {
l := launcher.New().Headless(*conf.Headless).Bin(getBrowserPathOrFallback()).
l := launcher.New().Headless(*conf.Headless).Bin(getBrowserPathOrFallback(conf)).
Set("allow-running-insecure-content").
Set("autoplay-policy", "user-gesture-required").
Set("disable-component-update").
Expand Down Expand Up @@ -714,9 +712,9 @@ func setBrowserCookies(browser *rod.Browser, config *appconfig.IMDb) error {
return nil
}

func getBrowserPathOrFallback() string {
if browserPath, found := os.LookupEnv(envVarKeyBrowserPath); found {
return browserPath
func getBrowserPathOrFallback(conf *appconfig.IMDb) string {
if browserPath := conf.BrowserPath; *browserPath != "" {
return *browserPath
}
if browserPath, found := launcher.LookPath(); found {
return browserPath
Expand Down

0 comments on commit 0dcd112

Please sign in to comment.