2021-01-19 21:37:31 +01:00
# bandcamp-fetch
2023-06-10 16:52:27 +02:00
Library for scraping Bandcamp content.
Coverage:
- Bandcamp Discover
- Album and track info
- Artists, labels, label artists, discography
- Articles (aka. Bandcamp Daily)
- Shows
- Tags, including releases and highlights by tag
- Search
- Fan collections, wishlists and following artists / genres
Packaged as ESM + CJS hybrid module with typings.
2021-01-19 21:37:31 +01:00
# Installation
```
npm i bandcamp-fetch --save
```
# Usage
```
2023-06-10 16:52:27 +02:00
import bcfetch from 'bandcamp-fetch';
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
const results = await bcfetch.discovery.discover(...);
2021-01-19 21:37:31 +01:00
```
# API
2023-06-10 16:52:27 +02:00
## Discovery API
To access the Discovery API:
```
import bcfetch from 'bandcamp-fetch';
const discovery = bcfetch.discovery;
const options = await discovery.getAvailableOptions();
const results = await discovery.discover(...);
```
**Methods:**
< details >
< summary > < code > discover([params])< / code > < / summary >
< br / >
[**Example** ](examples/discovery/discover.ts ) ([output](examples/discovery/discover_output.txt))
< p > Fetches albums through Bandcamp Discover.< / p >
**Params**
- `params` : ([DiscoverParams](docs/api/interfaces/DiscoverParams.md)) (*optional* and *all properties optional* )
- `genre` : (string)
- `subgenre` : (string) only valid when `genre` is set to something other than 'all'.
- `location` : (string)
- `sortBy` : (string)
- `artistRecommendationType` : (string) only valid when `sortBy` is 'rec' (artist recommended).
- `format` : (string)
- `time` : (number)
- `page` : (number)
- `albumImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md ))
- `artistImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md ))
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
To see what values can be set in `params` , call `getAvailableOptions()` .
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to [DiscoverResult ](docs/api/interfaces/DiscoverResult.md ).
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getAvailableOptions()< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/discovery/getAvailableOptions.ts ) ([output](examples/discovery/getAvailableOptions_output.txt))
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches Bandcamp Discover options that can be used to configure < code > params< / code > for passing into < code > discover()< / code > .< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to [DiscoverOptions ](docs/api/interfaces/DiscoverOptions.md ).
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > sanitizeDiscoverParams([params])< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/discovery/sanitizeDiscoverParams.ts ) ([output](examples/discovery/sanitizeDiscoverParams_output.txt))
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
< p > Sanitizes < code > params< / code > by setting default values for omitted properties and removing irrelevant or inapplicable ones.< / p >
< p >
Note that you don't have to call this method on params passed into < code > discover()< / code > as they will be sanitized automatically.
< / p >
**Params**
- `params` : ([DiscoverParams](docs/api/interfaces/DiscoverParams.md)) (*optional*) the discover params to sanitize.
**Returns**
Promise resolving to sanitized [DiscoverParams ](docs/api/interfaces/DiscoverParams.md ).
---
< / details >
## Image API
To access the Image API:
```
import bcfetch, { ImageFormatFilter } from 'bandcamp-fetch';
const image = bcfetch.image;
const formats = await image.getFormats(ImageFormatFilter.Album);
```
**Methods:**
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getFormats([filter])< / code > < / summary >
< br / >
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/image/getFormats.ts ) ([output](examples/image/getFormats_output.txt))
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches the list of image formats used in Bandcamp.< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
- `filter` : ([ImageFormatFilter](docs/api/enums/ImageFormatFilter.md)) (*optional*) if specified, narrows down the result to include only formats applicable to the specified value.
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2022-06-23 13:09:13 +02:00
2023-06-10 16:52:27 +02:00
Promise resolving to Array< [ImageFormat](docs/api/interfaces/ImageFormat.md)>.
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getImageFormat(target, [fallbackId])< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches the image format that matches < code > target< / code > . If none is found, the result will be < code > null< / code > .< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
- `target` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md ))
- If target is string or number, the method finds the image format with matching name or Id (as appropriate).
- If target satisfies the [ImageFormat ](docs/api/interfaces/ImageFormat.md ) interface constraint, then it is returned as is.
- `fallbackId` : (number) (*optional*) if no match is found for `target` , try to obtain format with Id matching `fallbackId` .
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-10-19 18:57:34 +02:00
2023-06-10 16:52:27 +02:00
Promise resolving to matching [ImageFormat ](docs/api/interfaces/ImageFormat.md ), or `null` if none matches `target` nor `fallbackId` (if specified).
2021-10-19 18:57:34 +02:00
2023-06-10 16:52:27 +02:00
---
< / details >
## Band API
A band can be an artist or label. To access the Band API:
```
import bcfetch from 'bandcamp-fetch';
const band = bcfetch.band;
const info = await band.getInfo(...);
```
**Methods:**
< details >
< summary > < code > getInfo(params)< / code > < / summary >
< br / >
[**Example** ](examples/band/getInfo.ts ) ([output](examples/band/getInfo_output.txt))
< p > Fetches information about an artist or label.< / p >
**Params**
- `params` : ([BandAPIGetInfoParams](docs/api/interfaces/BandAPIGetInfoParams.md))
- `bandUrl` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `labelId` : (number) (*optional*)
The method tries to assemble the most complete set of data by scraping the following pages (returning immediately at any point the data becomes complete):
1. The page referred to by `bandUrl`
2. The 'music' page of the artist or label (`bandUrl/music`)
2021-10-20 10:18:03 +02:00
3. The first album or track in the artist's or label's discography
2021-10-19 18:57:34 +02:00
2023-06-10 16:52:27 +02:00
Sometimes, label information is missing for artists even when they do belong to a label. If you know the `labelId` of the label that the artist belongs to, you can specify it in `params` . This will ensure that `label` will not be `null` in the artist info. If you pass a label URL to this function, you can find the `labelId` in the result.
**Returns**
Promise resolving to [Artist ](docs/api/interfaces/Artist.md ) or [Label ](docs/api/interfaces/Label.md ).
---
< / details >
< details >
< summary > < code > getLabelArtists(params)< / code > < / summary >
< br / >
[**Example** ](examples/band/getLabelArtists.ts ) ([output](examples/band/getLabelArtists_output.txt))
< p > Fetches the list of artists belonging to a label.< / p >
**Params**
- `params` : ([BandAPIGetLabelArtistsParams](docs/api/interfaces/BandAPIGetLabelArtistsParams.md))
- `labelUrl` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to Array< [LabelArtist](docs/api/README.md#labelartist)>.
---
< / details >
< details >
< summary > < code > getDiscography(params)< / code > < / summary >
< br / >
[**Example** ](examples/band/getDiscography.ts ) ([output](examples/band/getDiscography_output.txt))
< p > Fetches the list of albums and standalone tracks belonging to an artist or label.< / p >
**Params**
- `params` : ([BandAPIGetDiscographyParams](docs/api/interfaces/BandAPIGetDiscographyParams.md))
- `bandUrl` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to Array< [Album](docs/api/interfaces/Album.md) | [Track ](docs/api/interfaces/Track.md )>.
---
< / details >
## Album API
To access the Album API:
```
import bcfetch from 'bandcamp-fetch';
const album = bcfetch.album;
const info = await album.getInfo(...);
```
**Methods:**
< details >
< summary > < code > getInfo(params)< / code > < / summary >
< br / >
[**Example** ](examples/album/getInfo.ts ) ([output](examples/album/getInfo_output.txt))
< p > Fetches info about an album.< / p >
**Params**
- `params` : ([AlbumAPIGetInfoParams](docs/api/interfaces/AlbumAPIGetInfoParams.md))
- `albumUrl` : (string)
- `albumImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `artistImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `includeRawData` : (boolean) (*optional)
**Returns**
Promise resolving to [Album ](docs/api/interfaces/Album.md ).
> If artist URL is not found in the scraped data, then `artist.url` will be set to the same value as `publisher.url`
---
< / details >
## Track API
To access the Track API:
```
import bcfetch from 'bandcamp-fetch';
const track = bcfetch.track;
const info = await track.getInfo(...);
```
**Methods:**
< details >
< summary > < code > getInfo(params)< / code > < / summary >
< br / >
[**Example** ](examples/track/getInfo.ts ) ([output](examples/track/getInfo_output.txt))
< p > Fetches info about a track.< / p >
**Params**
- `params` : ([TrackAPIGetInfoParams](docs/api/interfaces/Tra))
- `trackUrl` : (string)
- `albumImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `artistImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `includeRawData` : (boolean) (*optional)
**Returns**
Promise resolving to [Track ](docs/api/interfaces/Track.md ).
> If artist URL is not found in the scraped data, then `artist.url` will be set to the same value as `publisher.url`
---
< / details >
## Tag API
To access the Tag API:
```
import bcfetch from 'bandcamp-fetch';
const tag = bcfetch.tag;
const info = await tag.getInfo(...);
const highlights = await tag.getAlbumHighlights(...);
```
**Methods:**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getInfo(tagUrl)< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/tag/getInfo.ts ) ([output](examples/tag/getInfo_output.txt))
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches info about a tag.< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
- `tagUrl` : (string)
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to [Tag ](docs/api/interfaces/Tag.md ).
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > list()< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/tag/list.ts ) ([output](examples/tag/list_output.txt))
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches the full list of tags.< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to [TagList ](docs/api/interfaces/TagList.md ), which groups results into `tags` (for non-location tags) and `locations` (for location tags).
2021-10-19 18:57:34 +02:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getAlbumHighlights(params)< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/tag/getAlbumHighlights.ts ) ([output](examples/tag/getAlbumHighlights_output.txt))
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches album highlights for the tag referred to by < code > params.tagUrl< / code > .< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Albums are placed in groups. Each group corresponds to a highlight category such as 'new and notable' and 'all-time best selling'.
2021-10-19 18:57:34 +02:00
2023-06-10 16:52:27 +02:00
**Params**
2021-10-19 18:57:34 +02:00
2023-06-10 16:52:27 +02:00
- `params` : ([TagAPIGetAlbumHighlightsParams](docs/api/interfaces/TagAPIGetAlbumHighlightsParams.md))
- `tagUrl` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to Array< [AlbumHighlightsByTag](docs/api/interfaces/AlbumHighlightsByTag.md)>.
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getReleases(params)< / code > < / summary >
< br / >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/tag/getReleases.ts ) ([output](examples/tag/getReleases_output.txt))
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches releases matching the tag referred to by < code > params.tagUrl< / code > .< / p >
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
- `params` : ([TagAPIGetReleasesParams](docs/api/interfaces/TagAPIGetReleasesParams.md))
- `tagUrl` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `useHardcodedDefaultFilters` : (boolean) (*optional*) if `true` , use hardcoded default values for filters not specified in `params.filters` . If `false` or unspecified, default filter values will be obtained by calling ``getReleasesAvailableFilters`()` (extra query means slower performance).
- `filters` : (object{ string: string | number | Array< string | number > }) (*optional*)
- `page` : (number) (*optional*) 1 if omitted.
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
#### `params.filters`:
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Properties of `params.filters` are not strictly defined. As of this documentation, the curent filters available on Bandcamp are:
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
- `location` : (number)
- `tags` : (Array< string> ) list of tags to match, in addition to the one referred to by `params.tagUrl` .
- `sort` : (string)
- `format` : (string)
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
Omitted properties are populated with default values obtained from `params.tagUrl` . Possible filter values can be obtained by calling `getReleasesAvailableFilters()` . For `location` and `tag` filters, you may look up additional values not returned by `getReleasesAvailableFilters()` through `getSuggestions()` of the [Autocomplete API ](#autocomplete-api ).
2021-01-19 21:37:31 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to [ReleasesByTag ](docs/api/interfaces/ReleasesByTag-1.md ).
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getReleasesAvailableFilters(tagUrl)< / code > < / summary >
< br / >
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/tag/getReleasesAvailableFilters.ts ) ([output](examples/tag/getReleasesAvailableFilters_output.txt))
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches the list of possible filter values for < code > getReleases()< / code > .< / p >
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
For `location` and `tag` filters, this method does not return an exhaustive list of values. You may use `getSuggestions()` of the [Autocomplete API ](#autocomplete-api ) to look up additional values.
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-02-03 11:09:12 +01:00
2023-06-10 16:52:27 +02:00
- `tagUrl` : (string) the URL of the tag for which filter values are to be returned.
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to Array< [ReleasesByTag.Filter](docs/api/interfaces/ReleasesByTag.Filter.md)>.
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
## Show API
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
To access the Show API:
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
```
import bcfetch from 'bandcamp-fetch';
const show = bcfetch.show;
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
const list = await show.list(...);
```
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
**Methods:**
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > list(params)< / code > < / summary >
< br / >
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/show/list.ts ) ([output](examples/show/list_output.txt))
2021-02-09 18:30:07 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches the full list of Bandcamp shows.< / p >
2021-02-14 12:34:30 +01:00
2023-06-10 16:52:27 +02:00
Each list entry contains basic info about a show. To obtain full details, pass its `url` to `getShow()` .
2021-02-14 12:34:30 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-02-14 12:34:30 +01:00
2023-06-10 16:52:27 +02:00
- `params` : ([ShowAPIListParams](docs/api/interfaces/ShowAPIListParams.md)) (*optional*)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to Array< [Show](docs/api/interfaces/Show.md)>.
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getShow(params)< / code > < / summary >
< br / >
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/show/getShow.ts ) ([output](examples/show/getShow_output.txt))
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches full details about the Bandcamp show referred to by < code > params.showUrl< / code > .< / p >
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
- `params` : ([ShowAPIGetShowParams](docs/api/interfaces/ShowAPIGetShowParams.md))
- `showUrl` : (string)
- `albumImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `artistImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `showImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
**Returns**
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
Promise resolving to [Show ](docs/api/interfaces/Show.md ).
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
## Article API
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
To access the Article API:
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
```
import bcfetch from 'bandcamp-fetch';
const article = bcfetch.article;
const list = await article.list(...);
```
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
**Methods:**
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getCategories()< / code > < / summary >
< br / >
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/article/getCategories.ts ) ([output](examples/article/getCategories_output.txt))
2021-02-13 17:20:02 +01:00
2023-06-10 16:52:27 +02:00
< p > Fetches the list of Bandcamp Daily article categories. Categories are grouped into sections.< / p >
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
**Returns**
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
Promise resolving to Array< [ArticleCategorySection](docs/api/interfaces/ArticleCategorySection.md)>.
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
---
< / details >
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > list(params)< / code > < / summary >
< br / >
2022-06-24 22:30:34 +02:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/article/list.ts ) ([output](examples/article/list_output.txt))
2022-06-24 22:30:34 +02:00
2023-06-10 16:52:27 +02:00
< p > Fetches the list of Bandcamp Daily articles under the category specified by < code > params.categoryUrl< / code > (or all categories if not specified).< / p >
2022-06-24 22:30:34 +02:00
2023-06-10 16:52:27 +02:00
**Params**
2022-06-24 22:30:34 +02:00
2023-06-10 16:52:27 +02:00
- `params` : ([ArticleAPIListParams](docs/api/interfaces/ArticleAPIListParams.md)) (*optional* and *all properties optional* )
- `categoryUrl` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md ))
- `page` : (number)
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
**Returns**
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
Promise resolving to [ArticleList ](docs/api/interfaces/ArticleList.md ).
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
---
< / details >
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > getArticle(params)< / code > < / summary >
< br / >
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
[**Example** ](examples/article/getArticle.ts ) ([output](examples/article/getArticle_output.txt))
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
< p > Fetches the contents of the Bandcamp Daily article at < code > params.articleUrl< / code > .< / p >
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
**Params**
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
- `params` : ([ArticleAPIGetArticleParams](docs/api/interfaces/ArticleAPIGetArticleParams.md))
- `articleUrl` : (string)
- `albumImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `artistImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `includeRawData` : (boolean) (*optional*)
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
**Returns**
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
Promise resolving to [Article ](docs/api/interfaces/Article.md ).
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
---
< / details >
2022-06-23 14:09:44 +02:00
2023-06-10 16:52:27 +02:00
## Fan API
2021-02-16 13:33:54 +01:00
2023-06-10 16:52:27 +02:00
To access the Fan API:
2021-02-16 13:33:54 +01:00
```
2023-06-10 16:52:27 +02:00
import bcfetch from 'bandcamp-fetch';
const fan = bcfetch.fan;
const info = await fan.getInfo(...);
const collection = await fan.getCollection(...);
2021-02-16 13:33:54 +01:00
```
2023-06-10 16:52:27 +02:00
**Methods:**
< details >
< summary > < code > getInfo(params)< / code > < / summary >
< br / >
[**Example** ](examples/fan/getInfo.ts ) ([output](examples/fan/getInfo_output.txt))
< p > Fetches info about a fan.< / p >
**Params**
- `params` : ([FanAPIGetInfoParams](docs/api/interfaces/FanAPIGetInfoParams.md))
- `username` : (string)
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to [Fan ](docs/api/interfaces/Fan.md ).
---
< / details >
< details >
< summary > < code > getCollection(params)< / code > < / summary >
< br / >
[**Example** ](examples/fan/getCollection.ts ) ([output](examples/fan/getCollection_output.txt))
< p > Fetches the list of albums and tracks in a fan's collection.< / p >
**Params**
- `params` : ([FanAPIGetItemsParams](docs/api/interfaces/FanAPIGetItemsParams.md))
- `target` : (string | [FanItemsContinuation ](docs/api/interfaces/FanItemsContinuation.md )) if username (string) is specified, returns the first batch of items in the collection. To obtain further items, call the method again but, instead of username, pass `continuation` from the result of the first call. If there are no further items available, `continuation` will be `null` .
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to ([FanPageItemsResult](docs/api/interfaces/FanPageItemsResult.md) | [FanContinuationItemsResult ](docs/api/interfaces/FanContinuationItemsResult.md ))< [Album](docs/api/interfaces/Album.md) | [Track ](docs/api/interfaces/Track.md )>.
---
< / details >
< details >
< summary > < code > getWishlist(params)< / code > < / summary >
< br / >
[**Example** ](examples/fan/getWishlist.ts ) ([output](examples/fan/getWishlist_output.txt))
< p > Fetches the list of albums and tracks added to a fan's wishlist.< / p >
**Params**
- `params` : ([FanAPIGetItemsParams](docs/api/interfaces/FanAPIGetItemsParams.md))
- `target` : (string | [FanItemsContinuation ](docs/api/interfaces/FanItemsContinuation.md )) if username (string) is specified, returns the first batch of items in the wishlist. To obtain further items, call the method again but, instead of username, pass `continuation` from the result of the first call. If there are no further items available, `continuation` will be `null` .
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to ([FanPageItemsResult](docs/api/interfaces/FanPageItemsResult.md) | [FanContinuationItemsResult ](docs/api/interfaces/FanContinuationItemsResult.md ))< [Album](docs/api/interfaces/Album.md) | [Track ](docs/api/interfaces/Track.md )>.
---
< / details >
< details >
< summary > < code > getFollowingArtistsAndLabels(params)< / code > < / summary >
< br / >
[**Example** ](examples/fan/getFollowingArtistsAndLabels.ts ) ([output](examples/fan/getFollowingArtistsAndLabels_output.txt))
< p > Fetches the list of artists and labels followed by a fan.< / p >
**Params**
- `params` : ([FanAPIGetItemsParams](docs/api/interfaces/FanAPIGetItemsParams.md))
- `target` : (string | [FanItemsContinuation ](docs/api/interfaces/FanItemsContinuation.md )) if username (string) is specified, returns the first batch of artists and labels. To obtain further items, call the method again but, instead of username, pass `continuation` from the result of the first call. If there are no further items available, `continuation` will be `null` .
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to ([FanPageItemsResult](docs/api/interfaces/FanPageItemsResult.md) | [FanContinuationItemsResult ](docs/api/interfaces/FanContinuationItemsResult.md ))< [UserKind](docs/api/interfaces/UserKind.md)>.
---
< / details >
< details >
< summary > < code > getFollowingGenres(params)< / code > < / summary >
< br / >
[**Example** ](examples/fan/getFollowingGenres.ts ) ([output](examples/fan/getFollowingGenres_output.txt))
< p > Fetches the list of genres followed by a fan.< / p >
Each genre is actually a Bandcamp tag, so you can, for example, pass its `url` to `getReleases()` of the [Tag API ](#tag-api ).
**Params**
- `params` : ([FanAPIGetItemsParams](docs/api/interfaces/FanAPIGetItemsParams.md))
- `target` : (string | [FanItemsContinuation ](docs/api/interfaces/FanItemsContinuation.md )) if username (string) is specified, returns the first batch of genres. To obtain further items, call the method again but, instead of username, pass `continuation` from the result of the first call. If there are no further items available, `continuation` will be `null` .
- `imageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to ([FanPageItemsResult](docs/api/interfaces/FanPageItemsResult.md) | [FanContinuationItemsResult ](docs/api/interfaces/FanContinuationItemsResult.md ))< [Tag](docs/api/interfaces/Tag.md)>.
---
< / details >
## Search API
To access the Search API:
```
import bcfetch from 'bandcamp-fetch';
const search = bcfetch.search;
const albums = await search.albums(...);
const all = await search.all(...);
```
**Methods:**
< details >
< summary > < code > all(params) / artistsAndLabels(params) / albums(params) / tracks(params) / fans(params)< / code > < / summary >
< br / >
[**Example** ](examples/search/search.ts ) ([output](examples/search/search_output.txt))
- `all(params)` : search all item types
- `artistsAndLabels(params)` : search artists and labels
- `albums(params)` : search albums
- `tracks(params)` : search tracks
- `fans(params)` : search fans
**Params**
- `params` : ([SearchAPISearchParams](docs/api/interfaces/SearchAPISearchParams.md))
- `query` : (string)
- `page` : (number) (*optional*) 1 if omitted
- `albumImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
- `artistImageFormat` : (string | number | [ImageFormat ](docs/api/interfaces/ImageFormat.md )) (*optional*)
**Returns**
Promise resolving to [SearchResults ](docs/api/interfaces/SearchResults.md )< `T`> , where `T` depends on the item type being searched and can be one of:
- Artist ([SearchResultArtist](docs/api/interfaces/SearchResultArtist.md))
- Label ([SearchResultLabel](docs/api/interfaces/SearchResultLabel.md))
- Album ([SearchResultAlbum](docs/api/interfaces/SearchResultAlbum.md))
- Track ([SearchResultTrack](docs/api/interfaces/SearchResultTrack.md))
- Fan ([SearchResultFan](docs/api/interfaces/SearchResultFan.md))
You can use the `type` property to determine the search result item type.
---
< / details >
## Autocomplete API
To access the Autocomplete API:
```
import bcfetch from 'bandcamp-fetch';
const autocomplete = bcfetch.autocomplete;
const suggestions = await autocomplete.getSuggestions(...);
```
**Methods:**
< details >
< summary > < code > getSuggestions(params)< / code > < / summary >
< br / >
[**Example** ](examples/autocomplete/getSuggestions.ts ) ([output](examples/autocomplete/getSuggestions_output.txt))
< p > Fetches autocomplete suggestions for tags and locations, based on partial and full matches against `params.query` .</ p >
The `value` property of returned suggestions can be used to set the `location` or `tags` property (as the case may be) of `params.filters` that is passed into `getReleases()` of the [Tag API ](#tag-api ).
**Params**
- `params` : ([AutocompleteAPIGetSuggestionsParams](docs/api/interfaces/AutocompleteAPIGetSuggestionsParams.md))
- `query` : (string)
- `itemType` : ([AutocompleteItemType](docs/api/enums/AutocompleteItemType.md)) 'Tag' or 'Location'
- limit: (number) (*optional*) the maximum number of results to return; 5 if omitted.
**Returns**
- If `params.itemType` is `AutocompleteItemType.Tag` , a Promise resolving to Array< [AutocompleteTag](docs/api/interfaces/AutoCompleteTag.md)>.
- If `params.itemType` is `AutocompleteItemType.Location` , a Promise resolving to Array< [AutocompleteLocation](docs/api/interfaces/AutocompleteLocation.md)>.
---
< / details >
# Rate Limiting
`bandcamp-fetch` comes with a rate limiter, which limits the number of requests made within a specific time period.
2021-02-16 13:33:54 +01:00
Rate limiting is useful when you need to make a large number of queries and don't want to run the risk of getting rejected by the server for making too many requests within a short time interval. If you get a '429 Too Many Requests' error, then you should consider using the rate limiter.
2023-06-10 16:52:27 +02:00
Each API has a limiter-enabled counterpart which you can access in the following manner:
```
import bcfetch from 'bandcamp-fetch';
// Album API - no limiter enabled
const albumAPI = bcfetch.album;
// Album API - limiter enabled
const limiterAlbumAPI = bcfetch.limiter.album;
```
[**Example** ](examples/limiter/limiter.ts ) ([output](examples/limiter/limiter_output.txt))
2021-02-16 13:33:54 +01:00
The library uses [Bottleneck ](https://www.npmjs.com/package/bottleneck ) for rate limiting. You can configure the rate limiter like this:
```
bcfetch.limiter.updateSettings({
maxConcurrent: 10, // default: 5
minTime: 100 // default: 200
});
```
`updateSettings()` is just a passthrough function to Bottleneck. Check the [Bottleneck doc ](https://www.npmjs.com/package/bottleneck#docs ) for the list of options you can set.
2023-06-10 16:52:27 +02:00
# Cache
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
The library maintains an in-memory cache for two types of data (as defined by [CacheDataType ](docs/api/enums/CacheDataType.md )):
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
1. `CacheDataType.Page` - pages fetched during scraping
2. `CacheDataType.Constants` - image formats and discover options
To access the cache:
2021-01-26 10:24:10 +01:00
```
2023-06-10 16:52:27 +02:00
import bcfetch, { CacheDataType } from 'bandcamp-fetch';
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
const cache = bcfetch.cache;
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
cache.setTTL(CacheDataType.Page, 500);
2021-01-26 10:24:10 +01:00
```
2023-06-10 16:52:27 +02:00
**Methods:**
< details >
< summary > < code > setTTL(type, ttl)< / code > < / summary >
< br / >
< p > Sets the expiry time, in seconds, of cache entries for the given data type.< / p >
**Params**
- `type` : ([CacheDataType](docs/api/enums/CacheDataType.md))
- `TTL` : (number) expiry time in seconds (default: 300 for `CacheDataType.Page` and 3600 for `CacheDataType.Constants` )
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
< details >
< summary > < code > setMaxPages(maxPages)< / code > < / summary >
< br / >
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
< p > Sets the maximum number of pages that can be stored in the cache. A negative value means unlimited. Default: 10.< / p >
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
**Params**
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
- `maxPages` : (number)
2021-01-26 10:24:10 +01:00
2023-06-10 16:52:27 +02:00
---
< / details >
< details >
< summary > < code > clear([type])< / code > < / summary >
< br / >
< p > Clears the cache entries for the specified data type (or all entries if no data type specified).< / p >
**Params**
- `type` : ([CacheDataType](docs/api/enums/CacheDataType.md)) (*optional*)
---
< / details >
2021-01-26 10:24:10 +01:00
2021-10-19 18:57:34 +02:00
# Changelog
2023-06-13 22:11:44 +02:00
1.0.1
- Fix limiter throwing private access errors
2023-06-10 16:52:27 +02:00
1.0.0 (breaking changes!)
- Move to TypeScript
- Package as ESM + CJS hybrid module
- Restructure API
- Remove `safe-eval` dependency
2022-06-24 22:44:26 +02:00
0.3.1-b.1
- Add `getFanCollection()` function
2022-06-23 21:44:49 +02:00
0.3.0-b.1
- Add fan functions
2021-11-14 18:06:19 +01:00
0.2.2-b.1
- Add `itemType` option to search params
2021-10-20 13:03:12 +02:00
0.2.1-b.20211020b
- Fix URL sometimes null in result of `getArtistOrLabelInfo()`
2021-10-20 10:18:03 +02:00
0.2.1-b.20211020
- Improve data fetching in `getArtistOrLabelInfo()`
2021-10-19 18:57:34 +02:00
0.2.0-b.20211020
- Adapt to Bandcamp changes since last version
- Add `publisher` and `label` to data fetched by `getAlbumInfo()` and `getTrackInfo()`
- Add `labelId` to data fetched by `getArtistOrLabelInfo(labelUrl)`
- Add `labelId` option to `getArtistOrLabelInfo()` for artist URLs
...(no changelog for earlier versions due to laziness)
2021-01-19 21:37:31 +01:00
# License
MIT