bandcamp-fetch
Advanced tools
Comparing version 0.1.0-a-20210126 to 0.1.0-a-20210203
@@ -239,2 +239,25 @@ const fetch = require('node-fetch'); | ||
async function getAllShows(options = {}) { | ||
const imageConstants = await _getImageConstants(); | ||
const opts = { | ||
imageBaseUrl: imageConstants.baseUrl, | ||
showImageFormat: await _parseImageFormatArg(options.showImageFormat, 25) | ||
}; | ||
return _fetchPage(utils.getAllShowsUrl(), true) | ||
.then( json => parser.parseAllShows(json, opts) ); | ||
} | ||
async function getShow(showUrl, options = {}) { | ||
const imageConstants = await _getImageConstants(); | ||
const opts = { | ||
showUrl, | ||
imageBaseUrl: imageConstants.baseUrl, | ||
albumImageFormat: await _parseImageFormatArg(options.albumImageFormat, 9), | ||
artistImageFormat: await _parseImageFormatArg(options.artistImageFormat, 21), | ||
showImageFormat: await _parseImageFormatArg(options.showImageFormat, 25) | ||
}; | ||
return _fetchPage(showUrl) | ||
.then( html => parser.parseShow(html, opts) ); | ||
} | ||
async function _fetchPage(url, json = false) { | ||
@@ -269,3 +292,5 @@ return _cache.getOrSet('page', url + (json ? ':json' : ':html'), () => { | ||
getTags, | ||
cache | ||
cache, | ||
getAllShows, | ||
getShow, | ||
}; |
@@ -634,2 +634,73 @@ const cheerio = require('cheerio'); | ||
function parseAllShows(json, opts) { | ||
const shows = []; | ||
if (typeof json === 'object' && Array.isArray(json.results)) { | ||
json.results.forEach( show => { | ||
shows.push({ | ||
type: 'show', | ||
name: show.title, | ||
url: utils.getShowUrl(show.id), | ||
publishedDate: show.published_date, | ||
description: show.desc, | ||
imageCaption: show.image_caption, | ||
subtitle: show.subtitle, | ||
imageUrl: opts.imageBaseUrl + '/img/' + show.v2_image_id + '_' + opts.showImageFormat.id + '.jpg', | ||
screenImageUrl: opts.imageBaseUrl + '/img/' + show.v2_image_id + '_0' | ||
}) | ||
}) | ||
} | ||
return shows; | ||
} | ||
function parseShow(html, opts) { | ||
const $ = cheerio.load(html); | ||
const blob = decode($('#pagedata[data-blob]').attr('data-blob')); | ||
const parsed = JSON.parse(blob); | ||
if (typeof parsed === 'object' && parsed.bcw_data) { | ||
const showInfo = parsed.bcw_data[utils.getShowIdFromUrl(opts.showUrl)]; | ||
if (showInfo) { | ||
const show = { | ||
type: 'show', | ||
name: showInfo.title, | ||
url: utils.getShowUrl(showInfo.show_id), | ||
publishedDate: showInfo.published_date, | ||
description: showInfo.desc, | ||
shortDescription: showInfo.short_desc, | ||
imageCaption: showInfo.image_caption, | ||
subtitle: showInfo.subtitle, | ||
duration: showInfo.audio_duration, | ||
imageUrl: opts.imageBaseUrl + '/img/' + showInfo.show_v2_image_id + '_' + opts.showImageFormat.id + '.jpg', | ||
screenImageUrl: opts.imageBaseUrl + '/img/' + showInfo.show_v2_image_id + '_0', | ||
streamUrl: showInfo.audio_stream, | ||
tracks: [] | ||
} | ||
showInfo.tracks.forEach( track => { | ||
const trackItem = { | ||
name: track.title, | ||
url: track.track_url, | ||
imageUrl: opts.imageBaseUrl + '/img/a' + track.track_art_id + '_' + opts.albumImageFormat.id + '.jpg', | ||
seekPosition: track.timecode, | ||
artist: { | ||
name: track.artist, | ||
url: 'https://' + track.url_hints.subdomain + '.bandcamp.com', | ||
imageUrl: opts.imageBaseUrl + '/img/' + track.bio_image_id + '_' + opts.artistImageFormat.id + '.jpg', | ||
location: track.location_text | ||
}, | ||
album: null | ||
}; | ||
if (track.album_title) { | ||
trackItem.album = { | ||
name: track.album_title, | ||
url: track.album_url | ||
} | ||
} | ||
show.tracks.push(trackItem); | ||
}); | ||
return show; | ||
} | ||
} | ||
return null; | ||
} | ||
module.exports = { | ||
@@ -646,3 +717,5 @@ parseDiscoverResults, | ||
parseAlbumHighlightsByTag, | ||
parseTags | ||
parseTags, | ||
parseAllShows, | ||
parseShow, | ||
}; |
@@ -117,2 +117,20 @@ const querystring = require('querystring'); | ||
function getAllShowsUrl() { | ||
return getSiteUrl() + '/api/bcweekly/3/list'; | ||
} | ||
function getShowIdFromUrl(showUrl) { | ||
const _url = splitUrl(showUrl); | ||
let qs = _url.query; | ||
if (qs.startsWith('?')) { | ||
qs = qs.substr(1); | ||
} | ||
const pqs = querystring.parse(qs); | ||
return pqs && pqs.show ? pqs.show : null; | ||
} | ||
function getShowUrl(showId) { | ||
return getSiteUrl() + '/?show=' + showId; | ||
} | ||
module.exports = { | ||
@@ -131,3 +149,6 @@ getUrl, | ||
stripMultipleWhitespaces, | ||
isAbsoluteUrl | ||
isAbsoluteUrl, | ||
getAllShowsUrl, | ||
getShowIdFromUrl, | ||
getShowUrl | ||
}; |
{ | ||
"name": "bandcamp-fetch", | ||
"version": "0.1.0a-20210126", | ||
"version": "0.1.0a-20210203", | ||
"description": "JS library for scraping Bandcamp content", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -165,2 +165,22 @@ # bandcamp-fetch | ||
### `getAllShows([options])` | ||
[**Example**](examples/getAllShows.js) ([output](examples/getAllShows_output.txt)) | ||
Fetches all Bandcamp shows. Each entry in the returned array contains basic information about a show. To retrieve details of a show, pass the `url` property of the entry to `getShow()`. | ||
- `options` (optional) | ||
- showImageFormat | ||
### `getShow(showUrl, [options])` | ||
[**Example**](examples/getShow.js) ([output](examples/getShow_output.txt)) | ||
Get show details for the given `showUrl`. | ||
- `options` (optional) | ||
- albumImageFormat | ||
- artistImageFormat | ||
- showImageFormat | ||
## Caching | ||
@@ -167,0 +187,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
291912
35
1293
221