Skip to content

Instantly share code, notes, and snippets.

@MikeModder
Last active June 3, 2019 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeModder/01767848731770e9c4acccf4dae71d80 to your computer and use it in GitHub Desktop.
Save MikeModder/01767848731770e9c4acccf4dae71d80 to your computer and use it in GitHub Desktop.
Test for automatically playing videos from GoGoAnime. Current doesn't work because of well-made browser security features.
package main
import (
"fmt"
"net/http"
neturl "net/url"
"regexp"
"syscall/js"
"github.com/PuerkitoBio/goquery"
)
var (
//https://vidstream.co/download\?id=.+&typesub=[\w-]+&title=(.*)
reAnimeName = regexp.MustCompile("https://vidstream.co/download\\?id=.+&typesub=[\\w-]+&title=(.*)")
)
func main() {
fmt.Println("GoGoAutoplay - I hate WASM edition")
js.Global().Set("extractRapidVideoURL", js.FuncOf(func(_ js.Value, v []js.Value) interface{} {
ch := make(chan map[string]string)
extractRapidVideoURL(v[0].String(), ch)
var data map[string]string = <-ch
return data
}))
select {}
/*ch := make(chan map[string]string)
go extractRapidVideoURL("https://www5.gogoanime.tv/toradora-episode-2", ch)
var data map[string]string = <-ch
if data["url"] == "" {
fmt.Printf("error: %s\n", data["error"])
js.Global().Get("document").Call("alert", fmt.Sprintf("error: %s\n", data["error"]))
return
}
fmt.Printf("%s - %s\n", data["title"], data["url"])
//fmt.Sprintf("%s?q=720p", data["url"]
iframe := js.Global().Get("document").Call("getElementById", "video-here")
iframe.Set("src", data["url"])
iframe.Set("width", js.Global().Get("document").Get("body").Get("clientWidth").Float())
iframe.Set("height", js.Global().Get("document").Get("body").Get("clientHeight").Float())*/
//iframe.Call("requestFullscreen")
/*go extractMp4URL(fmt.Sprintf("%s?q=720p", data["url"]), ch)
data = <-ch
if data["url"] == "" {
fmt.Printf("error: %s\n", data["error"])
return
}
fmt.Printf("mp4: %s\n", data["url"])*/
}
func extractRapidVideoURL(ggaUrl string, ch chan map[string]string) {
resp, err := http.Get(ggaUrl)
if err != nil {
ch <- map[string]string{
"error": err.Error(),
"url": "",
"title": "",
}
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
ch <- map[string]string{
"error": "status code not 200 ok",
"url": "",
"title": "",
}
return
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
ch <- map[string]string{
"error": err.Error(),
"url": "",
"title": "",
}
return
}
url, found := doc.Find(".rapidvideo").Children().First().Attr("data-video")
if !found {
ch <- map[string]string{
"error": "failed to find video url",
"url": "",
"title": "",
}
return
}
titleRaw, found := doc.Find(".download-anime").Children().First().Attr("href")
if !found {
ch <- map[string]string{
"error": "failed to find anime name",
"url": "",
"title": "",
}
return
}
title, err := neturl.QueryUnescape(reAnimeName.FindStringSubmatch(titleRaw)[1])
if err != nil {
ch <- map[string]string{
"error": err.Error(),
"url": "",
"title": "",
}
return
}
ch <- map[string]string{
"error": "",
"url": url,
"title": title,
}
return
}
func extractMp4URL(rvUrl string, ch chan map[string]string) {
resp, err := http.Get(rvUrl)
if err != nil {
ch <- map[string]string{
"error": err.Error(),
"url": "",
}
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
ch <- map[string]string{
"error": "status code not 200 ok",
"url": "",
}
return
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
ch <- map[string]string{
"error": err.Error(),
"url": "",
}
return
}
url, found := doc.Find("source").First().Attr("src")
if !found {
ch <- map[string]string{
"error": "failed to extract video url",
"url": "",
}
return
}
ch <- map[string]string{
"error": "",
"url": url,
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment