Skip to content

Commit 68cf37d

Browse files
committed
build(config): add browser path config field
1 parent 8bc8e09 commit 68cf37d

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ITS_IMDB_HEADLESS=true
55
ITS_IMDB_LISTS=ls000000000,ls111111111
66
ITS_IMDB_PASSWORD=password123
77
ITS_IMDB_TRACE=false
8+
ITS_IMDB_BROWSERPATH=
89
ITS_SYNC_HISTORY=false
910
ITS_SYNC_MODE=dry-run
1011
ITS_SYNC_RATINGS=false

.github/workflows/sync.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
- cron: "0 */12 * * *"
88
workflow_dispatch:
99
env:
10-
BROWSER_PATH: ${{ github.workspace }}/chrome-linux64/chrome
1110
ITS_IMDB_AUTH: ${{ secrets.IMDB_AUTH }}
1211
ITS_IMDB_EMAIL: ${{ secrets.IMDB_EMAIL }}
1312
ITS_IMDB_PASSWORD: ${{ secrets.IMDB_PASSWORD }}
@@ -16,6 +15,7 @@ env:
1615
ITS_IMDB_LISTS: ${{ secrets.IMDB_LISTS }}
1716
ITS_IMDB_TRACE: ${{ secrets.IMDB_TRACE }}
1817
ITS_IMDB_HEADLESS: true
18+
ITS_IMDB_BROWSERPATH: ${{ github.workspace }}/chrome-linux/chrome
1919
ITS_SYNC_MODE: ${{ secrets.SYNC_MODE }}
2020
ITS_SYNC_HISTORY: ${{ secrets.SYNC_HISTORY }}
2121
ITS_SYNC_RATINGS: ${{ secrets.SYNC_RATINGS }}
@@ -33,12 +33,12 @@ jobs:
3333
uses: actions/checkout@v4
3434
- name: Install Google Chrome
3535
run: |
36-
wget --progress=dot:giga https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-linux64.zip
37-
unzip -qq chrome-linux64.zip
38-
if test -f "$BROWSER_PATH"; then
39-
echo "Google Chrome binary stored at $BROWSER_PATH"
36+
wget -q https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1321438/chrome-linux.zip
37+
unzip -q chrome-linux.zip
38+
if test -f "$ITS_IMDB_BROWSERPATH"; then
39+
echo "Google Chrome binary stored at $ITS_IMDB_BROWSERPATH"
4040
else
41-
echo "Google Chrome binary not found at $BROWSER_PATH"
41+
echo "Google Chrome binary not found at $ITS_IMDB_BROWSERPATH"
4242
exit 1
4343
fi
4444
- name: Setup Go

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ FROM ubuntu:24.04
1010
WORKDIR /app
1111
COPY --from=build /app/build ./build
1212
COPY --from=build /app/config.yaml .
13+
ENV PATH=$PATH:/app/build
1314
ENV DEBIAN_FRONTEND=noninteractive
1415
ENV DEBCONF_NOWARNINGS=yes
1516
RUN apt-get update > /dev/null && \
@@ -24,10 +25,9 @@ RUN apt-get update > /dev/null && \
2425
unzip \
2526
wget > /dev/null && \
2627
rm -rf /var/lib/apt/lists/* && \
27-
wget -q https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-linux64.zip && \
28-
unzip -qq chrome-linux64.zip && \
29-
rm chrome-linux64.zip
30-
ENV BROWSER_PATH=/app/chrome-linux64/chrome
31-
ENV PATH=$PATH:/app/build
28+
wget -q https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1321438/chrome-linux.zip && \
29+
unzip -q chrome-linux.zip && \
30+
rm chrome-linux.zip
31+
ENV ITS_IMDB_BROWSERPATH=/app/chrome-linux/chrome
3232
ENTRYPOINT ["its"]
3333
CMD ["sync"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Follow the relevant section below, based on how you want to use the application.
3232
2. Clone the repository: `git clone git@github.com:cecobask/imdb-trakt-sync.git`
3333
3. Create a [Trakt App](https://trakt.tv/oauth/applications). Use **urn:ietf:wg:oauth:2.0:oob** as redirect uri
3434
4. Configure the application:
35-
- Create `.env` file with the same contents as [.env.example](config.yaml)
36-
- Populate the `.env` file with your secret values
35+
- Create `.env` file with the same contents as [.env.example](.env.example)
36+
- Populate the `.env` file with your own secret values
3737
- All secret keys should have `ITS_` prefix
3838
5. Open a terminal window in the repository folder and then:
3939
- Build a Docker image: `make package`

config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ IMDB:
3131
# For local debugging you can set this value to false
3232
# If running via GitHub Actions or other CI the value will always be true
3333
HEADLESS: true
34+
# The location of your preferred web browser
35+
# This browser is going to be used for web scraping
36+
# For local invocations you can override its value to match your own browser path
37+
# Alternatively, if you leave this value empty, the syncer will attempt to lookup common browser locations
38+
BROWSERPATH:
3439
SYNC:
3540
# Sync mode to be used when running the application
3641
# The value must be one of the following:

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type IMDb struct {
2424
Lists *[]string `koanf:"LISTS"`
2525
Trace *bool `koanf:"TRACE"`
2626
Headless *bool `koanf:"HEADLESS"`
27+
BrowserPath *string `koanf:"BROWSERPATH"`
2728
}
2829

2930
type Trakt struct {
@@ -199,6 +200,9 @@ func (c *Config) applyDefaults() {
199200
if c.IMDb.Headless == nil {
200201
c.IMDb.Headless = pointer(true)
201202
}
203+
if c.IMDb.BrowserPath == nil {
204+
c.IMDb.BrowserPath = pointer("")
205+
}
202206
if c.Sync.History == nil {
203207
c.Sync.History = pointer(false)
204208
}

pkg/client/imdb.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/csv"
77
"fmt"
88
"log/slog"
9-
"os"
109
"slices"
1110
"strconv"
1211
"strings"
@@ -21,7 +20,6 @@ import (
2120
)
2221

2322
const (
24-
envVarKeyBrowserPath = "BROWSER_PATH"
2523
imdbPathBase = "https://www.imdb.com"
2624
imdbPathExports = "/exports"
2725
imdbPathList = "/list/%s"
@@ -48,7 +46,7 @@ type imdbConfig struct {
4846
}
4947

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

717-
func getBrowserPathOrFallback() string {
718-
if browserPath, found := os.LookupEnv(envVarKeyBrowserPath); found {
719-
return browserPath
715+
func getBrowserPathOrFallback(conf *appconfig.IMDb) string {
716+
if browserPath := conf.BrowserPath; *browserPath != "" {
717+
return *browserPath
720718
}
721719
if browserPath, found := launcher.LookPath(); found {
722720
return browserPath

0 commit comments

Comments
 (0)