mirror of
https://github.com/BradNut/personal-website-sveltekit
synced 2025-09-08 23:20:18 +00:00
40 lines
979 B
TypeScript
40 lines
979 B
TypeScript
import { BANDCAMP_USERNAME } from '$env/static/private';
|
|
import scrapeIt from 'scrape-it';
|
|
import type { Album } from '../types/album';
|
|
|
|
export async function fetchBandcampAlbums() {
|
|
try {
|
|
const { data } = await scrapeIt(`https://bandcamp.com/${BANDCAMP_USERNAME}`, {
|
|
collectionItems: {
|
|
listItem: '.collection-item-container',
|
|
data: {
|
|
url: {
|
|
selector: '.collection-title-details > a.item-link',
|
|
attr: 'href'
|
|
},
|
|
artwork: {
|
|
selector: 'div.collection-item-art-container a img',
|
|
attr: 'src'
|
|
},
|
|
title: {
|
|
selector: 'span.item-link-alt > div.collection-item-title'
|
|
},
|
|
artist: {
|
|
selector: 'span.item-link-alt > div.collection-item-artist'
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
const albums: Album[] = data?.collectionItems || [];
|
|
console.log(`Albums ${JSON.stringify(albums)}`);
|
|
|
|
if (albums && albums?.length > 0) {
|
|
return albums;
|
|
} else {
|
|
return [];
|
|
}
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
}
|