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

feat(coverart): coverart builder to make specific queries to coverart api #45

Merged
merged 1 commit into from Jul 5, 2021

Conversation

ritiek
Copy link
Collaborator

@ritiek ritiek commented Jun 9, 2021

Ideally this will allow us to make specific calls to the coverart api. Such as to fetch front coverart for some release in 500px:

// https://coverartarchive.org/release/76df3287-6cda-33eb-8e9a-044b5e15ffdd/front-500
let in_utero_coverart = Release::fetch_coverart()
    .id("76df3287-6cda-33eb-8e9a-044b5e15ffdd")
    .front()
    .res_500()
    .execute()
    .expect("Unable to get cover art");

I'm not sure what the return type in our library should be here. The coverart api simply returns an image for this query.

Should we also return an image (maybe through the image crate), or maybe just return the redirect url from the original query (which looks like https://ia802607.us.archive.org/32/items/mbid-76df3287-6cda-33eb-8e9a-044b5e15ffdd/mbid-76df3287-6cda-33eb-8e9a-044b5e15ffdd-829521842_thumb500.jpg)?

Also, currently FetchCoverartQuery::execute() expects response content to be in json, but making these specific coverart calls does not return json. Not sure what the best way to deal with this in our library is.

@oknozor
Copy link
Owner

oknozor commented Jun 11, 2021

Hello @ritiek I won't have time to review this before next week.

Also I had a message from Yvan telling me that we need to give sign of life if we want to continue in the gsoc program.

I will contact you next week.

@ritiek
Copy link
Collaborator Author

ritiek commented Jun 11, 2021

Hello @ritiek I won't have time to review this before next week.

I see. Hope you're doing fine. Is there anything else you'd specifically want to me to work on until then? Otherwise I plan on implementing auto-retries for now as this feels something I wouldn't require much consulting on.

Also I had a message from Yvan telling me that we need to give sign of life if we want to continue in the gsoc program.

Totally understandable where this is coming from.

@oknozor
Copy link
Owner

oknozor commented Jun 11, 2021

Everything is fine, I am just super busy these days. Go for auto-retries !

@ritiek
Copy link
Collaborator Author

ritiek commented Jun 11, 2021

Good to know! Alright.

Copy link
Owner

@oknozor oknozor left a comment

Choose a reason for hiding this comment

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

This will work but it will allow to build invalid requests. For instance I could write :

Release::fetch_coverart()
    .id("1234")
    .back()
    .front()
    .res_1200()
    .res_500(); 

I see several ways to solve this :

  • Wrapping the request in an intermediate builder returned by the front and back. This builder would implement the res_ functions.
  • An alternative is to push the parameters (front, back and res) as some enum variant and check just before sending the request if all params are compatible.

I think I prefer the second approach because it allows to produce a detailed error message while being simple to implement and easy to extend.

@ritiek
Copy link
Collaborator Author

ritiek commented Jun 16, 2021

An alternative is to push the parameters (front, back and res) as some enum variant and check just before sending the request if all params are compatible.

Sounds good. How should I validate the request before sending it? Should I create another method (validate()?) that gets called as a part of execute() and checks whether the parameters are ordered correctly and are without repetition?

@oknozor
Copy link
Owner

oknozor commented Jun 20, 2021

Calling a validate() function as part of execute would do it, I don't think you need to check how method call are ordered since we can reorder everything when building the request. You only need to check for repetition.

@ritiek ritiek force-pushed the coverart-builder branch 2 times, most recently from f7d23c8 to 19dbdfa Compare June 21, 2021 14:55
@ritiek
Copy link
Collaborator Author

ritiek commented Jun 21, 2021

Alright. I've pushed new changes. What do you think?

@oknozor
Copy link
Owner

oknozor commented Jun 24, 2021

Also we need to update the readme.

@ritiek
Copy link
Collaborator Author

ritiek commented Jun 24, 2021

Also we need to update the readme.

Ok. Should I mention about the coverart feature in the features section in readme? And is it okay if I do this in a later PR? I'll also cover about get_coverart method and anything else worth mentioning about (retries?) in a later dedicated PR, if it's alright to you.

@ritiek ritiek marked this pull request as ready for review June 24, 2021 08:20
Copy link
Owner

@oknozor oknozor left a comment

Choose a reason for hiding this comment

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

Also we need to update the readme.

Ok. Should I mention about the coverart feature in the features section in readme? And is it okay if I do this in a later PR? I'll also cover about get_coverart method and anything else worth mentioning about (retries?) in a later dedicated PR, if it's alright to you.

Sure it's fine

src/lib.rs Outdated

pub fn res_1200(&mut self) -> &mut Self {
if self.0.target.img_res.is_some() {
panic!("coverart resolution is already set");
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need to panic here, we could just emit a warning to the standard output saying the call to res_xxx has been ignored

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I pushed a new commit to print these messages to stdout instead of panicking.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
HTTP_CLIENT.get(&self.0.path).send()?.json()
pub fn front(&mut self) -> &mut Self {
if self.0.target.img_type.is_some() {
panic!("coverart type is already set");
Copy link
Owner

Choose a reason for hiding this comment

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

Same here we shall just emit a warning, and ignore the additional image type, don't panic :)

@ritiek
Copy link
Collaborator Author

ritiek commented Jul 5, 2021

Is there anything else that needs to be addressed? Otherwise, this should be good to merge!

@oknozor oknozor merged commit 2213bcd into oknozor:main Jul 5, 2021
@ritiek ritiek deleted the coverart-builder branch July 5, 2021 09:02
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.

None yet

2 participants