DEV Community

pengwang
pengwang

Posted on Edited on Originally published at apify.com

Transcribe Douyin and Bilibili Videos into Timestamped Text (No API Keys Needed)

Most Chinese video platforms don't give you a usable transcript. Douyin's subtitle endpoint needs signed requests and a valid session. Bilibili's CC/AI subtitles return an empty array for anonymous requests — you need a logged-in SESSDATA cookie. And even when you do get subtitles, they cover maybe 20% of uploads.

So you end up writing the same pipeline over and over: download video → extract audio → run Whisper → stitch timestamps together. Each step has its own failure mode.

There is a way to skip all of it.

What this gets you

from apify_client import ApifyClient

client = ApifyClient("<YOUR_API_TOKEN>")
run = client.actor("jfishpw/chinese-video-transcript").call(
    run_input={"videoUrls": ["https://www.bilibili.com/video/BV1MzWU65Ewn"]},
)

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["text"])       # full transcript
    print(item["segments"])   # timestamped chunks
Enter fullscreen mode Exit fullscreen mode

One HTTP call. No API key for the transcription service, no cookie handling, no ffmpeg, no model downloads.

The output shape

One JSON object per video:

{
  "url": "https://www.bilibili.com/video/BV1MzWU65Ewn",
  "platform": "bilibili",
  "videoId": "BV1MzWU65Ewn",
  "title": "普通话水平测试网站(免费)",
  "author": "...",
  "durationSec": 23.8,
  "source": "asr",
  "modelSize": "base",
  "language": "zh",
  "text": "烤普通话,别再下毒了...",
  "segments": [{"start": 0.0, "end": 4.4, "text": "..."}],
  "segmentCount": 2,
  "charCount": 118,
  "billableMinutes": 1,
  "hasTranscript": true,
  "qualityCheck": true,
  "errorCode": null,
  "hint": null
}
Enter fullscreen mode Exit fullscreen mode

Two fields worth paying attention to:

  • segments carries second-level timestamps, so you can cite a specific moment rather than a wall of text.
  • qualityCheck is a self-check flag. It's true only when the transcript is non-empty and the last timestamp falls within 1.25× the audio duration. If a platform returns a placeholder or a truncated file, this goes false instead of silently giving you garbage.

Supported inputs

Input Example
Douyin video https://www.douyin.com/video/7534679152504376595
Douyin short link https://v.douyin.com/xxxxx/ (redirects are followed)
Bilibili video https://www.bilibili.com/video/BV1MzWU65Ewn
Bilibili ID BV1MzWU65Ewn / av170001
Direct media https://.../video.mp4, .m4a, .mp3, .wav, .m3u8

Batch up to 50 per run (maxItems). One failure doesn't abort the batch — it comes back as an errorCode with a hint while the rest keep going.

Recipe: video → RAG chunks

The reason I wanted timestamps in the first place was chunking. Splitting a transcript by character count breaks sentences; splitting on segment boundaries doesn't.

run = client.actor("jfishpw/chinese-video-transcript").call(
    run_input={
        "videoUrls": ["https://www.bilibili.com/video/BV1MzWU65Ewn"],
        "modelSize": "base",
        "withTimestamps": True,
    },
)

chunks = []
for video in client.dataset(run["defaultDatasetId"]).iterate_items():
    if not video.get("hasTranscript"):
        continue
    for seg in video.get("segments") or []:
        chunks.append({
            "content": seg["text"],
            "metadata": {
                "source": video["url"],
                "title": video["title"],
                "start": seg["start"],
                "end": seg["end"],
            },
        })

print(f"{len(chunks)} chunks ready for the vector store")
Enter fullscreen mode Exit fullscreen mode

Recipe: generating subtitles

Same data, SRT out:

def to_srt(segments):
    def ts(seconds):
        h, rem = divmod(int(seconds), 3600)
        m, s = divmod(rem, 60)
        ms = int((seconds - int(seconds)) * 1000)
        return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}"

    return "".join(
        f"{i}\n{ts(seg['start'])} --> {ts(seg['end'])}\n{seg['text']}\n\n"
        for i, seg in enumerate(segments, 1)
    )
Enter fullscreen mode Exit fullscreen mode

Recipe: scraping competitor scripts

A common reason to want this: seeing what a competitor's video actually says.

import csv

run = client.actor("jfishpw/chinese-video-transcript").call(
    run_input={"videoUrls": competitor_urls, "modelSize": "base"},
)

with open("scripts.csv", "w", newline="", encoding="utf-8") as fh:
    writer = csv.writer(fh)
    writer.writerow(["title", "url", "duration", "text"])
    for item in client.dataset(run["defaultDatasetId"]).iterate_items():
        writer.writerow([item["title"], item["url"], item["durationSec"], item["text"]])
Enter fullscreen mode Exit fullscreen mode

Accuracy and cost knobs

Setting Default Notes
modelSize base tiny is fastest/cheapest, small is most accurate and most expensive
language zh zh / auto / en
withTimestamps true Segment boundaries
includeMetadata true Title, author, view/like counts
maxDurationSec 300 Longer videos are skipped before download, so you don't pay for them

Pricing is $0.008 per transcript plus $0.01 per minute of audio. A one-minute video lands around $0.018. Failed items, skipped videos, and unsupported sources don't bill.

Things that don't work (yet)

  • Xiaohongshu — returns UNSUPPORTED_SOURCE, no charge
  • Silent video / music only — returns EMPTY_TRANSCRIPT, no charge
  • Videos over maxDurationSec — returns MEDIA_TOO_LONG, rejected before download, no charge

One more thing worth knowing: Bilibili's own subtitles are not used, even when they exist. The anonymous subtitle endpoint returns empty, and going through a logged-in cookie adds a credential you don't want to manage. Running ASR on the audio directly means every video gets a transcript, and the output is consistent across platforms.

Calling it from your AI agent

Via Apify's MCP server, Claude and Cursor can call it as a tool:

claude mcp add --transport http apify "https://mcp.apify.com?tools=jfishpw/chinese-video-transcript"
Enter fullscreen mode Exit fullscreen mode
{
  "mcpServers": {
    "apify": {
      "url": "https://mcp.apify.com?tools=jfishpw/chinese-video-transcript"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Then just say "transcribe this Bilibili video" and let the agent handle it.

Links

The Actor is pay-per-event, so you only pay for transcripts you actually get.

Top comments (0)