Created
April 14, 2019 14:07
-
-
Save MikeModder/448cce795bef9229d82099bb7b839559 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
neturl "net/url" | |
"regexp" | |
"os" | |
"os/exec" | |
"errors" | |
"github.com/PuerkitoBio/goquery" | |
) | |
var ( | |
errorNotOK = errors.New("response code not 200 OK") | |
errorNoURL = errors.New("unable to extract URL from GGA") | |
reAnimeName = regexp.MustCompile("https://vidstream.co/download\\?id=\\w+&typesub=[\\w-]+&title=(.*)") | |
) | |
func main() { | |
rv, title, err := getRapidVideoLink(os.Args[1]) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Got rv url: %s\nTitle: %s\n", rv, title) | |
mp4, err := getMp4FromRapidVideo(fmt.Sprintf("%s?q=720p", rv)) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("MP4 URL: %s\n", mp4) | |
c := exec.Command("mpv", mp4, "--title", title) | |
c.Stdout = os.Stdout | |
c.Stderr = os.Stderr | |
c.Run() | |
} | |
func getRapidVideoLink(url string) (string, string, error) { | |
page, err := http.Get(url) | |
if err != nil { | |
return "", "", err | |
} | |
defer page.Body.Close() | |
if page.StatusCode != 200 { | |
return "", "", errorNotOK | |
} | |
doc, err := goquery.NewDocumentFromReader(page.Body) | |
if err != nil { | |
return "", "", err | |
} | |
url, has := doc.Find(".rapidvideo").Children().First().Attr("data-video") | |
if !has { | |
return "", "", errorNoURL | |
} | |
titleRaw, has := doc.Find(".download-anime").Children().First().Attr("href") | |
if !has { | |
return "", "", errors.New("could not find anime title") | |
} | |
//fmt.Printf("%v\n", reAnimeName.FindStringSubmatch(titleRaw)) | |
title, err := neturl.QueryUnescape(reAnimeName.FindStringSubmatch(titleRaw)[1]) | |
if err != nil { | |
return "", "", err | |
} | |
return url, title, nil | |
} | |
func getMp4FromRapidVideo(url string) (string, error) { | |
page, err := http.Get(url) | |
if err != nil { | |
return "", err | |
} | |
defer page.Body.Close() | |
if page.StatusCode != 200 { | |
return "", errorNotOK | |
} | |
doc, err := goquery.NewDocumentFromReader(page.Body) | |
if err != nil { | |
return "", err | |
} | |
url, has := doc.Find("source").First().Attr("src") | |
if !has { | |
return "", errors.New("failed to get URL from rapidvideo") | |
} | |
return url, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment