Compare commits
No commits in common. "46ee612fed5fb1d5ea1ca3f3c17457bea71a09b4" and "261df7dbb3df95c1a1978d50957762fc568685ca" have entirely different histories.
46ee612fed
...
261df7dbb3
11
Dockerfile
11
Dockerfile
|
@ -1,11 +0,0 @@
|
||||||
# docker build -t dndmusicbot-js-build .
|
|
||||||
# docker run -it -v $(pwd)/public:/app/public dndmusicbot-js-build
|
|
||||||
FROM node:19-alpine3.16
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY . /app
|
|
||||||
|
|
||||||
RUN yarn
|
|
||||||
|
|
||||||
ENTRYPOINT ["yarn", "build"]
|
|
7
bot.go
7
bot.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -40,6 +41,11 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.mux = http.NewServeMux()
|
||||||
|
|
||||||
|
go http.ListenAndServe(":8826", app.mux)
|
||||||
|
|
||||||
log.Println("bot.go done.")
|
log.Println("bot.go done.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +66,7 @@ type App struct {
|
||||||
playlist *Playlist
|
playlist *Playlist
|
||||||
plm *sync.RWMutex
|
plm *sync.RWMutex
|
||||||
hubbub *gohubbub.Client
|
hubbub *gohubbub.Client
|
||||||
|
mux *http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -168,7 +168,7 @@ window.onload = function () {
|
||||||
url.innerText = ""
|
url.innerText = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelectorAll("#items .item").forEach(item => item.addEventListener("click", (e) => {
|
document.querySelectorAll("#items").forEach(item => item.addEventListener("click", (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.target.parentElement.style.pointerEvents = 'none'
|
e.target.parentElement.style.pointerEvents = 'none'
|
||||||
const disableui = setTimeout((t) => {
|
const disableui = setTimeout((t) => {
|
||||||
|
@ -182,7 +182,7 @@ window.onload = function () {
|
||||||
}))
|
}))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
document.querySelectorAll("#ambiance .item").forEach(item => item.addEventListener("click", (e) => {
|
document.querySelectorAll("#ambiance").forEach(item => item.addEventListener("click", (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.target.parentElement.style.pointerEvents = 'none'
|
e.target.parentElement.style.pointerEvents = 'none'
|
||||||
const disableui = setTimeout((t) => {
|
const disableui = setTimeout((t) => {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// apikey = "AIzaSyCWO1F6n6UAtOm3L_K-kzF-4UQoS_DmJW0"
|
||||||
yt_url = "https://www.youtube.com/watch?v=%s"
|
yt_url = "https://www.youtube.com/watch?v=%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
48
ytdl/ytdl.go
48
ytdl/ytdl.go
|
@ -3,24 +3,13 @@ package ytdl
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/cache/filecache"
|
|
||||||
"github.com/spf13/afero"
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cache *filecache.Cache
|
|
||||||
var yturl = "https://youtu.be/%s"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
cache = filecache.NewCache(fs, 6*time.Hour, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
type YTdl struct {
|
type YTdl struct {
|
||||||
Title string
|
Title string
|
||||||
Url string
|
Url string
|
||||||
|
@ -28,30 +17,19 @@ type YTdl struct {
|
||||||
Len time.Duration
|
Len time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewYTdl(vid string) (*YTdl, error) {
|
func NewYTdl(uri string) (*YTdl, error) {
|
||||||
log.Printf("Loading %s from youtube\n", vid)
|
ytdl_js, err := exec.Command(
|
||||||
_, ytdl_js, err := cache.GetOrCreateBytes(vid+".json", func() ([]byte, error) {
|
"./bin/yt-dlp_linux",
|
||||||
log.Printf("%s not found in cache, downloading info.\n", vid)
|
uri,
|
||||||
js, err := exec.Command(
|
"--cookies", "./cookies.txt",
|
||||||
"./bin/yt-dlp_linux",
|
"--no-call-home",
|
||||||
fmt.Sprintf(yturl, vid),
|
"--no-cache-dir",
|
||||||
"--cookies", "./cookies.txt",
|
"--ignore-errors",
|
||||||
"--no-call-home",
|
"--newline",
|
||||||
"--no-cache-dir",
|
"--restrict-filenames",
|
||||||
"--ignore-errors",
|
"-f", "140",
|
||||||
"--newline",
|
"-j",
|
||||||
"--restrict-filenames",
|
).Output()
|
||||||
"-f", "140",
|
|
||||||
"-j",
|
|
||||||
).Output()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("%s is now cached.\n", vid)
|
|
||||||
|
|
||||||
return js, nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue