跳转到内容

快速开始

API 是公开的,不需要密钥。本页所有示例都可以直接运行。

GET /api/v1/songs/{id}
尚未发送

server 选择资料目录:jp,或代表 Global 的 intl(默认)。文本字段是数组,顺序为日语、英语、繁体中文、简体中文、韩语。空字符串表示该语言还没有文本。

GET /api/v1/songs
尚未发送

列表返回 items,还有更多内容时附带 nextCursor。把它作为 cursor 传回即可读取下一页:

const base = "https://haneoka.org/api/v1/songs?server=jp&limit=100";
const songs = [];
let cursor = null;
do {
const url = cursor ? `${base}&cursor=${encodeURIComponent(cursor)}` : base;
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const page = await response.json();
songs.push(...page.items);
cursor = page.nextCursor;
} while (cursor);
console.log(songs.length);

图片字段是 haneoka.org 上的路径,使用时要加上域名,并设置 referrerpolicy="no-referrer":文件会拒绝来源为其他网站的请求。

<img id="jacket" alt="" width="240" height="240" referrerpolicy="no-referrer">
<h1 id="title"></h1>
<script type="module">
const origin = "https://haneoka.org";
const song = await (await fetch(`${origin}/api/v1/songs/100091?server=jp`)).json();
document.querySelector("#title").textContent = song.musicTitle[0];
document.querySelector("#jacket").src = origin + song.jacketUrl;
</script>