Skip to content

Commit f1e8c67

Browse files
Merge pull request #64 from manojkarthick/fix/clippy
Fix all cargo clippy warnings
2 parents f687d64 + e9fed2d commit f1e8c67

File tree

4 files changed

+29
-38
lines changed

4 files changed

+29
-38
lines changed

src/auth.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ impl<'a> Client<'a> {
4141
agent: &'a str,
4242
) -> Self {
4343
Self {
44-
client_id: &id,
45-
client_secret: &secret,
46-
username: &username,
47-
password: &password,
48-
user_agent: &agent,
44+
client_id: id,
45+
client_secret: secret,
46+
username,
47+
password,
48+
user_agent: agent,
4949
}
5050
}
5151

src/download.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ impl<'a> Downloader<'a> {
190190
PostMetadata { subreddit, author: post_author, id: post_id };
191191

192192
let is_valid = if let Some(s) = self.subreddits.as_ref() {
193-
if s.contains(&subreddit) {
194-
true
195-
} else {
196-
false
197-
}
193+
s.contains(&subreddit)
198194
} else {
199195
true
200196
};
@@ -327,7 +323,7 @@ impl<'a> Downloader<'a> {
327323
/// Helper function to download reddit videos
328324
async fn download_reddit_video(
329325
&self,
330-
media_urls: &Vec<String>,
326+
media_urls: &[String],
331327
media_type: MediaType,
332328
post_metadata: &PostMetadata<'_>,
333329
) -> Result<(i32, i32), ReddSaverError> {
@@ -340,7 +336,7 @@ impl<'a> Downloader<'a> {
340336
for (index, url) in media_urls.iter().enumerate() {
341337
let mut item_index = format!("{}", index);
342338
let mut extension =
343-
String::from(url.split('.').last().unwrap_or("unknown")).replace("/", "_");
339+
String::from(url.split('.').next_back().unwrap_or("unknown")).replace("/", "_");
344340

345341
// if the media is a reddit video, they have separate audio and video components.
346342
// to differentiate this from albums, which use the regular _0, _1, etc indices,
@@ -357,7 +353,7 @@ impl<'a> Downloader<'a> {
357353
{
358354
extension = format!("{}.{}", extension, ".mp4");
359355
}
360-
let file_name = self.generate_file_name(&url, &extension, &item_index, post_metadata);
356+
let file_name = self.generate_file_name(url, &extension, &item_index, post_metadata);
361357

362358
if self.should_download {
363359
let status = save_or_skip(url, &file_name);
@@ -392,7 +388,7 @@ impl<'a> Downloader<'a> {
392388
if self.ffmpeg_available {
393389
debug!("Assembling components together");
394390
let first_url = media_urls.first().expect("checked len == 2");
395-
let extension = String::from(first_url.split('.').last().unwrap_or("unknown"));
391+
let extension = String::from(first_url.split('.').next_back().unwrap_or("unknown"));
396392
// this generates the name of the media without the component indices
397393
// this file name is used for saving the ffmpeg combined file
398394
let combined_file_name =
@@ -454,7 +450,7 @@ impl<'a> Downloader<'a> {
454450
debug!("Skipping combining reddit video.");
455451
}
456452

457-
return Ok((media_downloaded, media_skipped));
453+
Ok((media_downloaded, media_skipped))
458454
}
459455

460456
/// Helper function to download youtube videos
@@ -468,7 +464,7 @@ impl<'a> Downloader<'a> {
468464

469465
if self.should_download {
470466
if self.ytdlp_available {
471-
let file_name = self.generate_file_name(&media_url, "mp4", "0", post_metadata);
467+
let file_name = self.generate_file_name(media_url, "mp4", "0", post_metadata);
472468

473469
if check_path_present(&file_name) {
474470
debug!("Youtube video from url {} already downloaded. Skipping...", media_url);
@@ -510,7 +506,7 @@ impl<'a> Downloader<'a> {
510506
media_skipped += 1;
511507
}
512508

513-
return Ok((media_downloaded, media_skipped));
509+
Ok((media_downloaded, media_skipped))
514510
}
515511

516512
/// Helper function to download other media
@@ -527,13 +523,13 @@ impl<'a> Downloader<'a> {
527523
let extension = if media_type == MediaType::RedgifsVideo {
528524
String::from("mp4")
529525
} else {
530-
String::from(media_url.split('.').last().unwrap_or("unknown")).replace("/", "_")
526+
String::from(media_url.split('.').next_back().unwrap_or("unknown")).replace("/", "_")
531527
};
532528

533-
let file_name = self.generate_file_name(&media_url, &extension, &index, post_metadata);
529+
let file_name = self.generate_file_name(media_url, &extension, index, post_metadata);
534530

535531
if self.should_download {
536-
let status = save_or_skip(&*media_url, &file_name);
532+
let status = save_or_skip(media_url, &file_name);
537533
// update the summary statistics based on the status
538534
match status.await? {
539535
MediaStatus::Downloaded => {
@@ -548,17 +544,17 @@ impl<'a> Downloader<'a> {
548544
media_skipped += 1;
549545
}
550546

551-
return Ok((media_downloaded, media_skipped));
547+
Ok((media_downloaded, media_skipped))
552548
}
553549
}
554550

555551
/// Helper function that downloads and saves a single media from Reddit or Imgur
556552
async fn save_or_skip(url: &str, file_name: &str) -> Result<MediaStatus, ReddSaverError> {
557-
if check_path_present(&file_name) {
553+
if check_path_present(file_name) {
558554
debug!("Media from url {} already downloaded. Skipping...", url);
559555
Ok(MediaStatus::Skipped)
560556
} else {
561-
let save_status = download_media(&file_name, &url).await?;
557+
let save_status = download_media(file_name, url).await?;
562558
if save_status {
563559
Ok(MediaStatus::Downloaded)
564560
} else {
@@ -604,7 +600,7 @@ async fn download_media(file_name: &str, url: &str) -> Result<bool, ReddSaverErr
604600
let maybe_data = response.bytes().await;
605601
if let Ok(data) = maybe_data {
606602
debug!("Bytes length of the data: {:#?}", data.len());
607-
let maybe_output = File::create(&file_name);
603+
let maybe_output = File::create(file_name);
608604
match maybe_output {
609605
Ok(mut output) => {
610606
debug!("Created a file: {}", file_name);
@@ -668,7 +664,7 @@ async fn get_reddit_video(url: &str) -> Result<Option<SupportedMedia>, ReddSaver
668664
if let Some(dash_video) = maybe_dash_video {
669665
let present = dash_video.contains("DASH");
670666
// todo: find exhaustive collection of these, or figure out if they are (x, x*2) pairs
671-
let dash_video_only = vec!["DASH_1_2_M", "DASH_2_4_M", "DASH_4_8_M"];
667+
let dash_video_only = ["DASH_1_2_M", "DASH_2_4_M", "DASH_4_8_M"];
672668
if present {
673669
return if dash_video_only.contains(&dash_video) {
674670
let supported_media = SupportedMedia {
@@ -804,7 +800,7 @@ async fn get_media(data: &PostData) -> Result<Vec<SupportedMedia>, ReddSaverErro
804800
.and_then(|mm| mm.get(&item.media_id))
805801
.and_then(|v| v.get("m"))
806802
.and_then(|m| m.as_str())
807-
.and_then(|mime| mime.split('/').last())
803+
.and_then(|mime| mime.split('/').next_back())
808804
.map(|sub| if sub == "jpeg" { "jpg" } else { sub })
809805
.unwrap_or("jpg");
810806
let image_url = format!(
@@ -827,10 +823,8 @@ async fn get_media(data: &PostData) -> Result<Vec<SupportedMedia>, ReddSaverErro
827823
media_type: MediaType::GfycatGif,
828824
};
829825
media.push(supported_media);
830-
} else {
831-
if let Some(supported_media) = gfy_to_mp4(url).await? {
832-
media.push(supported_media);
833-
}
826+
} else if let Some(supported_media) = gfy_to_mp4(url).await? {
827+
media.push(supported_media);
834828
}
835829
}
836830

src/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a> User<'a> {
142142
// during the first call to the API, we would not provide the after query parameter
143143
// in subsequent calls, we use the value for after from the response of the
144144
// previous request and continue doing so till the value of after is null
145-
let base_url = format!("https://oauth.reddit.com/user/{}/{}", self.name, listing_type.to_string());
145+
let base_url = format!("https://oauth.reddit.com/user/{}/{}", self.name, listing_type);
146146

147147
let mut request = client
148148
.get(&base_url)

src/utils.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn check_path_present(file_path: &str) -> bool {
4747
/// Function that masks sensitive data such as password and client secrets
4848
pub fn mask_sensitive(word: &str) -> String {
4949
let word_length = word.len();
50-
return if word.is_empty() {
50+
if word.is_empty() {
5151
// return with indication if string is empty
5252
String::from("<EMPTY>")
5353
} else if word_length > 0 && word_length <= 3 {
@@ -60,21 +60,18 @@ pub fn mask_sensitive(word: &str) -> String {
6060
.enumerate()
6161
.map(|(i, c)| if i == 0 || i == 1 || i == word_length - 1 { c } else { '*' })
6262
.collect()
63-
};
63+
}
6464
}
6565

6666
/// Return delimited subreddit names or EMPTY if None
6767
pub fn print_subreddits(subreddits: &Option<Vec<&str>>) -> String {
68-
return if let Some(s) = subreddits { s.join(",") } else { String::from("<ALL>") };
68+
if let Some(s) = subreddits { s.join(",") } else { String::from("<ALL>") }
6969
}
7070

7171
/// Check if the given application is present in the $PATH
7272
pub fn application_present(name: String) -> bool {
7373
let result = which(name);
74-
match result {
75-
Ok(_) => true,
76-
_ => false,
77-
}
74+
result.is_ok()
7875
}
7976

8077
/// Fetch a temporary bearer token from the RedGifs v2 auth endpoint

0 commit comments

Comments
 (0)