43 lines
817 B
Go
43 lines
817 B
Go
package realdebrid
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func (rd *RealDebrid) UnrestrictUntilOk(link string, serveFromRclone bool) *Download {
|
|
if !strings.HasPrefix(link, "http") {
|
|
return nil
|
|
}
|
|
resp, _ := rd.UnrestrictLink(link, serveFromRclone)
|
|
if resp != nil {
|
|
return resp
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (rd *RealDebrid) CanFetchFirstByte(url string) bool {
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
req.Header.Set("Range", "bytes=0-0")
|
|
|
|
resp, err := rd.client.Do(req)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
// If server supports partial content
|
|
if resp.StatusCode == http.StatusPartialContent || resp.StatusCode == http.StatusOK {
|
|
buffer := make([]byte, 1)
|
|
_, err = resp.Body.Read(buffer)
|
|
if err == nil {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|