tfonteyn / NeverTooManyBooks

A book collection app for Android
GNU General Public License v3.0
70 stars 3 forks source link

(feature request) Use images from open library. #48

Closed realeatham closed 1 month ago

realeatham commented 2 months ago

Most of the time when adding a book, the image is wrong and back is missing. I try the other editions feature and it returns no results or not the correct cover. But , when I look at open library, both covers are there. It would be nice to scan the image from there instead of me having to take a photo myself.

Also, is there a way you know of to get a source the app uses to send a photo ofy book to them so they can update theirs? Sorry for the bad english I am half asleep.

tfonteyn commented 2 months ago

the image is wrong and back is missing

yes, I can only get what is available on the site; however, read on...

It's quite possible OpenLibrary is not switched on - please double check either in "Settings" / "Search - Websites" or the menu option on the search screens.

If it is switched on, can you please post an example ISBN here and I'll see what could be wrong.

get a source the app uses to send a photo ofy book to them so they can update theirs It's not impossible, but it would involve create a login and supporting code in my app to do this. And this will not work for most sites anyhow unless you have an account with them which allows this.

realeatham commented 2 months ago

the image is wrong and back is missing

yes, I can only get what is available on the site; however, read on...

It's quite possible OpenLibrary is not switched on - please double check either in "Settings" / "Search - Websites" or the menu option on the search screens.

If it is switched on, can you please post an example ISBN here and I'll see what could be wrong.

Open library was enabled, here are the codes and links https://openlibrary.org/books/OL47304760M/Wundersmith

9780734418227

get a source the app uses to send a photo ofy book to them so they can update theirs

It's not impossible, but it would involve create a login and supporting code in my app to do this. And this will not work for most sites anyhow unless you have an account with them which allows this.

I didn't mean in the app, was just asking if you knew

realeatham commented 2 months ago

I checked and open library allows me to update covers

tfonteyn commented 2 months ago

Notes to self:

wget https://covers.openlibrary.org/b/id/13769253-L.jpg --2024-04-16 17:00:55-- https://covers.openlibrary.org/b/id/13769253-L.jpg Resolving covers.openlibrary.org (covers.openlibrary.org)... 207.241.234.146 Connecting to covers.openlibrary.org (covers.openlibrary.org)|207.241.234.146|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://archive.org/download/l_covers_0013/l_covers_0013_76.zip/0013769253-L.jpg [following] --2024-04-16 17:00:56-- https://archive.org/download/l_covers_0013/l_covers_0013_76.zip/0013769253-L.jpg Resolving archive.org (archive.org)... 207.241.224.2 Connecting to archive.org (archive.org)|207.241.224.2|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://ia601909.us.archive.org/view_archive.php?archive=/31/items/l_covers_0013/l_covers_0013_76.zip&file=0013769253-L.jpg [following] --2024-04-16 17:00:56-- https://ia601909.us.archive.org/view_archive.php?archive=/31/items/l_covers_0013/l_covers_0013_76.zip&file=0013769253-L.jpg Resolving ia601909.us.archive.org (ia601909.us.archive.org)... 207.241.227.49 Connecting to ia601909.us.archive.org (ia601909.us.archive.org)|207.241.227.49|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [image/jpeg] Saving to: ‘13769253-L.jpg’

tfonteyn commented 2 months ago

I checked and open library allows me to update covers It's what I do with the ISFDB site.

Apologies if the next bit is too technical

--- techie --- ok - I ran a test for that particular book. It seems I get the correct information back when I do the lookup; in other words, I get the url https://covers.openlibrary.org/b/id/13769253-L.jpg in the JSON response. So far so good, and nothing new as that always worked in the past. The code then follows that url and gets the image normally.

But when debugging, I found that url is now returning a 404, NOT FOUND to my app... and hence you don't get the image as expected.

I ran a manual wget download (see earlier comment) ... and it seems OpenLibrary is doing multiple redirects. In theory this should not be an issue, as the app/Android will follow those redirect just fine. --- end of techie ---

Bottomline: there is nothing 'wrong' in the app, and it merely gets the 404 NOT FOUND. But of course this should not be the case. I'll need to investigate further and see if this is new behaviour from OpenLibrary and/or what can be done.

