Skip to content

Commit 8a392e5

Browse files
committed
Improved openlibrary API + updated readme
Fixed missing ratings, page numbers and also added an option to add specific editions using search by ID, this method also enables you to search by isbn ID.
1 parent 9518ede commit 8a392e5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,11 @@ Now you select the result you want and the plugin will cast it's magic and creat
162162
- you can find this ID in the URL
163163
- e.g. for "Factorio" the URL looks like this `https://store.steampowered.com/app/427520/Factorio/` so the ID is `427520`
164164
- [Open Library](https://openlibrary.org)
165-
- The ID you need is the "work" ID and not the "book" ID, it needs to start with `/works/`. You can find this ID in the URL
166-
- e.g. for "Fantastic Mr. Fox" the URL looks like this `https://openlibrary.org/works/OL45804W` so the ID is `/works/OL45804W`
165+
- The ID can either be the "/work/" ID, the "/book/" ID, or the "/isbn/" ID it needs to start with `/works/`. You can find this ID in the URL
166+
- e.g. for "Fantastic Mr. Fox" the "/works/" URL looks like this `https://openlibrary.org/works/OL45804W` so the ID is `/works/OL45804W`
167167
- This URL is located near the top of the page above the title, see `An edition of Fantastic Mr Fox (1970) `
168+
- For a specific edition of "Fantastic Mr. Fox" the "/books/" URL looks like this `https://openlibrary.org/books/OL3567303M/` so the ID is `/books/OL3567303M`
169+
- This URL is located in the editions section`
168170
- [Moby Games](https://www.mobygames.com)
169171
- you can find this ID in the URL
170172
- e.g. for "Bioshock 2" the URL looks like this `https://www.mobygames.com/game/45089/bioshock-2/` so the ID is `45089`

src/api/apis/OpenLibraryAPI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class OpenLibraryAPI extends APIModel {
5252
async getById(id: string): Promise<MediaTypeModel> {
5353
console.log(`MDB | api "${this.apiName}" queried by ID`);
5454

55-
const searchUrl = `https://openlibrary.org/search.json?q=key:${encodeURIComponent(id)}`;
55+
const searchUrl = `https://openlibrary.org/search.json?q=${encodeURIComponent(id)}&fields=key,title,author_name,number_of_pages_median,first_publish_year,isbn,ratings_score,first_sentence,title_suggest,rating*,cover_edition_key`;
5656
const fetchData = await fetch(searchUrl);
5757
// console.debug(fetchData);
5858

@@ -68,8 +68,8 @@ export class OpenLibraryAPI extends APIModel {
6868
title: result.title,
6969
year: result.first_publish_year,
7070
dataSource: this.apiName,
71-
url: `https://openlibrary.org` + result.key,
72-
id: result.key,
71+
url: `https://openlibrary.org` + data.q,
72+
id: data.q,
7373
isbn: (result.isbn ?? []).find((el: string | any[]) => el.length <= 10) ?? 'unknown',
7474
isbn13: (result.isbn ?? []).find((el: string | any[]) => el.length == 13) ?? 'unknown',
7575
englishTitle: result.title_english ?? result.title,

0 commit comments

Comments
 (0)