Skip to content

Conversation

@vanoudt
Copy link

@vanoudt vanoudt commented Nov 28, 2024

OpenLibrary does redirects, and this allows the actual expected file to be cached.

OpenLibrary does redirects, and this allows the actual expected file to be cached.
@fredericd
Copy link
Owner

Hello Nicholas.
Thanks. Could you explain your patch. I don't get it.

@vanoudt
Copy link
Author

vanoudt commented Dec 20, 2024

Of course! Sorry about the delay; the notification got lost in the email! :-)

I notice that one of the resolvers, OpenLibrary, doesn't give the correct URL for the cover from the api request. The link it gives returns an HTTP redirect code. On a browser, this isn't an issue - the browser transparently goes through and follows the redirects to the actual cover. The problem comes when you turn on image caching, like we have done. Without this patch, you end up with a text file saying something like, "File relocated".

In essence, this patch simply follows the HTTP 301/302 redirect instructions until it gets to the actual book cover image!

For instance, searching for the ISBN 0851111955 on openlibrary returns the following cover URL:
https://covers.openlibrary.org/b/id/12433118-M.jpg
That URL redirects you to the following URL:
https://archive.org/download/m_covers_0012/m_covers_0012_43.zip/0012433118-M.jpg
And that URL finally redirects you to the URL for the actual cover:
https://ia800505.us.archive.org/view_archive.php?archive=/5/items/m_covers_0012/m_covers_0012_43.zip&file=0012433118-M.jpg

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.

2 participants