Skip to content

Commit

Permalink
feat: add id to video search response to align with video page
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Jul 20, 2023
1 parent d6d585f commit 88ebf8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/Search.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/scrapers/search/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ 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'
import type { CheerioAPI } from 'cheerio'

export interface VideoListResult {
title: string
id: string
url: string
views: string
duration: string
Expand Down Expand Up @@ -46,12 +48,15 @@ export function parseVideoResult($: CheerioAPI, container: string) {
const thumb = item.find('.linkVideoThumb').eq(0)
const title = getAttribute<string>(thumb, 'title', '')
const path = getAttribute<string>(thumb, 'href', '')
const url = urlcat(BASE_URL, path)
const id = UrlParser.getVideoID(url)
const img = item.find('img')
const preview = getAttribute<string>(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,
Expand Down

0 comments on commit 88ebf8b

Please sign in to comment.