bandcamp-fetch
Version:
Scrape Bandcamp content
69 lines • 3.78 kB
JavaScript
;
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _LimiterArticleAPI_limiter;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LimiterArticleAPI = void 0;
const BaseAPIWithImageSupport_js_1 = __importDefault(require("../common/BaseAPIWithImageSupport.js"));
const Constants_js_1 = require("../utils/Constants.js");
const Parse_js_1 = require("../utils/Parse.js");
const ArticleCategoryParser_js_1 = __importDefault(require("./ArticleCategoryParser.js"));
const ArticleListParser_js_1 = __importDefault(require("./ArticleListParser.js"));
const ArticleParser_js_1 = __importDefault(require("./ArticleParser.js"));
class ArticleAPI extends BaseAPIWithImageSupport_js_1.default {
async getCategories() {
const html = await this.fetch(Constants_js_1.URLS.DAILY);
return ArticleCategoryParser_js_1.default.parseCategories(html);
}
async getArticle(params) {
const imageConstants = await this.imageAPI.getConstants();
const opts = {
imageBaseUrl: imageConstants.baseUrl,
albumImageFormat: await this.imageAPI.getFormat(params.albumImageFormat, 9),
artistImageFormat: await this.imageAPI.getFormat(params.artistImageFormat, 21),
includeRawData: !!params.includeRawData
};
const html = await this.fetch(params.articleUrl);
return ArticleParser_js_1.default.parseArticle(html, opts);
}
async list(params) {
let url = params?.categoryUrl ? params.categoryUrl : (0, Parse_js_1.normalizeUrl)('latest', Constants_js_1.URLS.DAILY);
if (params?.page) {
url += `?page=${params.page}`;
}
const opts = {
imageFormat: await this.imageAPI.getFormat(params?.imageFormat)
};
const html = await this.fetch(url);
return ArticleListParser_js_1.default.parseList(html, opts);
}
}
exports.default = ArticleAPI;
class LimiterArticleAPI extends ArticleAPI {
constructor(params) {
super(params);
_LimiterArticleAPI_limiter.set(this, void 0);
__classPrivateFieldSet(this, _LimiterArticleAPI_limiter, params.limiter, "f");
}
async getCategories() {
return __classPrivateFieldGet(this, _LimiterArticleAPI_limiter, "f").schedule(() => super.getCategories());
}
async getArticle(params) {
return __classPrivateFieldGet(this, _LimiterArticleAPI_limiter, "f").schedule(() => super.getArticle(params));
}
}
exports.LimiterArticleAPI = LimiterArticleAPI;
_LimiterArticleAPI_limiter = new WeakMap();
//# sourceMappingURL=ArticleAPI.js.map