1.0.1 • Published 9 years ago

hmv-scraper v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

hmv-scraper

Dependency Status TravisCI Status

Scraper that searches products on the Canadian HMV store hmv.ca.

install

Using npm.

npm install hmv-scraper

usage

new HmvScraper(onProductError)

Optional param onProductError is a function that will be called when a product unexpectedly fail the validation. It takes respectively, the product, an array of AJV Error, and a string that represents the errors.

var HmvScraper = require('hmv-scraper');
var onProductError = function (product, errors, errorsText) {
  console.log('Product failed validation: ' + errorsText);
  console.log(product);
};
var hmv = new HmvScraper(onProductError);

// or

var HmvScraper = require('hmv-scraper');
var hmv = new HmvScraper();

searchByKeyword(query, callback(error, results))

Search products by keyword.

hmv.searchByKeyword({
  query: 'James Bond'  
}, function(error, results) {
  if (error) {
    console.log(error);
  } else {
    console.log(results);
  }
});

searchByArtist(query, callback(error, results))

Search products by artist.

hmv.searchByArtist({
  query: 'Céline Dion',
  sort: 'Bestselling',
  filter: 'All',
  page: 3
}, function(error, results) {
  if (error) {
    console.log(error);
  } else {
    console.log(results);
  }
});

param query

NameDescriptionAccepted valuesDefault valueRequired
queryThe keyword or the artist you search.StringYes
pageThe page of result that you want.Integer1No
filterThe group in which you want to search.'All', 'CD', 'Vinyl', 'DVD', 'Bluray', '3dBluray', 'Headphones', 'GiftsCollect', 'Apparel''All'No
sortThe order in which the products should sort.'Bestselling', 'Date of release', 'Price: Low to High', 'Price: High to Low', 'Alphabetical: A to Z', 'Alphabetical: Z to A''Bestselling'No

param callback(error, products)

Function that is called when the request is done or when there is an error.

product

The structure of a product is described below, for more details check the product JSON schema.

NameTypeDescriptionAlways present
idIntegerIdYes
skuIntegerSKUYes
nameStringName of the productYes
priceInCentsIntegerPrice in cents in Canadian dollarYes
categoryStringThe category ('Music', 'Film', 'Apparel', 'Headphones', 'Gift')Yes
kindStringThe kind of product or its format if the category is 'Music' or 'Film'Yes
availableBooleanIf the product is available onlineYes
urlStringUrl of the product in the storeYes
reservationUrlStringThe reservation URL to find a store and reserve the productYes
catalogueStringCatalogue number or serial numberNo
promotionStringThe promotionsNo
supplierStringThe supplier nameNo
smallImageUrlStringSmall image URLNo
mediumImageUrlStringMedium image URLNo
largeImageUrlStringLarge image URLNo
releaseDateStringThe released date in ISO 8601 date formatOnly if category is 'Music' or 'Film'
artistStringThe artist of the productOnly if category is 'Music'

Example:

{
  id: 72201,
  sku: 246337,
  name: 'NEW DAY HAS COME',
  priceInCents: 1500,
  category: 'Music',
  kind: 'CD',
  available: true,
  url: 'https://www.hmv.ca/en/Search/Details?sku=246337',
  reservationUrl: 'https://www.hmv.ca/en/Stores?reserve=true&id=72201',
  catalogue: 'CK86400',
  supplier: 'COLUMBIA',
  smallImageUrl: 'https://www.hmv.ca/images/Music/75/44/4443/444344.jpg',
  mediumImageUrl: 'https://www.hmv.ca/images/Music/170/44/4443/444344.jpg',
  largeImageUrl: 'https://www.hmv.ca/images/Music/450/44/4443/444344.jpg',
  artist: 'CELINE DION',
  releaseDate: '2002-03-26'
}

Contributing

Contribution is welcome! Open an issue first.

test

npm test

license

MIT

1.0.1

9 years ago

1.0.0

9 years ago

0.1.1

10 years ago

0.1.0

10 years ago