Skip to content

sanctumr/mpvacious

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mpvacious

Chat GitHub Patreon GitHub top language Lines of code AUR

mpvacious is your semi-automatic subs2srs for mpv. It supports multiple workflows and allows you to quickly create Anki cards while watching your favorite TV show. Video demonstration.

Table of contents

Requirements

GNU/Linux Windows 10 macOS Comments
mpv mpv mpv v0.32.0 or newer.
Anki Anki
AnkiConnect Install from AnkiWeb.
curl curl Installed by default on all platforms except Windows 7.
xclip pbcopy To copy subtitle text to clipboard.

Install all dependencies at once (on Arch-based distros):

$ sudo pacman -Syu mpv anki curl xclip --needed

Prerequisites

  • If you're on a Windows machine, watch this tutorial. Make sure you choose a build by shinchiro, otherwise you may encounter problems when making Anki cards.
  • macOS users should use homebrew or manually add mpv to PATH.
  • If you're using a GNU/Linux distro different from Arch Linux, make sure that your build of mpv supports encoding of audio and images. To test that, this shell command can be used:
    $ mpv 'test_video.mkv' --loop-file=no --frames=1 -o='test_image.jpg'
    
    If the command fails, find a compatible build on the mpv website.

Installation

Manually

Save subs2srs.lua in the mpv scripts folder:

OS Location
GNU/Linux ~/.config/mpv/scripts/
Windows C:/Users/Username/AppData/Roaming/mpv/scripts/

Note: in Celluloid user scripts are installed by switching to the "Plugins" tab in the preferences dialog and dropping the files there.

From the AUR

mpvacious can be installed with the mpv-mpvacious package.

Using curl

$ curl -o ~/.config/mpv/scripts/subs2srs.lua --create-dirs 'https://raw.githubusercontent.com/Ajatt-Tools/mpvacious/master/subs2srs.lua'

Using git

If you already have your dotfiles set up according to Arch Wiki recommendations, execute:

$ config submodule add 'https://github.com/Ajatt-Tools/mpvacious.git' ~/.config/mpv/scripts/subs2srs

If not, either proceed to Arch Wiki and come back when you're done, or simply clone the repo:

$ git clone 'https://github.com/Ajatt-Tools/mpvacious.git' ~/.config/mpv/scripts/subs2srs

Since you've just cloned the script to its own subfolder, you need to tell mpv where to look for it.

Note: the step below is not necessary if you're running mpv v0.33 or newer.

Open or create ~/.config/mpv/scripts/modules.lua and add these lines:

local mpv_scripts_dir_path = os.getenv("HOME") ..  "/.config/mpv/scripts/"
function load(relative_path) dofile(mpv_scripts_dir_path .. relative_path) end
load("subs2srs/subs2srs.lua")

Updating with git

Install method Command
Submodules $ config submodule update --remote --merge
Plain git $ cd ~/.config/mpv/scripts/subs2srs && git pull

Configuration

The config file should be created by the user, if needed.

OS Config location
GNU/Linux ~/.config/mpv/script-opts/subs2srs.conf
Windows C:/Users/Username/AppData/Roaming/mpv/script-opts/subs2srs.conf
Windows (portable) mpv.exeフォルダ/portable_config/script-opts/subs2srs.conf

If a parameter is not specified in the config file, the default value will be used. mpv doesn't tolerate spaces before and after =.

Example configuration file

Sentence field should be first in the note type settings. Otherwise, Anki won't allow mpvacious to add new notes. Alternatively, refer to Modifying cards added with Yomichan or use an addon that allows empty first field.

Tip: Try this note type if you don't want to configure note fields yourself.

If you are having problems playing media files on older mobile devices, set audio_format to mp3 and/or snapshot_format to jpg. Otherwise, I recommend sticking with opus and webp, as they greatly reduce the size of the generated files.

Key bindings

The user may change some key bindings, though this step is not necessary. See Usage for the explanation of what they do.

OS Config location
GNU/Linux ~/.config/mpv/input.conf
Windows C:/Users/Username/AppData/Roaming/mpv/input.conf

Default bindings:

Ctrl+c       script-binding mpvacious-copy-sub-to-clipboard
Ctrl+e       script-binding mpvacious-export-note
Ctrl+h       script-binding mpvacious-sub-rewind
Ctrl+Shift+h script-binding mpvacious-sub-replay
a            script-binding mpvacious-menu-open
H            script-binding mpvacious-sub-seek-back
L            script-binding mpvacious-sub-seek-forward
Alt+h        script-binding mpvacious-sub-seek-back-pause
Alt+l        script-binding mpvacious-sub-seek-forward-pause

