bandcamp-fetch
Version:
Scrape Bandcamp content
153 lines • 8.84 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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 _BandcampFetch_cookie, _BandcampFetch_fetcher, _BandcampFetch_cache, _BandcampFetch_wrappedCache, _BandcampFetch_limiter, _CacheWrapper_cache;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheWrapper = void 0;
const AlbumAPI_js_1 = __importStar(require("./album/AlbumAPI.js"));
const ArticleAPI_js_1 = __importStar(require("./article/ArticleAPI.js"));
const AutocompleteAPI_js_1 = __importStar(require("./autocomplete/AutocompleteAPI.js"));
const BandAPI_js_1 = __importStar(require("./band/BandAPI.js"));
const DiscoveryAPI_js_1 = __importStar(require("./discovery/DiscoveryAPI.js"));
const FanAPI_js_1 = __importStar(require("./fan/FanAPI.js"));
const ImageAPI_js_1 = __importStar(require("./image/ImageAPI.js"));
const SearchAPI_js_1 = __importStar(require("./search/SearchAPI.js"));
const ShowAPI_js_1 = __importStar(require("./show/ShowAPI.js"));
const TagAPI_js_1 = __importStar(require("./tag/TagAPI.js"));
const TrackAPI_js_1 = __importStar(require("./track/TrackAPI.js"));
const Cache_js_1 = __importStar(require("./utils/Cache.js"));
const Fetcher_js_1 = __importDefault(require("./utils/Fetcher.js"));
const Limiter_js_1 = __importDefault(require("./utils/Limiter.js"));
const StreamAPI_js_1 = __importStar(require("./stream/StreamAPI.js"));
class BandcampFetch {
constructor(params) {
_BandcampFetch_cookie.set(this, void 0);
_BandcampFetch_fetcher.set(this, void 0);
_BandcampFetch_cache.set(this, void 0);
_BandcampFetch_wrappedCache.set(this, void 0);
_BandcampFetch_limiter.set(this, void 0);
__classPrivateFieldSet(this, _BandcampFetch_cookie, params?.cookie, "f");
__classPrivateFieldSet(this, _BandcampFetch_cache, new Cache_js_1.default({
[Cache_js_1.CacheDataType.Constants]: 3600,
[Cache_js_1.CacheDataType.Page]: 300
}, { page: 10 }), "f");
__classPrivateFieldSet(this, _BandcampFetch_wrappedCache, new CacheWrapper(__classPrivateFieldGet(this, _BandcampFetch_cache, "f")), "f");
__classPrivateFieldSet(this, _BandcampFetch_fetcher, new Fetcher_js_1.default({
cookie: __classPrivateFieldGet(this, _BandcampFetch_cookie, "f"),
cache: __classPrivateFieldGet(this, _BandcampFetch_cache, "f")
}), "f");
__classPrivateFieldSet(this, _BandcampFetch_limiter, new Limiter_js_1.default(), "f");
const baseAPIParams = {
fetcher: __classPrivateFieldGet(this, _BandcampFetch_fetcher, "f"),
cache: __classPrivateFieldGet(this, _BandcampFetch_cache, "f"),
limiter: __classPrivateFieldGet(this, _BandcampFetch_limiter, "f")
};
this.image = new ImageAPI_js_1.default(baseAPIParams);
const baseAPIWithImageSupportParams = {
...baseAPIParams,
imageAPI: this.image
};
this.album = new AlbumAPI_js_1.default(baseAPIWithImageSupportParams);
this.track = new TrackAPI_js_1.default(baseAPIWithImageSupportParams);
this.discovery = new DiscoveryAPI_js_1.default(baseAPIWithImageSupportParams);
this.image = new ImageAPI_js_1.default(baseAPIParams);
this.band = new BandAPI_js_1.default(baseAPIWithImageSupportParams);
this.tag = new TagAPI_js_1.default(baseAPIWithImageSupportParams);
this.article = new ArticleAPI_js_1.default(baseAPIWithImageSupportParams);
this.show = new ShowAPI_js_1.default(baseAPIWithImageSupportParams);
this.fan = new FanAPI_js_1.default(baseAPIWithImageSupportParams);
this.search = new SearchAPI_js_1.default(baseAPIWithImageSupportParams);
this.autocomplete = new AutocompleteAPI_js_1.default(baseAPIParams);
this.stream = new StreamAPI_js_1.default(baseAPIParams);
this.limiter = {
album: new AlbumAPI_js_1.LimiterAlbumAPI(baseAPIWithImageSupportParams),
track: new TrackAPI_js_1.LimiterTrackAPI(baseAPIWithImageSupportParams),
discovery: new DiscoveryAPI_js_1.LimiterDiscoveryAPI(baseAPIWithImageSupportParams),
image: new ImageAPI_js_1.LimiterImageAPI(baseAPIParams),
band: new BandAPI_js_1.LimiterBandAPI(baseAPIWithImageSupportParams),
tag: new TagAPI_js_1.LimiterTagAPI(baseAPIWithImageSupportParams),
article: new ArticleAPI_js_1.LimiterArticleAPI(baseAPIWithImageSupportParams),
show: new ShowAPI_js_1.LimiterShowAPI(baseAPIWithImageSupportParams),
fan: new FanAPI_js_1.LimiterFanAPI(baseAPIWithImageSupportParams),
search: new SearchAPI_js_1.LimiterSearchAPI(baseAPIWithImageSupportParams),
autocomplete: new AutocompleteAPI_js_1.LimiterAutocompleteAPI(baseAPIParams),
stream: new StreamAPI_js_1.LimiterStreamAPI(baseAPIParams),
updateSettings: __classPrivateFieldGet(this, _BandcampFetch_limiter, "f").updateSettings.bind(__classPrivateFieldGet(this, _BandcampFetch_limiter, "f"))
};
}
setCookie(value) {
__classPrivateFieldSet(this, _BandcampFetch_cookie, value, "f");
__classPrivateFieldGet(this, _BandcampFetch_fetcher, "f").setCookie(value);
}
get cookie() {
return __classPrivateFieldGet(this, _BandcampFetch_cookie, "f");
}
get cache() {
return __classPrivateFieldGet(this, _BandcampFetch_wrappedCache, "f");
}
}
_BandcampFetch_cookie = new WeakMap(), _BandcampFetch_fetcher = new WeakMap(), _BandcampFetch_cache = new WeakMap(), _BandcampFetch_wrappedCache = new WeakMap(), _BandcampFetch_limiter = new WeakMap();
exports.default = BandcampFetch;
class CacheWrapper {
constructor(cache) {
_CacheWrapper_cache.set(this, void 0);
__classPrivateFieldSet(this, _CacheWrapper_cache, cache, "f");
}
clear(type) {
__classPrivateFieldGet(this, _CacheWrapper_cache, "f").clear(type);
}
setTTL(type, ttl) {
__classPrivateFieldGet(this, _CacheWrapper_cache, "f").setTTL(type, ttl);
}
setMaxPages(maxPages) {
__classPrivateFieldGet(this, _CacheWrapper_cache, "f").setMaxEntries(Cache_js_1.CacheDataType.Page, maxPages);
}
}
exports.CacheWrapper = CacheWrapper;
_CacheWrapper_cache = new WeakMap();
//# sourceMappingURL=BandcampFetch.js.map