-
Notifications
You must be signed in to change notification settings - Fork 9.6k
feat(route): add rule34video latest route #21696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,134 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import { load } from 'cheerio'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { Context } from 'hono'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import type { Route } from '@/types'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import got from '@/utils/got'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { parseRelativeDate } from '@/utils/parse-date'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export const route: Route = { | ||||||||||||||||||||||||||||||||||||||||||||||
| path: '/latest', | ||||||||||||||||||||||||||||||||||||||||||||||
| categories: ['multimedia'], | ||||||||||||||||||||||||||||||||||||||||||||||
| example: '/rule34video/latest', | ||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Latest updates from Rule34 Video', | ||||||||||||||||||||||||||||||||||||||||||||||
| features: { | ||||||||||||||||||||||||||||||||||||||||||||||
| requireConfig: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| requirePuppeteer: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| antiCrawler: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| supportBT: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| supportPodcast: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| supportScihub: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| nsfw: true, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| radar: [ | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| source: ['rule34video.com/latest-updates/'], | ||||||||||||||||||||||||||||||||||||||||||||||
| target: '/rule34video/latest', | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||
| name: 'Latest Updates', | ||||||||||||||||||||||||||||||||||||||||||||||
| maintainers: ['Dgama'], | ||||||||||||||||||||||||||||||||||||||||||||||
| handler, | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| interface VideoItem { | ||||||||||||||||||||||||||||||||||||||||||||||
| title: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| link: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| preview?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| duration?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| added?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| rating?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| views?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| hasSound: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
| isHD: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
| videoId?: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| async function handler(_ctx: Context) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| const response = await got({ | ||||||||||||||||||||||||||||||||||||||||||||||
| method: 'get', | ||||||||||||||||||||||||||||||||||||||||||||||
| url: 'https://www.rule34video.com/latest-updates/', | ||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||
| Referer: 'https://www.rule34video.com', | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const $ = load(response.data); | ||||||||||||||||||||||||||||||||||||||||||||||
| const items = $('a.th.js-open-popup') | ||||||||||||||||||||||||||||||||||||||||||||||
| .toArray() | ||||||||||||||||||||||||||||||||||||||||||||||
| .map((element) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const $el = $(element); | ||||||||||||||||||||||||||||||||||||||||||||||
| const title = $el.attr('title')?.trim() || $el.find('.thumb_title').text().trim(); | ||||||||||||||||||||||||||||||||||||||||||||||
| const link = $el.attr('href')?.trim() || ''; | ||||||||||||||||||||||||||||||||||||||||||||||
| const preview = $el.find('img.thumb.lazy-load').attr('data-original'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const duration = $el.find('.time').text().trim() || undefined; | ||||||||||||||||||||||||||||||||||||||||||||||
| const added = $el.find('.added').text().replaceAll(/\s+/g, ' ').trim() || undefined; | ||||||||||||||||||||||||||||||||||||||||||||||
| const rating = $el.find('.rating').text().trim() || undefined; | ||||||||||||||||||||||||||||||||||||||||||||||
| const views = $el.find('.views').text().trim() || undefined; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+66
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant fallback to RSSHub/lib/routes/rule34video/latest.ts Lines 98 to 119 in 6aa8cf7
|
||||||||||||||||||||||||||||||||||||||||||||||
| const hasSound = $el.find('.sound').length > 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| const isHD = $el.find('.quality').length > 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| const videoId = link.match(/\/video\/(\d+)\//)?.[1]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||
| title, | ||||||||||||||||||||||||||||||||||||||||||||||
| link, | ||||||||||||||||||||||||||||||||||||||||||||||
| preview, | ||||||||||||||||||||||||||||||||||||||||||||||
| duration, | ||||||||||||||||||||||||||||||||||||||||||||||
| added, | ||||||||||||||||||||||||||||||||||||||||||||||
| rating, | ||||||||||||||||||||||||||||||||||||||||||||||
| views, | ||||||||||||||||||||||||||||||||||||||||||||||
| hasSound, | ||||||||||||||||||||||||||||||||||||||||||||||
| isHD, | ||||||||||||||||||||||||||||||||||||||||||||||
| videoId, | ||||||||||||||||||||||||||||||||||||||||||||||
| } as VideoItem; | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| .filter((item) => item.title && item.link); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||
| allowEmpty: true, | ||||||||||||||||||||||||||||||||||||||||||||||
| title: 'Rule34 Video Latest Updates', | ||||||||||||||||||||||||||||||||||||||||||||||
| link: 'https://www.rule34video.com/latest-updates/', | ||||||||||||||||||||||||||||||||||||||||||||||
| description: 'Latest updates from Rule34 Video', | ||||||||||||||||||||||||||||||||||||||||||||||
| item: items.map((item) => buildDataItem(item)), | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| function buildDataItem(item: VideoItem) { | ||||||||||||||||||||||||||||||||||||||||||||||
| let description = ''; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (item.duration) { | ||||||||||||||||||||||||||||||||||||||||||||||
| description += `<p>Duration: ${item.duration}</p>`; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (item.views) { | ||||||||||||||||||||||||||||||||||||||||||||||
| description += `<p>Views: ${item.views}</p>`; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (item.rating) { | ||||||||||||||||||||||||||||||||||||||||||||||
| description += `<p>Rating: ${item.rating}</p>`; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const qualities: string[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||
| if (item.isHD) { | ||||||||||||||||||||||||||||||||||||||||||||||
| qualities.push('HD'); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (item.hasSound) { | ||||||||||||||||||||||||||||||||||||||||||||||
| qualities.push('Has Sound'); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (qualities.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| description += `<p>Quality: ${qualities.join(', ')}</p>`; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (item.preview) { | ||||||||||||||||||||||||||||||||||||||||||||||
| description += `<img src="${item.preview}" alt="${item.title}" />`; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const pubDate = item.added ? parseRelativeDate(item.added) : undefined; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||
| title: item.title, | ||||||||||||||||||||||||||||||||||||||||||||||
| link: item.link, | ||||||||||||||||||||||||||||||||||||||||||||||
| description, | ||||||||||||||||||||||||||||||||||||||||||||||
| image: item.preview, | ||||||||||||||||||||||||||||||||||||||||||||||
| ...(pubDate && { pubDate: pubDate.toISOString() }), | ||||||||||||||||||||||||||||||||||||||||||||||
| guid: item.videoId ? `rule34video:${item.videoId}` : item.link, | ||||||||||||||||||||||||||||||||||||||||||||||
| category: item.isHD ? ['HD'] : [], | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'Rule34Video', | ||
| url: 'rule34video.com', | ||
| lang: 'en', | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.