mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Change all etp rt related stuff to refresh token
This commit is contained in:
parent
6239d10d22
commit
f7a21fbfb2
4 changed files with 23 additions and 23 deletions
|
|
@ -15,7 +15,7 @@ var (
|
||||||
loginEncryptFlag bool
|
loginEncryptFlag bool
|
||||||
|
|
||||||
loginSessionIDFlag bool
|
loginSessionIDFlag bool
|
||||||
loginEtpRtFlag bool
|
loginRefreshTokenFlag bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var Cmd = &cobra.Command{
|
var Cmd = &cobra.Command{
|
||||||
|
|
@ -26,8 +26,8 @@ var Cmd = &cobra.Command{
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if loginSessionIDFlag {
|
if loginSessionIDFlag {
|
||||||
return loginSessionID(args[0])
|
return loginSessionID(args[0])
|
||||||
} else if loginEtpRtFlag {
|
} else if loginRefreshTokenFlag {
|
||||||
return loginEtpRt(args[0])
|
return loginRefreshToken(args[0])
|
||||||
} else {
|
} else {
|
||||||
return loginCredentials(args[0], args[1])
|
return loginCredentials(args[0], args[1])
|
||||||
}
|
}
|
||||||
|
|
@ -48,12 +48,12 @@ func init() {
|
||||||
"session-id",
|
"session-id",
|
||||||
false,
|
false,
|
||||||
"Use a session id to login instead of username and password")
|
"Use a session id to login instead of username and password")
|
||||||
Cmd.Flags().BoolVar(&loginEtpRtFlag,
|
Cmd.Flags().BoolVar(&loginRefreshTokenFlag,
|
||||||
"etp-rt",
|
"refresh-token",
|
||||||
false,
|
false,
|
||||||
"Use a etp rt cookie to login instead of username and password")
|
"Use a refresh token to login instead of username and password. Can be obtained by copying the `etp-rt` cookie from beta.crunchyroll.com")
|
||||||
|
|
||||||
Cmd.MarkFlagsMutuallyExclusive("session-id", "etp-rt")
|
Cmd.MarkFlagsMutuallyExclusive("session-id", "refresh-token")
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginCredentials(user, password string) error {
|
func loginCredentials(user, password string) error {
|
||||||
|
|
@ -132,11 +132,11 @@ func loginSessionID(sessionID string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginEtpRt(etpRt string) error {
|
func loginRefreshToken(refreshToken string) error {
|
||||||
utils.Log.Debug("Logging in via etp rt")
|
utils.Log.Debug("Logging in via refresh token")
|
||||||
var c *crunchyroll.Crunchyroll
|
var c *crunchyroll.Crunchyroll
|
||||||
var err error
|
var err error
|
||||||
if c, err = crunchyroll.LoginWithEtpRt(etpRt, utils.SystemLocale(false), utils.Client); err != nil {
|
if c, err = crunchyroll.LoginWithRefreshToken(refreshToken, utils.SystemLocale(false), utils.Client); err != nil {
|
||||||
utils.Log.Err(err.Error())
|
utils.Log.Err(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -3,7 +3,7 @@ module github.com/crunchy-labs/crunchy-cli
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220724174415-375eaf9007bd
|
github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220808230013-bb434a0fba7a
|
||||||
github.com/grafov/m3u8 v0.11.1
|
github.com/grafov/m3u8 v0.11.1
|
||||||
github.com/spf13/cobra v1.5.0
|
github.com/spf13/cobra v1.5.0
|
||||||
)
|
)
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -1,6 +1,6 @@
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220724174415-375eaf9007bd h1:wxMjLwhvilxwTnYCOXmBPenMNymhC63m4aFzQ5C7ipQ=
|
github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220808230013-bb434a0fba7a h1:q5M2xmCTu2njig5rlRAd83LJDaPANmweFJjYsnxi5zM=
|
||||||
github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220724174415-375eaf9007bd/go.mod h1:SjTQD3IX7Z+MLsMSd2fP5ttsJ4KtpXY6r08bHLwrOLM=
|
github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220808230013-bb434a0fba7a/go.mod h1:SjTQD3IX7Z+MLsMSd2fP5ttsJ4KtpXY6r08bHLwrOLM=
|
||||||
github.com/grafov/m3u8 v0.11.1 h1:igZ7EBIB2IAsPPazKwRKdbhxcoBKO3lO1UY57PZDeNA=
|
github.com/grafov/m3u8 v0.11.1 h1:igZ7EBIB2IAsPPazKwRKdbhxcoBKO3lO1UY57PZDeNA=
|
||||||
github.com/grafov/m3u8 v0.11.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
|
github.com/grafov/m3u8 v0.11.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
func SaveSession(crunchy *crunchyroll.Crunchyroll) error {
|
func SaveSession(crunchy *crunchyroll.Crunchyroll) error {
|
||||||
file := filepath.Join(os.TempDir(), ".crunchy")
|
file := filepath.Join(os.TempDir(), ".crunchy")
|
||||||
return os.WriteFile(file, []byte(crunchy.EtpRt), 0600)
|
return os.WriteFile(file, []byte(crunchy.RefreshToken), 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveCredentialsPersistent(user, password string, encryptionKey []byte) error {
|
func SaveCredentialsPersistent(user, password string, encryptionKey []byte) error {
|
||||||
|
|
@ -62,7 +62,7 @@ func SaveSessionPersistent(crunchy *crunchyroll.Crunchyroll) error {
|
||||||
if err = os.MkdirAll(filepath.Join(configDir, "crunchy-cli"), 0755); err != nil {
|
if err = os.MkdirAll(filepath.Join(configDir, "crunchy-cli"), 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.WriteFile(file, []byte(crunchy.EtpRt), 0600)
|
return os.WriteFile(file, []byte(crunchy.RefreshToken), 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsTempSession() bool {
|
func IsTempSession() bool {
|
||||||
|
|
@ -118,11 +118,11 @@ func loadTempSession(file string) (*crunchyroll.Crunchyroll, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
crunchy, err := crunchyroll.LoginWithEtpRt(string(body), SystemLocale(true), Client)
|
crunchy, err := crunchyroll.LoginWithRefreshToken(string(body), SystemLocale(true), Client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Debug("Failed to login with temp etp rt cookie: %v", err)
|
Log.Debug("Failed to login with temp refresh token: %v", err)
|
||||||
} else {
|
} else {
|
||||||
Log.Debug("Logged in with etp rt cookie %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", body)
|
Log.Debug("Logged in with refresh token %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", body)
|
||||||
return crunchy, nil
|
return crunchy, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,15 +160,15 @@ func loadPersistentSession(file string, encryptionKey []byte) (crunchy *crunchyr
|
||||||
}
|
}
|
||||||
Log.Debug("Logged in with credentials")
|
Log.Debug("Logged in with credentials")
|
||||||
} else {
|
} else {
|
||||||
if crunchy, err = crunchyroll.LoginWithEtpRt(split[0], SystemLocale(true), Client); err != nil {
|
if crunchy, err = crunchyroll.LoginWithRefreshToken(split[0], SystemLocale(true), Client); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
Log.Debug("Logged in with etp rt cookie %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", split[0])
|
Log.Debug("Logged in with refresh token %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", split[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// the etp rt is written to a temp file to reduce the amount of re-logging in.
|
// the refresh token is written to a temp file to reduce the amount of re-logging in.
|
||||||
// it seems like that crunchyroll has also a little cooldown if a user logs in too often in a short time
|
// it seems like that crunchyroll has also a little cooldown if a user logs in too often in a short time
|
||||||
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(crunchy.EtpRt), 0600); err != nil {
|
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(crunchy.RefreshToken), 0600); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue