logo
0
0
WeChat Login

歌词播放器测试服务器

🚀 快速启动

1. 安装依赖

npm install

2. 启动服务器

npm start

服务器将在 http://localhost:3000 启动

📡 API端点

基础信息

  • Base URL: http://localhost:3000
  • CORS: 已启用

可用端点

1. 健康检查

GET /api/health

响应示例:

{ "status": "ok", "timestamp": "2026-03-17T12:00:00.000Z", "endpoints": { "/api/subtitles": "GET - 获取所有字幕列表", "/api/subtitles/:id": "GET - 获取单个字幕信息", "/api/subtitles/:id/content": "GET - 获取字幕文件内容", "/api/tracks/:trackId": "GET - 模拟原网站track API", "/api/subtitles": "POST - 上传字幕", "/api/subtitles/:id": "DELETE - 删除字幕" } }

2. 获取所有字幕

GET /api/subtitles

响应示例:

{ "success": true, "data": [ { "id": "test-001", "title": "社团JK交换_测试字幕", "audioUrl": "/audio/test.mp3", "vttUrl": "/subtitles/test-001.vtt", "duration": 115, "format": "vtt" }, { "id": "sample-lrc", "title": "示例LRC歌词", "audioUrl": "/audio/sample.mp3", "lrcUrl": "/subtitles/sample.lrc", "duration": 120, "format": "lrc" } ] }

3. 获取单个字幕信息

GET /api/subtitles/:id

示例:

GET /api/subtitles/test-001

响应示例:

{ "success": true, "data": { "id": "test-001", "title": "社团JK交换_测试字幕", "audioUrl": "/audio/test.mp3", "vttUrl": "/subtitles/test-001.vtt", "duration": 115, "format": "vtt" } }

4. 获取字幕文件内容

GET /api/subtitles/:id/content

示例:

GET /api/subtitles/test-001/content

响应类型: text/vtttext/plain

响应示例:

WEBVTT 00:00.000 --> 00:03.500 社团的事啊、有的没的,他也帮我出了很多主意,帮了我很多忙 00:03.500 --> 00:08.200 果然还是…刺刺痒痒的…没办法像小鸟那样… ...

5. 模拟原网站Track API

GET /api/tracks/:trackId?v=2

示例:

GET /api/tracks/01444800?v=2

响应示例:

[ { "type": "folder", "title": "测试曲目", "children": [ { "type": "folder", "title": "字幕文件", "children": [ { "type": "audio", "hash": "test/001", "title": "测试音频.mp3", "workTitle": "测试曲目 - 示例字幕", "mediaStreamUrl": "/audio/test.mp3", "mediaDownloadUrl": "/audio/test.mp3", "duration": 115, "size": 5000000 }, { "type": "text", "hash": "test/002", "title": "测试字幕.vtt", "workTitle": "测试曲目 - 示例字幕", "mediaStreamUrl": "/api/subtitles/test-001", "mediaDownloadUrl": "/api/subtitles/test-001", "duration": 115, "size": 5000 } ] } ] } ]

6. 上传字幕

POST /api/subtitles Content-Type: application/json

请求体:

{ "id": "custom-001", "title": "自定义字幕", "format": "vtt", "content": "WEBVTT\n\n00:00.000 --> 00:05.000\n测试字幕" }

响应示例:

{ "success": true, "data": { "id": "custom-001", "title": "自定义字幕", "format": "vtt", "duration": 120, "vttUrl": "/api/subtitles/custom-001/content", "content": "WEBVTT\n\n00:00.000 --> 00:05.000\n测试字幕" } }

7. 删除字幕

DELETE /api/subtitles/:id

示例:

DELETE /api/subtitles/test-001

响应示例:

{ "success": true, "message": "Subtitle deleted" }

🎨 测试页面

1. API测试控制台

http://localhost:3000/api-test.html

功能:

  • 查看所有字幕
  • 测试单个字幕API
  • 上传自定义字幕
  • 测试Track API
  • 实时响应显示

2. 歌词播放器

http://localhost:3000/test-player.html

功能:

  • 从API加载字幕
  • 播放/暂停控制
  • 歌词同步显示
  • 点击跳转
  • 双击展开完整列表

🔧 测试用例

测试1: 获取所有字幕

curl http://localhost:3000/api/subtitles

测试2: 获取单个字幕

curl http://localhost:3000/api/subtitles/test-001

测试3: 获取字幕内容

curl http://localhost:3000/api/subtitles/test-001/content

测试4: 模拟Track API

curl "http://localhost:3000/api/tracks/01444800?v=2"

测试5: 上传字幕

curl -X POST http://localhost:3000/api/subtitles \ -H "Content-Type: application/json" \ -d '{ "title": "测试字幕", "format": "vtt", "content": "WEBVTT\n\n00:00.000 --> 00:05.000\n测试内容" }'

测试6: 删除字幕

curl -X DELETE http://localhost:3000/api/subtitles/custom-001

📊 内置测试数据

test-001 (VTT格式)

  • ID: test-001
  • 标题: 社团JK交换_测试字幕
  • 格式: VTT
  • 时长: 115秒
  • 行数: 12行

sample-lrc (LRC格式)

  • ID: sample-lrc
  • 标题: 示例LRC歌词
  • 格式: LRC
  • 时长: 120秒
  • 行数: 17行

🛠️ 开发说明

项目结构

/workspace/ ├── server.js # Express服务器 ├── package.json # 依赖配置 ├── api-test.html # API测试控制台 ├── test-player.html # 歌词播放器 ├── sample-lyrics.lrc # 示例LRC歌词 └── README-SERVER.md # 本文档

添加新的测试字幕

方法1: 通过API上传

fetch('/api/subtitles', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: 'new-001', title: '新字幕', format: 'vtt', content: 'WEBVTT\n\n00:00.000 --> 00:05.000\n新字幕内容' }) });

方法2: 直接修改server.js中的subtitleDatabase对象

🐛 调试技巧

1. 查看服务器日志

服务器启动后会显示所有API请求:

📋 GET /api/subtitles 📄 GET /api/subtitles/test-001 📝 GET /api/subtitles/test-001/content

2. 使用浏览器开发者工具

  • Network标签: 查看所有API请求
  • Console标签: 查看播放器日志
  • Application标签: 查看localStorage

3. 常见问题

问题: CORS错误

解决方案: 服务器已启用CORS,确保使用http://localhost:3000访问

问题: 字幕不显示

解决方案: 检查Console日志,确认API返回数据格式正确

问题: 歌词不同步

解决方案: 检查VTT/LRC格式是否正确,时间戳是否递增

📝 注意事项

  1. 端口占用: 如果3000端口被占用,请修改server.js中的PORT常量
  2. 数据持久化: 当前数据存储在内存中,重启服务器后数据会重置
  3. 音频文件: 当前使用模拟播放,需要真实的音频文件才能播放声音
  4. 性能限制: 单个字幕文件建议不超过10MB

🔗 相关资源

📞 支持

如有问题,请查看:

  1. 服务器控制台日志
  2. 浏览器开发者工具
  3. API响应内容