discogs-marketplace-api-nodejs 1.12.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 +151 -176
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/interfaces/api/shop-details-result.api.interface.d.ts +33 -0
- package/dist/interfaces/api/shop-result.api.interface.d.ts +111 -0
- package/dist/interfaces/search-params.interface.d.ts +166 -63
- package/dist/interfaces/search-result.interface.d.ts +39 -26
- package/dist/scrapers/legacy.scraper.d.ts +11 -0
- package/dist/scrapers/legacy.scraper.js +200 -0
- package/dist/scrapers/modern.scraper.d.ts +11 -0
- package/dist/scrapers/modern.scraper.js +167 -0
- package/dist/scrapers/wantlist.scraper.d.ts +11 -0
- package/dist/scrapers/wantlist.scraper.js +53 -0
- package/dist/search.d.ts +6 -6
- package/dist/search.js +21 -134
- package/dist/types/api.type.d.ts +4 -0
- package/dist/types/api.type.js +2 -0
- package/dist/types/from.type.d.ts +2 -1
- package/package.json +2 -2
- package/dist/get-search-params.d.ts +0 -10
- package/dist/get-search-params.js +0 -122
- package/dist/scrape.d.ts +0 -10
- package/dist/scrape.js +0 -126
- package/dist/types/hours-range.type.d.ts +0 -4
- package/dist/types/search-type.type.d.ts +0 -4
- /package/dist/{types/hours-range.type.js → interfaces/api/shop-details-result.api.interface.js} +0 -0
- /package/dist/{types/search-type.type.js → interfaces/api/shop-result.api.interface.js} +0 -0
package/dist/scrape.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = scrape;
|
|
4
|
-
// These variables are injected by the browser context when the page is loaded.
|
|
5
|
-
const { Country, Currency } = globalThis;
|
|
6
|
-
/**
|
|
7
|
-
* Parses the page and returns the items found.
|
|
8
|
-
* This function is called by the browser context when the page is loaded.
|
|
9
|
-
* @returns Items found and total
|
|
10
|
-
*/
|
|
11
|
-
function scrape() {
|
|
12
|
-
/**
|
|
13
|
-
* Converts a currency string to a standardized format.
|
|
14
|
-
* @param value String to clean
|
|
15
|
-
* @returns Cleaned-up string
|
|
16
|
-
*/
|
|
17
|
-
const convertCurrency = (value) => {
|
|
18
|
-
if (!value) {
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
const currencyFound = Object.keys(Currency).find(key => value.includes(key));
|
|
22
|
-
if (!currencyFound) {
|
|
23
|
-
return '';
|
|
24
|
-
}
|
|
25
|
-
const currencyClean = Currency[currencyFound];
|
|
26
|
-
const amount = value
|
|
27
|
-
.replace(currencyClean !== 'JPY' ? /[.](?=.*[.])/g : /\./g, '') // Remove all dots but the last, except for JPY
|
|
28
|
-
.replace(currencyFound, '') // Remove original currency
|
|
29
|
-
.replace(/\s\s+/g, ''); // Remove spaces
|
|
30
|
-
const amountParsed = Number.parseFloat(amount);
|
|
31
|
-
if (Number.isNaN(amountParsed)) {
|
|
32
|
-
return '';
|
|
33
|
-
}
|
|
34
|
-
return `${amountParsed} ${currencyClean}`;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Safely parses a number from a string.
|
|
38
|
-
* @param value String to parse
|
|
39
|
-
* @returns Parsed number or 0 if invalid
|
|
40
|
-
*/
|
|
41
|
-
const safeParseInt = (value) => {
|
|
42
|
-
const parsed = Number.parseInt(value ?? '', 10);
|
|
43
|
-
return Number.isNaN(parsed) ? 0 : parsed;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Extracts and cleans text content from an element.
|
|
47
|
-
* @param selector CSS selector
|
|
48
|
-
* @param context Parent element to query from
|
|
49
|
-
* @returns Cleaned text content or an empty string
|
|
50
|
-
*/
|
|
51
|
-
const getTextContent = (selector, context = document) => context.querySelector(selector)?.textContent?.trim() ?? '';
|
|
52
|
-
const total = safeParseInt(getTextContent('.pagination_total')
|
|
53
|
-
.split(' ')
|
|
54
|
-
.filter(x => x)
|
|
55
|
-
.pop()
|
|
56
|
-
?.replace(/(,|\.|\s)/g, ''));
|
|
57
|
-
const items = [...document.querySelectorAll('table.table_block tbody tr')].map(el => {
|
|
58
|
-
const itemHref = el.querySelector('a.item_description_title')?.getAttribute('href') ?? '';
|
|
59
|
-
const mediaCondition = getTextContent('.item_condition span:nth-child(3)', el).split('\n')[0] ?? '';
|
|
60
|
-
const sleeveCondition = getTextContent('.item_condition span.item_sleeve_condition', el);
|
|
61
|
-
const countryName = getTextContent('.seller_info li:nth-child(3)', el).split(':').pop() ?? '';
|
|
62
|
-
const originalTitle = getTextContent('a.item_description_title', el);
|
|
63
|
-
const firstIndexOfDash = originalTitle.indexOf(' - ');
|
|
64
|
-
const lastIndexOfParenthesis = originalTitle.lastIndexOf(' (');
|
|
65
|
-
const releaseHref = el.querySelector('a.item_release_link')?.getAttribute('href') ?? '';
|
|
66
|
-
return {
|
|
67
|
-
id: safeParseInt(itemHref.split('/').pop()),
|
|
68
|
-
title: {
|
|
69
|
-
original: originalTitle,
|
|
70
|
-
artist: firstIndexOfDash > -1 ? originalTitle.substring(0, firstIndexOfDash) : '',
|
|
71
|
-
item: firstIndexOfDash > -1 && lastIndexOfParenthesis > -1
|
|
72
|
-
? originalTitle.substring(firstIndexOfDash + 3, lastIndexOfParenthesis)
|
|
73
|
-
: '',
|
|
74
|
-
formats: lastIndexOfParenthesis > -1
|
|
75
|
-
? originalTitle.substring(lastIndexOfParenthesis + 2, originalTitle.length - 1).split(', ')
|
|
76
|
-
: [],
|
|
77
|
-
},
|
|
78
|
-
url: `https://www.discogs.com${itemHref}`,
|
|
79
|
-
labels: [...el.querySelectorAll(".label_and_cat a[href^='https://www.discogs.com/']")]
|
|
80
|
-
.map(x => x.textContent?.trim() ?? '')
|
|
81
|
-
.filter((value, index, self) => self.indexOf(value) === index),
|
|
82
|
-
catnos: getTextContent('.label_and_cat .item_catno', el) // cspell:disable-line
|
|
83
|
-
.split(', ')
|
|
84
|
-
.filter(x => x !== 'none'),
|
|
85
|
-
imageUrl: el.querySelector('.marketplace_image')?.getAttribute('data-src') ?? '',
|
|
86
|
-
description: getTextContent('.item_condition + *', el),
|
|
87
|
-
isAcceptingOffer: getTextContent('.item_add_to_cart p a strong', el).split('/').length > 1,
|
|
88
|
-
isAvailable: !el.classList.contains('unavailable'),
|
|
89
|
-
condition: {
|
|
90
|
-
media: {
|
|
91
|
-
full: mediaCondition,
|
|
92
|
-
short: /\(([^)]+)\)/.exec(mediaCondition)?.[1] ?? '',
|
|
93
|
-
},
|
|
94
|
-
sleeve: {
|
|
95
|
-
full: sleeveCondition,
|
|
96
|
-
short: /\(([^)]+)\)/.exec(sleeveCondition)?.[1] ?? '',
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
seller: {
|
|
100
|
-
name: getTextContent('.seller_info a', el),
|
|
101
|
-
url: `https://www.discogs.com${el.querySelector('.seller_info a')?.getAttribute('href') ?? ''}`,
|
|
102
|
-
score: getTextContent('.seller_info li:nth-child(2) strong', el),
|
|
103
|
-
notes: safeParseInt(getTextContent('.seller_info li:nth-child(2) .section_link', el)),
|
|
104
|
-
},
|
|
105
|
-
price: {
|
|
106
|
-
base: convertCurrency(getTextContent('.price', el).replace(/,/, '.')),
|
|
107
|
-
shipping: convertCurrency(getTextContent('.item_shipping', el)
|
|
108
|
-
.replace(/(\s+|\+)/g, ' ')
|
|
109
|
-
.replace(',', '.')),
|
|
110
|
-
},
|
|
111
|
-
country: {
|
|
112
|
-
name: countryName,
|
|
113
|
-
code: Country[countryName],
|
|
114
|
-
},
|
|
115
|
-
community: {
|
|
116
|
-
have: safeParseInt(getTextContent('.community_summary .community_result:nth-child(1) .community_number', el)),
|
|
117
|
-
want: safeParseInt(getTextContent('.community_summary .community_result:nth-child(2) .community_number', el)),
|
|
118
|
-
},
|
|
119
|
-
release: {
|
|
120
|
-
id: safeParseInt(releaseHref.split('release/').pop()?.split('-').shift()),
|
|
121
|
-
url: `https://www.discogs.com${releaseHref}`,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
return { total, items };
|
|
126
|
-
}
|
/package/dist/{types/hours-range.type.js → interfaces/api/shop-details-result.api.interface.js}
RENAMED
|
File without changes
|
|
File without changes
|