From 6a8fd406ac6607a2023023c8f5ccc10cd590fca5 Mon Sep 17 00:00:00 2001 From: Maksym Date: Tue, 17 Jun 2025 20:07:43 +0200 Subject: [PATCH] patch --- README.md | 26 +++----------------------- package.json | 4 ++-- src/lib/band/DiscographyParser.ts | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 57df372..0618869 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,10 @@ -Buy Me a Coffee at ko-fi.com +Buy Me a Coffee at ko-fi.com(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 ``` diff --git a/package.json b/package.json index 52f2f64..5062288 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/band/DiscographyParser.ts b/src/lib/band/DiscographyParser.ts index c403630..22febb6 100644 --- a/src/lib/band/DiscographyParser.ts +++ b/src/lib/band/DiscographyParser.ts @@ -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('/');