These additional bindings aren't enabled by default but can be accessed via the menu by pressing a.

Ctrl+s script-binding mpvacious-set-starting-line
Ctrl+r script-binding mpvacious-reset-timings
Ctrl+t script-binding mpvacious-toggle-sub-autocopy
Ctrl+u script-binding mpvacious-update-last-note

Usage

Global bindings

These bindings work everywhere, even if the menu (covered later) is closed.

  • Shift+h and Shift+l - Seek to the previous or the next subtitle.
  • Alt+h and Alt+l - Seek to the previous, or the next subtitle, and pause.
  • Ctrl+h - Seek to the start of the currently visible subtitle. Use it if you missed something.
  • Ctrl+Shift+h - Replay current subtitle line, and pause.
  • Ctrl+e - Export a card with the currently visible subtitle line on the front. Use this when your subs are perfectly timed, and the target sentence doesn't span multiple subs.
  • Ctrl+c - Copy current subtitle string to the system clipboard. For automatic copying see Modifying cards added with Yomichan.

Menu options

  • a - Open advanced menu with a list of all available keybindings.

Let's say your subs are still perfectly timed, but the sentence you want to add is split between multiple subs. We need to combine the lines before making a card.

  • c - Set timings to the current sub and remember the corresponding line. It does nothing if there are no subs on screen.

Then seek with shift+h and shift+l to the previous/next line that you want to add. Press n to make the card.

  • r - Forget all previously saved timings and associated dialogs.

If subs are badly timed, first of all, you could try to re-time them. ffsubsync is a program that will do it for you. Another option would be to shift timings using key bindings provided by mpv.

  • z and Shift+z - Adjust subtitle delay.

If above fails, you have to manually set timings.

  • s - Set the start time.
  • e - Set the end time.

Then, as earlier, press n to make the card.

Tip: change playback speed by pressing [ and ] to precisely mark start and end of the phrase.

How to add definitions to new cards

After the card is created, you can find it by typing tag:subs2srs added:1 in the Anki Browser. Then use qolibri or similar software to add definitions to the card.

Modifying cards added with Yomichan

You can add a card first using Yomichan, and then append an audio clip and a snapshot to it.

Pressing t in the advanced menu toggles the autoclip option. Now as subtitles appear on the screen, they will be immediately copied to the clipboard. You can use it in combination with Yomichan clipboard monitor.

The process:

  1. Open Yomichan Search by pressing Alt+Insert in your web browser.
  2. Enable Clipboard autocopy in mpvacious by pressing t in the advanced menu.
  3. When you find an unknown word, click + in Yomichan to make a card for it.
  4. Go back to mpv and add the snapshot and the audio clip to the card you've just made by pressing m in the advanced menu. Pressing Shift+m will overwrite any existing data in media fields.

Don't forget to set the right timings and join lines together if the sentence is split between multiple subs.

Example sentence card

With the addon you can make cards like this in just a few seconds.

card-example

Audio cards

It is possible to make a card with just audio, and a picture when subtitles for the show you are watching aren't available, for example. mpv by default allows you to do a 1 second exact seek by pressing Shift+LEFT and Shift+RIGHT. Open the mpvacious menu by pressing a, seek to the position you need, and set the timings. Then press g to invoke the Add Cards dialog.

If the show is hardsubbed, you can use Tesseract or ShareX OCR to add text to the card.

Other tools

If you don't like the default Yomichan Search tool, try:

  • Clipboard Inserter browser add-on (chrome) (firefox)
  • An html page (1) (2) to paste the contents of you clipboard to

You can use any html page as long as it has <body></body> in it.

Additional mpv key bindings

I recommend adding these lines to your input.conf for smoother experience.

# vim-like seeking
l seek 5
h seek -5
j seek -60
k seek 60

# Cycle between subtitle files
K cycle sub
J cycle sub down

# Add/subtract 50 ms delay from subs
Z add sub-delay +0.05
z add sub-delay -0.05

# Adjust timing to previous/next subtitle
X sub-step 1
x sub-step -1

Hacking

If you want to modify this script or make an entirely new one from scratch, these links may help.

About

Adds mpv keybindings to create Anki cards from movies and TV shows.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 99.0%
  • Makefile 1.0%