diff --git a/cli/commands/login/login.go b/cli/commands/login/login.go index 20ceb6a..9fce181 100644 --- a/cli/commands/login/login.go +++ b/cli/commands/login/login.go @@ -14,8 +14,8 @@ var ( loginPersistentFlag bool loginEncryptFlag bool - loginSessionIDFlag bool - loginEtpRtFlag bool + loginSessionIDFlag bool + loginRefreshTokenFlag bool ) var Cmd = &cobra.Command{ @@ -26,8 +26,8 @@ var Cmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { if loginSessionIDFlag { return loginSessionID(args[0]) - } else if loginEtpRtFlag { - return loginEtpRt(args[0]) + } else if loginRefreshTokenFlag { + return loginRefreshToken(args[0]) } else { return loginCredentials(args[0], args[1]) } @@ -48,12 +48,12 @@ func init() { "session-id", false, "Use a session id to login instead of username and password") - Cmd.Flags().BoolVar(&loginEtpRtFlag, - "etp-rt", + Cmd.Flags().BoolVar(&loginRefreshTokenFlag, + "refresh-token", 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 { @@ -132,11 +132,11 @@ func loginSessionID(sessionID string) error { return nil } -func loginEtpRt(etpRt string) error { - utils.Log.Debug("Logging in via etp rt") +func loginRefreshToken(refreshToken string) error { + utils.Log.Debug("Logging in via refresh token") var c *crunchyroll.Crunchyroll 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()) os.Exit(1) } diff --git a/go.mod b/go.mod index 37a4e42..d7f0eba 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/crunchy-labs/crunchy-cli go 1.18 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/spf13/cobra v1.5.0 ) diff --git a/go.sum b/go.sum index 34683e1..225fce4 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ 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-20220724174415-375eaf9007bd/go.mod h1:SjTQD3IX7Z+MLsMSd2fP5ttsJ4KtpXY6r08bHLwrOLM= +github.com/crunchy-labs/crunchyroll-go/v3 v3.0.0-20220808230013-bb434a0fba7a h1:q5M2xmCTu2njig5rlRAd83LJDaPANmweFJjYsnxi5zM= +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/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= diff --git a/utils/save.go b/utils/save.go index ef6d0ec..7660974 100644 --- a/utils/save.go +++ b/utils/save.go @@ -15,7 +15,7 @@ import ( func SaveSession(crunchy *crunchyroll.Crunchyroll) error { 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 { @@ -62,7 +62,7 @@ func SaveSessionPersistent(crunchy *crunchyroll.Crunchyroll) error { if err = os.MkdirAll(filepath.Join(configDir, "crunchy-cli"), 0755); err != nil { return err } - return os.WriteFile(file, []byte(crunchy.EtpRt), 0600) + return os.WriteFile(file, []byte(crunchy.RefreshToken), 0600) } func IsTempSession() bool { @@ -118,11 +118,11 @@ func loadTempSession(file string) (*crunchyroll.Crunchyroll, error) { if err != nil { return nil, err } - crunchy, err := crunchyroll.LoginWithEtpRt(string(body), SystemLocale(true), Client) + crunchy, err := crunchyroll.LoginWithRefreshToken(string(body), SystemLocale(true), Client) 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 { - 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 } } @@ -160,15 +160,15 @@ func loadPersistentSession(file string, encryptionKey []byte) (crunchy *crunchyr } Log.Debug("Logged in with credentials") } 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 } - 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 - 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 } }