From c1923cc538a1bb84164d6b001dc53f878dffe17a Mon Sep 17 00:00:00 2001 From: Nagara <39037656+gideonsenku@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:30:38 +0800 Subject: [PATCH] feat(route): support hkushop (#18644) * feat(route): support hkushop * fix: route params * fix: bot review * fix: review --------- Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> --- lib/routes/hkushop/namespace.ts | 9 +++ lib/routes/hkushop/vinyl-or-picture-lp.ts | 87 +++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 lib/routes/hkushop/namespace.ts create mode 100644 lib/routes/hkushop/vinyl-or-picture-lp.ts diff --git a/lib/routes/hkushop/namespace.ts b/lib/routes/hkushop/namespace.ts new file mode 100644 index 000000000..8af35abcd --- /dev/null +++ b/lib/routes/hkushop/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '環球唱片(香港)官方網上商店', + url: 'hkushop.com', + lang: 'zh-HK', + categories: ['shopping'], + description: '環球唱片(香港)官方網上商店', +}; diff --git a/lib/routes/hkushop/vinyl-or-picture-lp.ts b/lib/routes/hkushop/vinyl-or-picture-lp.ts new file mode 100644 index 000000000..c69296541 --- /dev/null +++ b/lib/routes/hkushop/vinyl-or-picture-lp.ts @@ -0,0 +1,87 @@ +import { Route } from '@/types'; +import puppeteer from '@/utils/puppeteer'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/vinyl/:cat?', + categories: ['shopping'], + example: '/hkushop/vinyl', + parameters: { + cat: '分类,见下表,默认不分类', + }, + features: { + requireConfig: false, + requirePuppeteer: true, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + supportRadar: true, + }, + radar: [ + { + source: ['hkushop.com/vinyl-or-picture-lp.html', 'hkushop.com/'], + target: '/vinyl', + }, + ], + name: 'HKU Shop 黑胶专区', + maintainers: ['gideonsenku'], + handler, + description: `常见分类: +| 華語音樂 | 經典復刻 | 古典跨界 | 爵士音樂 | 國際音樂 | 電影原聲帶 | 黑膠日本音樂 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| 37 | 38 | 40 | 41 | 39 | 170 | 224 |`, + url: 'hkushop.com/vinyl-or-picture-lp.html', +}; + +async function handler(ctx) { + const baseUrl = 'https://hkushop.com'; + const cat = ctx.req.param('cat') ?? ''; + const url = cat ? `${baseUrl}/vinyl-or-picture-lp.html?cat=${cat}` : `${baseUrl}/vinyl-or-picture-lp.html`; + + const browser = await puppeteer(); + const page = await browser.newPage(); + await page.setRequestInterception(true); + page.on('request', (request) => { + request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort(); + }); + await page.goto(url, { + waitUntil: 'domcontentloaded', + }); + + const response = await page.content(); + await page.close(); + await browser.close(); + + const $ = load(response); + + const list = $('.products.list.items.product-items .product-item') + .toArray() + .map((item) => { + const $item = $(item); + const $link = $item.find('.product-item-link'); + const $price = $item.find('.price'); + const $image = $item.find('.product-image-photo'); + const $artist = $item.find('.artist a').text().trim(); + + return { + title: $link.text().trim(), + link: $link.attr('href'), + description: ` + +

作者: ${$artist}

+

价格: ${$price.text().trim()}

+ `, + guid: $link.attr('href'), + }; + }); + + const title = cat ? `黑胶\\彩胶系列 - ${$('.page-title').text().trim()}` : String.raw`黑胶\\彩胶系列 - HKU Shop 环球唱片网店`; + + return { + title, + link: url, + description: 'HKU Shop 黑胶唱片最新商品信息', + item: list, + }; +}