Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor download logic #1

Merged
merged 15 commits into from
Nov 7, 2022
Prev Previous commit
Next Next commit
filter out self posts
  • Loading branch information
mcdallas committed Nov 7, 2022
commit c5433496fd16ba4c2b5745bcfb266e2c8f8cf569
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async fn main() -> Result<(), GertError> {
for subreddit in &subreddits {
let listing = Subreddit::new(subreddit).get_feed(feed, limit, period).await?;
posts.extend(
listing.data.children.into_iter().filter(|post| post.data.url.is_some()).filter(
listing.data.children.into_iter().filter(|post| post.data.url.is_some() && !post.data.is_self).filter(
|post| pattern.is_match(post.data.title.as_ref().unwrap_or(&"".to_string())),
),
);
Expand Down
4 changes: 3 additions & 1 deletion src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub struct PostData {
pub is_video: Option<bool>,
/// Reddit Media info
pub media: Option<PostMedia>,

pub is_self: bool,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -268,7 +270,7 @@ impl Post {
return MediaType::ImgurAlbum;
}
if url.contains(IMGUR_SUBDOMAIN) {
if url.ends_with(GIFV_EXTENSION) {
if url.ends_with(GIFV_EXTENSION) || url.ends_with(GIF_EXTENSION) {
return MediaType::ImgurGif;
} else if url.ends_with(PNG_EXTENSION) || url.ends_with(JPG_EXTENSION) {
return MediaType::ImgurImage;
Expand Down