diff --git a/lib/index.js b/lib/index.js index f9135b8..5122e1f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,15 @@ async function discover(params, options = {}) { let resultParams; return sanitizeDiscoverParams(params) .then( sanitizedParams => { - resultParams = sanitizedParams; + resultParams = Object.assign({}, sanitizedParams); + // Passing an 'all' type subgenre (e.g. 'all-metal') in the discover url + // actually returns far fewer / zero results than without. + // The Bandcamp site also does not seem to include it in its discover requests... + if (sanitizedParams.time !== undefined) { + // If 'time' exists in sanitized params, then we have an 'all' type subgenre + // - refer to sanitizeDiscoverParams() + delete sanitizedParams.subgenre; + } return utils.getDiscoverUrl(sanitizedParams); }) .then( url => fetch(url) ) @@ -54,6 +62,8 @@ async function sanitizeDiscoverParams(params) { if (subgenreOptions) { // false if genre is 'all' sanitized.subgenre = getOptionValue(subgenreOptions, params.subgenre); } + // 'Time' option only available when there is effectively no subgenre (e.g. genre is 'all' + // or subgenre is 'all-metal') const timeAllowed = sanitized.subgenre === undefined || sanitized.subgenre == subgenreOptions[0].value; if (timeAllowed) { sanitized.time = getOptionValue(options.times, params.time);