discogs-marketplace-api-nodejs 1.2.12 → 1.3.4
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 +203 -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 +291 -278
- 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,278 +1,291 @@
|
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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/translates/EDiscogsCurrencyToIsoCode"));
|
|
35
|
+
const EDiscogsCountryNameToIsoCode_1 = __importDefault(require("./enum/iso/translates/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, _60;
|
|
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 = ((_r = Object.keys(ECountryCode_1.default)
|
|
213
|
+
.find((key) => ECountryName_1.default[key] === countryName
|
|
214
|
+
|| EDiscogsCountryNameToIsoCode_1.default[countryName])) !== null && _r !== void 0 ? _r : '');
|
|
215
|
+
const releaseId = Number.parseInt((_w = (_v = (_u = (_t = (_s = el.querySelector('a.item_release_link')) === null || _s === void 0 ? void 0 : _s.href.split('release/')) === null || _t === void 0 ? void 0 : _t.pop()) === null || _u === void 0 ? void 0 : _u.split('-')) === null || _v === void 0 ? void 0 : _v.shift()) !== null && _w !== void 0 ? _w : '0', 10);
|
|
216
|
+
const itemId = Number.parseInt((_z = (_y = (_x = el.querySelector('a.item_description_title')) === null || _x === void 0 ? void 0 : _x.href) === null || _y === void 0 ? void 0 : _y.split('/').pop()) !== null && _z !== void 0 ? _z : '0', 10);
|
|
217
|
+
const notes = Number.parseInt((_6 = (_5 = (_4 = (_3 = (_2 = (_1 = (_0 = el.querySelector('.seller_info li:nth-child(2) .section_link')) === null || _0 === void 0 ? void 0 : _0.textContent) === null || _1 === void 0 ? void 0 : _1.replace(/\s+/g, ' ')) === null || _2 === void 0 ? void 0 : _2.trim()) === null || _3 === void 0 ? void 0 : _3.split(' ')) === null || _4 === void 0 ? void 0 : _4[0]) === null || _5 === void 0 ? void 0 : _5.replace(/,/g, '')) !== null && _6 !== void 0 ? _6 : '', 10);
|
|
218
|
+
const originalTitle = (_7 = el.querySelector('a.item_description_title')) === null || _7 === void 0 ? void 0 : _7.textContent;
|
|
219
|
+
const firstIndexOfDash = (_8 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.indexOf(' - ')) !== null && _8 !== void 0 ? _8 : -1;
|
|
220
|
+
const lastIndexOfParenthesis = (_9 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.lastIndexOf(' (')) !== null && _9 !== void 0 ? _9 : -1;
|
|
221
|
+
return {
|
|
222
|
+
itemId: Number.isNaN(itemId) ? 0 : itemId,
|
|
223
|
+
title: {
|
|
224
|
+
original: originalTitle !== null && originalTitle !== void 0 ? originalTitle : '',
|
|
225
|
+
artist: (_10 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(0, firstIndexOfDash)) !== null && _10 !== void 0 ? _10 : '',
|
|
226
|
+
item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
|
|
227
|
+
? (_11 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)) !== null && _11 !== void 0 ? _11 : ''
|
|
228
|
+
: '',
|
|
229
|
+
formats: lastIndexOfParenthesis > -1
|
|
230
|
+
? ((_13 = (_12 = originalTitle === null || originalTitle === void 0 ? void 0 : originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1)) === null || _12 === void 0 ? void 0 : _12.split(', ')) !== null && _13 !== void 0 ? _13 : [])
|
|
231
|
+
: [],
|
|
232
|
+
},
|
|
233
|
+
url: `https://www.discogs.com${(_14 = el.querySelector('a.item_description_title')) === null || _14 === void 0 ? void 0 : _14.href}`,
|
|
234
|
+
labels: (_16 = (_15 = [...el.querySelectorAll('.label_and_cat a[href^=\'https://www.discogs.com/\']')]) === null || _15 === void 0 ? void 0 : _15.map(x => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.textContent) !== null && _a !== void 0 ? _a : ''; })) === null || _16 === void 0 ? void 0 : _16.filter((value, index, self) => self.indexOf(value) === index),
|
|
235
|
+
catnos: (_21 = (_20 = (_19 = (_18 = (_17 = el.querySelector('.label_and_cat .item_catno')) === null || _17 === void 0 ? void 0 : _17.textContent) === null || _18 === void 0 ? void 0 : _18.replace(/\s+/g, ' ')) === null || _19 === void 0 ? void 0 : _19.split(', ')) === null || _20 === void 0 ? void 0 : _20.filter(x => x !== 'none')) !== null && _21 !== void 0 ? _21 : [],
|
|
236
|
+
imageUrl: (_23 = (_22 = el.querySelector('.marketplace_image')) === null || _22 === void 0 ? void 0 : _22.getAttribute('data-src')) !== null && _23 !== void 0 ? _23 : '',
|
|
237
|
+
description: (_28 = (_27 = (_26 = (_25 = (_24 = el.querySelector('.item_condition')) === null || _24 === void 0 ? void 0 : _24.nextElementSibling) === null || _25 === void 0 ? void 0 : _25.textContent) === null || _26 === void 0 ? void 0 : _26.replace(/\s+/g, ' ')) === null || _27 === void 0 ? void 0 : _27.trim()) !== null && _28 !== void 0 ? _28 : '',
|
|
238
|
+
isAcceptingOffer: ((_32 = (_31 = (_30 = (_29 = el.querySelector('.item_add_to_cart p a strong')) === null || _29 === void 0 ? void 0 : _29.textContent) === null || _30 === void 0 ? void 0 : _30.split('/')) === null || _31 === void 0 ? void 0 : _31.length) !== null && _32 !== void 0 ? _32 : 0) > 1,
|
|
239
|
+
isAvailable: !((_33 = el.classList) === null || _33 === void 0 ? void 0 : _33.contains('unavailable')),
|
|
240
|
+
condition: {
|
|
241
|
+
media: {
|
|
242
|
+
full: (_37 = (_36 = (_35 = (_34 = el.querySelector('.item_condition span:nth-child(3)')) === null || _34 === void 0 ? void 0 : _34.textContent) === null || _35 === void 0 ? void 0 : _35.replace(/\s+/g, ' ')) === null || _36 === void 0 ? void 0 : _36.trim()) !== null && _37 !== void 0 ? _37 : '',
|
|
243
|
+
short: (_43 = (_42 = (_41 = (_40 = (_39 = (_38 = el.querySelector('.item_condition span:nth-child(3)')) === null || _38 === void 0 ? void 0 : _38.textContent) === null || _39 === void 0 ? void 0 : _39.replace(/\s+/g, ' ')) === null || _40 === void 0 ? void 0 : _40.trim()) === null || _41 === void 0 ? void 0 : _41.match(/\(([^)]+)\)/)) === null || _42 === void 0 ? void 0 : _42[1]) !== null && _43 !== void 0 ? _43 : '',
|
|
244
|
+
},
|
|
245
|
+
sleeve: {
|
|
246
|
+
full: (_45 = (_44 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _44 === void 0 ? void 0 : _44.textContent) !== null && _45 !== void 0 ? _45 : '',
|
|
247
|
+
short: (_49 = (_48 = (_47 = (_46 = el.querySelector('.item_condition span.item_sleeve_condition')) === null || _46 === void 0 ? void 0 : _46.textContent) === null || _47 === void 0 ? void 0 : _47.match(/\(([^)]+)\)/)) === null || _48 === void 0 ? void 0 : _48[1]) !== null && _49 !== void 0 ? _49 : '',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
seller: {
|
|
251
|
+
name: (_51 = (_50 = el.querySelector('.seller_info a')) === null || _50 === void 0 ? void 0 : _50.textContent) !== null && _51 !== void 0 ? _51 : '',
|
|
252
|
+
url: `https://www.discogs.com${(_52 = el.querySelector('.seller_info a')) === null || _52 === void 0 ? void 0 : _52.href}`,
|
|
253
|
+
score: (_54 = (_53 = el.querySelector('.seller_info li:nth-child(2) strong')) === null || _53 === void 0 ? void 0 : _53.textContent) !== null && _54 !== void 0 ? _54 : '',
|
|
254
|
+
notes: Number.isNaN(notes) ? 0 : notes,
|
|
255
|
+
},
|
|
256
|
+
price: {
|
|
257
|
+
base: this.convertDevise((_58 = (_57 = (_56 = (_55 = el.querySelector('.price')) === null || _55 === void 0 ? void 0 : _55.textContent) === null || _56 === void 0 ? void 0 : _56.replace(/\s+/g, ' ')) === null || _57 === void 0 ? void 0 : _57.replace(/,/, '.')) !== null && _58 !== void 0 ? _58 : ''),
|
|
258
|
+
shipping: Number.isNaN(parseFloat(shipping)) ? null : shipping,
|
|
259
|
+
},
|
|
260
|
+
from: {
|
|
261
|
+
countryName,
|
|
262
|
+
isoCountryName: (_59 = ECountryName_1.default[isoCountryCode]) !== null && _59 !== void 0 ? _59 : '',
|
|
263
|
+
isoCountryCode,
|
|
264
|
+
},
|
|
265
|
+
community: {
|
|
266
|
+
have: Number.isNaN(have) ? 0 : have,
|
|
267
|
+
want: Number.isNaN(want) ? 0 : want,
|
|
268
|
+
},
|
|
269
|
+
release: {
|
|
270
|
+
id: Number.isNaN(releaseId) ? 0 : releaseId,
|
|
271
|
+
url: `https://www.discogs.com${(_60 = el.querySelector('a.item_release_link')) === null || _60 === void 0 ? void 0 : _60.href}`,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
})) || [],
|
|
275
|
+
page: {
|
|
276
|
+
current: this.page,
|
|
277
|
+
total: Math.ceil(totalItems / this.limit),
|
|
278
|
+
},
|
|
279
|
+
result: {
|
|
280
|
+
total: totalItems,
|
|
281
|
+
perPage: this.limit,
|
|
282
|
+
},
|
|
283
|
+
search: {
|
|
284
|
+
value: (_f = this.searchValue) !== null && _f !== void 0 ? _f : '',
|
|
285
|
+
type: this.searchType,
|
|
286
|
+
},
|
|
287
|
+
urlGenerated: this.url,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.default = Marketplace;
|