discogs-marketplace-api-nodejs 1.13.0 → 1.14.0
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 +150 -157
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/interfaces/search-params.interface.d.ts +168 -67
- package/dist/interfaces/search-result.interface.d.ts +37 -26
- package/dist/scrapers/legacy.scraper.d.ts +2 -2
- package/dist/scrapers/legacy.scraper.js +70 -71
- package/dist/scrapers/modern.scraper.d.ts +2 -5
- package/dist/scrapers/modern.scraper.js +57 -41
- package/dist/scrapers/wantlist.scraper.d.ts +2 -2
- package/dist/scrapers/wantlist.scraper.js +3 -7
- package/dist/search.d.ts +6 -3
- package/dist/search.js +19 -16
- package/dist/types/api.type.d.ts +4 -0
- package/dist/types/from.type.d.ts +2 -1
- package/package.json +1 -1
- package/dist/get-search-params.d.ts +0 -10
- package/dist/get-search-params.js +0 -119
- package/dist/types/search-type.type.d.ts +0 -4
- /package/dist/types/{search-type.type.js → api.type.js} +0 -0
|
@@ -6,35 +6,68 @@ import type { From } from '../types/from.type.js';
|
|
|
6
6
|
import type { Genre } from '../types/genre.type.js';
|
|
7
7
|
import type { Lang } from '../types/lang.type.js';
|
|
8
8
|
import type { Limit } from '../types/limit.type.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { Api } from '../types/api.type.js';
|
|
10
10
|
import type { Sort } from '../types/sort.type.js';
|
|
11
11
|
import type { Style } from '../types/style.type.js';
|
|
12
|
-
|
|
13
|
-
* Parameters used to search listings on the Discogs Marketplace.
|
|
14
|
-
*/
|
|
15
|
-
export default interface SearchParams {
|
|
12
|
+
interface SearchParamsBase {
|
|
16
13
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* |-------------|--------------------------------|
|
|
20
|
-
* | `q` | Basic query search |
|
|
21
|
-
* | `master_id` | Search within a master release |
|
|
22
|
-
* | `release_id`| Search within a release |
|
|
23
|
-
* | `label_id` | Search within a label |
|
|
24
|
-
* | `artist_id` | Search by artist |
|
|
25
|
-
* | `user` | Search a user's wantlist |
|
|
26
|
-
* @default 'q'
|
|
14
|
+
* List of formats.
|
|
15
|
+
* @example ['Vinyl', 'CD']
|
|
27
16
|
*/
|
|
28
|
-
|
|
17
|
+
formats?: Array<Format>;
|
|
29
18
|
/**
|
|
30
|
-
*
|
|
19
|
+
* List of format descriptions.
|
|
20
|
+
* @example ['Limited Edition', 'Numbered']
|
|
31
21
|
*/
|
|
32
|
-
|
|
22
|
+
formatDescriptions?: Array<FormatDescription>;
|
|
23
|
+
/**
|
|
24
|
+
* Range of years.
|
|
25
|
+
*/
|
|
26
|
+
years?: {
|
|
27
|
+
/** Minimum year */
|
|
28
|
+
min: number;
|
|
29
|
+
/** Maximum year */
|
|
30
|
+
max: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* If true, only listings that accept offers are returned.
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
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
|
+
/**
|
|
44
|
+
* Page number of results.
|
|
45
|
+
* Must be less than 401 to avoid Discogs 404 errors.
|
|
46
|
+
* @default 1
|
|
47
|
+
*/
|
|
48
|
+
page?: number;
|
|
49
|
+
}
|
|
50
|
+
interface SearchParamsLegacyBase extends SearchParamsBase {
|
|
51
|
+
/**
|
|
52
|
+
* Api version to use.
|
|
53
|
+
*
|
|
54
|
+
* Choose `legacy` for the legacy API that scrapes HTML page. Required if you want to search on master or label.
|
|
55
|
+
*/
|
|
56
|
+
api: Extract<Api, 'legacy'>;
|
|
57
|
+
/**
|
|
58
|
+
* Query string to filter.
|
|
59
|
+
*/
|
|
60
|
+
query?: string;
|
|
33
61
|
/**
|
|
34
62
|
* Currency code for price filtering.
|
|
35
63
|
* @example 'USD'
|
|
36
64
|
*/
|
|
37
65
|
currency?: Currency;
|
|
66
|
+
/**
|
|
67
|
+
* Media conditions.
|
|
68
|
+
* @example 'Mint (M)'
|
|
69
|
+
*/
|
|
70
|
+
condition?: Condition;
|
|
38
71
|
/**
|
|
39
72
|
* Genre filter.
|
|
40
73
|
* @example 'Rock'
|
|
@@ -44,79 +77,147 @@ export default interface SearchParams {
|
|
|
44
77
|
* List of styles.
|
|
45
78
|
* @example ['Death Metal', 'Heavy Metal']
|
|
46
79
|
*/
|
|
47
|
-
|
|
80
|
+
styles?: Array<Style>;
|
|
48
81
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
82
|
+
* Expedition country filter.
|
|
83
|
+
* @example 'France'
|
|
51
84
|
*/
|
|
52
|
-
|
|
85
|
+
from?: From;
|
|
53
86
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
87
|
+
* Sort order for the results.
|
|
88
|
+
* @default 'listed,desc'
|
|
56
89
|
*/
|
|
57
|
-
|
|
90
|
+
sort?: Sort;
|
|
58
91
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @example ['Mint (M)', 'Very Good Plus (VG+)']
|
|
92
|
+
* Seller's name.
|
|
61
93
|
*/
|
|
62
|
-
|
|
94
|
+
seller?: string;
|
|
63
95
|
/**
|
|
64
|
-
*
|
|
65
|
-
* Do not use together with `years`.
|
|
96
|
+
* User's name.
|
|
66
97
|
*/
|
|
67
|
-
|
|
98
|
+
user?: string;
|
|
68
99
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
100
|
+
* Language code for Discogs interface.
|
|
101
|
+
* @default 'en'
|
|
71
102
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
103
|
+
lang?: Lang;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parameters used to search listings on the Discogs Marketplace via new old HTML Scraping.
|
|
107
|
+
*/
|
|
108
|
+
export type SearchParamsLegacy = ({
|
|
109
|
+
/** Master release ID. */
|
|
110
|
+
masterId?: number;
|
|
111
|
+
labelId?: never;
|
|
112
|
+
releaseId?: never;
|
|
113
|
+
artistId?: never;
|
|
114
|
+
} | {
|
|
115
|
+
masterId?: never;
|
|
116
|
+
/** Label ID. */
|
|
117
|
+
labelId?: number;
|
|
118
|
+
releaseId?: never;
|
|
119
|
+
artistId?: never;
|
|
120
|
+
} | {
|
|
121
|
+
masterId?: never;
|
|
122
|
+
labelId?: never;
|
|
123
|
+
/** Release ID. */
|
|
124
|
+
releaseId?: number;
|
|
125
|
+
artistId?: never;
|
|
126
|
+
} | {
|
|
127
|
+
masterId?: never;
|
|
128
|
+
labelId?: never;
|
|
129
|
+
releaseId?: never;
|
|
130
|
+
/** Artist ID. */
|
|
131
|
+
artistId?: number;
|
|
132
|
+
}) & SearchParamsLegacyBase;
|
|
133
|
+
interface SearchParamsModernBase extends SearchParamsBase {
|
|
134
|
+
/**
|
|
135
|
+
* Api version to use.
|
|
136
|
+
*
|
|
137
|
+
* Choose `v2` for the modern API that uses JSON (used in the `https://www.discogs.com/shop/mywants` page).
|
|
138
|
+
*/
|
|
139
|
+
api: Extract<Api, 'v2'>;
|
|
140
|
+
/**
|
|
141
|
+
* List of currency codes for price filtering.
|
|
142
|
+
* @example ['USD']
|
|
143
|
+
*/
|
|
144
|
+
currencies?: Array<Currency>;
|
|
78
145
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
146
|
+
* List of media conditions.
|
|
147
|
+
* @example ['Mint (M)', 'Very Good Plus (VG+)']
|
|
81
148
|
*/
|
|
82
|
-
|
|
149
|
+
conditions?: Array<Condition>;
|
|
83
150
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @example '
|
|
151
|
+
* List of genres.
|
|
152
|
+
* @example ['Rock']
|
|
86
153
|
*/
|
|
87
|
-
|
|
154
|
+
genres?: Array<Genre>;
|
|
88
155
|
/**
|
|
89
|
-
*
|
|
156
|
+
* Expedition country filter.
|
|
157
|
+
* @example 'France'
|
|
90
158
|
*/
|
|
91
|
-
|
|
159
|
+
from?: Array<From>;
|
|
92
160
|
/**
|
|
93
161
|
* Sort order for the results.
|
|
94
162
|
* @default 'listed,desc'
|
|
95
163
|
*/
|
|
96
|
-
sort?: Sort
|
|
164
|
+
sort?: Exclude<Sort, 'label,asc' | 'label,desc'>;
|
|
97
165
|
/**
|
|
98
|
-
*
|
|
99
|
-
* Allowed values: 25, 50, 100, 250.
|
|
100
|
-
* @default 25
|
|
166
|
+
* List of artist IDs.
|
|
101
167
|
*/
|
|
102
|
-
|
|
168
|
+
artistIds?: Array<number>;
|
|
103
169
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
170
|
+
* List of seller IDs.
|
|
171
|
+
*
|
|
172
|
+
* You can easily find someone's ID via the Discogs API: https://api.discogs.com/users/{seller_name}
|
|
107
173
|
*/
|
|
108
|
-
|
|
174
|
+
sellerIds?: Array<number>;
|
|
109
175
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @default 'en'
|
|
176
|
+
* Price range filter.
|
|
112
177
|
*/
|
|
113
|
-
|
|
178
|
+
priceRange?: {
|
|
179
|
+
/** Minimum price */
|
|
180
|
+
min: number;
|
|
181
|
+
/** Maximum price */
|
|
182
|
+
max: number;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Minimum seller rating, from 0 to 100.
|
|
186
|
+
* @default 0
|
|
187
|
+
*/
|
|
188
|
+
sellerRatingMin?: number;
|
|
189
|
+
/**
|
|
190
|
+
* Include generic sleeves.
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
includeGenericSleeves?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Include sleeveless media.
|
|
196
|
+
* @default true
|
|
197
|
+
*/
|
|
198
|
+
includeSleevelessMedia?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Show unavailable items.
|
|
201
|
+
* @default true
|
|
202
|
+
*/
|
|
203
|
+
showUnavailable?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Minimum seller rating count.
|
|
206
|
+
* @default 0
|
|
207
|
+
*/
|
|
208
|
+
sellerRatingCountMin?: number;
|
|
114
209
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
210
|
+
/**
|
|
211
|
+
* Parameters used to search listings on the Discogs Marketplace via new new modern API.
|
|
212
|
+
*/
|
|
213
|
+
export type SearchParamsModern = ({
|
|
214
|
+
/** User's wantlist name. */
|
|
215
|
+
wantlist?: string;
|
|
216
|
+
releaseIds?: never;
|
|
217
|
+
} | {
|
|
218
|
+
wantlist?: never;
|
|
219
|
+
/** List of release IDs. */
|
|
220
|
+
releaseIds?: Array<number>;
|
|
221
|
+
}) & SearchParamsModernBase;
|
|
222
|
+
export type SearchParams = SearchParamsLegacy | SearchParamsModern;
|
|
223
|
+
export {};
|
|
@@ -8,29 +8,47 @@ export default interface SearchResult {
|
|
|
8
8
|
items: Array<{
|
|
9
9
|
/** Unique identifier for the listing */
|
|
10
10
|
id: number;
|
|
11
|
-
/**
|
|
12
|
-
title:
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/** Full title of the listing */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Artists details */
|
|
14
|
+
artists: Array<{
|
|
15
|
+
/** Artist ID */
|
|
16
|
+
id: number | null;
|
|
15
17
|
/** Artist name */
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
name: string;
|
|
19
|
+
/** Artist URL */
|
|
20
|
+
url: string | null;
|
|
21
|
+
}>;
|
|
22
|
+
/** Release details */
|
|
23
|
+
release: {
|
|
24
|
+
/** Release ID */
|
|
25
|
+
id: number;
|
|
26
|
+
/** Release name */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Release URL */
|
|
29
|
+
url: string;
|
|
21
30
|
};
|
|
31
|
+
/** List of formats */
|
|
32
|
+
formats: Array<string>;
|
|
33
|
+
/** labels */
|
|
34
|
+
labels: Array<{
|
|
35
|
+
/** Label ID */
|
|
36
|
+
id: number;
|
|
37
|
+
/** Label name */
|
|
38
|
+
name: string;
|
|
39
|
+
/** Label URL */
|
|
40
|
+
url: string;
|
|
41
|
+
}>;
|
|
22
42
|
/** URL to the listing on Discogs */
|
|
23
43
|
url: string;
|
|
24
44
|
/** Date the item was listed */
|
|
25
45
|
listedAt: Date | null;
|
|
26
|
-
/** Array of label names */
|
|
27
|
-
labels: Array<string>;
|
|
28
46
|
/** Array of catalog numbers */
|
|
29
47
|
catnos: Array<string>;
|
|
30
48
|
/** URL to the item's image */
|
|
31
|
-
imageUrl: string;
|
|
49
|
+
imageUrl: string | null;
|
|
32
50
|
/** Text description of the item */
|
|
33
|
-
description: string;
|
|
51
|
+
description: string | null;
|
|
34
52
|
/** Indicates if offers are accepted */
|
|
35
53
|
isAcceptingOffer: boolean;
|
|
36
54
|
/** Availability status of the item */
|
|
@@ -47,9 +65,9 @@ export default interface SearchResult {
|
|
|
47
65
|
/** Sleeve condition */
|
|
48
66
|
sleeve: {
|
|
49
67
|
/** Full description */
|
|
50
|
-
full: string;
|
|
68
|
+
full: string | null;
|
|
51
69
|
/** Short code */
|
|
52
|
-
short: string;
|
|
70
|
+
short: string | null;
|
|
53
71
|
};
|
|
54
72
|
};
|
|
55
73
|
/** Seller information */
|
|
@@ -59,9 +77,9 @@ export default interface SearchResult {
|
|
|
59
77
|
/** Seller's profile URL */
|
|
60
78
|
url: string;
|
|
61
79
|
/** Seller rating/score */
|
|
62
|
-
score: string;
|
|
80
|
+
score: string | null;
|
|
63
81
|
/** Number of notes/reviews */
|
|
64
|
-
notes: number;
|
|
82
|
+
notes: number | null;
|
|
65
83
|
};
|
|
66
84
|
/** Pricing details */
|
|
67
85
|
price: {
|
|
@@ -69,12 +87,12 @@ export default interface SearchResult {
|
|
|
69
87
|
* Base price as a string combining amount and currency.
|
|
70
88
|
* @example '12.34 USD'
|
|
71
89
|
*/
|
|
72
|
-
base: `${number} ${CurrencyValues}
|
|
90
|
+
base: `${number} ${CurrencyValues}`;
|
|
73
91
|
/**
|
|
74
92
|
* Shipping cost as a string combining amount and currency.
|
|
75
93
|
* @example '5.67 USD'
|
|
76
94
|
*/
|
|
77
|
-
shipping: `${number} ${CurrencyValues}` |
|
|
95
|
+
shipping: `${number} ${CurrencyValues}` | null;
|
|
78
96
|
};
|
|
79
97
|
/** Shipping origin country */
|
|
80
98
|
country: {
|
|
@@ -93,13 +111,6 @@ export default interface SearchResult {
|
|
|
93
111
|
/** Number of users who want this item */
|
|
94
112
|
want: number;
|
|
95
113
|
};
|
|
96
|
-
/** Release details */
|
|
97
|
-
release: {
|
|
98
|
-
/** Release ID */
|
|
99
|
-
id: number;
|
|
100
|
-
/** Release URL */
|
|
101
|
-
url: string;
|
|
102
|
-
};
|
|
103
114
|
}>;
|
|
104
115
|
/** Pagination information */
|
|
105
116
|
page: {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type SearchResult from '../interfaces/search-result.interface.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SearchParamsLegacy } from '../interfaces/search-params.interface.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parses the page and returns the items found.
|
|
5
5
|
* @param url Url to scrape
|
|
6
6
|
* @returns Items found and total
|
|
7
7
|
*/
|
|
8
|
-
export default function scrapeLegacy({
|
|
8
|
+
export default function scrapeLegacy({ currency, genre, styles, formats, formatDescriptions, condition, years, isMakeAnOfferOnly, from, sort, limit, page, seller, lang, masterId, labelId, artistId, releaseId, user, query, }: SearchParamsLegacy): Promise<Pick<SearchResult, 'items' | 'urlGenerated'> & {
|
|
9
9
|
/** Total items found */
|
|
10
10
|
total: SearchResult['result']['total'];
|
|
11
11
|
}>;
|
|
@@ -7,39 +7,21 @@ exports.default = scrapeLegacy;
|
|
|
7
7
|
const linkedom_1 = require("linkedom");
|
|
8
8
|
const currency_data_1 = __importDefault(require("../data/currency.data.js"));
|
|
9
9
|
const country_data_1 = __importDefault(require("../data/country.data.js"));
|
|
10
|
+
const search_1 = require("../search.js");
|
|
10
11
|
/**
|
|
11
12
|
* Generate URL to be parsed
|
|
12
13
|
* @returns Url
|
|
13
14
|
*/
|
|
14
|
-
function generateUrl({
|
|
15
|
+
function generateUrl({ seller, lang, user, }) {
|
|
15
16
|
const baseUrl = `https://www.discogs.com/${lang}`;
|
|
16
17
|
if (seller) {
|
|
17
|
-
const path =
|
|
18
|
+
const path = user ? 'mywants' : 'profile';
|
|
18
19
|
return `${baseUrl}/seller/${seller}/${path}`;
|
|
19
20
|
}
|
|
20
21
|
else {
|
|
21
|
-
|
|
22
|
-
return `${baseUrl}/sell/${path}`;
|
|
22
|
+
return `${baseUrl}/sell/list`;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Serialize params URL
|
|
27
|
-
* @param params Object of GET parameters
|
|
28
|
-
* @returns Url
|
|
29
|
-
*/
|
|
30
|
-
function serializeParams(params) {
|
|
31
|
-
return Object.entries(params)
|
|
32
|
-
.flatMap(([key, value]) => {
|
|
33
|
-
if (value === undefined || value === null) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
return value.map(v => `${key}=${encodeURIComponent(v)}`);
|
|
38
|
-
}
|
|
39
|
-
return [`${key}=${encodeURIComponent(value)}`];
|
|
40
|
-
})
|
|
41
|
-
.join('&');
|
|
42
|
-
}
|
|
43
25
|
/**
|
|
44
26
|
* Converts a currency string to a standardized format.
|
|
45
27
|
* @param value String to clean
|
|
@@ -47,22 +29,22 @@ function serializeParams(params) {
|
|
|
47
29
|
*/
|
|
48
30
|
function convertCurrency(value) {
|
|
49
31
|
if (!value) {
|
|
50
|
-
return
|
|
32
|
+
return null;
|
|
51
33
|
}
|
|
52
34
|
const currencyFound = Object.keys(currency_data_1.default).find(key => value.includes(key));
|
|
53
35
|
if (!currencyFound) {
|
|
54
|
-
return
|
|
36
|
+
return null;
|
|
55
37
|
}
|
|
56
38
|
const currencyClean = currency_data_1.default[currencyFound];
|
|
57
39
|
const amount = value
|
|
58
40
|
.replace(currencyClean !== 'JPY' ? /[.](?=.*[.])/g : /\./g, '') // Remove all dots but the last, except for JPY
|
|
59
41
|
.replace(currencyFound, '') // Remove original currency
|
|
60
42
|
.replace(/\s\s+/g, ''); // Remove spaces
|
|
61
|
-
const amountParsed = Number.parseFloat(amount);
|
|
43
|
+
const amountParsed = currencyClean === 'JPY' ? Number.parseInt(amount) : Number.parseFloat(amount);
|
|
62
44
|
if (Number.isNaN(amountParsed)) {
|
|
63
|
-
return
|
|
45
|
+
return null;
|
|
64
46
|
}
|
|
65
|
-
return `${amountParsed} ${currencyClean}`;
|
|
47
|
+
return currencyClean === 'JPY' ? `${amountParsed} ${currencyClean}` : `${amountParsed.toFixed(2)} ${currencyClean}`;
|
|
66
48
|
}
|
|
67
49
|
/**
|
|
68
50
|
* Safely parses a number from a string.
|
|
@@ -78,34 +60,42 @@ function safeParseInt(value) {
|
|
|
78
60
|
* @param url Url to scrape
|
|
79
61
|
* @returns Items found and total
|
|
80
62
|
*/
|
|
81
|
-
async function scrapeLegacy({
|
|
63
|
+
async function scrapeLegacy({ currency, genre, styles, formats, formatDescriptions, condition, years, isMakeAnOfferOnly = false, from, sort = search_1.DEFAULT_SORT, limit = search_1.DEFAULT_LIMIT, page = search_1.DEFAULT_PAGE, seller, lang = 'en', masterId, labelId, artistId, releaseId, user, query, }) {
|
|
82
64
|
/** Url to be called by the browser */
|
|
83
65
|
const urlGenerated = [
|
|
84
|
-
generateUrl({
|
|
85
|
-
|
|
86
|
-
[
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
66
|
+
generateUrl({ seller, lang, user }),
|
|
67
|
+
new URLSearchParams([
|
|
68
|
+
['master_id', masterId?.toString() ?? ''],
|
|
69
|
+
['label_id', labelId?.toString() ?? ''],
|
|
70
|
+
['artist_id', artistId?.toString() ?? ''],
|
|
71
|
+
['release_id', releaseId?.toString() ?? ''],
|
|
72
|
+
['user', user?.toString() ?? ''],
|
|
73
|
+
['q', query ?? ''],
|
|
74
|
+
['currency', currency ?? ''],
|
|
75
|
+
['genre', genre ?? ''],
|
|
76
|
+
...(styles?.map(s => ['style', s]) ?? []),
|
|
77
|
+
...(formats?.map(f => ['format', f]) ?? []),
|
|
78
|
+
...(formatDescriptions?.map(fd => ['format_desc', fd]) ?? []),
|
|
79
|
+
['condition', condition ?? ''],
|
|
80
|
+
['year1', years?.min ? years.min.toString() : ''],
|
|
81
|
+
['year2', years?.max ? years.max.toString() : ''],
|
|
82
|
+
['offers', isMakeAnOfferOnly ? '1' : ''],
|
|
83
|
+
['ships_from', Object.keys(country_data_1.default).find(key => from === country_data_1.default[key]) ?? ''],
|
|
84
|
+
['limit', limit.toString()],
|
|
85
|
+
['page', page.toString()],
|
|
86
|
+
['sort', sort],
|
|
87
|
+
].filter(([, p]) => !!p)).toString(),
|
|
102
88
|
].join('?');
|
|
89
|
+
const headers = new Headers({
|
|
90
|
+
'User-Agent': 'Discogs',
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
});
|
|
93
|
+
// If there a seller and user, we cannot use PJAX otherwise 404 error
|
|
94
|
+
if (!(seller && user)) {
|
|
95
|
+
headers.set('X-PJAX', 'true');
|
|
96
|
+
}
|
|
103
97
|
const response = await globalThis.fetch(urlGenerated, {
|
|
104
|
-
headers
|
|
105
|
-
'User-Agent': 'Discogs',
|
|
106
|
-
'Content-Type': 'application/json',
|
|
107
|
-
'X-PJAX': 'true',
|
|
108
|
-
},
|
|
98
|
+
headers,
|
|
109
99
|
referrer: 'https://discogs.com',
|
|
110
100
|
});
|
|
111
101
|
const content = await response.text();
|
|
@@ -139,26 +129,38 @@ async function scrapeLegacy({ searchType, searchValue, currency, genre, style, f
|
|
|
139
129
|
const releaseHref = el.querySelector('a.item_release_link')?.getAttribute('href') ?? '';
|
|
140
130
|
return {
|
|
141
131
|
id: safeParseInt(itemHref.split('/').pop()),
|
|
142
|
-
title:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
title: originalTitle,
|
|
133
|
+
artists: [
|
|
134
|
+
{
|
|
135
|
+
id: null,
|
|
136
|
+
name: firstIndexOfDash > -1 ? originalTitle.substring(0, firstIndexOfDash) : '',
|
|
137
|
+
url: null,
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
release: {
|
|
141
|
+
id: safeParseInt(releaseHref.split('release/').pop()?.split('-').shift()),
|
|
142
|
+
name: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
|
|
146
143
|
? originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)
|
|
147
144
|
: '',
|
|
148
|
-
|
|
149
|
-
? originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1).split(', ')
|
|
150
|
-
: [],
|
|
145
|
+
url: `https://www.discogs.com${releaseHref}`,
|
|
151
146
|
},
|
|
147
|
+
formats: lastIndexOfParenthesis > -1
|
|
148
|
+
? originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1).split(', ')
|
|
149
|
+
: [],
|
|
150
|
+
labels: [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]
|
|
151
|
+
.map(x => ({
|
|
152
|
+
id: safeParseInt(x.getAttribute('href')?.split('label/').pop()?.split('-').shift()),
|
|
153
|
+
name: x.textContent?.trim() ?? '',
|
|
154
|
+
url: `https://www.discogs.com${x.getAttribute('href') ?? ''}`,
|
|
155
|
+
}))
|
|
156
|
+
.filter((value, index, self) => self.findIndex(v => v.name === value.name) === index),
|
|
152
157
|
url: `https://www.discogs.com${itemHref}`,
|
|
153
158
|
listedAt: null,
|
|
154
|
-
labels: [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]
|
|
155
|
-
.map(x => x.textContent?.trim() ?? '')
|
|
156
|
-
.filter((value, index, self) => self.indexOf(value) === index),
|
|
157
159
|
catnos: getTextContent('.label_and_cat .item_catno', el) // cspell:disable-line
|
|
158
160
|
.split(', ')
|
|
159
161
|
.filter(x => x !== 'none'),
|
|
160
|
-
imageUrl: el.querySelector('.marketplace_image')?.getAttribute('data-src') ??
|
|
161
|
-
description: getTextContent('.item_condition + *', el),
|
|
162
|
+
imageUrl: el.querySelector('.marketplace_image')?.getAttribute('data-src') ?? null,
|
|
163
|
+
description: getTextContent('.item_condition + *', el) || null,
|
|
162
164
|
isAcceptingOffer: getTextContent('.item_add_to_cart p a strong', el).split('/').length > 1,
|
|
163
165
|
isAvailable: !el.classList.contains('unavailable'),
|
|
164
166
|
condition: {
|
|
@@ -167,17 +169,18 @@ async function scrapeLegacy({ searchType, searchValue, currency, genre, style, f
|
|
|
167
169
|
short: /\(([^)]+)\)/.exec(mediaCondition)?.[1] ?? '',
|
|
168
170
|
},
|
|
169
171
|
sleeve: {
|
|
170
|
-
full: sleeveCondition,
|
|
171
|
-
short: /\(([^)]+)\)/.exec(sleeveCondition)?.[1] ??
|
|
172
|
+
full: sleeveCondition || null,
|
|
173
|
+
short: /\(([^)]+)\)/.exec(sleeveCondition)?.[1] ?? null,
|
|
172
174
|
},
|
|
173
175
|
},
|
|
174
176
|
seller: {
|
|
175
177
|
name: getTextContent('.seller_info a', el),
|
|
176
178
|
url: `https://www.discogs.com${el.querySelector('.seller_info a')?.getAttribute('href') ?? ''}`,
|
|
177
|
-
score: getTextContent('.seller_info li:nth-child(2) strong', el),
|
|
178
|
-
notes: safeParseInt(getTextContent('.seller_info li:nth-child(2) .section_link', el)),
|
|
179
|
+
score: getTextContent('.seller_info li:nth-child(2) strong', el) || null,
|
|
180
|
+
notes: safeParseInt(getTextContent('.seller_info li:nth-child(2) .section_link', el)) || null,
|
|
179
181
|
},
|
|
180
182
|
price: {
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
181
184
|
base: convertCurrency(getTextContent('.price', el).replace(/,/, '.')),
|
|
182
185
|
shipping: convertCurrency(getTextContent('.item_shipping', el)
|
|
183
186
|
.replace(/(\s+|\+)/g, ' ')
|
|
@@ -191,10 +194,6 @@ async function scrapeLegacy({ searchType, searchValue, currency, genre, style, f
|
|
|
191
194
|
have: safeParseInt(getTextContent('.community_summary .community_result:nth-child(1) .community_number', el)),
|
|
192
195
|
want: safeParseInt(getTextContent('.community_summary .community_result:nth-child(2) .community_number', el)),
|
|
193
196
|
},
|
|
194
|
-
release: {
|
|
195
|
-
id: safeParseInt(releaseHref.split('release/').pop()?.split('-').shift()),
|
|
196
|
-
url: `https://www.discogs.com${releaseHref}`,
|
|
197
|
-
},
|
|
198
197
|
};
|
|
199
198
|
});
|
|
200
199
|
return { total, items, urlGenerated };
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type SearchResult from '../interfaces/search-result.interface.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SearchParamsModern } from '../interfaces/search-params.interface.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parses the page and returns the items found.
|
|
5
5
|
* @param SearchParams Search parameters
|
|
6
6
|
* @returns Items found and total
|
|
7
7
|
*/
|
|
8
|
-
export default function scrape({
|
|
9
|
-
/** Releases */
|
|
10
|
-
releases?: Array<number>;
|
|
11
|
-
}): Promise<Pick<SearchResult, 'items' | 'urlGenerated'> & {
|
|
8
|
+
export default function scrape({ currencies, genres, formats, formatDescriptions, conditions, years, isMakeAnOfferOnly, from, sort, limit, page, releaseIds, sellerIds, artistIds, priceRange, sellerRatingMin, includeGenericSleeves, includeSleevelessMedia, showUnavailable, sellerRatingCountMin, }: SearchParamsModern): Promise<Pick<SearchResult, 'items' | 'urlGenerated'> & {
|
|
12
9
|
/** Total items found */
|
|
13
10
|
total: SearchResult['result']['total'];
|
|
14
11
|
}>;
|