Skip to content

Commit

Permalink
Replace all username login reference with email login
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Dec 9, 2023
1 parent d2b3cc8 commit afd0d48
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ use crunchyroll_rs::parse::UrlType;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// log in to crunchyroll with your username and password
// Log in to Crunchyroll with your email and password.
// Support for username login was dropped by Crunchyroll on December 6th, 2023
let crunchyroll = Crunchyroll::builder()
.login_with_credentials("<username>", "<password>")
.login_with_credentials("<email>", "<password>")
.await?;

let url = crunchyroll_rs::parse_url("https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome").expect("url is not valid");
Expand Down
4 changes: 2 additions & 2 deletions examples/browse-genre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use std::env;

#[tokio::main]
async fn main() -> Result<()> {
let user = env::var("USER").expect("'USER' environment variable not found");
let email = env::var("EMAIL").expect("'EMAIL' environment variable not found");
let password = env::var("PASSWORD").expect("'PASSWORD' environment variable not found");

let crunchyroll = Crunchyroll::builder()
.login_with_credentials(user, password)
.login_with_credentials(email, password)
.await?;

let options = BrowseOptions::default()
Expand Down
4 changes: 2 additions & 2 deletions examples/search-series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::env;

#[tokio::main]
async fn main() -> Result<()> {
let user = env::var("USER").expect("'USER' environment variable not found");
let email = env::var("EMAIL").expect("'EMAIL' environment variable not found");
let password = env::var("PASSWORD").expect("'PASSWORD' environment variable not found");

let crunchyroll = Crunchyroll::builder()
.login_with_credentials(user, password)
.login_with_credentials(email, password)
.await?;

let mut query_result = crunchyroll.query("darling");
Expand Down
4 changes: 2 additions & 2 deletions examples/stream-episode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::env;

#[tokio::main]
async fn main() -> Result<()> {
let user = env::var("USER").expect("'USER' environment variable not found");
let email = env::var("EMAIL").expect("'EMAIL' environment variable not found");
let password = env::var("PASSWORD").expect("'PASSWORD' environment variable not found");

let crunchyroll = Crunchyroll::builder()
.login_with_credentials(user, password)
.login_with_credentials(email, password)
.await?;

let episode: Episode = crunchyroll.media_from_id("GRDKJZ81Y").await?;
Expand Down
11 changes: 5 additions & 6 deletions src/crunchyroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ mod auth {

async fn auth_with_credentials(
client: &Client,
user: String,
email: String,
password: String,
device_id: Option<String>,
device_type: Option<String>,
) -> Result<AuthResponse> {
let endpoint = "https://www.crunchyroll.com/auth/v1/token";
let mut body = vec![
("username", user.as_ref()),
("username", email.as_ref()),
("password", password.as_ref()),
("grant_type", "password"),
("scope", "offline_access"),
Expand Down Expand Up @@ -645,18 +645,17 @@ mod auth {
self.post_login(login_response, session_token).await
}

/// Logs in with credentials (username or email and password) and returns a new `Crunchyroll`
/// instance.
/// Logs in with credentials (email and password) and returns a new `Crunchyroll` instance.
pub async fn login_with_credentials<S: AsRef<str>>(
self,
user: S,
email: S,
password: S,
) -> Result<Crunchyroll> {
self.pre_login().await?;

let login_response = Executor::auth_with_credentials(
&self.client,
user.as_ref().to_string(),
email.as_ref().to_string(),
password.as_ref().to_string(),
self.device_identifier
.as_ref()
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
//! // set the language in which results should be returned
//! .locale(Locale::en_US)
//! // login with user credentials (other login options are also available)
//! .login_with_credentials("username", "password")
//! // support for username login was dropped by Crunchyroll on December 6th, 2023
//! .login_with_credentials("email", "password")
//! .await?;
//! ```
//!
Expand Down
4 changes: 2 additions & 2 deletions tests/_test_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::env;

#[tokio::test]
async fn login_with_credentials() {
let user = env::var("USER").expect("'USER' environment variable not found");
let email = env::var("EMAIL").expect("'EMAIL' environment variable not found");
let password = env::var("PASSWORD").expect("'PASSWORD' environment variable not found");

let crunchy = Crunchyroll::builder()
.login_with_credentials(user, password)
.login_with_credentials(email, password)
.await;

assert_result!(crunchy);
Expand Down

0 comments on commit afd0d48

Please sign in to comment.