tap
Back

bilibili/search

bilibiliRead-only

Search Bilibili videos by keyword

www.bilibili.com
Last 7 days
0
Last 30 days
0
All time
0
bilibili/search.js
/* @meta
{
  "name": "bilibili/search",
  "description": "Search Bilibili videos by keyword",
  "domain": "www.bilibili.com",
  "args": {
    "keyword": {"required": true, "description": "Search keyword"},
    "page": {"required": false, "description": "Page number (default: 1)"},
    "count": {"required": false, "description": "Results per page (default: 20, max: 50)"},
    "order": {"required": false, "description": "Sort order: totalrank (default), click (views), pubdate (newest), dm (danmaku), stow (favorites)"}
  },
  "capabilities": ["network"],
  "readOnly": true,
  "example": "tap site bilibili/search 编程"
}
*/

async function(args) {
  if (!args.keyword) return {error: 'Missing argument: keyword'};
  const page = parseInt(args.page) || 1;
  const ps = Math.min(parseInt(args.count) || 20, 50);
  const order = args.order || 'totalrank';
  const params = new URLSearchParams({search_type: 'video', keyword: args.keyword, page: String(page), page_size: String(ps), order});
  const resp = await fetch('https://api.bilibili.com/x/web-interface/wbi/search/type?' + params, {credentials: 'include'});
  if (!resp.ok) return {error: 'HTTP ' + resp.status, hint: 'Not logged in?'};
  const d = await resp.json();
  if (d.code !== 0) return {error: d.message || 'API error ' + d.code, hint: 'Not logged in?'};
  const stripHtml = s => (s || '').replace(/<[^>]*>/g, '');
  const videos = (d.data?.result || []).map(r => ({
    bvid: r.bvid,
    title: stripHtml(r.title),
    author: r.author,
    author_mid: r.mid,
    description: stripHtml(r.description).substring(0, 200),
    duration: r.duration,
    play: r.play,
    danmaku: r.danmaku,
    like: r.like,
    favorites: r.favorites,
    cover: r.pic?.startsWith('//') ? 'https:' + r.pic : r.pic,
    pub_date: r.pubdate ? new Date(r.pubdate * 1000).toISOString() : null,
    tags: r.tag || '',
    url: 'https://www.bilibili.com/video/' + r.bvid
  }));
  return {keyword: args.keyword, page, total: d.data?.numResults || 0, count: videos.length, videos};
}
Updated Mar 31, 2026Created Mar 31, 2026SHA-256: 2b93d3bfc988