mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Change login type from session id to etp rt
This commit is contained in:
parent
c94ce0fb59
commit
0780a2a2bc
2 changed files with 49 additions and 11 deletions
|
|
@ -12,6 +12,7 @@ var (
|
||||||
loginPersistentFlag bool
|
loginPersistentFlag bool
|
||||||
|
|
||||||
loginSessionIDFlag bool
|
loginSessionIDFlag bool
|
||||||
|
loginEtpRtFlag bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var loginCmd = &cobra.Command{
|
var loginCmd = &cobra.Command{
|
||||||
|
|
@ -22,6 +23,8 @@ var loginCmd = &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 {
|
||||||
|
return loginEtpRt(args[0])
|
||||||
} else {
|
} else {
|
||||||
return loginCredentials(args[0], args[1])
|
return loginCredentials(args[0], args[1])
|
||||||
}
|
}
|
||||||
|
|
@ -38,6 +41,10 @@ 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")
|
||||||
|
loginCmd.Flags().BoolVar(&loginEtpRtFlag,
|
||||||
|
"etp-rt",
|
||||||
|
false,
|
||||||
|
"Use a etp rt cookie to login instead of username and password")
|
||||||
|
|
||||||
rootCmd.AddCommand(loginCmd)
|
rootCmd.AddCommand(loginCmd)
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +67,7 @@ func loginCredentials(user, password string) error {
|
||||||
out.Info("The login information will be stored permanently UNENCRYPTED on your drive (%s)", filepath.Join(configDir, "crunchyroll-go", "crunchy"))
|
out.Info("The login information will be stored permanently UNENCRYPTED on your drive (%s)", filepath.Join(configDir, "crunchyroll-go", "crunchy"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(c.SessionID), 0600); err != nil {
|
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(c.EtpRt), 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +80,38 @@ func loginCredentials(user, password string) error {
|
||||||
|
|
||||||
func loginSessionID(sessionID string) error {
|
func loginSessionID(sessionID string) error {
|
||||||
out.Debug("Logging in via session id")
|
out.Debug("Logging in via session id")
|
||||||
if _, err := crunchyroll.LoginWithSessionID(sessionID, systemLocale(false), client); err != nil {
|
var c *crunchyroll.Crunchyroll
|
||||||
|
var err error
|
||||||
|
if c, err = crunchyroll.LoginWithSessionID(sessionID, systemLocale(false), client); err != nil {
|
||||||
|
out.Err(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if loginPersistentFlag {
|
||||||
|
if configDir, err := os.UserConfigDir(); err != nil {
|
||||||
|
return fmt.Errorf("could not save credentials persistent: %w", err)
|
||||||
|
} else {
|
||||||
|
os.MkdirAll(filepath.Join(configDir, "crunchyroll-go"), 0755)
|
||||||
|
if err = os.WriteFile(filepath.Join(configDir, "crunchyroll-go", "crunchy"), []byte(c.EtpRt), 0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out.Info("The login information will be stored permanently UNENCRYPTED on your drive (%s)", filepath.Join(configDir, "crunchyroll-go", "crunchy"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(c.EtpRt), 0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !loginPersistentFlag {
|
||||||
|
out.Info("Due to security reasons, you have to login again on the next reboot")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loginEtpRt(etpRt string) error {
|
||||||
|
out.Debug("Logging in via etp rt")
|
||||||
|
if _, err := crunchyroll.LoginWithEtpRt(etpRt, systemLocale(false), client); err != nil {
|
||||||
out.Err(err.Error())
|
out.Err(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
@ -84,13 +122,13 @@ func loginSessionID(sessionID string) error {
|
||||||
return fmt.Errorf("could not save credentials persistent: %w", err)
|
return fmt.Errorf("could not save credentials persistent: %w", err)
|
||||||
} else {
|
} else {
|
||||||
os.MkdirAll(filepath.Join(configDir, "crunchyroll-go"), 0755)
|
os.MkdirAll(filepath.Join(configDir, "crunchyroll-go"), 0755)
|
||||||
if err = os.WriteFile(filepath.Join(configDir, "crunchyroll-go", "crunchy"), []byte(sessionID), 0600); err != nil {
|
if err = os.WriteFile(filepath.Join(configDir, "crunchyroll-go", "crunchy"), []byte(etpRt), 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Info("The login information will be stored permanently UNENCRYPTED on your drive (%s)", filepath.Join(configDir, "crunchyroll-go", "crunchy"))
|
out.Info("The login information will be stored permanently UNENCRYPTED on your drive (%s)", filepath.Join(configDir, "crunchyroll-go", "crunchy"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(sessionID), 0600); err != nil {
|
if err = os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(etpRt), 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,10 +147,10 @@ func loadCrunchy() {
|
||||||
out.StopProgress("Failed to read login information: %v", err)
|
out.StopProgress("Failed to read login information: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if crunchy, err = crunchyroll.LoginWithSessionID(url.QueryEscape(string(body)), systemLocale(true), client); err != nil {
|
if crunchy, err = crunchyroll.LoginWithEtpRt(url.QueryEscape(string(body)), systemLocale(true), client); err != nil {
|
||||||
out.Debug("Failed to login with temp session id: %w", err)
|
out.Debug("Failed to login with temp etp rt: %w", err)
|
||||||
} else {
|
} else {
|
||||||
out.Debug("Logged in with session id %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", body)
|
out.Debug("Logged in with etp rt %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", body)
|
||||||
|
|
||||||
out.StopProgress("Logged in")
|
out.StopProgress("Logged in")
|
||||||
return
|
return
|
||||||
|
|
@ -168,20 +168,20 @@ func loadCrunchy() {
|
||||||
split := strings.SplitN(string(body), "\n", 2)
|
split := strings.SplitN(string(body), "\n", 2)
|
||||||
if len(split) == 1 || split[1] == "" {
|
if len(split) == 1 || split[1] == "" {
|
||||||
split[0] = url.QueryEscape(split[0])
|
split[0] = url.QueryEscape(split[0])
|
||||||
if crunchy, err = crunchyroll.LoginWithSessionID(split[0], systemLocale(true), client); err != nil {
|
if crunchy, err = crunchyroll.LoginWithEtpRt(split[0], systemLocale(true), client); err != nil {
|
||||||
out.StopProgress(err.Error())
|
out.StopProgress(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
out.Debug("Logged in with session id %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", split[0])
|
out.Debug("Logged in with etp rt %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", split[0])
|
||||||
} else {
|
} else {
|
||||||
if crunchy, err = crunchyroll.LoginWithCredentials(split[0], split[1], systemLocale(true), client); err != nil {
|
if crunchy, err = crunchyroll.LoginWithCredentials(split[0], split[1], systemLocale(true), client); err != nil {
|
||||||
out.StopProgress(err.Error())
|
out.StopProgress(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
out.Debug("Logged in with session id %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", crunchy.SessionID)
|
out.Debug("Logged in with etp rt cookie %s. BLANK THIS LINE OUT IF YOU'RE ASKED TO POST THE DEBUG OUTPUT SOMEWHERE", crunchy.EtpRt)
|
||||||
// the session id is written to a temp file to reduce the amount of re-logging in.
|
// the session id 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
|
||||||
os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(crunchy.SessionID), 0600)
|
os.WriteFile(filepath.Join(os.TempDir(), ".crunchy"), []byte(crunchy.EtpRt), 0600)
|
||||||
}
|
}
|
||||||
out.StopProgress("Logged in")
|
out.StopProgress("Logged in")
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue