Skip to content

Why this tool exist?

nanashi edited this page Feb 11, 2024 Β· 1 revision

The Problem

Downloaded content from bilibili doesn't get saved as one file. It saves the audio, video, and subtitles separately. And they aren't saved with human-readable names. They are saved with their IDs as their name. Although the subtitle has been in SSA format recently, there are still older uploads in the proprietary JSON subtitle format by bilibili.

Example of the structure
download/
└── s_34641
    β”œβ”€β”€ 342865
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 35813381d9f4a5f623e052af678072aca867054e.json
    β”‚   └── entry.json
    β”œβ”€β”€ 346992
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 7678f3b1b74e728ccf8a301ac36bc2a440e2a983.json
    β”‚   └── entry.json
    β”œβ”€β”€ 350165
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── fae1bea747dfdbba0bc9734cbf36b66ee44ef602.json
    β”‚   └── entry.json
    β”œβ”€β”€ 355184
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 95422040af142e903cf3501f1efbbd4d650f0788.json
    β”‚   └── entry.json
    β”œβ”€β”€ 358304
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 38bb9688fba53f2b25b860cbf80fccdd4bfefb9e.json
    β”‚   └── entry.json
    β”œβ”€β”€ 359293
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 09d37641f164d657bf139b7ac6b6721fb8c22342.json
    β”‚   └── entry.json
    β”œβ”€β”€ 359295
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── b880308196740c89f6a591d51171f3586799a69a.json
    β”‚   └── entry.json
    β”œβ”€β”€ 359296
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 87829ca0dda97d9356ccd07cc9f8b642f85ec608.json
    β”‚   └── entry.json
    β”œβ”€β”€ 359297
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 4885e942e5c0731bff07b78ab56d696e08030b4b.json
    β”‚   └── entry.json
    β”œβ”€β”€ 359298
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── 45ccbcee9c73355dc658603a8a673cf8b4726f34.json
    β”‚   └── entry.json
    β”œβ”€β”€ 359300
    β”‚   β”œβ”€β”€ 112
    β”‚   β”‚   β”œβ”€β”€ audio.m4s
    β”‚   β”‚   β”œβ”€β”€ index.json
    β”‚   β”‚   └── video.m4s
    β”‚   β”œβ”€β”€ en
    β”‚   β”‚   └── bb6e5a10c0c917c9ed23bfb4cff66cd048708696.json
    β”‚   └── entry.json
    └── 359301
        β”œβ”€β”€ 112
        β”‚   β”œβ”€β”€ audio.m4s
        β”‚   β”œβ”€β”€ index.json
        β”‚   └── video.m4s
        β”œβ”€β”€ en
        β”‚   └── f9171d78e6aa73b2079d15ceb9b5e4f9139cd157.json
        └── entry.json

The Solution

Firstly, the subtitle problem, a program that can translate it to other formats compatible with FFmpeg, is employed. The files are then compiled into one .mkv file using FFmpeg. Folders are then created to store the .mkv files about to be extracted. The folders are named based on the entry title. Then the .mkv files are renamed and moved to their specified folder.