This commit is contained in:
Maksym 2025-06-17 20:07:43 +02:00
parent 7d7431a2d5
commit 6a8fd406ac
3 changed files with 28 additions and 26 deletions

View File

@ -1,24 +1,10 @@
<a href='https://ko-fi.com/C0C5RGOOP' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
<a href='https://ko-fi.com/C0C5RGOOP' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>(donate to the creator of the [library](https://github.com/patrickkfkan/bandcamp-fetch))
# bandcamp-fetch
This fork removes Node dependencies to work with Cloudflare Pages. It might work in other environments that provide `fetch` as well!
This is the fork of the [fork](https://github.com/encode42/bandcamp-fetch) of the [main repository](https://github.com/patrickkfkan/bandcamp-fetch).
- `node-cache` has been replaced with a simple in-memory record store.
- `URL` has been replaced with a bare-bones implementation.
- `EOL` has been replaced with `\\n`.
* Development outside of Linux might not be supported!
- `node-fetch` has been removed, falling back to the environment's native `fetch` functions.
Additionally, some quality-of-life changes have been made.
- `description` field has been added to `Track`.
- Both the above and `Album`'s `description` will use Linux newlines.
- `url` option to replace `albumUrl` and `trackUrl`.
* The original fields will still take priority!
- `slug` field on `Album` and `Track`.
- `Track`'s `streamUrl` will be overridden by `streamUrlHQ` if available.
This fork will likely not be maintained outside my own interest!
It adds a handler for data-client-items attribute from BandCamp. As a result, you get **all** albums/tracks from artists/bands/labels instead of just a limited amount of them.
---
@ -37,12 +23,6 @@ Coverage:
Packaged as ESM + CJS hybrid module with typings.
# Installation
```
npm i bandcamp-fetch --save
```
# Usage
```

View File

@ -1,6 +1,6 @@
{
"name": "@encode42/bandcamp-fetch",
"version": "1.2.8",
"name": "@maksimgrs98/bandcamp-fetch",
"version": "1.2.9",
"description": "Scrape Bandcamp content (supports Cloudflare Pages)",
"scripts": {
"build": "npm run prepare",

View File

@ -132,8 +132,30 @@ export default class DiscographyParser {
}
}
});
const dataClientItems: typeof items | undefined = (() => {
const data: typeof items = {};
const musicGridElem = $("#music-grid");
if (musicGridElem === null) return;
const musicGridClientData = musicGridElem.data("client-items");
if (!Array.isArray(musicGridClientData)) return;
for (const item of musicGridClientData) {
const url = new URL(item["page_url"], opts.bandUrl);
let itemRef = data[url.toString()];
if (itemRef === undefined) itemRef = {};
else continue;
itemRef.type = url.pathname.startsWith("/track/") ? "track" : "album";
itemRef.name = item.title;
itemRef.artist = { name: defaultArtistName };
itemRef.imageUrl = reformatImageUrl(
`https://f4.bcbits.com/img/a${item["art_id"]}_10.jpg`,
opts.imageFormat
)!;
data[url.toString()] = itemRef;
}
return data;
})();
const results = [];
for (const [ url, props ] of Object.entries(items)) {
for (const [ url, props ] of Object.entries(Object.assign({}, items, dataClientItems))) {
if (props.type && props.name) {
const urlParts = url.split('/');