npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

danmaku-to-ass

v1.6.3

Published

Convert bilibili & acfun danmaku to ass subtitle

Downloads

47

Readme

A站B站弹幕转字幕文件

本工具主要解决部分已经下架的视频的弹幕播放问题,转为ass字幕后可以使用任意支持字幕的播放器播放。

具体获取A站、B站弹幕的方法请自行搜索,B站可考虑使用BiliPlus哔哩哔哩唧唧

感谢tiansh/us-danmaku提供诸多指导。

安装方式

由于本工具使用了node-canvas进行字符长度的计算,而需要计算汉字的宽度,需要安装pango库,因此先参考node-canvas的安装说明进行安装。macOS除正常的依赖外,请额外安装pango库:

brew install pango

之后使用npm进行安装:

npm install -g danmaku-to-ass

使用方式

danmaku [参数] [文件列表]

默认输入为.xml文件时解析为B站弹幕,为.json文件(尚未实现)时解析为A站弹幕。

也可以提供一个由本工具生成的.ass文件(必须以--inlude-raw=true参数生成),以达到调整生成参数的目的,如以下命令可以将字号变小并覆盖原字幕文件:

danmaku --font-size=12,18,24 --out-dir=./subtitle ./subtitle

当然也可以使用--out参数单独处理一个文件,或指定不同的--out-dir保留旧文件。

参数

必要参数

  • --out {输出文件}:使用该参数时将输出保存至参数指定的文件,与--out-dir二选一。
  • --out-dir {输出目录}:使用该参数可以将多个文件进行批量转换并保存到指定的目录下,如果使用该参数则不要使用--out参数。

配置参数

  • --config:指定一个配置文件,格式见后文,指定该参数后其它配置参数都会失效。
  • --font-size:指定字号列表,必须是3个从小到大的数字并用逗号连接,比如18,25,36
  • --font-name:指定字体名称。
  • --color:指定默认弹幕颜色,可以使用ff3300#fc9730#fff000这几种格式。
  • --outline-color:指定边框颜色。
  • --back-color:指定阴影颜色。
  • --outline:边框的像素宽度。
  • --shadow:阴影的像素深度。
  • --bold:指定是否使用粗体,值为true时表示使用粗体。
  • --opacity: 指定字体的透明度,必须是0-1之间的小数。
  • --padding: 指定每条弹幕四周的空白,必须是4个数字并用逗号连接,比如2,2,2,2
  • --play-res-x:视频播放区域的宽度。
  • --play-res-y:视频播放区域的高度,这个参数与宽度共同决定视频的长宽比例,具体数值不是很重要。
  • --scroll-time:滚动弹幕的持续时间,单位为秒。
  • --fix-time:固定弹幕(上方或下方)的持续时间,单位为秒。
  • --bottom-space:底部留空的区域大小,以防止弹幕覆盖原始字幕。
  • --include-raw:是否在生成的文件中保留原始信息,保留原始信息可以在后期重新使用本工具修改弹幕生成的参数,但会导致文件变大约1/3。该参数默认值为true,可提供false强制不保留原始信息。
  • --merge-in:指定n秒内出现相同弹幕合并为一条,参数值为一个数字,以秒为单位。
  • --block:提供正则来屏蔽弹幕,可以多次使用该参数,每次提供一个正则或内置规则。
  • --block-file:提供一个文件来屏蔽弹幕,文件中的每一行都是一个正则或内置规则,如果这个参数与--block一起出现,两者会被合并。这个参数在配置文件中无效。

屏蔽规则

在使用--block--block-file时,每一个屏蔽规则都是一个正则表达式或一个内置规则,比如:

.{4,}
呵呵

则表示屏幕所有长度大于4的弹幕以及包含关键字“呵呵”的弹幕。除此之外也可以使用以下内置规则:

  • COLOR:屏蔽所有彩色弹幕。
  • TOP:屏蔽所有顶部弹幕。
  • BOTTOM:屏幕所有底部弹幕。

需要注意的是,从已有的.ass文件生成新的字幕时,原有的屏蔽规则会失效,所有屏蔽规则均以此次执行命令的配置为准。

参考配置文件

以下除fontName名均为默认值。

{
    "fontSize": [25, 36],
    "fontName": "黑体",
    "color": "#ffffff",
    "outlineColor": null,
    "backColor": null,
    "outline": 2,
    "shadow": 0,
    "bold": false,
    "padding": [2, 2, 2, 2],
    "playResX": 1280,
    "playResY": 720,
    "scrollTime": 8,
    "fixTime": 4,
    "opacity": 0.6,
    "bottomSpace": 60,
    "block": [],
    "includeRaw": true
}

程序调用

同样可以使用程序进行调用:

import convert from 'danmaku-to-ass';
import {readFileSync} from 'fs';

let text = readFileSync('av12345.xml', 'utf-8');
let ass = convert(text, {}, {source: 'bilibili', filename: 'av12345.xml'});

函数签名:

{string} convert({string} text, {Object} configOverrides, {Object} context);

参数说明:

  • text:弹幕文件内容,如果是Bilibili则为XML文本,Acfun为JSON文本。
  • configOverrides:覆盖默认配置的内容,见上文的配置文件参考。
  • context:转换的上下文信息,需要2个属性:
    • {string} source:内容的来源类型,为"bilibili""acfun"(注意全小写)。
    • {string} filename:来源文件名,如果没有的话可以随便写一个,主要放在ass文件的信息部分。