Coder Social home page Coder Social logo

yt-dlp-danmaku's Introduction

yt-dlp-danmaku

yt-dlp plugin for converting Bilibili danmaku into ASS format. Powered by biliass.

Installation and upgrading

Requires yt-dlp 2023.01.02 or above.

You can install or upgrade this package with pip:

pip install -U yt-dlp-danmaku

Usage

Download video along with the ASS subtitle

yt-dlp --write-subs --use-postprocessor danmaku https://www.bilibili.com/video/BV1Sm4y1N78J

Download video embedded with danmaku as a subtitle stream

Bilibili videos are originally mp4 format, but this format does not support ASS subtitle. Therefore, you need to use another format that supports it, such as mkv:

yt-dlp --embed-subs --use-postprocessor danmaku --remux-video mkv https://www.bilibili.com/video/BV1Sm4y1N78J

You can then try playing this video with players that support ASS subtitles, such as mpv and VLC.

Download video and "burn" the danmaku onto it

You need to run FFmpeg yourself to do this. Here is an example how you can do that:

yt-dlp --write-subs --use-postprocessor danmaku --output input https://www.bilibili.com/video/BV1Sm4y1N78J
ffmpeg -i input.mp4 -vf subtitles=input.danmaku.ass output.mp4
rm input.mp4 input.danmaku.ass

Get ASS subtitle without downloading the video

yt-dlp --write-subs --use-postprocessor danmaku:when=before_dl --skip-download https://www.bilibili.com/video/BV1Sm4y1N78J

Use with mpv

mpv --script-opts=ytdl_hook-ytdl_path=yt-dlp --ytdl-raw-options=use-postprocessor=danmaku:when=before_dl,write-subs=,no-simulate=,skip-download= https://www.bilibili.com/video/BV1Sm4y1N78J

You can turn on and off danmaku by using j (by default). Add --sid=1 to turn on danmaku on start. You can add these options to your mpv config file.

Notice: this will leave an ASS file in the current directory. Delete it afterwards if you do not want it.

Configuration

You can pass options to this plugin. For example, to set the opacity of danmaku texts to 0.1 and reserve the bottom 150 pixels, use --use-postprocessor danmaku:text_opacity=0.1;reserve_blank=150. All available options:

Option Default Meaning
lang danmaku Language selector; you do not normally need to set this
reserve_blank 0
font_face sans-serif
font_size 25
text_opacity 0.8
duration_marquee 15
duration_still 10
comment_filter
is_reduce_comments false

Run biliass -h for more information about these options.

Development

See the Plugin Development section of the yt-dlp wiki.

License

MIT.

yt-dlp-danmaku's People

Contributors

ulysseszh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

yt-dlp-danmaku's Issues

Considring add an opption to specify the saving directory of the ass files

yt-dlp-danmaku saving the ass files to current workdir, but when I use ff2mpv-rust with it, ff2mpv-rust's workdir is /usr/bin, which is not writable so yt-dlp-danmaku fails with permission denied, and mpv fails to launch. So may be we could consider add an opption to specify the saving directory of the ass files.

I tried some modifictions like this and it worked for me.

diff --git a/yt_dlp_danmaku/__init__.py b/yt_dlp_danmaku/__init__.py
index a4caa0e..9683ca2 100644
--- a/yt_dlp_danmaku/__init__.py
+++ b/yt_dlp_danmaku/__init__.py
@@ -1,4 +1,5 @@
 from pathlib import Path
+import os
 import sys
 
 from biliass import Danmaku2ASS
@@ -15,6 +16,13 @@ class YoutubeDLDanmaku:
 		sys.stderr.write('\n')
 
 	def read_args(self):
+		ass_dir = self._kwargs.get('ass_dir', os.getcwd())
+		ass_dir = os.path.expanduser(os.path.expandvars(ass_dir))
+		if not os.path.exists(ass_dir):
+			os.makedirs(ass_dir)
+		if os.path.isdir(ass_dir):
+			os.chdir(ass_dir)
+
 		self.lang = self._kwargs.get('lang', 'danmaku')
 		self.reserve_blank = int(self._kwargs.get('reserve_blank', 0))
 		self.font_face = self._kwargs.get('font_face', 'sans-serif')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.