discogs-marketplace-api-nodejs 1.14.0 → 1.14.2
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:
|
|
@@ -34,12 +34,6 @@ interface SearchParamsBase {
|
|
|
34
34
|
* @default false
|
|
35
35
|
*/
|
|
36
36
|
isMakeAnOfferOnly?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Number of results to return per page.
|
|
39
|
-
* Allowed values: 25, 50, 100, 250.
|
|
40
|
-
* @default 25
|
|
41
|
-
*/
|
|
42
|
-
limit?: Limit;
|
|
43
37
|
/**
|
|
44
38
|
* Page number of results.
|
|
45
39
|
* Must be less than 401 to avoid Discogs 404 errors.
|
|
@@ -88,6 +82,12 @@ interface SearchParamsLegacyBase extends SearchParamsBase {
|
|
|
88
82
|
* @default 'listed,desc'
|
|
89
83
|
*/
|
|
90
84
|
sort?: Sort;
|
|
85
|
+
/**
|
|
86
|
+
* Number of results to return per page.
|
|
87
|
+
* Allowed values: 25, 50, 100, 250.
|
|
88
|
+
* @default 25
|
|
89
|
+
*/
|
|
90
|
+
limit?: Limit;
|
|
91
91
|
/**
|
|
92
92
|
* Seller's name.
|
|
93
93
|
*/
|
|
@@ -162,6 +162,11 @@ interface SearchParamsModernBase extends SearchParamsBase {
|
|
|
162
162
|
* @default 'listed,desc'
|
|
163
163
|
*/
|
|
164
164
|
sort?: Exclude<Sort, 'label,asc' | 'label,desc'>;
|
|
165
|
+
/**
|
|
166
|
+
* Number of results to return per page.
|
|
167
|
+
* @default 25
|
|
168
|
+
*/
|
|
169
|
+
limit?: number;
|
|
165
170
|
/**
|
|
166
171
|
* List of artist IDs.
|
|
167
172
|
*/
|
|
@@ -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,7 +95,11 @@ async function scrape({ currencies, genres, formats, formatDescriptions, conditi
|
|
|
91
95
|
},
|
|
92
96
|
},
|
|
93
97
|
}),
|
|
94
|
-
})
|
|
98
|
+
});
|
|
99
|
+
if (!detailsResponse.ok) {
|
|
100
|
+
throw new Error(detailsResponse.statusText || `An error ${detailsResponse.status} occurred.`);
|
|
101
|
+
}
|
|
102
|
+
const detailsResult = (await detailsResponse.json());
|
|
95
103
|
const details = Object.fromEntries(detailsResult.data?.releases?.map(release => [
|
|
96
104
|
release.discogsId ?? 0,
|
|
97
105
|
{
|
|
@@ -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');
|
|
@@ -47,7 +51,7 @@ async function scrapeWantlist(searchParams) {
|
|
|
47
51
|
const wantlistIds = wants.flat();
|
|
48
52
|
// If there's nothing for sale
|
|
49
53
|
if (wantlistIds.length === 0) {
|
|
50
|
-
return {
|
|
54
|
+
return (0, modern_scraper_1.default)({ ...searchParams, releaseIds: [0], wantlist: undefined });
|
|
51
55
|
}
|
|
52
56
|
return (0, modern_scraper_1.default)({ ...searchParams, releaseIds: wantlistIds, wantlist: undefined });
|
|
53
57
|
}
|