Fix merge issues again, I love this shit

This commit is contained in:
bytedream 2022-06-10 16:12:58 +02:00
parent ae075ed4c9
commit 137f3779ea
2 changed files with 14 additions and 29 deletions

View file

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -110,6 +111,9 @@ type loginResponse struct {
Scope string `json:"scope"` Scope string `json:"scope"`
Country string `json:"country"` Country string `json:"country"`
AccountID string `json:"account_id"` AccountID string `json:"account_id"`
Error bool `json:"error"`
Message string `json:"message"`
} }
// LoginWithCredentials logs in via crunchyroll username or email and password. // LoginWithCredentials logs in via crunchyroll username or email and password.
@ -133,16 +137,13 @@ func LoginWithCredentials(user string, password string, locale LOCALE, client *h
} }
defer resp.Body.Close() defer resp.Body.Close()
if loginResp.StatusCode != http.StatusOK { var loginResp loginResponse
return nil, fmt.Errorf("failed to auth with credentials: %s", loginResp.Status) json.NewDecoder(resp.Body).Decode(&loginResp)
} else { if resp.StatusCode != http.StatusOK {
var loginRespBody map[string]interface{} return nil, fmt.Errorf("failed to auth with credentials: %s", resp.Status)
json.NewDecoder(loginResp.Body).Decode(&loginRespBody) } else if loginResp.Error {
return nil, fmt.Errorf("an unexpected login error occoured: %s", loginResp.Message)
if loginRespBody["error"].(bool) { }
return nil, fmt.Errorf("an unexpected login error occoured: %s", loginRespBody["message"])
}
}
var etpRt string var etpRt string
for _, cookie := range resp.Cookies() { for _, cookie := range resp.Cookies() {
@ -186,12 +187,10 @@ func LoginWithSessionID(sessionID string, locale LOCALE, client *http.Client) (*
} }
data := jsonBody["data"].(map[string]interface{}) data := jsonBody["data"].(map[string]interface{})
crunchy.Config.CountryCode = data["country_code"].(string)
user := data["user"] user := data["user"]
if user == nil { if user == nil {
return nil, errors.New("invalid session id, user is not logged in") return nil, errors.New("invalid session id, user is not logged in")
} }
crunchy.Config.Premium = user.(map[string]interface{})["premium"] != ""
var etpRt string var etpRt string
for _, cookie := range resp.Cookies() { for _, cookie := range resp.Cookies() {
@ -260,21 +259,7 @@ func postLogin(loginResp loginResponse, etpRt string, locale LOCALE, client *htt
cms := jsonBody["cms"].(map[string]any) cms := jsonBody["cms"].(map[string]any)
crunchy.Config.Bucket = strings.TrimPrefix(cms["bucket"].(string), "/") crunchy.Config.Bucket = strings.TrimPrefix(cms["bucket"].(string), "/")
if strings.HasSuffix(crunchy.Config.Bucket, "crunchyroll") { crunchy.Config.Premium = strings.HasSuffix(crunchy.Config.Bucket, "crunchyroll")
crunchy.Config.Premium = true
crunchy.Config.Channel = "crunchyroll"
} else {
crunchy.Config.Premium = false
crunchy.Config.Channel = "-"
}
if strings.Contains(cms["bucket"].(string), "crunchyroll") {
crunchy.Config.Premium = true
crunchy.Config.Channel = "crunchyroll"
} else {
crunchy.Config.Premium = false
crunchy.Config.Channel = "-"
}
// / is trimmed so that urls which require it must be in .../{bucket}/... like format. // / is trimmed so that urls which require it must be in .../{bucket}/... like format.
// this just looks cleaner // this just looks cleaner

View file

@ -84,7 +84,7 @@ func fromVideoStreams(crunchy *Crunchyroll, endpoint string) (streams []*Stream,
if !crunchy.Config.Premium { if !crunchy.Config.Premium {
return nil, fmt.Errorf("no stream available, this might be the result of using a non-premium account") return nil, fmt.Errorf("no stream available, this might be the result of using a non-premium account")
} else { } else {
return nil, errors.New("no stream available") return nil, fmt.Errorf("no stream available")
} }
} }