This commit is contained in:
parent
995fc6ceea
commit
35d76f4ead
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
.idea
|
||||
*.iml
|
||||
*.db3
|
||||
*.db3-*
|
||||
*.bak*
|
||||
/downloads/
|
||||
/temp/
|
||||
|
46
main.go
46
main.go
@ -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)
|
||||
}
|
||||
|
1
migrations/5_add_watch_state.sql
Normal file
1
migrations/5_add_watch_state.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE videos ADD COLUMN watch_state TEXT;
|
0
res/index.html
Normal file
0
res/index.html
Normal file
@ -3,4 +3,5 @@ package main
|
||||
type VideoInfoVM struct {
|
||||
Title string
|
||||
Description string
|
||||
Thumbnail string
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
<div class="video-box">
|
||||
<h2>{{.Title}}</h2>
|
||||
<div>{{.Description}}</div>
|
||||
<img src="{{.Thumbnail}}" alt="Thumbnail" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
41
webview.go
41
webview.go
@ -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) {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user