Allow users to add clips
j3s j3s@c3f.net
Thu, 18 Mar 2021 00:13:10 -0500
1 files changed,
22 insertions(+),
5 deletions(-)
jump to
M
main.go
→
main.go
@@ -67,7 +67,7 @@ }
keys = append(keys, k) } sort.Strings(keys) - list := strings.Join(keys, "\n") + list := strings.Join(keys, "<br>") e.Sender.Send(list) } var file string@@ -80,14 +80,31 @@ if matched && strings.HasPrefix(e.Message, "!") {
m := regexp.MustCompile(`https:\/\/(www.)?youtube\.com\/watch\?v=[A-z_\-0-9]{11}`) videoUrl := m.FindString(e.Message) fmt.Println("downloading...") - parts := strings.Split(videoUrl, "?v=") + + // !rick=https://www.youtube.com/watch?v=dQw4w9WgXcQ + // this is handled separately because of weird mumble HTML + // business + setcmd := regexp.MustCompile(` > [a-z]+`) + cmd := setcmd.FindString(e.Message) + fmt.Println(e.Message) + fmt.Println(cmd) + cmdname := "video.mp4" + if cmd != "" { + splits := strings.Split(cmd, " ") + // the name + cmdname = "sounds/" + splits[2] + fmt.Println(cmdname) + files[splits[2]] = cmdname + } + + fmt.Println(cmdname) + parts := strings.Split(videoUrl, "=") fmt.Printf("%v", parts) if len(parts) != 2 { fmt.Println("youtube url is weird") return } fmt.Println(parts[1]) - // videoID := parts[1] videoID := parts[1] client := youtube.Client{} video, err := client.GetVideo(videoID)@@ -103,7 +120,7 @@ return
} defer resp.Body.Close() - wfile, err := os.Create("video.mp4") + wfile, err := os.Create(cmdname) if err != nil { fmt.Println(err) return@@ -115,7 +132,7 @@ if err != nil {
fmt.Println(err) return } - file = "video.mp4" + file = cmdname } else { var ok bool file, ok = files[e.Message]