Properly show newest video
Some checks failed
Build / build (push) Failing after 1m1s

This commit is contained in:
Sebastiaan de Schaetzen 2025-03-16 10:11:05 +01:00
parent 995fc6ceea
commit 35d76f4ead
7 changed files with 60 additions and 31 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.idea
*.iml
*.db3
*.db3-*
*.bak*
/downloads/
/temp/

46
main.go
View File

@ -1,25 +1,31 @@
package main
import (
"flag"
"github.com/playwright-community/playwright-go"
"log"
)
func main() {
//var err error
//var onlyInstall = flag.Bool("install", false, "install the required browser and do nothing else")
//flag.Parse()
//
//options := &playwright.RunOptions{
// Browsers: []string{"firefox"},
//}
//err = playwright.Install(options)
//if err != nil {
// log.Panicf("error installing playwright: %v", err)
//}
//
//if *onlyInstall {
// return
//}
//
//db := openDatabase()
//defer db.Close()
//
var err error
var onlyInstall = flag.Bool("install", false, "install the required browser and do nothing else")
flag.Parse()
options := &playwright.RunOptions{
Browsers: []string{"firefox"},
}
err = playwright.Install(options)
if err != nil {
log.Panicf("error installing playwright: %v", err)
}
if *onlyInstall {
return
}
db := openDatabase()
defer db.MustClose()
//sleepTimeStr := os.Getenv("VIVAPLUS_SLEEPTIME")
//sleepTime := 15
//if sleepTimeStr != "" {
@ -65,5 +71,5 @@ func main() {
// log.Printf("Sleeping %d minutes until next run", sleepTime)
// time.Sleep(time.Duration(sleepTime) * time.Minute)
//}
serveWebview()
serveWebview(db)
}

View File

@ -0,0 +1 @@
ALTER TABLE videos ADD COLUMN watch_state TEXT;

0
res/index.html Normal file
View File

View File

@ -3,4 +3,5 @@ package main
type VideoInfoVM struct {
Title string
Description string
Thumbnail string
}

View File

@ -11,6 +11,7 @@
<div class="video-box">
<h2>{{.Title}}</h2>
<div>{{.Description}}</div>
<img src="{{.Thumbnail}}" alt="Thumbnail" />
</div>
</body>
</html>

View File

@ -1,28 +1,47 @@
package main
import (
"gitea.seeseepuff.be/seeseemelk/mysqlite"
"log"
"net/http"
)
func serveWebview() {
func serveWebview(db *mysqlite.Db) {
addr := "localhost:8081"
log.Printf("Listening on %s", addr)
http.Handle("/static/", http.StripPrefix("/static/", staticFileServer()))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
vm := VideoInfoVM{
Title: "Foo",
Description: "Lorem Ipsum sed dolor...",
}
err := renderTemplate(w, "index", vm)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
http.HandleFunc("/", serveIndex(db))
http.HandleFunc("/video/", serveVideo(db))
err := http.ListenAndServe(addr, nil)
if err != nil {
panic(err)
}
}
func serveIndex(db *mysqlite.Db) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
// Query the database for the oldest unwatched episode
var title, description, thumbnail string
err := db.Query(`SELECT title, description, thumbnail FROM videos WHERE (watch_state IS NULL OR watch_state != 'watched') ORDER BY upload_date, episode LIMIT 1`).ScanSingle(&title, &description, &thumbnail)
if err != nil {
http.Error(w, "No unwatched episodes found", http.StatusNotFound)
return
}
vm := VideoInfoVM{
Title: title,
Description: description,
Thumbnail: thumbnail,
}
err = renderTemplate(w, "index", vm)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
func serveVideo(db *mysqlite.Db) func(w http.ResponseWriter, r *http.Request) {
}