anpigon / obsidian-book-search-plugin

Obsidian plugin that automatically creates notes by searching for books

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Replace the thumbnail of the cover with a HQ version of the cover

ltctceplrm opened this issue · comments

It seems like if you use this URL https://books.google.com/books/publisher/content/images/frontcover/\(bookImgId)?fife=w400-h600&source=gbs_api and replace (bookImgId) with the book ID then you can have a HQ version of the cover instead of the current thumbnail.

I embed the cover inside the note itself so the current thumbnail just doesn't look very pretty, if could it use the HQ cover instead then it would be great

Have you found a way to do this other than doing it manually?

Well I found a semi automatic way to do it, I made a templater search and replace script and configured a hotkey so it loads the template and replaces the LQ url with the HQ one. It would be better if it would work when the note gets created but I wasn't able to do that, this way works pretty well for me though so it's good enough for now. I still hope anpigon will add it natively in the plugin.

Here's the template:

<%* 
var file = app.workspace.getActiveFile()
var t = await app.vault.read(file)
var s = t.replaceAll("http://books.google.com/books/content?id=", "https://books.google.com/books/publisher/content/images/frontcover/").replaceAll("&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api","?fife=w600-h900&source=gbs_api").replaceAll("&printsec=frontcover&img=1&zoom=1","?fife=w600-h900&source=gbs_api")

app.vault.modify(file, s)
-%>

Edit: Sometimes there are several versions of books to choose from and some of those only have LQ images so you sometimes need to select another version and try again.

Thank you! I'm such a noob it took me over an hour to figure out how to use this; but, I did it and it works flawlessly.

For future readers:

  1. Copy that script from above.
  2. Paste it into a new Obsidian note.
  3. Give the note a memorable title (mine is HQ Book Cover).
  4. Move that note into the folder with your Templater templates.
  5. Open one of your book notes made with the Book Search Plugin. Or, use the Book Search Plugin to make a book note.
  6. Hit Command-P to open the command palate.
  7. Type "tem" then select "Templater: Open Insert Template modal".
  8. Select your new script note (again, mine is HQ Book Cover) and hit return.
  9. Voila! Your low-quality images are replaced with high-quality ones.

If you are going to do this a lot, it will be faster to assign a hotkey to invoke this Templater script. Here's how you do it:

  1. Go to Templater settings and find the "Template Hotkeys" section.
  2. Click "Add new hotkey for template".
  3. In the box, search for your new HQ Book Cover script. Select it.
  4. Hit the "Plus" button, which takes you to the core Hotkeys Plugin.
  5. Hit the "Plus" button next to your new script note. This allows you to set the hotkeys.
  6. Pick your hotkeys. Mine is command-shift-h.

Now, all you need to do is open or create a book note, smash the hotkeys, and you're done!

Well I found a semi automatic way to do it, I made a templater search and replace script and configured a hotkey so it loads the template and replaces the LQ url with the HQ one. It would be better if it would work when the note gets created but I wasn't able to do that, this way works pretty well for me though so it's good enough for now. I still hope anpigon will add it natively in the plugin.

Here's the template:

<%* 
var file = app.workspace.getActiveFile()
var t = await app.vault.read(file)
var s = t.replaceAll("http://books.google.com/books/content?id=", "https://books.google.com/books/publisher/content/images/frontcover/").replaceAll("&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api","?fife=w600-h900&source=gbs_api").replaceAll("&printsec=frontcover&img=1&zoom=1","?fife=w600-h900&source=gbs_api")

app.vault.modify(file, s)
-%>

Edit: Sometimes there are several versions of books to choose from and some of those only have LQ images so you sometimes need to select another version and try again.

A non-templater solution for this to get the cover in one go:

<%=book.coverUrl ? `https://books.google.com/books/publisher/content/images/frontcover/${[...book.coverUrl.split("&")[0].matchAll(/id.?(.*)/g)][0][1]}?fife=w600-h900&source=gbs_api` : ''%>

This will build the same URL on the note creation via this plugin.

Impressive @uroybd, I didn't even know that was possible, thanks for the heads up.

Calling the Google API with the zoom parameter - 0 removes the scaling

https://books.google.com/books/content?id=6xVTDwAAQBAJ&printsec=frontcover&img=1&zoom=0

The default set right now in the plugin is 5, which makes the image so small...
Although the @uroybd is nice, it won't download the image locally, meaning that it needs internet / the Google API might change in the future breaking all cover images