-
Notifications
You must be signed in to change notification settings - Fork 9.6k
feat: add jable #21641
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?
feat: add jable #21641
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,162 @@ | ||
| import { load } from 'cheerio'; | ||
|
|
||
| import type { Route } from '@/types'; | ||
| import cache from '@/utils/cache'; | ||
| import got from '@/utils/got'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/search/:query', | ||
| categories: ['multimedia'], | ||
| example: '/jable/search/みなみ羽琉', | ||
| parameters: { | ||
| query: 'Search keyword', | ||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| nsfw: true, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['jable.tv/search/:query'], | ||
| target: '/:query', | ||
| }, | ||
| ], | ||
| name: 'Jable 搜索结果', | ||
| maintainers: [], | ||
| handler, | ||
| }; | ||
|
|
||
| const GOT_HEADERS = { | ||
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', | ||
|
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. Does the site only work with this specific version of Chrome on Windows instead of RSSHub's default UA which is a randomised version of Chrome on mac? |
||
| 'Accept-Language': 'en-US,en;q=0.9', | ||
| Referer: 'https://jable.tv/', | ||
| }; | ||
|
|
||
| // function renderDescription(item) { | ||
| // return ` | ||
| // <a href="${item.link}"> | ||
| // <img src="${item.thumb}" style="max-width:100%" /> | ||
| // </a> | ||
| // <p> | ||
| // ${item.duration ? `<strong>Duration:</strong> ${item.duration}` : ''} | ||
| // ${item.views ? `|<strong>Views:</strong> ${item.views}` : ''} | ||
| // ${item.favorites ? `|<strong>Favorites:</strong> ${item.favorites}` : ''} | ||
| // ${item.author ? `|<strong>Author:</strong> ${item.author}` : ''} | ||
| // </p> | ||
| // `.trim(); | ||
| // } | ||
|
|
||
| async function handler(ctx) { | ||
| const { query } = ctx.req.param(); | ||
| const params = new URLSearchParams({ | ||
| mode: 'async', | ||
| function: 'get_block', | ||
| block_id: 'list_videos_videos_list_search_result', | ||
| q: query, | ||
| sort_by: 'post_date', | ||
| }); | ||
| const encodedQuery = encodeURIComponent(query); | ||
| const apiUrl = `https://jable.tv/search/${encodedQuery}/?${params.toString()}`; | ||
| const response = await got(apiUrl, { headers: GOT_HEADERS }); | ||
| const $ = load(response.data); | ||
|
|
||
| const author = $('section.content-header h2').first().text().trim() || query; | ||
|
|
||
| const items = await Promise.all( | ||
| $('.video-img-box') | ||
| .toArray() | ||
| .map((el) => { | ||
| const $el = $(el); | ||
|
|
||
| const $titleLink = $el.find('.detail h6.title a'); | ||
| const title = $titleLink.text().trim(); | ||
| const link = $titleLink.attr('href') ?? ''; | ||
|
|
||
| const thumb = $el.find('img[data-src]').attr('data-src') ?? ''; | ||
| const preview = $el.find('img[data-preview]').attr('data-preview') ?? ''; | ||
|
Comment on lines
+81
to
+82
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. These are referring to the same element. Do not use |
||
|
|
||
| // const duration = $el.find('.label').text().trim(); | ||
| // const subText = $el.find('.sub-title').text().trim(); | ||
| // const nums = subText.split(/\s+/); | ||
| // const views = nums[0] ?? ''; | ||
| // const favorites = nums[1] ?? ''; | ||
|
|
||
| const videoId = $el.find('[data-fav-video-id]').attr('data-fav-video-id') ?? link; | ||
|
|
||
| return cache.tryGet(`jable:video:${videoId}`, async () => { | ||
| let pubDate; | ||
| let videoUrl; | ||
|
|
||
| try { | ||
| const { data } = await got(link, { headers: GOT_HEADERS }); | ||
|
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. Do not visit |
||
| const $page = load(data); | ||
|
|
||
| const dateText = $page('.video-date').text().trim(); | ||
| if (dateText) { | ||
| pubDate = parseDate(dateText); | ||
| } | ||
|
|
||
| const script = $page('script') | ||
| .toArray() | ||
| .map((s) => $(s).html()) | ||
| .find((s) => s && s.includes('sources')); | ||
|
|
||
| if (script) { | ||
| const match = script.match(/file:\s*"([^"]+)"/); | ||
| if (match) { | ||
| videoUrl = match[1]; | ||
| } | ||
| } | ||
| } catch { | ||
| // 忽略错误 | ||
| } | ||
|
|
||
| return { | ||
| title, | ||
| link, | ||
| guid: `jable:video:${videoId}`, | ||
| pubDate, | ||
| author, | ||
| // description: renderDescription({ | ||
| // title, | ||
| // link, | ||
| // thumb, | ||
| // duration, | ||
| // views, | ||
| // favorites, | ||
| // author, | ||
| // }), | ||
| media: { | ||
| content: preview | ||
| ? { | ||
| url: preview, | ||
| type: 'video/mp4', | ||
| } | ||
| : videoUrl | ||
| ? { | ||
| url: videoUrl, | ||
| type: 'video/mp4', | ||
| } | ||
| : undefined, | ||
| thumbnail: { | ||
| url: thumb, | ||
| }, | ||
| }, | ||
| }; | ||
| }); | ||
| }) | ||
| ); | ||
|
|
||
| return { | ||
| title: query, | ||
| link: `https://jable.tv/search/${encodedQuery}/`, | ||
| description: `Search results for ${query}`, | ||
| item: items, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'jable', | ||
| url: 'jable.tv', | ||
| lang: 'zh', | ||
| }; |
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.
Missing maintainer GitHub id.