However, while checking, I found that OpenLibrary has flagged the API I use as "Legacy" and has a new one. Maybe that will be a long term solution (and hopefully also will mean better data). I'll need to follow up on that as well. Luckily enough interfacing with OpenLibrary is fairly easy.

realeatham commented 2 months ago

K. If you get it to work, that would be epic. I won't add the rest of my books to it incase you do.

Also, thank you for the technical bit, it explains well.

tfonteyn commented 2 months ago

No need to wait. You can add them without covers for now, and then use the "Update Fields" option later to fetch the covers. The "Update Fields" option is IMHO very flexible.

realeatham commented 2 months ago

You can update the stuff after you add it ? This app is actually amazing. Can you also chose what to update?

tfonteyn commented 2 months ago

From the main list screen, on most rows, the context menu for that row will contain "Update Books"; or on individual books, use the toolbar option menu "Update fields"

An then... you get to decide what/if/how to update fields. If you get lost, use the option menu on that screen where you can "Deselect all" or "Reset"

Keep in mind that if you run this for a row on the list, and lets say for example you execute it on an Author with a 100 books ... it will take quite some time to run. Use with care!

Books can be "locked", so they will get skipped in such a process. In the Settings, scroll to the bottom and enable "Allow editing website book id". When you then edit a book, there will be a new tab at the end with the native website book id's (at least for some) which then can be edited.... and the locking switch is below.

That website id tab is hidden by default for a reason.... a) I've not documented the use + b) using an invalid or the wrong id there followed by running an update can unintentionally to bad things.... your book might get the wrong data, or at an extreme.... send a website the wrong id too many times, and they might notice/block you. USE WITH EXTREME CARE.

The lock switch on it's own is safe to use of course. To be honest.... I put it on the wrong tab, I should move if elsewhere.

realeatham commented 2 months ago

Already figured it out,but thanks anyway. Found a bug, when you try to use alternative edition for the cover, it fails to save and says out of storage. If it is the cover the app loads first, all fine. I have enough storage.

realeatham commented 2 months ago

Also, when you fix the open library API, can you test back covers? Try https://openlibrary.org/books/OL28508809M/Percy_Jackson_and_the_Battle_of_the_Labyrinth as I just added covers for it

tfonteyn commented 2 months ago

back covers Their api is not returning that info. I found some of the data they return is [bleep]. See my my old notes I'll revisit this later when I look at their new API.

Found a bug, Please log a new issue, with a full description and example ISBN. While doing so, repeat the operation that led to the error, then go to the Settings, scroll all the way down to Maintenance, and then create a bug report and attach it to the news issue.

enough storage. yes, my error message is misleading 👎 ... it's one of the things on my todo list.

tfonteyn commented 1 month ago

ok - got some news:

Their API is not 100% (yet) though. For example, the book "Wundersmith" which on the site shows a cover, does not return a cover when using their API. Nothing I can do about that, but I presume this will fix itself when they improve their code.

The "Percy_Jackson_and_the_Battle_of_the_Labyrinth" you mentioned will now return a front and backover as expected.

I want to run some more tests and optimize the code. Give me a week or so, I have another issue I encountered myself which I want to fix first.

btw, don't forget to log a new issue for your "when you try to use alternative edition for the cover, it fails to save and says out of storage." problem.

tfonteyn commented 1 month ago

btw, don't forget to log a new issue

oh heck.... no longer needed - I can reproduce it. It seems LibraryThing (owned by Amazon...) is no longer accepting calls for alternative editions at all.

ngocanhtve commented 1 month ago

It seems LibraryThing (owned by Amazon...)

Looks like Amazon owns every service related to books 😁

realeatham commented 1 month ago

ok - got some news:

* I implemented their new API and it seems better than the old one.

* some extra fields are now present in their data (like the physical format)

* multiple cover images are supported; so I added support for them as well with
  the restriction that I will fetch 2 images maximum.

Their API is not 100% (yet) though. For example, the book "Wundersmith" which on the site shows a cover, does not return a cover when using their API. Nothing I can do about that, but I presume this will fix itself when they improve their code.

The "Percy_Jackson_and_the_Battle_of_the_Labyrinth" you mentioned will now return a front and backover as expected.

I want to run some more tests and optimize the code. Give me a week or so, I have another issue I encountered myself which I want to fix first.

