Skip to content

Commit

Permalink
rewrote the whole thing in golang + added NPO 3FM
Browse files Browse the repository at this point in the history
  • Loading branch information
janyksteenbeek committed Dec 25, 2023
1 parent ad5104a commit d99276a
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 282 deletions.
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/.idea
bun.lockb
package-lock.json
node_modules/
.DS_Store
/dist
/dist
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
vendor/
go.work
nporadio-visualradio-stream-grabber
43 changes: 12 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
FROM node:20-bookworm
FROM golang:latest

# Create app directory
WORKDIR /usr/src/app
RUN apt-get update && apt-get install -y wget gnupg2 \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable

RUN apt-get update && apt-get install gnupg wget -y && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install google-chrome-stable -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . /app

RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /usr/src/app
RUN go mod download

USER pptruser

# Install app dependencies
COPY package*.json ./

RUN npm install

# Bundle app source
COPY . .

ENV NODE_ENV=production
ENV NO_SANDBOX=true

RUN npx puppeteer browsers install chrome
RUN npm run build

EXPOSE 8080
CMD [ "node", "dist/index.js" ]
RUN go build -o nporadio-visualradio-stream-grabber cmd/grabber/main.go
RUN chmod +x nporadio-visualradio-stream-grabber

CMD ["/app/nporadio-visualradio-stream-grabber"]
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# NPO Radio 2 Visual Radio stream link grabber
# NPO Radio Visual Radio stream link grabber

> This project is work in progress
This is a simple HTTP server that grabs the stream link from the NPO Radio 2 Visual Radio page and redirects to it. This because the stream link is not directly available.
This is a Go HTTP service that NPO Radio stream links with DRM. It saves the stream links into cache and updates them every 2 hours. This is done to prevent the stream links from expiring.

## Usage

```bash
bun install
bun run index.ts

go mod download
go build -o nporadio-visualradio-stream-grabber cmd/grabber/main.go
./nporadio-visualradio-stream-grabber
```

After that, the server is available on port 8080.
Expand All @@ -20,14 +18,17 @@ The following streams are available:

- `/nporadio2.m3u8` - M3U8 stream with FairPlay DRM (HLS)
- `/nporadio2.mpd` - MPEG-DASH stream with Widevine DRM (DASH)
- `/npo3fm.m3u8` - M3U8 stream with FairPlay DRM (HLS)
- `/npo3fm.mpd` - MPEG-DASH stream with Widevine DRM (DASH)


## Environment variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| `GRAB_TIMEOUT` | The timeout for the grabber in milliseconds | `4000` |
| `GRAB_PORT` | The port to listen on | `8080` |
| `NO_SANDBOX` | Whether to run Puppeteer in a sandbox | `false` |
| Name | type | Description | Default |
|----------------|-----------------|---------------------------------------------|--------------------|
| `GRAB_TIMEOUT` | duration string | The timeout for the grabber in milliseconds | ` 4 * time.Second` |
| `GRAB_PORT` | int | The port to listen on | `8080` |
| `GRAB_REFRESH` | duration string | The refresh interval | `2 * time.Hour` |


## Button for Home Assistant
Expand All @@ -54,5 +55,5 @@ Make sure to replace `<device_id>` and `<your_ip>` with the correct values.

## License

> As this project is grabbing stuff from the NPO Radio 2 website, I have licensed this specific project under a non-commercial license. Please only use this for personal use and do not host this publicly.
> As this project is grabbing stuff from the NPO Radio websites, I have licensed this specific project under a non-commercial license. Please only use this for personal use and do not host this publicly.
This project is licensed under the CC BY-NC-SA 4.0 license. See [LICENSE](LICENSE) for more information.
9 changes: 9 additions & 0 deletions cmd/grabber/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/janyksteenbeek/nporadio-visualradio-stream-grabber/internal/server"
)

func main() {
server.StartServer()
}
13 changes: 13 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/janyksteenbeek/nporadio-visualradio-stream-grabber

go 1.21.5

require github.com/go-rod/rod v0.114.5

require (
github.com/ysmood/fetchup v0.2.3 // indirect
github.com/ysmood/goob v0.4.0 // indirect
github.com/ysmood/got v0.34.1 // indirect
github.com/ysmood/gson v0.7.3 // indirect
github.com/ysmood/leakless v0.8.0 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/go-rod/rod v0.114.5 h1:1x6oqnslwFVuXJbJifgxspJUd3O4ntaGhRLHt+4Er9c=
github.com/go-rod/rod v0.114.5/go.mod h1:aiedSEFg5DwG/fnNbUOTPMTTWX3MRj6vIs/a684Mthw=
github.com/ysmood/fetchup v0.2.3 h1:ulX+SonA0Vma5zUFXtv52Kzip/xe7aj4vqT5AJwQ+ZQ=
github.com/ysmood/fetchup v0.2.3/go.mod h1:xhibcRKziSvol0H1/pj33dnKrYyI2ebIvz5cOOkYGns=
github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
github.com/ysmood/gop v0.0.2/go.mod h1:rr5z2z27oGEbyB787hpEcx4ab8cCiPnKxn0SUHt6xzk=
github.com/ysmood/got v0.34.1 h1:IrV2uWLs45VXNvZqhJ6g2nIhY+pgIG1CUoOcqfXFl1s=
github.com/ysmood/got v0.34.1/go.mod h1:yddyjq/PmAf08RMLSwDjPyCvHvYed+WjHnQxpH851LM=
github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM=
github.com/ysmood/gson v0.7.3 h1:QFkWbTH8MxyUTKPkVWAENJhxqdBa4lYTQWqZCiLG6kE=
github.com/ysmood/gson v0.7.3/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg=
github.com/ysmood/leakless v0.8.0 h1:BzLrVoiwxikpgEQR0Lk8NyBN5Cit2b1z+u0mgL4ZJak=
github.com/ysmood/leakless v0.8.0/go.mod h1:R8iAXPRaG97QJwqxs74RdwzcRHT1SWCGTNqY8q0JvMQ=
94 changes: 0 additions & 94 deletions index.ts

This file was deleted.

Loading

0 comments on commit d99276a

Please sign in to comment.