Skip to content

Commit

Permalink
Add about page
Browse files Browse the repository at this point in the history
  • Loading branch information
rroller committed Dec 15, 2024
1 parent 3101d19 commit b139195
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 15 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
require (
github.com/dustin/go-humanize v1.0.1
github.com/go-chi/chi/v5 v5.1.0
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f
github.com/rs/zerolog v1.33.0
golang.org/x/sync v0.10.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+m
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f h1:XDrsC/9hdgiU9ecceSmYsS2E3fBtFiYc34dAMFgegnM=
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f/go.mod h1:aEt7p9Rvh67BYApmZwNDPpgircTO2kgdmDUoF/1QmwA=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down
1 change: 1 addition & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
router.Get("/fetch", media.FetchMedia)
router.Get("/api/download", media.FetchMediaApi)
router.Get("/download", media.ServeMedia)
router.Get("/about", media.AboutIndex)
})
fileServer(router, "/static", "static/")

Expand Down
42 changes: 42 additions & 0 deletions src/media/about.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package media

import (
"github.com/matishsiao/goInfo"
"github.com/rs/zerolog/log"
"html/template"
"media-roller/src/utils"
"net/http"
"regexp"
"strings"
)

var aboutIndexTmpl = template.Must(template.ParseFiles("templates/media/about.html"))

var newlineRegex = regexp.MustCompile("\r?\n")

func AboutIndex(w http.ResponseWriter, _ *http.Request) {
pythonVersion := utils.RunCommand("python3", "--version")
if pythonVersion == "" {
pythonVersion = utils.RunCommand("python", "--version")
}

gi, _ := goInfo.GetInfo()

data := map[string]interface{}{
"ytDlpVersion": CachedYtDlpVersion,
"goVersion": strings.TrimPrefix(utils.RunCommand("go", "version"), "go version "),
"pythonVersion": strings.TrimPrefix(pythonVersion, "Python "),
"ffmpegVersion": newlineRegex.Split(utils.RunCommand("ffmpeg", "-version"), -1),
"os": gi.OS,
"kernel": gi.Kernel,
"core": gi.Core,
"platform": gi.Platform,
"hostname": gi.Hostname,
"cpus": gi.CPUs,
}

if err := aboutIndexTmpl.Execute(w, data); err != nil {
log.Error().Msgf("Error rendering template: %v", err)
http.Error(w, "Internal error", http.StatusInternalServerError)
}
}
14 changes: 2 additions & 12 deletions src/media/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"github.com/rs/zerolog/log"
"io"
"media-roller/src/utils"
"os"
"os/exec"
"strings"
"sync"
)

Expand Down Expand Up @@ -61,17 +61,7 @@ func UpdateYtDlp() error {
}

func GetInstalledVersion() string {
cmd := exec.Command("yt-dlp", "--version")

var s bytes.Buffer
cmd.Stdout = &s
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
log.Error().Err(err).Msgf("Error getting installed version")
}

version := strings.TrimSpace(s.String())
version := utils.RunCommand("yt-dlp", "--version")
if version == "" {
version = "unknown"
}
Expand Down
23 changes: 23 additions & 0 deletions src/utils/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package utils

import (
"bytes"
"github.com/rs/zerolog/log"
"os"
"os/exec"
"strings"
)

func RunCommand(name string, args ...string) string {
cmd := exec.Command(name, args...)

var s bytes.Buffer
cmd.Stdout = &s
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
log.Error().Err(err).Msgf("Error running command " + strings.Join(args, " "))
}

return strings.TrimSpace(s.String())
}
55 changes: 55 additions & 0 deletions templates/media/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<title>about - media-roller</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="/static/css//bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
</head>
<body>
<div class="container d-flex flex-column text-light">
<div class="flex-grow-1"></div>
<div class="jumbotron bg-transparent flex-grow-1">
<h1 class="display-4"><a class="text-light" href="/">media roller</a></h1>
<div>
{{ .details }}
<table>
<tbody>
<tr>
<td style="width:110px;">Source</td>
<td><a href="https://github.com/rroller/media-roller">https://github.com/rroller/media-roller</a>
</td>
</tr>
<tr>
<td><a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a></td>
<td>{{ $.ytDlpVersion }}</td>
</tr>
<tr>
<td><a href="https://go.dev/doc/install">Golang</a></td>
<td>{{ $.goVersion }}</td>
</tr>
<tr>
<td><a href="https://www.python.org/downloads/">Python</a></td>
<td>{{ $.pythonVersion }}</td>
</tr>
<tr><td>os</td><td>{{ $.os }}</td></tr>
<tr><td>kernel</td><td>{{ $.kernel }}</td></tr>
<tr><td>core</td><td>{{ $.core }}</td></tr>
<tr><td>platform</td><td>{{ $.platform }}</td></tr>
<tr><td>hostname</td><td>{{ $.hostname }}</td></tr>
<tr><td>cpus</td><td>{{ $.cpus }}</td></tr>
<tr>
<td style="vertical-align: top"><a href="https://www.ffmpeg.org/download.html">ffmpeg</a></td>
<td>{{range $element := .ffmpegVersion}}{{ $element }}<br>{{end}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<footer>
<div>
</div>
</footer>
</div>
</body>
</html>
5 changes: 2 additions & 3 deletions templates/media/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ <h4 style="margin-top:20px;">Error</h4>
</div>
<footer>
<div>
Running <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> version {{ $.ytDlpVersion }}<br>
<p class="text-muted">Source at <a class="text-light" href="https://github.com/rroller/media-roller">https://github.com/rroller/media-roller</a>
</p>
<a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> version {{ $.ytDlpVersion }}<br>
<p><a href="/about">about media-roller</a></p>
</div>
</footer>
</div>
Expand Down

0 comments on commit b139195

Please sign in to comment.