When you come back to this can you check the ISBN 9780141339092? It has the correct cover on open library, but the app finds some other cover. Alternative editions doesn't help

tfonteyn commented 1 month ago

seems a commit closed this issue prematurely.

9780141339092 is the same problem as I have seen often with OpenLibrary... errors in their database.

ID Numbers

Open Library OL27104332M ISBN 10 0141339098 ISBN 13 9780141339092

The API call is:

http://covers.openlibrary.org/b/isbn/9780141339092-M.jpg http://covers.openlibrary.org/b/olid/OL27104332M-M.jpg

=> different covers.

I'll see if I can improve the code and perhaps use the OLID key

tfonteyn commented 1 month ago

do me a favour... take a picture of the copyright page of that book and post it here - I might have an idea what's going on.

tfonteyn commented 1 month ago

never mind, just confirmed it. Take a look here:

https://openlibrary.org/books/OL8364375M/Artemis_Fowl

ID Numbers

Open Library OL8364375M ISBN 10 0141339098 ISBN 13 9780141339092

See the identical ISBN number, and the image :)

It's a fairly common situation with reprinted books where the publisher reuses the ISBN from the 1st printing. Based on ISBN, there is simpy no solution of course.

But you can use the OL number to add it to NTMB when you use the what I mentioned earlier:

 In the Settings, scroll to the bottom and enable "Allow editing website book id". 
When you then edit a book, there will be a new tab at the end with the native 
website book id's (at least for some) 

It's not just that extra tab, but it's also an extra option in the [+] (the fab button) menu to add books: "Website book id". Use that option, and enter

OL27104332M

and you'll get the exact book you want.

realeatham commented 1 month ago

Thank you, that worked. Quick question, why doesn't it show up in alternate editions if it has the same ISBN number but a different cover and both are on open library?

tfonteyn commented 1 month ago

rather simple answer: the data has to exist for me to find it :-)

Alternative edition information came primarily from LibraryThing, which has now taken that API down:

https://www.librarything.com/api/thingISBN/9781913755201

The secondary site for alt.ed. is ISFDB, and while the first printing of that book is listed on their site, the one you have is not.

With LT getting more useless each time they block/change something, I'll need to look for an alternative - not that easy.

realeatham commented 1 month ago

Does the OL api not have alt edition? On the site it does, surely the API has all the things on the site? I will check later

tfonteyn commented 1 month ago

Does the OL api not have alt edition

it does although, I have not tried it yet, as until recently LibraryThing was providing very good info on alt.ed.'s

The one thing with OL I keep running into is that their data is not as reliable, but having said that, their new book-search API is certainly better then the old one.

tfonteyn commented 1 month ago

I've tested their Editions API, and it's working ok. I've implemented it successfully and get a nice list with information about other editions including their ISBN and covers. So far so good - this is useful.

However, a follow up on 404, NOT FOUND... It looks this is an Android core issue. Basically:

HttpURLConnection with url set to "https://covers.openlibrary.org/b/id/13414586-M.jpg?default=false"
and redirects true; execute:
request.connect()
responseCode = request.getResponseCode();

response:

404 + request.getUrl: "https://archive.org/download/m_covers_0013/m_covers_0013_41.zip/0013414586-M.jpg"

So it receives the redirect (wget clearly shows a 302), changes the reponse to a 404 and tells me to get [bleeped]. Nice one Android....

realeatham commented 1 month ago

K nice

realeatham commented 1 month ago

So alt editions will work with ol in the next version?

tfonteyn commented 1 month ago

I have implemented a manual redirect for those situations where Google/Android do the wrong thing (which happens far to often.... grumble grumble)...

But YES, the alt.ed. 's are working now with OpenLibrary.

The 404 might cause a minor slowdown, but this cannot be helped unless Google fixes their code (we can dream...) If there are only a couple of alt.ed.'s this will not be noticeable.

With all the changes, I'd like to run a beta test with users. I'll notify you (and others) when I have one ready.

tfonteyn commented 1 month ago

Here you go ... 6.0.0 apk

Should you have any issues, then of course feel free to log a new issue.

Make sure to check via Settings, Websites that the "alt. ed." (Alternative editions) are enabled for OpenLibrary.

realeatham commented 1 month ago

It worked

realeatham commented 1 month ago

Thanks for fixing it