discogs-marketplace-api-nodejs 1.14.1 → 1.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD
CHANGED
|
@@ -170,6 +170,7 @@ Both share common search filters and extend them with API-specific options via t
|
|
|
170
170
|
| `genres` | `Genre[]` | Filter by multiple genres. | `['Rock', 'Jazz']` | – |
|
|
171
171
|
| `from` | `From[]` | Filter by seller’s countries. | `['FR', 'DE']` | – |
|
|
172
172
|
| `sort` | `Sort` | Sort and sort order. | `'listed,desc'` | `'listed,desc'` |
|
|
173
|
+
| `limit` | `number` | Number of results per page. | `100` | `25` |
|
|
173
174
|
| `artistIds` | `number[]` | Filter by artist IDs. | `[123, 456]` | – |
|
|
174
175
|
| `sellerIds` | `number[]` | Filter by seller IDs. | `[789, 1011]` | – |
|
|
175
176
|
| `priceRange.min`/`max` | `number` | Filter by price range. | `{ min: 10, max: 100 }` | – |
|
|
@@ -195,6 +196,7 @@ Both share common search filters and extend them with API-specific options via t
|
|
|
195
196
|
| `styles` | `Style[]` | Filter by style. | `['Death Metal', 'Heavy Metal']` | – |
|
|
196
197
|
| `from` | `From` | Filter by seller’s country. | `'FR'` | – |
|
|
197
198
|
| `sort` | `Sort` | Sort order for results. | `'listed,desc'` | `'listed,desc'` |
|
|
199
|
+
| `limit` | `25 \| 50 \| 100 \| 250` | Number of results per page. | `100` | `25` |
|
|
198
200
|
| `seller` | `string` | Filter by seller username. | `"seller_name"` | – |
|
|
199
201
|
| `user` | `string` | Filter by user. | `"my_username"` | – |
|
|
200
202
|
| `lang` | `Lang` | Discogs interface language. | `'en'` | `'en'` |
|
|
@@ -213,7 +215,6 @@ Both share common search filters and extend them with API-specific options via t
|
|
|
213
215
|
| `formatDescriptions` | `FormatDescription[]` | List of format descriptions. | `['Limited Edition', 'Numbered']` | – |
|
|
214
216
|
| `years.min` / `max` | `number` | Year range. | `{ min: 1980, max: 1990 }` | – |
|
|
215
217
|
| `isMakeAnOfferOnly` | `boolean` | Only return listings that accept offers. | – | `false` |
|
|
216
|
-
| `limit` | `25 \| 50 \| 100 \| 250` | Number of results per page. | `100` | `25` |
|
|
217
218
|
| `page` | `number` | Page number (must be `< 401` to avoid 404). | `2` | `1` |
|
|
218
219
|
|
|
219
220
|
On success, a `SearchResult` interface is returned:
|
|
@@ -100,8 +100,7 @@ async function scrapeLegacy({ currency, genre, styles, formats, formatDescriptio
|
|
|
100
100
|
});
|
|
101
101
|
const content = await response.text();
|
|
102
102
|
const { document } = (0, linkedom_1.parseHTML)(content);
|
|
103
|
-
|
|
104
|
-
if (response.status >= 400) {
|
|
103
|
+
if (!response.ok) {
|
|
105
104
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
106
105
|
const errorMessage = document.querySelector('h1 + p')?.innerHTML.trim() || `An error ${response.status} occurred.`;
|
|
107
106
|
throw new Error(errorMessage);
|
|
@@ -145,7 +144,10 @@ async function scrapeLegacy({ currency, genre, styles, formats, formatDescriptio
|
|
|
145
144
|
url: `https://www.discogs.com${releaseHref}`,
|
|
146
145
|
},
|
|
147
146
|
formats: lastIndexOfParenthesis > -1
|
|
148
|
-
? originalTitle
|
|
147
|
+
? originalTitle
|
|
148
|
+
.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1)
|
|
149
|
+
.split(', ')
|
|
150
|
+
.filter(x => x)
|
|
149
151
|
: [],
|
|
150
152
|
labels: [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]
|
|
151
153
|
.map(x => ({
|
|
@@ -62,15 +62,19 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
|
|
|
62
62
|
['priceRangeHigh', priceRange?.max.toString() ?? ''],
|
|
63
63
|
].filter(([, p]) => !!p)).toString(),
|
|
64
64
|
].join('?');
|
|
65
|
-
const
|
|
65
|
+
const response = await globalThis.fetch(urlGenerated, {
|
|
66
66
|
method: 'GET',
|
|
67
67
|
headers: {
|
|
68
68
|
'User-Agent': 'Discogs',
|
|
69
69
|
'Content-Type': 'application/json',
|
|
70
70
|
},
|
|
71
71
|
referrer: 'https://discogs.com',
|
|
72
|
-
})
|
|
73
|
-
|
|
72
|
+
});
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(response.statusText || `An error ${response.status} occurred.`);
|
|
75
|
+
}
|
|
76
|
+
const result = (await response.json());
|
|
77
|
+
const detailsResponse = await globalThis.fetch('https://www.discogs.com/graphql', {
|
|
74
78
|
method: 'POST',
|
|
75
79
|
headers: {
|
|
76
80
|
'User-Agent': 'Discogs',
|
|
@@ -91,15 +95,24 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
|
|
|
91
95
|
},
|
|
92
96
|
},
|
|
93
97
|
}),
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
});
|
|
99
|
+
if (!detailsResponse.ok) {
|
|
100
|
+
throw new Error(detailsResponse.statusText || `An error ${detailsResponse.status} occurred.`);
|
|
101
|
+
}
|
|
102
|
+
const detailsResult = (await detailsResponse.json());
|
|
103
|
+
const details = Object.fromEntries(detailsResult.data?.releases?.map(release => {
|
|
104
|
+
if (!release?.discogsId) {
|
|
105
|
+
return [0, { imageUrl: null, want: 0, have: 0 }];
|
|
106
|
+
}
|
|
107
|
+
return [
|
|
108
|
+
release.discogsId ?? 0,
|
|
109
|
+
{
|
|
110
|
+
imageUrl: release.images?.edges?.[0]?.node?.thumbnail?.webpUrl ?? null,
|
|
111
|
+
want: release.inWantlistCount ?? 0,
|
|
112
|
+
have: release.inCollectionCount ?? 0,
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
}) ?? []);
|
|
103
116
|
const items = result.items?.map(item => {
|
|
104
117
|
const detail = details[item.release?.releaseId ?? 0];
|
|
105
118
|
return {
|
|
@@ -14,7 +14,7 @@ const PER_PAGE = 250;
|
|
|
14
14
|
*/
|
|
15
15
|
async function scrapeWantlist(searchParams) {
|
|
16
16
|
/** Fetch the first page of user wantlist */
|
|
17
|
-
const
|
|
17
|
+
const firstPageResponse = await globalThis.fetch(`https://www.discogs.com/wantlist?${new URLSearchParams({
|
|
18
18
|
page: '1',
|
|
19
19
|
limit: PER_PAGE.toString(),
|
|
20
20
|
user: searchParams.wantlist ?? '',
|
|
@@ -22,7 +22,11 @@ async function scrapeWantlist(searchParams) {
|
|
|
22
22
|
}).toString()}`, {
|
|
23
23
|
headers: { 'User-Agent': 'Discogs', 'Content-Type': 'application/json' },
|
|
24
24
|
referrer: 'https://discogs.com',
|
|
25
|
-
})
|
|
25
|
+
});
|
|
26
|
+
if (!firstPageResponse.ok && firstPageResponse.status !== 404) {
|
|
27
|
+
throw new Error(firstPageResponse.statusText || `An error ${firstPageResponse.status} occurred.`);
|
|
28
|
+
}
|
|
29
|
+
const firstPage = await firstPageResponse.text();
|
|
26
30
|
const { document: firstPageDocument } = (0, linkedom_1.parseHTML)(firstPage);
|
|
27
31
|
/** Total number of items in the wantlist */
|
|
28
32
|
const total = +(firstPageDocument.querySelector('.pagination_total')?.textContent?.split(' of ').pop()?.replace(',', '') ?? '0');
|