discogs-marketplace-api-nodejs 1.3.1 → 1.3.5
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/LICENSE +20 -20
- package/README.MD +217 -197
- package/dist/enum/ECurrency.d.ts +18 -19
- package/dist/enum/ECurrency.js +21 -23
- package/dist/enum/EFormat.d.ts +59 -60
- package/dist/enum/EFormat.js +62 -64
- package/dist/enum/EFormatDescription.d.ts +144 -145
- package/dist/enum/EFormatDescription.js +147 -149
- package/dist/enum/EFrom.d.ts +251 -252
- package/dist/enum/EFrom.js +255 -256
- package/dist/enum/EFromIso.d.ts +316 -316
- package/dist/enum/EFromIso.js +321 -321
- package/dist/enum/EGenre.d.ts +21 -22
- package/dist/enum/EGenre.js +24 -26
- package/dist/enum/ELang.d.ts +15 -16
- package/dist/enum/ELang.js +18 -20
- package/dist/enum/EMediaCondition.d.ts +14 -15
- package/dist/enum/EMediaCondition.js +17 -19
- package/dist/enum/ESort.d.ts +62 -63
- package/dist/enum/ESort.js +65 -67
- package/dist/enum/EStyle.d.ts +255 -256
- package/dist/enum/EStyle.js +258 -260
- package/dist/enum/EType.d.ts +30 -31
- package/dist/enum/EType.js +33 -35
- package/dist/enum/iso/ECountryCode.d.ts +255 -0
- package/dist/enum/iso/ECountryCode.js +258 -0
- package/dist/enum/iso/ECountryName.d.ts +255 -0
- package/dist/enum/iso/ECountryName.js +258 -0
- package/dist/enum/iso/EDiscogsCountryNameToIsoCode.d.ts +69 -0
- package/dist/enum/iso/EDiscogsCountryNameToIsoCode.js +72 -0
- package/dist/enum/iso/EDiscogsCurrencyToIsoCode.d.ts +23 -0
- package/dist/enum/iso/EDiscogsCurrencyToIsoCode.js +26 -0
- package/dist/enum/iso/translate/EDiscogsCountryNameToIsoCode.d.ts +69 -0
- package/dist/enum/iso/translate/EDiscogsCountryNameToIsoCode.js +72 -0
- package/dist/enum/iso/translate/EDiscogsCurrencyToIsoCode.d.ts +23 -0
- package/dist/enum/iso/translate/EDiscogsCurrencyToIsoCode.js +26 -0
- package/dist/enum/iso/translates/EDiscogsCountryNameToIsoCode.d.ts +69 -0
- package/dist/enum/iso/translates/EDiscogsCountryNameToIsoCode.js +72 -0
- package/dist/enum/iso/translates/EDiscogsCurrencyToIsoCode.d.ts +23 -0
- package/dist/enum/iso/translates/EDiscogsCurrencyToIsoCode.js +26 -0
- package/dist/index.d.ts +22 -22
- package/dist/index.js +40 -39
- package/dist/interface/IDiscogsMarketplace.d.ts +11 -12
- package/dist/interface/IDiscogsMarketplace.js +7 -7
- package/dist/interface/IInput.d.ts +89 -89
- package/dist/interface/IInput.js +17 -6
- package/dist/interface/IItem.d.ts +54 -48
- package/dist/interface/IItem.js +7 -2
- package/dist/interface/IOutputError.d.ts +7 -7
- package/dist/interface/IOutputError.js +2 -2
- package/dist/interface/IOutputSuccess.d.ts +21 -21
- package/dist/interface/IOutputSuccess.js +7 -6
- package/dist/interface/IYears.d.ts +7 -7
- package/dist/interface/IYears.js +2 -2
- package/dist/marketplace.d.ts +56 -70
- package/dist/marketplace.js +290 -286
- package/dist/type/TLimit.d.ts +5 -6
- package/dist/type/TLimit.js +2 -2
- package/package.json +52 -45
- package/.gitattributes +0 -1
- package/notes.md +0 -9
- package/tsconfig.build.json +0 -40
package/dist/marketplace.js
CHANGED
|
@@ -1,286 +1,290 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
'
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ECountryCode_1 = __importDefault(require("./enum/iso/ECountryCode"));
|
|
16
|
+
const ECountryName_1 = __importDefault(require("./enum/iso/ECountryName"));
|
|
17
|
+
const ECurrency_1 = __importDefault(require("./enum/ECurrency"));
|
|
18
|
+
const EFormat_1 = __importDefault(require("./enum/EFormat"));
|
|
19
|
+
const EFormatDescription_1 = __importDefault(require("./enum/EFormatDescription"));
|
|
20
|
+
const EFrom_1 = __importDefault(require("./enum/EFrom"));
|
|
21
|
+
const EGenre_1 = __importDefault(require("./enum/EGenre"));
|
|
22
|
+
const ELang_1 = __importDefault(require("./enum/ELang"));
|
|
23
|
+
const EMediaCondition_1 = __importDefault(require("./enum/EMediaCondition"));
|
|
24
|
+
const ESort_1 = __importDefault(require("./enum/ESort"));
|
|
25
|
+
const EStyle_1 = __importDefault(require("./enum/EStyle"));
|
|
26
|
+
const EType_1 = __importDefault(require("./enum/EType"));
|
|
27
|
+
const IInput_1 = __importDefault(require("./interface/IInput"));
|
|
28
|
+
const IOutputError_1 = __importDefault(require("./interface/IOutputError"));
|
|
29
|
+
const IOutputSuccess_1 = __importDefault(require("./interface/IOutputSuccess"));
|
|
30
|
+
const IYears_1 = __importDefault(require("./interface/IYears"));
|
|
31
|
+
const TLimit_1 = __importDefault(require("./type/TLimit"));
|
|
32
|
+
const playwright_chromium_1 = require("playwright-chromium");
|
|
33
|
+
const user_agents_1 = __importDefault(require("user-agents"));
|
|
34
|
+
const EDiscogsCurrencyToIsoCode_1 = __importDefault(require("./enum/iso/translate/EDiscogsCurrencyToIsoCode"));
|
|
35
|
+
const EDiscogsCountryNameToIsoCode_1 = __importDefault(require("./enum/iso/translate/EDiscogsCountryNameToIsoCode"));
|
|
36
|
+
const linkedom_1 = require("linkedom");
|
|
37
|
+
/**
|
|
38
|
+
* Discogs Marketplace
|
|
39
|
+
*/
|
|
40
|
+
class Marketplace {
|
|
41
|
+
constructor({ searchType = EType_1.default.STRING, searchValue = undefined, currency = undefined, genre = undefined, style = [], format = [], formatDescription = [], mediaCondition = [], year = undefined, years = undefined, isAudioSample = false, isMakeAnOfferOnly = false, from = undefined, seller = undefined, sort = ESort_1.default.LISTED_NEWEST, limit = 25, page = 1, lang = ELang_1.default.ENGLISH, }) {
|
|
42
|
+
/** Url generated by Playwright */
|
|
43
|
+
this.url = '';
|
|
44
|
+
this.searchType = searchType;
|
|
45
|
+
this.searchValue = searchValue;
|
|
46
|
+
this.currency = currency;
|
|
47
|
+
this.genre = genre;
|
|
48
|
+
this.style = style;
|
|
49
|
+
this.format = format;
|
|
50
|
+
this.formatDescription = formatDescription;
|
|
51
|
+
this.mediaCondition = mediaCondition;
|
|
52
|
+
this.year = year;
|
|
53
|
+
this.years = years;
|
|
54
|
+
this.isAudioSample = isAudioSample;
|
|
55
|
+
this.isMakeAnOfferOnly = isMakeAnOfferOnly;
|
|
56
|
+
this.from = from;
|
|
57
|
+
this.seller = seller;
|
|
58
|
+
this.sort = sort;
|
|
59
|
+
this.limit = limit;
|
|
60
|
+
this.page = page;
|
|
61
|
+
this.lang = lang;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Search elements on discogs
|
|
65
|
+
* @returns Items found
|
|
66
|
+
*/
|
|
67
|
+
search() {
|
|
68
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
try {
|
|
71
|
+
/** Init browser */
|
|
72
|
+
const browser = yield playwright_chromium_1.chromium.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
|
|
73
|
+
/** Init context */
|
|
74
|
+
const context = yield browser.newContext({
|
|
75
|
+
userAgent: new user_agents_1.default().toString(),
|
|
76
|
+
});
|
|
77
|
+
/** Init page */
|
|
78
|
+
const page = yield context.newPage();
|
|
79
|
+
/** Block useless ressources */
|
|
80
|
+
yield page.route('**/*', route => ([
|
|
81
|
+
'stylesheet',
|
|
82
|
+
'image',
|
|
83
|
+
'media',
|
|
84
|
+
'font',
|
|
85
|
+
'script',
|
|
86
|
+
'texttrack',
|
|
87
|
+
'xhr',
|
|
88
|
+
'fetch',
|
|
89
|
+
'eventsource',
|
|
90
|
+
'websocket',
|
|
91
|
+
'manifest',
|
|
92
|
+
'other',
|
|
93
|
+
].includes(route.request().resourceType()) ? route.abort() : route.continue()));
|
|
94
|
+
/** Init page */
|
|
95
|
+
const response = yield page.goto(`${this.generateUrl()}?${this.serializeParams({
|
|
96
|
+
[this.searchType]: this.searchValue,
|
|
97
|
+
currency: this.currency,
|
|
98
|
+
genre: this.genre,
|
|
99
|
+
style: ((_a = this.style) === null || _a === void 0 ? void 0 : _a.length) ? this.style : undefined,
|
|
100
|
+
format: ((_b = this.format) === null || _b === void 0 ? void 0 : _b.length) ? (_c = this.format) === null || _c === void 0 ? void 0 : _c[0] : undefined,
|
|
101
|
+
format_desc: ((_d = this.formatDescription) === null || _d === void 0 ? void 0 : _d.length) ? this.formatDescription[0] : undefined,
|
|
102
|
+
condition: ((_e = this.mediaCondition) === null || _e === void 0 ? void 0 : _e.length) ? this.mediaCondition[0] : undefined,
|
|
103
|
+
year: this.year && !this.years ? this.year : undefined,
|
|
104
|
+
year1: ((_f = this.years) === null || _f === void 0 ? void 0 : _f.min) && !this.year ? (_g = this.years) === null || _g === void 0 ? void 0 : _g.min : undefined,
|
|
105
|
+
year2: ((_h = this.years) === null || _h === void 0 ? void 0 : _h.max) && !this.year ? (_j = this.years) === null || _j === void 0 ? void 0 : _j.max : undefined,
|
|
106
|
+
audio: this.isAudioSample ? 1 : 0,
|
|
107
|
+
offers: this.isMakeAnOfferOnly ? 1 : 0,
|
|
108
|
+
ships_from: ((_k = this.from) === null || _k === void 0 ? void 0 : _k.length) ? this.from : undefined,
|
|
109
|
+
limit: this.limit,
|
|
110
|
+
page: this.page,
|
|
111
|
+
sort: this.sort,
|
|
112
|
+
})}`);
|
|
113
|
+
/** Get url */
|
|
114
|
+
this.url = page.url();
|
|
115
|
+
/** Get HTML */
|
|
116
|
+
const bodyHTML = yield page.evaluate(() => { var _a; return (_a = document.querySelector('table.table_block')) === null || _a === void 0 ? void 0 : _a.outerHTML; });
|
|
117
|
+
/** Close browser */
|
|
118
|
+
yield browser.close();
|
|
119
|
+
/** If error, reject */
|
|
120
|
+
if (((_l = response === null || response === void 0 ? void 0 : response.status()) !== null && _l !== void 0 ? _l : 0) >= 400)
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
122
|
+
throw { document: bodyHTML, status: (_m = response === null || response === void 0 ? void 0 : response.status()) !== null && _m !== void 0 ? _m : 0 };
|
|
123
|
+
return this.getItem((0, linkedom_1.parseHTML)(bodyHTML).document);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if ((error === null || error === void 0 ? void 0 : error.document) && error.status)
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
128
|
+
throw {
|
|
129
|
+
message: (_r = (_q = (_p = (_o = (0, linkedom_1.parseHTML)(error.document).document) === null || _o === void 0 ? void 0 : _o.querySelector('h1 + p')) === null || _p === void 0 ? void 0 : _p.innerHTML) === null || _q === void 0 ? void 0 : _q.trim()) !== null && _r !== void 0 ? _r : 'An error occured',
|
|
130
|
+
code: error.status,
|
|
131
|
+
};
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
133
|
+
throw {
|
|
134
|
+
message: 'An error occured',
|
|
135
|
+
code: 500,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Generate URL to be parsed
|
|
142
|
+
* @returns Url
|
|
143
|
+
*/
|
|
144
|
+
generateUrl() {
|
|
145
|
+
let url = `https://www.discogs.com/${this.lang}/`;
|
|
146
|
+
if (this.seller) {
|
|
147
|
+
url += `seller/${this.seller}/`;
|
|
148
|
+
url += this.searchType === EType_1.default.USER ? 'mywants' : 'profile';
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
url += 'sell/';
|
|
152
|
+
url += this.searchType === EType_1.default.USER ? 'mywants' : 'list';
|
|
153
|
+
}
|
|
154
|
+
return url;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Serialize params URL
|
|
158
|
+
* @param params Object of GET parameters
|
|
159
|
+
* @returns Url
|
|
160
|
+
*/
|
|
161
|
+
// eslint-disable-next-line class-methods-use-this
|
|
162
|
+
serializeParams(params) {
|
|
163
|
+
const param = [];
|
|
164
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
165
|
+
for (const key in params)
|
|
166
|
+
if (params[key] === undefined || params[key] === null)
|
|
167
|
+
// eslint-disable-next-line no-continue
|
|
168
|
+
continue;
|
|
169
|
+
else if (Array.isArray(params[key]))
|
|
170
|
+
/** Custom handle for array */
|
|
171
|
+
if (params[key].length > 0)
|
|
172
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
173
|
+
for (const el of params[key])
|
|
174
|
+
param.push(`${key}=${encodeURIComponent(el)}`);
|
|
175
|
+
else
|
|
176
|
+
// eslint-disable-next-line no-continue
|
|
177
|
+
continue;
|
|
178
|
+
else
|
|
179
|
+
param.push(`${key}=${encodeURIComponent(params[key])}`);
|
|
180
|
+
return param.join('&');
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Function to convert devise to ISO name
|
|
184
|
+
* @param str String to clean
|
|
185
|
+
* @returns Cleanup string
|
|
186
|
+
*/
|
|
187
|
+
// eslint-disable-next-line class-methods-use-this
|
|
188
|
+
convertDevise(value) {
|
|
189
|
+
var _a;
|
|
190
|
+
if (!value)
|
|
191
|
+
return value;
|
|
192
|
+
const currency = (_a = Object.keys(EDiscogsCurrencyToIsoCode_1.default).find(key => value.includes(key))) !== null && _a !== void 0 ? _a : '';
|
|
193
|
+
if (!currency)
|
|
194
|
+
return value;
|
|
195
|
+
return `${value.replace(currency, '')} ${EDiscogsCurrencyToIsoCode_1.default[currency]}`.replace(/\s\s+/g, ' ');
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Parse HTML to clean result
|
|
199
|
+
* @param document Document to parse
|
|
200
|
+
* @returns Items found
|
|
201
|
+
*/
|
|
202
|
+
getItem(document) {
|
|
203
|
+
var _a, _b, _c, _d, _e, _f;
|
|
204
|
+
const totalItems = parseFloat(((_d = (_c = (_b = (_a = document.querySelector('.pagination_total')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.split(' ')) === null || _c === void 0 ? void 0 : _c.filter((x) => x).pop()) === null || _d === void 0 ? void 0 : _d.replace(/(,|\.|\s)/g, '')) || '0');
|
|
205
|
+
return {
|
|
206
|
+
items: ((_e = [...document.querySelectorAll('table.table_block tbody tr')]) === null || _e === void 0 ? void 0 : _e.map(el => {
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59;
|
|
208
|
+
const shipping = this.convertDevise((_g = (_f = (_e = (_d = (_c = (_b = (_a = el.querySelector('.item_shipping')) === null || _a === void 0 ? void 0 : _a.childNodes) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.replace(/(\s+|\+)/g, ' ')) === null || _e === void 0 ? void 0 : _e.trim()) === null || _f === void 0 ? void 0 : _f.replace(',', '.')) !== null && _g !== void 0 ? _g : '');
|
|
209
|
+
const have = Number.parseInt((_j = (_h = el.querySelector('.community_summary .community_result:nth-child(1) .community_number')) === null || _h === void 0 ? void 0 : _h.textContent) !== null && _j !== void 0 ? _j : '', 10);
|
|
210
|
+
const want = Number.parseInt((_l = (_k = el.querySelector('.community_summary .community_result:nth-child(2) .community_number')) === null || _k === void 0 ? void 0 : _k.textContent) !== null && _l !== void 0 ? _l : '', 10);
|
|
211
|
+
const countryName = (_q = (_p = (_o = (_m = el.querySelector('.seller_info li:nth-child(3)')) === null || _m === void 0 ? void 0 : _m.textContent) === null || _o === void 0 ? void 0 : _o.split(':')) === null || _p === void 0 ? void 0 : _p[1]) !== null && _q !== void 0 ? _q : '';
|
|
212
|
+
const isoCountryCode = (Object.keys(ECountryCode_1.default).find((key) => (ECountryName_1.default[key] === countryName))
|
|
213
|
+
|| EDiscogsCountryNameToIsoCode_1.default[countryName]);
|
|
214
|
+
const releaseId = Number.parseInt((_v = (_u = (_t = (_s = (_r = el.querySelector('a.item_release_link')) === null || _r === void 0 ? void 0 : _r.href.split('release/')) === null || _s === void 0 ? void 0 : _s.pop()) === null || _t === void 0 ? void 0 : _t.split('-')) === null || _u === void 0 ? void 0 : _u.shift()) !== null && _v !== void 0 ? _v : '0', 10);
|
|
215
|
+
const itemId = Number.parseInt((_y = (_x = (_w = el.querySelector('a.item_description_title')) === null || _w === void 0 ? void 0 : _w.href) === null || _x === void 0 ? void 0 : _x.split('/').pop()) !== null && _y !== void 0 ? _y : '0', 10);
|
|
216
|
+
const notes = Number.parseInt((_5 = (_4 = (_3 = (_2 = (_1 = (_0 = (_z = el.querySelector('.seller_info li:nth-child(2) .section_link')) === null || _z === void 0 ? void 0 : _z.textContent) === null || _0 === void 0 ? void 0 : _0.replace(/\s+/g, ' ')) === null || _1 === void 0 ? void 0 : _1.trim()) === null || _2 === void 0 ? void 0 : _2.split(' ')) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.replace(/,/g, '')) !== null && _5 !== void 0 ? _5 : '', 10);
|
|
217
|
+
const originalTitle = (_6 = el.querySelector('a.item_description_title')) === null || _6 === void 0 ? void 0 : _6.textContent;
|
|
218
|
+
const firstIndexOfDash = (_7 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.indexOf(' - ')) !== null && _7 !== void 0 ? _7 : -1;
|
|
219
|
+
const lastIndexOfParenthesis = (_8 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _8 !== void 0 ? _8 : -1;
|
|
220
|
+
return {
|
|
221
|
+
itemId: Number.isNaN(itemId) ? 0 : itemId,
|
|
222
|
+
title: {
|
|
223
|
+
original: originalTitle !== null && originalTitle !== void 0 ? originalTitle : '',
|
|
224
|
+
artist: (_9 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash)) !== null && _9 !== void 0 ? _9 : '',
|
|
225
|
+
item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
|
|
226
|
+
? (_10 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)) !== null && _10 !== void 0 ? _10 : ''
|
|
227
|
+
: '',
|
|
228
|
+
formats: lastIndexOfParenthesis > -1
|
|
229
|
+
? ((_12 = (_11 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1)) === null || _11 === void 0 ? void 0 : _11.split(', ')) !== null && _12 !== void 0 ? _12 : [])
|
|
230
|
+
: [],
|
|
231
|
+
},
|
|
232
|
+
url: `https://www.discogs.com${(_13 = el.querySelector('a.item_description_title')) === null || _13 === void 0 ? void 0 : _13.href}`,
|
|
233
|
+
labels: (_15 = (_14 = [...el.querySelectorAll('.label_and_cat a[href^=\'https://www.discogs.com/\']')]) === null || _14 === void 0 ? void 0 : _14.map(x => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.textContent) !== null && _a !== void 0 ? _a : ''; })) === null || _15 === void 0 ? void 0 : _15.filter((value, index, self) => self.indexOf(value) === index),
|
|
234
|
+
catnos: (_20 = (_19 = (_18 = (_17 = (_16 = el.querySelector('.label_and_cat .item_catno')) === null || _16 === void 0 ? void 0 : _16.textContent) === null || _17 === void 0 ? void 0 : _17.replace(/\s+/g, ' ')) === null || _18 === void 0 ? void 0 : _18.split(', ')) === null || _19 === void 0 ? void 0 : _19.filter(x => x !== 'none')) !== null && _20 !== void 0 ? _20 : [],
|
|
235
|
+
imageUrl: (_22 = (_21 = el.querySelector('.marketplace_image')) === null || _21 === void 0 ? void 0 : _21.getAttribute('data-src')) !== null && _22 !== void 0 ? _22 : '',
|
|
236
|
+
description: (_27 = (_26 = (_25 = (_24 = (_23 = el.querySelector('.item_condition')) === null || _23 === void 0 ? void 0 : _23.nextElementSibling) === null || _24 === void 0 ? void 0 : _24.textContent) === null || _25 === void 0 ? void 0 : _25.replace(/\s+/g, ' ')) === null || _26 === void 0 ? void 0 : _26.trim()) !== null && _27 !== void 0 ? _27 : '',
|
|
237
|
+
isAcceptingOffer: ((_31 = (_30 = (_29 = (_28 = el.querySelector('.item_add_to_cart p a strong')) === null || _28 === void 0 ? void 0 : _28.textContent) === null || _29 === void 0 ? void 0 : _29.split('/')) === null || _30 === void 0 ? void 0 : _30.length) !== null && _31 !== void 0 ? _31 : 0) > 1,
|
|
238
|
+
isAvailable: !((_32 = el.classList) === null || _32 === void 0 ? void 0 : _32.contains('unavailable')),
|
|
239
|
+
condition: {
|
|
240
|
+
media: {
|
|
241
|
+
full: (_36 = (_35 = (_34 = (_33 = el.querySelector('.item_condition span:nth-child(3)')) === null || _33 === void 0 ? void 0 : _33.textContent) === null || _34 === void 0 ? void 0 : _34.replace(/\s+/g, ' ')) === null || _35 === void 0 ? void 0 : _35.trim()) !== null && _36 !== void 0 ? _36 : '',
|
|
242
|
+
short: (_42 = (_41 = (_40 = (_39 = (_38 = (_37 = el.querySelector('.item_condition span:nth-child(3)')) === null || _37 === void 0 ? void 0 : _37.textContent) === null || _38 === void 0 ? void 0 : _38.replace(/\s+/g, ' ')) === null || _39 === void 0 ? void 0 : _39.trim()) === null || _40 === void 0 ? void 0 : _40.match(/\(([^)]+)\)/)) === null || _41 === void 0 ? void 0 : _41[1]) !== null && _42 !== void 0 ? _42 : '',
|
|
243
|
+
},
|
|
244
|
+
sleeve: {
|
|
245
|
+
full: (_44 = (_43 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _43 === void 0 ? void 0 : _43.textContent) !== null && _44 !== void 0 ? _44 : '',
|
|
246
|
+
short: (_48 = (_47 = (_46 = (_45 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _45 === void 0 ? void 0 : _45.textContent) === null || _46 === void 0 ? void 0 : _46.match(/\(([^)]+)\)/)) === null || _47 === void 0 ? void 0 : _47[1]) !== null && _48 !== void 0 ? _48 : '',
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
seller: {
|
|
250
|
+
name: (_50 = (_49 = el.querySelector('.seller_info a')) === null || _49 === void 0 ? void 0 : _49.textContent) !== null && _50 !== void 0 ? _50 : '',
|
|
251
|
+
url: `https://www.discogs.com${(_51 = el.querySelector('.seller_info a')) === null || _51 === void 0 ? void 0 : _51.href}`,
|
|
252
|
+
score: (_53 = (_52 = el.querySelector('.seller_info li:nth-child(2) strong')) === null || _52 === void 0 ? void 0 : _52.textContent) !== null && _53 !== void 0 ? _53 : '',
|
|
253
|
+
notes: Number.isNaN(notes) ? 0 : notes,
|
|
254
|
+
},
|
|
255
|
+
price: {
|
|
256
|
+
base: this.convertDevise((_57 = (_56 = (_55 = (_54 = el.querySelector('.price')) === null || _54 === void 0 ? void 0 : _54.textContent) === null || _55 === void 0 ? void 0 : _55.replace(/\s+/g, ' ')) === null || _56 === void 0 ? void 0 : _56.replace(/,/, '.')) !== null && _57 !== void 0 ? _57 : ''),
|
|
257
|
+
shipping: Number.isNaN(parseFloat(shipping)) ? null : shipping,
|
|
258
|
+
},
|
|
259
|
+
from: {
|
|
260
|
+
countryName,
|
|
261
|
+
isoCountryName: (_58 = ECountryName_1.default[isoCountryCode]) !== null && _58 !== void 0 ? _58 : '',
|
|
262
|
+
isoCountryCode,
|
|
263
|
+
},
|
|
264
|
+
community: {
|
|
265
|
+
have: Number.isNaN(have) ? 0 : have,
|
|
266
|
+
want: Number.isNaN(want) ? 0 : want,
|
|
267
|
+
},
|
|
268
|
+
release: {
|
|
269
|
+
id: Number.isNaN(releaseId) ? 0 : releaseId,
|
|
270
|
+
url: `https://www.discogs.com${(_59 = el.querySelector('a.item_release_link')) === null || _59 === void 0 ? void 0 : _59.href}`,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
})) || [],
|
|
274
|
+
page: {
|
|
275
|
+
current: this.page,
|
|
276
|
+
total: Math.ceil(totalItems / this.limit),
|
|
277
|
+
},
|
|
278
|
+
result: {
|
|
279
|
+
total: totalItems,
|
|
280
|
+
perPage: this.limit,
|
|
281
|
+
},
|
|
282
|
+
search: {
|
|
283
|
+
value: (_f = this.searchValue) !== null && _f !== void 0 ? _f : '',
|
|
284
|
+
type: this.searchType,
|
|
285
|
+
},
|
|
286
|
+
urlGenerated: this.url,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.default = Marketplace;
|