streamd: optional keys, per-stream proxy, auto deps; agent module.yaml sync; RTE AutoPlay; Telegram release announces
All checks were successful
release / build-and-upload (push) Successful in 6m20s
modules-release / build-and-upload (push) Successful in 4m51s

- streamd: MPD-only start, proxy field, ffmpeg/NRE/mp4decrypt auto-install
- GET/PUT /api/modules for module.yaml sync; agent sync_modules
- RTE Live-tab AutoPlay fixes; modules zip named bbc/rte/tg4.zip
- Telegram notify scripts wired into Forgejo release workflows
This commit is contained in:
404errordeveloper 2026-10-09 00:17:23 +02:00
parent f9c28be3f1
commit ac8701b5a6
36 changed files with 1460 additions and 143 deletions

View file

@ -0,0 +1,153 @@
package deps
import (
"archive/tar"
"archive/zip"
"compress/gzip"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
)
// extractNamed finds a file whose base name matches wantName (case-insensitive
// on Windows) inside archivePath and writes it to destPath.
func extractNamed(archivePath, _ /*binDir*/, wantName, destPath string) error {
lower := strings.ToLower(archivePath)
switch {
case strings.HasSuffix(lower, ".zip"):
return extractZipNamed(archivePath, wantName, destPath)
case strings.HasSuffix(lower, ".tar.gz"), strings.HasSuffix(lower, ".tgz"):
return extractTarGZNamed(archivePath, wantName, destPath)
case strings.HasSuffix(lower, ".tar.xz"):
return extractTarXZNamed(archivePath, wantName, destPath)
default:
return fmt.Errorf("unsupported archive type: %s", archivePath)
}
}
func nameMatch(base, want string) bool {
return strings.EqualFold(filepath.Base(base), want)
}
func extractZipNamed(archivePath, wantName, destPath string) error {
r, err := zip.OpenReader(archivePath)
if err != nil {
return err
}
defer r.Close()
for _, f := range r.File {
if f.FileInfo().IsDir() {
continue
}
if !nameMatch(f.Name, wantName) {
continue
}
rc, err := f.Open()
if err != nil {
return err
}
err = writeFile(destPath, rc)
_ = rc.Close()
return err
}
return fmt.Errorf("%s not found in %s", wantName, filepath.Base(archivePath))
}
func extractTarGZNamed(archivePath, wantName, destPath string) error {
f, err := os.Open(archivePath)
if err != nil {
return err
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
return err
}
defer gz.Close()
return readTarNamed(gz, wantName, destPath, filepath.Base(archivePath))
}
// extractTarXZNamed shells out to tar when available (linux/mac; Git Bash on Windows).
func extractTarXZNamed(archivePath, wantName, destPath string) error {
tmp, err := os.MkdirTemp("", "ffmpeg-xz-*")
if err != nil {
return err
}
defer os.RemoveAll(tmp)
tarBin, err := exec.LookPath("tar")
if err != nil {
return fmt.Errorf("tar required to extract .tar.xz (install tar or place %s in bin/): %w", wantName, err)
}
cmd := exec.Command(tarBin, "-xJf", archivePath, "-C", tmp)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("tar extract: %w (%s)", err, strings.TrimSpace(string(out)))
}
var found string
_ = filepath.Walk(tmp, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return nil
}
if nameMatch(path, wantName) {
found = path
return io.EOF
}
return nil
})
if found == "" {
return fmt.Errorf("%s not found in %s", wantName, filepath.Base(archivePath))
}
in, err := os.Open(found)
if err != nil {
return err
}
defer in.Close()
return writeFile(destPath, in)
}
func readTarNamed(r io.Reader, wantName, destPath, archiveBase string) error {
tr := tar.NewReader(r)
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if hdr.Typeflag != tar.TypeReg {
continue
}
if !nameMatch(hdr.Name, wantName) {
continue
}
return writeFile(destPath, tr)
}
return fmt.Errorf("%s not found in %s", wantName, archiveBase)
}
func writeFile(dest string, r io.Reader) error {
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
return err
}
tmp := dest + ".partial"
f, err := os.OpenFile(tmp, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o755)
if err != nil {
return err
}
_, copyErr := io.Copy(f, r)
closeErr := f.Close()
if copyErr != nil {
_ = os.Remove(tmp)
return copyErr
}
if closeErr != nil {
_ = os.Remove(tmp)
return closeErr
}
_ = os.Remove(dest)
return os.Rename(tmp, dest)
}

