From 88ebf8bd5ea894b389075ab3e63b9419dada3597 Mon Sep 17 00:00:00 2001 From: Pionxzh Date: Fri, 21 Jul 2023 01:58:35 +0800 Subject: [PATCH] feat: add `id` to video search response to align with video page #68 --- doc/Search.md | 3 ++- src/scrapers/search/video.ts | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/Search.md b/doc/Search.md index a62630f..e77e86f 100644 --- a/doc/Search.md +++ b/doc/Search.md @@ -78,7 +78,8 @@ res.data.forEach((item) => { console.log(item) /* { title: 'tokyo hot ep1', - url: 'https://www.pornhub.com/view_video.php?viewkey=***', + id: 'phxxxxx', + url: 'https://www.pornhub.com/view_video.php?viewkey=phxxxxx', duration: '21:43', hd: true, premium: false, diff --git a/src/scrapers/search/video.ts b/src/scrapers/search/video.ts index 562e032..aa85621 100644 --- a/src/scrapers/search/video.ts +++ b/src/scrapers/search/video.ts @@ -2,6 +2,7 @@ import urlcat from 'urlcat' import { Route } from '../../apis' import { getAttribute, getCheerio } from '../../utils/cheerio' import { BASE_URL } from '../../utils/constant' +import { UrlParser } from '../../utils/url' import { parseCounting, parsePaging } from './base' import type { Engine } from '../../core/engine' import type { Counting, Paging, VideoSearchOptions } from '../../types' @@ -9,6 +10,7 @@ import type { CheerioAPI } from 'cheerio' export interface VideoListResult { title: string + id: string url: string views: string duration: string @@ -46,12 +48,15 @@ export function parseVideoResult($: CheerioAPI, container: string) { const thumb = item.find('.linkVideoThumb').eq(0) const title = getAttribute(thumb, 'title', '') const path = getAttribute(thumb, 'href', '') + const url = urlcat(BASE_URL, path) + const id = UrlParser.getVideoID(url) const img = item.find('img') const preview = getAttribute(img, 'src', '') return { title, - url: urlcat(BASE_URL, path), + id, + url, views: item.find('.videoDetailsBlock .views var').text(), duration: item.find('.duration').text(), hd: !!item.find('.hd-thumbnail').length,