small api
This commit is contained in:
70
main.go
Normal file
70
main.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
)
|
||||
|
||||
func handler(c fiber.Ctx) error {
|
||||
url := fmt.Sprintf("https://www.werstreamt.es/filme-serien/?q=%v&action_results=suchen", c.Params("q"))
|
||||
|
||||
log.Info(url)
|
||||
|
||||
response, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
//body, err := io.ReadAll(response.Body)
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(response.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var providers strings.Builder
|
||||
|
||||
doc.Find(".provider").Each(func(i int, s *goquery.Selection) {
|
||||
provider, _ := s.Attr("data-ext-provider-name")
|
||||
log.Info("Found Provider: ", provider)
|
||||
|
||||
if s.Find(".fi-check").HasClass("fi-check") {
|
||||
//fmt.Printf("Ist auf Netflix")
|
||||
log.Info("Stream available")
|
||||
if strings.Contains(providers.String(), provider) {
|
||||
return
|
||||
}
|
||||
if providers.Len() != 0 {
|
||||
providers.WriteString(",")
|
||||
}
|
||||
providers.WriteString(provider)
|
||||
}
|
||||
})
|
||||
return c.JSON(fiber.Map{
|
||||
"service": providers.String(),
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
var port int
|
||||
|
||||
flag.IntVar(&port, "p", 3000, "Provide a port number")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
app.Get("/api/v1/getStreamingProviders/:q", handler)
|
||||
|
||||
app.Listen(fmt.Sprint(":", port))
|
||||
}
|
||||
Reference in New Issue
Block a user