View file

@ -0,0 +1,235 @@
// Package deps ensures media tools (ffmpeg, N_m3u8DL-RE, mp4decrypt) exist
// under bin/ next to the install, downloading static builds when missing.
package deps
import (
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
"drmdecryption/repo"
)
// Status is the resolved path for each tool after Ensure.
type Status struct {
BinDir string `json:"bin_dir"`
FFmpeg string `json:"ffmpeg"`
NRE string `json:"nre"`
MP4Decrypt string `json:"mp4decrypt"`
Notes []string `json:"notes,omitempty"`
}
// Options controls Ensure.
type Options struct {
// BinDir overrides where binaries are installed. Empty → <repo.Root()>/bin
// or the directory containing the running executable.
BinDir string
// SkipDownload only resolves existing paths (flags/env/bin/PATH).
SkipDownload bool
Log *log.Logger
}
func (o Options) logf(format string, args ...any) {
if o.Log != nil {
o.Log.Printf(format, args...)
} else {
log.Printf(format, args...)
}
}
// Ensure resolves ffmpeg, N_m3u8DL-RE and mp4decrypt, downloading into BinDir
// when missing (unless SkipDownload). Returns paths suitable for the supervisor.
func Ensure(o Options, preferNRE, preferFFmpeg, preferDecrypt string) (Status, error) {
st := Status{}
binDir := o.BinDir
if binDir == "" {
binDir = defaultBinDir()
}
if err := os.MkdirAll(binDir, 0o755); err != nil {
return st, err
}
st.BinDir = binDir
var notes []string
ff, err := resolveOrFetch(o, "ffmpeg", preferFFmpeg, binDir, ffmpegCandidates(binDir), fetchFFmpeg)
if err != nil {
notes = append(notes, "ffmpeg: "+err.Error())
o.logf("[!] deps: ffmpeg: %v", err)
} else {
st.FFmpeg = ff
o.logf("[+] deps: ffmpeg → %s", ff)
}
nre, err := resolveOrFetch(o, "N_m3u8DL-RE", preferNRE, binDir, nreCandidates(binDir), fetchNRE)
if err != nil {
notes = append(notes, "N_m3u8DL-RE: "+err.Error())
o.logf("[!] deps: N_m3u8DL-RE: %v", err)
} else {
st.NRE = nre
o.logf("[+] deps: N_m3u8DL-RE → %s", nre)
}
dec, err := resolveOrFetch(o, "mp4decrypt", preferDecrypt, binDir, decryptCandidates(binDir), fetchMP4Decrypt)
if err != nil {
notes = append(notes, "mp4decrypt: "+err.Error())
o.logf("[!] deps: mp4decrypt: %v", err)
} else {
st.MP4Decrypt = dec
o.logf("[+] deps: mp4decrypt → %s", dec)
}
st.Notes = notes
// Serve can start even if a tool is missing; stream start will fail clearly.
return st, nil
}
func defaultBinDir() string {
root := repo.Root()
if root != "" {
return filepath.Join(root, "bin")
}
exe, err := os.Executable()
if err != nil {
return "bin"
}
if resolved, err := filepath.EvalSymlinks(exe); err == nil {
exe = resolved
}
dir := filepath.Dir(exe)
if strings.EqualFold(filepath.Base(dir), "bin") {
return dir
}
return filepath.Join(dir, "bin")
}
type fetchFunc func(binDir string, logf func(string, ...any)) (string, error)
func resolveOrFetch(o Options, label, prefer, binDir string, candidates []string, fetch fetchFunc) (string, error) {
if p := firstExisting(prefer); p != "" {
return p, nil
}
for _, c := range candidates {
if p := firstExisting(c); p != "" {
return p, nil
}
}
if o.SkipDownload {
return "", fmt.Errorf("%s not found (auto-download disabled)", label)
}
o.logf("[*] deps: %s missing → downloading into %s …", label, binDir)
return fetch(binDir, o.logf)
}
func firstExisting(paths ...string) string {
for _, p := range paths {
p = strings.TrimSpace(p)
if p == "" {
continue
}
if filepath.IsAbs(p) || strings.ContainsAny(p, `/\`) {
if st, err := os.Stat(p); err == nil && !st.IsDir() {
return p
}
continue
}
if abs, err := exec.LookPath(p); err == nil {
return abs
}
}
return ""
}
func ffmpegCandidates(binDir string) []string {
name := "ffmpeg"
if runtime.GOOS == "windows" {
name = "ffmpeg.exe"
}
return []string{
os.Getenv("FFMPEG_PATH"),
os.Getenv("FFMPEG"),
filepath.Join(binDir, name),
name,
}
}
func nreCandidates(binDir string) []string {
names := []string{"N_m3u8DL-RE"}
if runtime.GOOS == "windows" {
names = []string{"N_m3u8DL-RE.exe", "N_m3u8DL-RE"}
}
out := []string{os.Getenv("NRE_PATH"), os.Getenv("N_M3U8DL_RE")}
for _, n := range names {
out = append(out, filepath.Join(binDir, n), n)
}
return out
}
func decryptCandidates(binDir string) []string {
name := "mp4decrypt"
if runtime.GOOS == "windows" {
name = "mp4decrypt.exe"
}
return []string{
os.Getenv("MP4DECRYPT_PATH"),
os.Getenv("MP4DECRYPT"),
filepath.Join(binDir, name),
name,
}
}
func httpGet(url string) (*http.Response, error) {
client := &http.Client{Timeout: 10 * time.Minute}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "null-drm-streamd/1.0")
return client.Do(req)
}
func downloadTo(url, dest string, logf func(string, ...any)) error {
logf("[*] deps: GET %s", url)
resp, err := httpGet(url)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("download %s: HTTP %s", url, resp.Status)
}
tmp := dest + ".partial"
f, err := os.Create(tmp)
if err != nil {
return err
}
n, copyErr := io.Copy(f, resp.Body)
closeErr := f.Close()
if copyErr != nil {
_ = os.Remove(tmp)
return copyErr
}
if closeErr != nil {
_ = os.Remove(tmp)
return closeErr
}
if err := os.Rename(tmp, dest); err != nil {
_ = os.Remove(tmp)
return err
}
logf("[+] deps: saved %s (%d bytes)", dest, n)
return nil
}
func chmodX(path string) {
if runtime.GOOS == "windows" {
return
}
_ = os.Chmod(path, 0o755)
}

View file

@ -0,0 +1,64 @@
package deps
import (
"fmt"
"os"
"path/filepath"
"runtime"
)
// BtbN static GPL builds (linked from ffmpeg.org). No official BtbN macOS
// builds — on darwin we leave a clear note to use Homebrew.
func fetchFFmpeg(binDir string, logf func(string, ...any)) (string, error) {
url, archiveName, err := ffmpegURL()
if err != nil {
return "", err
}
archivePath := filepath.Join(binDir, archiveName)
if err := downloadTo(url, archivePath, logf); err != nil {
return "", err
}
defer func() { _ = os.Remove(archivePath) }()
want := "ffmpeg"
if runtime.GOOS == "windows" {
want = "ffmpeg.exe"
}
dest := filepath.Join(binDir, want)
if err := extractNamed(archivePath, binDir, want, dest); err != nil {
return "", err
}
chmodX(dest)
// Best-effort ffprobe alongside ffmpeg.
probeWant := "ffprobe"
if runtime.GOOS == "windows" {
probeWant = "ffprobe.exe"
}
probeDest := filepath.Join(binDir, probeWant)
_ = extractNamed(archivePath, binDir, probeWant, probeDest)
chmodX(probeDest)
return dest, nil
}
func ffmpegURL() (url, archiveName string, err error) {
switch runtime.GOOS + "/" + runtime.GOARCH {
case "windows/amd64":
return "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip",
"ffmpeg-win64-gpl.zip", nil
case "windows/arm64":
return "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-winarm64-gpl.zip",
"ffmpeg-winarm64-gpl.zip", nil
case "linux/amd64":
return "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz",
"ffmpeg-linux64-gpl.tar.xz", nil
case "linux/arm64":
return "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz",
"ffmpeg-linuxarm64-gpl.tar.xz", nil
case "darwin/amd64", "darwin/arm64":
return "", "", fmt.Errorf("no static ffmpeg auto-build for macOS; install with: brew install ffmpeg")
default:
return "", "", fmt.Errorf("unsupported platform %s/%s for ffmpeg auto-download", runtime.GOOS, runtime.GOARCH)
}
}

View file

@ -0,0 +1,50 @@
package deps
import (
"fmt"
"os"
"path/filepath"
"runtime"
)
// Official Bento4 SDK binaries from bento4.com (v1.6.0-641).
// linux/arm64 and windows/arm64 are not published there — clear error.
func fetchMP4Decrypt(binDir string, logf func(string, ...any)) (string, error) {
url, archiveName, err := bento4URL()
if err != nil {
return "", err
}
archivePath := filepath.Join(binDir, archiveName)
if err := downloadTo(url, archivePath, logf); err != nil {
return "", err
}
defer func() { _ = os.Remove(archivePath) }()
want := "mp4decrypt"
if runtime.GOOS == "windows" {
want = "mp4decrypt.exe"
}
dest := filepath.Join(binDir, want)
if err := extractNamed(archivePath, binDir, want, dest); err != nil {
return "", err
}
chmodX(dest)
return dest, nil
}
func bento4URL() (url, archiveName string, err error) {
const base = "https://www.bok.net/Bento4/binaries/"
switch runtime.GOOS + "/" + runtime.GOARCH {
case "windows/amd64":
name := "Bento4-SDK-1-6-0-641.x86_64-microsoft-win32.zip"
return base + name, name, nil
case "linux/amd64":
name := "Bento4-SDK-1-6-0-641.x86_64-unknown-linux.zip"
return base + name, name, nil
case "darwin/amd64", "darwin/arm64":
name := "Bento4-SDK-1-6-0-641.universal-apple-macosx.zip"
return base + name, name, nil
default:
return "", "", fmt.Errorf("no Bento4 binary for %s/%s (place mp4decrypt in bin/ manually)", runtime.GOOS, runtime.GOARCH)
}
}

View file

@ -0,0 +1,71 @@
package deps
import (
"fmt"
"os"
"path/filepath"
"runtime"
)
const nreTag = "v0.6.0-beta"
const nreBase = "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/" + nreTag + "/"
func fetchNRE(binDir string, logf func(string, ...any)) (string, error) {
url, archiveName, binName, err := nreURL()
if err != nil {
return "", err
}
archivePath := filepath.Join(binDir, archiveName)
if err := downloadTo(url, archivePath, logf); err != nil {
return "", err
}
defer func() { _ = os.Remove(archivePath) }()
dest := filepath.Join(binDir, binName)
if err := extractNamed(archivePath, binDir, binName, dest); err != nil {
// Some archives nest the binary or use a slightly different name.
if err2 := extractNamed(archivePath, binDir, "N_m3u8DL-RE", dest); err2 != nil {
if runtime.GOOS == "windows" {
if err3 := extractNamed(archivePath, binDir, "N_m3u8DL-RE.exe", dest); err3 != nil {
return "", err
}
} else {
return "", err
}
}
}
chmodX(dest)
return dest, nil
}
func nreURL() (url, archiveName, binName string, err error) {
binName = "N_m3u8DL-RE"
if runtime.GOOS == "windows" {
binName = "N_m3u8DL-RE.exe"
}
switch runtime.GOOS + "/" + runtime.GOARCH {
case "windows/amd64":
name := "N_m3u8DL-RE_v0.6.0-beta_win-x64_20260629.zip"
return nreBase + name, name, binName, nil
case "windows/arm64":
name := "N_m3u8DL-RE_v0.6.0-beta_win-arm64_20260629.zip"
return nreBase + name, name, binName, nil
case "windows/386":
name := "N_m3u8DL-RE_v0.6.0-beta_win-NT6.0-x86_20260629.zip"
return nreBase + name, name, binName, nil
case "linux/amd64":
name := "N_m3u8DL-RE_v0.6.0-beta_linux-x64_20260629.tar.gz"
return nreBase + name, name, binName, nil
case "linux/arm64":
name := "N_m3u8DL-RE_v0.6.0-beta_linux-arm64_20260629.tar.gz"
return nreBase + name, name, binName, nil
case "darwin/amd64":
name := "N_m3u8DL-RE_v0.6.0-beta_osx-x64_20260629.tar.gz"
return nreBase + name, name, binName, nil
case "darwin/arm64":
name := "N_m3u8DL-RE_v0.6.0-beta_osx-arm64_20260629.tar.gz"
return nreBase + name, name, binName, nil
default:
return "", "", "", fmt.Errorf("unsupported platform %s/%s for N_m3u8DL-RE auto-download", runtime.GOOS, runtime.GOARCH)
}
}