mirror of
https://github.com/teacat/chaturbate-dvr.git
synced 2025-10-29 16:59:59 +00:00
2.0.2, Related #104, X-Request
This commit is contained in:
parent
eaf61e7f4a
commit
65397fb3a1
@ -44,11 +44,6 @@ func FetchStream(ctx context.Context, client *internal.Req, username string) (*S
|
|||||||
return nil, fmt.Errorf("failed to get page body: %w", err)
|
return nil, fmt.Errorf("failed to get page body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for Cloudflare protection page
|
|
||||||
if strings.Contains(body, "<title>Just a moment...</title>") {
|
|
||||||
return nil, internal.ErrCloudflareBlocked
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that the playlist.m3u8 file is present in the response
|
// Ensure that the playlist.m3u8 file is present in the response
|
||||||
if !strings.Contains(body, "playlist.m3u8") {
|
if !strings.Contains(body, "playlist.m3u8") {
|
||||||
return nil, internal.ErrChannelOffline
|
return nil, internal.ErrChannelOffline
|
||||||
|
|||||||
@ -6,6 +6,7 @@ var (
|
|||||||
ErrChannelExists = errors.New("channel exists")
|
ErrChannelExists = errors.New("channel exists")
|
||||||
ErrChannelNotFound = errors.New("channel not found")
|
ErrChannelNotFound = errors.New("channel not found")
|
||||||
ErrCloudflareBlocked = errors.New("blocked by Cloudflare; try with `-cookies` and `-user-agent`")
|
ErrCloudflareBlocked = errors.New("blocked by Cloudflare; try with `-cookies` and `-user-agent`")
|
||||||
|
ErrAgeVerification = errors.New("age verification required; try with `-cookies` and `-user-agent`")
|
||||||
ErrChannelOffline = errors.New("channel offline")
|
ErrChannelOffline = errors.New("channel offline")
|
||||||
ErrPrivateStream = errors.New("channel went offline or private")
|
ErrPrivateStream = errors.New("channel went offline or private")
|
||||||
ErrPaused = errors.New("channel paused")
|
ErrPaused = errors.New("channel paused")
|
||||||
|
|||||||
@ -62,11 +62,25 @@ func (h *Req) GetBytes(ctx context.Context, url string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
b, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for Cloudflare protection
|
||||||
|
if strings.Contains(string(b), "<title>Just a moment...</title>") {
|
||||||
|
return nil, ErrCloudflareBlocked
|
||||||
|
}
|
||||||
|
// Check for Age Verification
|
||||||
|
if strings.Contains(string(b), "Verify your age") {
|
||||||
|
return nil, ErrAgeVerification
|
||||||
|
}
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusForbidden {
|
if resp.StatusCode == http.StatusForbidden {
|
||||||
return nil, fmt.Errorf("forbidden: %w", ErrPrivateStream)
|
return nil, fmt.Errorf("forbidden: %w", ErrPrivateStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReadResponseBody(resp)
|
return b, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRequest constructs an HTTP GET request with necessary headers.
|
// CreateRequest constructs an HTTP GET request with necessary headers.
|
||||||
@ -83,6 +97,8 @@ func CreateRequest(ctx context.Context, url string) (*http.Request, context.Canc
|
|||||||
|
|
||||||
// SetRequestHeaders applies necessary headers to the request.
|
// SetRequestHeaders applies necessary headers to the request.
|
||||||
func SetRequestHeaders(req *http.Request) {
|
func SetRequestHeaders(req *http.Request) {
|
||||||
|
req.Header.Set("X-Requested-With", "XMLHttpRequest") // So Cloudflare would likely accept the request, and no Age Verification
|
||||||
|
|
||||||
if server.Config.UserAgent != "" {
|
if server.Config.UserAgent != "" {
|
||||||
req.Header.Set("User-Agent", server.Config.UserAgent)
|
req.Header.Set("User-Agent", server.Config.UserAgent)
|
||||||
}
|
}
|
||||||
@ -94,15 +110,6 @@ func SetRequestHeaders(req *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadResponseBody reads and returns the response body.
|
|
||||||
func ReadResponseBody(resp *http.Response) ([]byte, error) {
|
|
||||||
b, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("read body: %w", err)
|
|
||||||
}
|
|
||||||
return b, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseCookies converts a cookie string into a map.
|
// ParseCookies converts a cookie string into a map.
|
||||||
func ParseCookies(cookieStr string) map[string]string {
|
func ParseCookies(cookieStr string) map[string]string {
|
||||||
cookies := make(map[string]string)
|
cookies := make(map[string]string)
|
||||||
|
|||||||
2
main.go
2
main.go
@ -30,7 +30,7 @@ const logo = `
|
|||||||
func main() {
|
func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "chaturbate-dvr",
|
Name: "chaturbate-dvr",
|
||||||
Version: "2.0.1",
|
Version: "2.0.2",
|
||||||
Usage: "Record your favorite Chaturbate streams automatically. 😎🫵",
|
Usage: "Record your favorite Chaturbate streams automatically. 😎🫵",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user