Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdallas committed Nov 28, 2022
1 parent 0fa7dd4 commit f2f82cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<'a> Downloader<'a> {
let maybe_data = response.bytes().await;
if let Ok(data) = maybe_data {
debug!("Bytes length of the data: {:#?}", data.len());
let maybe_output = File::create(&file_name);
let maybe_output = File::create(file_name);
match maybe_output {
Ok(mut output) => {
debug!("Created a file: {}", file_name);
Expand Down Expand Up @@ -663,9 +663,9 @@ impl<'a> Downloader<'a> {
let output_file = video_path.replace(".mp4", "-merged.mp4");
let mut command = tokio::process::Command::new("ffmpeg")
.arg("-i")
.arg(&video_path)
.arg(video_path)
.arg("-i")
.arg(&audio_path)
.arg(audio_path)
.arg("-c")
.arg("copy")
.arg("-map")
Expand Down
5 changes: 4 additions & 1 deletion src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ impl Post {
if url.contains(REDDIT_IMAGE_SUBDOMAIN) {
// if the URL uses the reddit image subdomain and if the extension is
// jpg, png or gif, then we can use the URL as is.
if url.ends_with(JPG_EXTENSION) || url.ends_with(PNG_EXTENSION) || url.ends_with(JPEG_EXTENSION) {
if url.ends_with(JPG_EXTENSION)
|| url.ends_with(PNG_EXTENSION)
|| url.ends_with(JPEG_EXTENSION)
{
return MediaType::RedditImage;
} else if url.ends_with(GIF_EXTENSION) {
return MediaType::RedditGif;
Expand Down
25 changes: 17 additions & 8 deletions src/subreddit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::errors::GertError;
use crate::structures::{Listing, Post};
use log::debug;
use reqwest::Client;
use std::fmt::Write;
use log::debug;

pub struct Subreddit {
/// Name of subreddit.
Expand All @@ -24,7 +24,7 @@ impl Subreddit {
ty: &str,
limit: u32,
period: Option<&str>,
after: Option<&str>
after: Option<&str>,
) -> Result<Listing, GertError> {
let url = &mut format!("{}/{}.json?limit={}", self.url, ty, limit);

Expand All @@ -39,11 +39,20 @@ impl Subreddit {
Ok(self.client.get(&url.to_owned()).send().await?.json::<Listing>().await?)
}

pub async fn get_posts(&self, feed:&str, limit: u32, period: Option<&str>) -> Result<Vec<Post>, GertError> {
pub async fn get_posts(
&self,
feed: &str,
limit: u32,
period: Option<&str>,
) -> Result<Vec<Post>, GertError> {
if limit <= 100 {
return Ok(self.get_feed(feed, limit, period, None).await?.data
.children
.into_iter().collect())
return Ok(self
.get_feed(feed, limit, period, None)
.await?
.data
.children
.into_iter()
.collect());
}
let mut page = 1;
let mut posts: Vec<Post> = Vec::new();
Expand All @@ -53,12 +62,12 @@ impl Subreddit {
debug!("Fetching page {} of {} from r/{} [{}]", page, limit / 100, self.name, feed);
let limit = if remaining > 100 { 100 } else { remaining };
let listing = self.get_feed(feed, limit, period, after).await?;

posts.extend(listing.data.children.into_iter().collect::<Vec<Post>>());
let last_post = posts.last().unwrap();
after = Some(&last_post.data.name);
remaining -= limit;
page+=1;
page += 1;
}
Ok(posts)
}
Expand Down

0 comments on commit f2f82cd

Please sign in to comment.