mirror of
https://codeberg.org/librarian/librarian
synced 2024-12-06 19:16:35 +01:00
Fix video playback
This commit is contained in:
+18
-4
@@ -68,7 +68,22 @@ func GetStream(video string) (Stream, error) {
|
||||
}
|
||||
|
||||
func checkStream(url string) (Stream, error) {
|
||||
res, err := http.Head(url)
|
||||
req, err := http.NewRequest("HEAD", url, nil)
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept-Language", "en-US,en;q=0.5")
|
||||
req.Header.Set("Cache-Control", "no-cache")
|
||||
req.Header.Set("Pragma", "no-cache")
|
||||
req.Header.Set("DNT", "1")
|
||||
req.Header.Set("Origin", "https://odysee.com")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-site")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/109.0")
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return Stream{}, err
|
||||
}
|
||||
@@ -76,12 +91,11 @@ func checkStream(url string) (Stream, error) {
|
||||
if res.StatusCode == 403 {
|
||||
return Stream{}, fmt.Errorf("this content cannot be accessed due to a DMCA request")
|
||||
}
|
||||
|
||||
isHls := res.Header.Get("Content-Type") == "application/x-mpegurl"
|
||||
|
||||
return Stream{
|
||||
Type: res.Header.Get("Content-Type"),
|
||||
URL: res.Request.URL.String(),
|
||||
FallbackURL: url,
|
||||
HLS: isHls,
|
||||
HLS: res.Header.Get("Content-Type") == "application/x-mpegurl",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -108,7 +108,16 @@ func main() {
|
||||
})
|
||||
|
||||
app.Use(recover.New())
|
||||
app.Use(etag.New())
|
||||
app.Use(etag.New(etag.Config{
|
||||
Next: func(c *fiber.Ctx) bool {
|
||||
if strings.HasPrefix(c.Path(), "/stream") || strings.HasPrefix(c.Path(), "/live") {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
Weak: true,
|
||||
}))
|
||||
app.Use("/static", filesystem.New(filesystem.Config{
|
||||
Next: func(c *fiber.Ctx) bool {
|
||||
c.Response().Header.Add("Cache-Control", "public,max-age=2592000")
|
||||
|
||||
+4
-4
@@ -15,9 +15,9 @@ func HandleStream(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0")
|
||||
req.Header.Set("Origin", "https://odysee.com/")
|
||||
req.Header.Set("Referer", "https://odysee.com/")
|
||||
req.Header.Set("Accept", "*/*")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/109.0")
|
||||
req.Header.Set("Origin", "https://odysee.com")
|
||||
if c.Get("Range") != "" {
|
||||
req.Header.Set("Range", c.Get("Range"))
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func HandleStream(c *fiber.Ctx) error {
|
||||
if res.Header.Get("Content-Range") != "" {
|
||||
c.Set("Content-Range", res.Header.Get("Content-Range"))
|
||||
}
|
||||
if res.Header.Get("Content-Type") == "application/x-mpegurl" && !strings.HasSuffix(c.Path(), ".m3u8") {
|
||||
if res.Header.Get("Location") != "" {
|
||||
c.Set("Location", strings.ReplaceAll(res.Request.URL.String(), "https://player.odycdn.com", "/stream"))
|
||||
res.StatusCode = 308
|
||||
}
|
||||
|
||||
+16
-2
@@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
@@ -34,11 +35,10 @@ func Request(url string, byteLimit int64, dataArr ...Data) ([]byte, error) {
|
||||
req.Header.Set("Pragma", "no-cache")
|
||||
req.Header.Set("DNT", "1")
|
||||
req.Header.Set("Origin", "https://odysee.com")
|
||||
req.Header.Set("Referer", "https://odysee.com/")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-site")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/109.0")
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
@@ -76,3 +76,17 @@ func RequestJSON(url string, data interface{}) (gjson.Result, error) {
|
||||
|
||||
return gjson.Parse(string(body)), nil
|
||||
}
|
||||
|
||||
func SetDefaultHeaders(req http.Request) (http.Request) {
|
||||
req.Header.Set("Accept-Encoding", "br")
|
||||
req.Header.Set("Accept-Language", "en-US,en;q=0.5")
|
||||
req.Header.Set("Cache-Control", "no-cache")
|
||||
req.Header.Set("Pragma", "no-cache")
|
||||
req.Header.Set("DNT", "1")
|
||||
req.Header.Set("Origin", "https://odysee.com")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-site")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/109.0")
|
||||
return req
|
||||
}
|
||||
Reference in New Issue
Block a user