Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(config): add browser path config field #72

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 6 additions & 6 deletions .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- cron: "0 */12 * * *"
workflow_dispatch:
env:
BROWSER_PATH: ${{ github.workspace }}/chrome-linux64/chrome
ITS_IMDB_AUTH: ${{ secrets.IMDB_AUTH }}
ITS_IMDB_EMAIL: ${{ secrets.IMDB_EMAIL }}
ITS_IMDB_PASSWORD: ${{ secrets.IMDB_PASSWORD }}
Expand All @@ -16,6 +15,7 @@ env:
ITS_IMDB_LISTS: ${{ secrets.IMDB_LISTS }}
ITS_IMDB_TRACE: ${{ secrets.IMDB_TRACE }}
ITS_IMDB_HEADLESS: true
ITS_IMDB_BROWSERPATH: ${{ github.workspace }}/chrome-linux/chrome
ITS_SYNC_MODE: ${{ secrets.SYNC_MODE }}
ITS_SYNC_HISTORY: ${{ secrets.SYNC_HISTORY }}
ITS_SYNC_RATINGS: ${{ secrets.SYNC_RATINGS }}
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 -q https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1321438/chrome-linux.zip
unzip -q 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
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ FROM ubuntu:24.04
WORKDIR /app
COPY --from=build /app/build ./build
COPY --from=build /app/config.yaml .
ENV PATH=$PATH:/app/build
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NOWARNINGS=yes
RUN apt-get update > /dev/null && \
Expand All @@ -24,10 +25,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
ENV PATH=$PATH:/app/build
wget -q https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1321438/chrome-linux.zip && \
unzip -q chrome-linux.zip && \
rm chrome-linux.zip
ENV ITS_IMDB_BROWSERPATH=/app/chrome-linux/chrome
ENTRYPOINT ["its"]
CMD ["sync"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Follow the relevant section below, based on how you want to use the application.
2. Clone the repository: `git clone git@github.com:cecobask/imdb-trakt-sync.git`
3. Create a [Trakt App](https://trakt.tv/oauth/applications). Use **urn:ietf:wg:oauth:2.0:oob** as redirect uri
4. Configure the application:
- Create `.env` file with the same contents as [.env.example](config.yaml)
- Populate the `.env` file with your secret values
- Create `.env` file with the same contents as [.env.example](.env.example)
- Populate the `.env` file with your own secret values
- All secret keys should have `ITS_` prefix
5. Open a terminal window in the repository folder and then:
- Build a Docker image: `make package`
Expand Down
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ 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
# For local invocations you can override its value to match your own browser path
# Alternatively, if you leave this value empty, the syncer will attempt to lookup common browser locations
BROWSERPATH:
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