Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/htmlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ exports.parseArtistInfo = function (html, artistUrl) {
selector: '.bio-pic a',
attr: 'href'
},
bannerImage: {
selector: ".desktop-header a img",
attr: 'src'
},
description: 'p#bio-text',
albums: {
listItem: '.music-grid-item',
Expand Down Expand Up @@ -453,14 +457,34 @@ exports.parseArtistInfo = function (html, artistUrl) {
const albums = data.albums.map(mapAlbums)
const mergedAlbums = [...new Set([...albums, ...data.discographyAlbums])]

// Parse raw.
const scriptWithRaw = $('script[data-tralbum]')
if (scriptWithRaw.length > 0) {
data.raw = scriptWithRaw.data('band')
} else {
let raw = this.extractJavascriptObjectVariable(html, 'BandData')
// The only javascript in the variable is the concatenation of the base url
// with the current album path. We nned to do it yourself.
// Ex:
// url: "http://musique.coeurdepirate.com" + "/album/blonde",
raw = raw ? raw.replace('" + "', '') : ''
try {
data.raw = JSON5.parse(raw)
} catch (error) {
console.error(error)
}
}

return {
name: data.name,
location: data.location,
description: data.description,
coverImage: data.coverImage,
bannerImage: data.bannerImage,
albums: mergedAlbums,
shows: data.shows,
bandLinks: data.bandLinks
bandLinks: data.bandLinks,
raw: data.raw
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ const urlHelper = require('url')
const htmlParser = require('./htmlParser.js')
const utils = require('./utils.js')

const checkNotFound = function (html) {
return (html.includes("Sorry, that something isn’t here.") || html.includes('<meta property="og:url" content="https://bandcamp.com/">'));
}

exports.search = function (params, cb) {
const url = utils.generateSearchUrl(params)
req(url, function (error, html) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const searchResults = htmlParser.parseSearchResults(html)
cb(null, searchResults)
}
Expand All @@ -21,6 +26,7 @@ exports.getAlbumsWithTag = function (params, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const tagResults = htmlParser.parseTagResults(html)
cb(null, tagResults)
}
Expand All @@ -33,6 +39,7 @@ exports.getAlbumUrls = function (artistUrl, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const albumUrls = htmlParser.parseAlbumUrls(html, artistUrl)
cb(null, albumUrls)
}
Expand All @@ -44,6 +51,7 @@ exports.getAlbumInfo = function (albumUrl, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const albumInfo = htmlParser.parseAlbumInfo(html, albumUrl)
cb(null, albumInfo)
}
Expand All @@ -55,6 +63,7 @@ exports.getAlbumProducts = function (albumUrl, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const products = htmlParser.parseAlbumProducts(html, albumUrl)
cb(null, products)
}
Expand All @@ -67,6 +76,7 @@ exports.getArtistUrls = function (labelUrl, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const artistUrls = htmlParser.parseArtistUrls(html, labelUrl)
cb(null, artistUrls)
}
Expand All @@ -78,6 +88,7 @@ exports.getArtistInfo = function (artistUrl, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const artistInfo = htmlParser.parseArtistInfo(html, artistUrl)
cb(null, artistInfo)
}
Expand All @@ -89,6 +100,7 @@ exports.getTrackInfo = function (trackUrl, cb) {
if (error) {
cb(error, null)
} else {
if (checkNotFound(html)) return cb("404", null);
const trackInfo = htmlParser.parseTrackInfo(html, trackUrl)
cb(null, trackInfo)
}
Expand Down
Loading