diff --git a/src/.main.go.swp b/src/.main.go.swp
new file mode 100644
index 0000000..a07d72c
--- /dev/null
+++ b/src/.main.go.swp
Binary files differdiff --git a/src/main.go b/src/main.go
new file mode 100644
index 0000000..1b021c5
--- /dev/null
+++ b/src/main.go
@@ -0,0 +1,78 @@
+package main
+
+import (
+ "fmt"
+ "github.com/gorilla/mux"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os/exec"
+ "time"
+)
+
+var (
+ fileindex int
+)
+
+func main() {
+ r := mux.NewRouter()
+
+ r.HandleFunc("/", indexGET).Methods("GET")
+ r.HandleFunc("/", indexPOST).Methods("POST")
+
+ log.Fatal(http.ListenAndServe(":8080", r))
+}
+
+func indexGET(w http.ResponseWriter, r *http.Request) {
+ log.Println("GET")
+ site := `<html>
+ <head>
+ </head>
+ <body>
+ <form action="/" method="POST">
+ gify url:<br>
+ <input type="text" name="url"><br>
+ </form>
+ </body>
+</html>`
+ fmt.Fprintf(w, "%s", site)
+}
+
+func indexPOST(w http.ResponseWriter, r *http.Request) {
+ log.Println("recievend gif, downloading...")
+ url := r.PostFormValue("url")
+
+ resp, err := http.Get(url)
+ defer resp.Body.Close()
+ if err != nil {
+ log.Printf("Could not makr http request to %s", url)
+ }
+
+ // read the response content
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ log.Println("Could not parse the body")
+ }
+
+ // write the content to a file
+ ioutil.WriteFile(fmt.Sprintf("gifs/%d", fileindex), body, 0644)
+ bodyText := string(body)
+
+ log.Println("Response length: ", len(bodyText))
+
+ // Convert to rune slice to take substring.
+ runeSlice := []rune(bodyText)
+ fmt.Println("First chars: ", string(runeSlice[0:10]))
+
+ cmd := exec.Command("killall", "mpv")
+ cmd.Start()
+
+ time.Sleep(1 * time.Second)
+
+ cmd = exec.Command("mpv", "--loop-file=inf", "--fs", fmt.Sprintf("gifs/%d", fileindex))
+ cmd.Start()
+
+ fileindex++
+
+ http.Redirect(w, r, "/", 302)
+}
|