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

Add support for PostSampleAlternates #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zevaryx
Copy link

@zevaryx zevaryx commented Feb 24, 2021

Reasoning

The API now has a field inside of sample called alternates. This field is usually empty, but is filled when there are different resolution sizes for a sample for videos. See post 2474986 for a rating:s sample. Additionally, with an update between when I first started this patch and now, they added it so every post now has this field (see post 39 for a rating: example of it being applied to an extremely old post).

Solution

An extra struct (PostSampleAlternates) and an extra field (alternates) allow for proper handling of this.

Example usage:

let client = rs621::client::Client::new("https://e926.net", "rs621/0.6.0 (by zevaryx on e621)")?;
let mut post_stream = client.get_posts(&[2474986]);

while let Some(post) = post_stream.next().await {
    let tmp_post = post?;
    print!("Post #{}:", tmp_post.id);
    for key in tmp_post.sample.alternates.keys() {
        print!(" {}", key);
    }
    println!("");
}

@nasso
Copy link
Owner

nasso commented Feb 16, 2022

Oh my god I just realised I wasn't watching the repository for some reason so I was never notified of your pull request. My bad.

I will take a look as soon as I can!

@zevaryx
Copy link
Author

zevaryx commented Feb 18, 2022

No worries! I actually forgot about this PR, so not a big deal

Copy link
Owner

@nasso nasso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the tests still pass? The fake payloads might have to be updated.

Also please rebase onto master!

@@ -48,11 +48,21 @@ pub struct PostPreview {
pub url: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct PostSampleAlternates {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be singular: PostSampleAlternate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants