• Stars
    star
    572
  • Rank 77,995 (Top 2 %)
  • Language
    Lua
  • License
    GNU General Publi...
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

mpvacious

AUR Chat GitHub Patreon

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.

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 or wl-copy 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

  • A guide on how to set up Anki can be found on our site. Note that it is not recommended to use FlatPak or similar containers.

  • If you're on a Windows or a Windows-like machine, a mpv build by shinchiro is recommended.

  • macOS users are advised to use homebrew or manually add mpv to PATH.

  • Make sure that your build of mpv supports encoding of audio and images. This shell command can be used to test it.

    $ 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 or instead install FFmpeg and enable FFmpeg support in mpvacious's config file.

    Most problems with adding audio or images to Anki cards can be fixed by installing and enabling FFmpeg separately.

Installation

There are multiple ways you can install mpvacious. I recommend installing with git so that you can easily update on demand.

mpvacious is a user-script for mpv, so it has to be installed in the directory mpv reads its user-scripts from.

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

Windows is not recommended, but we acknowledge that some people haven't switched to GNU/Linux yet.

Using git

Clone the repo to the scripts directory.

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

To update, run the following command.

cd ~/.config/mpv/scripts/subs2srs && git pull

From the AUR

mpvacious can be installed with the mpv-mpvacious package.

Manually

Download the repository or the latest release and extract the folder containing subs2srs.lua to your mpv scripts directory.

Expected directory tree
~/.config/mpv/scripts
|-- other script 1
|-- other script 2
|-- subs2srs
|   |-- main.lua
|   |-- subs2srs.lua
|   `-- other files
`-- other script 3
A note for mpv v0.32 and older

Older versions of mpv don't know how to handle user-scripts in subdirectories. You need to tell mpv where to look for mpvacious.

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

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

Note: in Celluloid user scripts are installed in /.config/celluloid/scripts/. When following the instructions above, replace .config/mpv with .config/celluloid and optionally subs2srs with the name of the folder mpvacious is cloned into.

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.

Tip: Try our official note type if you don't want to configure note fields yourself. Alternatively, we have a collection of user-created note types, which you can browse here.

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.

If no matter what mpvacious fails to create audio clips and/or snapshots, change use_ffmpeg to yes. By using ffmpeg instead of the encoder built in mpv you can work around most encoder issues. You need to have ffmpeg installed for this to work.

Key bindings

The user may change some global 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:

a            script-binding mpvacious-menu-open

Ctrl+n       script-binding mpvacious-export-note

Ctrl+m       script-binding mpvacious-update-last-note
Ctrl+M       script-binding mpvacious-overwrite-last-note

Ctrl+c       script-binding mpvacious-copy-sub-to-clipboard
Ctrl+t       script-binding mpvacious-autocopy-toggle

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

Ctrl+h       script-binding mpvacious-sub-rewind
Ctrl+H       script-binding mpvacious-sub-replay
Ctrl+L       script-binding mpvacious-sub-play-up-to-next

Ctrl+v       script-binding mpvacious-secondary-sid-toggle
Ctrl+k       script-binding mpvacious-secondary-sid-prev
Ctrl+j       script-binding mpvacious-secondary-sid-next

Note: A capital letter means that you need to press Shift in order to activate the corresponding binding. For example, Ctrl+M actually means Ctrl+Shift+m. mpv accepts both variants in input.conf.

Usage

Global bindings

Menu:

  • a - Open advanced menu.

Enable\Disable animation:

  • Ctrl+g - If animation is enabled, animated snapshots will be generated instead of static images. Animated snapshot are like GIFs (just in a different format) and will capture the video from the start to the end times selected.

Make a card:

  • Ctrl+n - Export a card with the currently visible subtitle line on the front. Use this when your subs are well-timed, and the target sentence doesn't span multiple subs.

Update the last card:

  • Ctrl+m - Append to the media fields of the newly added Anki card.
  • Ctrl+Shift+m - Overwrite media fields of the newly added Anki card.

Clipboard:

  • Ctrl+c - Copy current subtitle string to the system clipboard.
  • Ctrl+t - Toggle automatic copying of subtitles to the clipboard.

Seeking:

  • 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+Shift+l - Play until the end of the next subtitle, and pause. Useful for beginners who need to look up words in each and every dialogue line.

Secondary subtitles:

  • Ctrl+v - Toggle visibility.
  • Ctrl+k - Switch to the previous subtitle if it's not already selected.
  • Ctrl+j - Switch to the next subtitle if it's not already selected.

Menu options

Advanced menu has the following options:

  • c - Interactive subtitle selection. The range of the currently displayed subtitle line is selected. The selection then grows both ways based on the following displayed lines. It does nothing if there are no subs on screen.

  • shift+s - Set the start time to the current sub. The selection then grows forward based on the following displayed lines. The default selection spans across the range of the currently displayed subtitle line.

  • shift+e - Set the end time to the current sub. The selection then grows backward based on the following displayed lines. The default selection spans across the range of the currently displayed subtitle line.

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.

  • z and Shift+z - Adjust subtitle delay.

If above fails, you have to manually set timings.

  • s - Set the start time. The selection then grows forward based on the following displayed lines. The default selection spans across the selected start point and the end of the subtitle line.
  • e - Set the end time. The selection then grows backward based on the following displayed lines. The default selection spans across the selected end point and the start of the subtitle line.

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.

My subtitles are not in sync

If subs are badly timed, first, you could try to re-time them. Read Retiming subtitles. Or shift timings using key bindings provided by mpv (usually z and Shift+z).

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. Here's a video demonstration.

If the show is hard-subbed, you can use transformers-ocr to recognize and add text to the card.

Secondary subtitles

If you want to add a translation to your cards, and you have the subtitles in that language, you can add them as secondary subtitles if you run mpv with --secondary-sid=<sid> parameter, sid being the track identifier for the subtitle.

You also need to specify secondary_field in the config file if it is different from the default.

If you want to load secondary subtitles automatically, don't modify the run parameters and instead set the desired languages in the config file (secondary_sub_lang option).

Secondary subtitles will be visible when hovering over the top part of the mpv window.

screencast.mp4

By pressing Ctrl+v you can control secondary sid visibility without using the mouse.

Other tools

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

  • Clipboard Inserter browser add-on (chrome) (firefox)
  • A html page (1) (2) to paste the contents of your 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

Profiles

Mpvacious supports config profiles. To make use of them, create a new config file called subs2srs_profiles.conf in the same folder as your subs2srs.conf. Inside the file, define available profile names (without .conf) and the name of the active profile:

profiles=subs2srs,english,german
active=subs2srs

In the example above, I have three profiles. The first one is the default, the second one is for learning English, the third one is for learning German.

Then in the same folder create config files for each of the defined profiles. For example, below is the contents of my english.conf file:

deck_name=English sentence mining
model_name=General
sentence_field=Question
audio_field=Audio
image_field=Extra

You don't have to redefine all settings in the new profile. Specify only the ones you want to be different from the default.

To cycle profiles, open the advanced menu by pressing a and then press p. At any time you can see what profile is active in the menu's status bar.

Hacking

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

More Repositories

1

videoclip

🍗 Easily create videoclips with mpv.
Lua
94
star
2

anki.koplugin

KOReader plugin enabling Anki card generations for words looked up in the internal dictionary.
Lua
50
star
3

impd

🍵 AJATT-style passive listening and condensed audio without bloat.
Shell
35
star
4

AnkiNoteTypes

🍉 A collection of note types for Anki 2.1
HTML
32
star
5

transformers_ocr

🍤 An OCR tool using maim with Transformers.
Python
27
star
6

gd-tools

🍣 A set of tools to enhance GoldenDict.
C++
26
star
7

Japanese

🍚 Automatically generate furigana and other data on Anki cards.
Python
26
star
8

PasteImagesAsWebP

🍙 An Anki add-on that makes your images small.
Python
23
star
9

sub-transition

🍩 Speed up the video if no subtitles are visible.
Lua
15
star
10

kitsunekko-mirror

🌸 A backup mirror of kitsunekko. Downloaded using kitsunekko-tools.
SRecode Template
14
star
11

dictpopup

Looks up selected (Japanese) text in your Yomichan dictionaries and displays the result as a popup.
C
13
star
12

FlexibleGrading

🍶 Bring keyboard-driven reviewing to Anki 2.1.
Python
13
star
13

kitsunekko-tools

🍥 A set of scripts for creating a local kitsunekko mirror.
HTML
12
star
14

mortician

🌽 Buries time-wasting cards that you keep failing.
Python
10
star
15

mecab_controller

🍣 Mecab wrapper to generate furigana readings.
Python
9
star
16

mergenotes

🥗 Merge content of selected cards
Python
8
star
17

learn-now-button

🍝 Put cards in the learning queue and answer cards from the Card Browser.
Python
8
star
18

Furigana

Automatically generate furigana on Anki cards.
Python
8
star
19

RefoldEase

🌮 Sets the ease factor of Anki cards to the value you choose.
Python
6
star
20

shinmeikai_8_pronunciations_index

📢 Shinmeikai 8 pronunciations source for AJT Japanese
5
star
21

cropro

🍱 Anki Add-on: Cross-Profile Search and Import. Find notes in another profile and import them into current profile.
Python
4
star
22

next-episode

🍿 a simple script to jump between episodes in mpv
Lua
4
star
23

blur-mpv

📺 a standalone script to produce blur effect in mpv
Lua
4
star
24

nhk_2016_pronunciations_index

🎤️ NHK 2016 pronunciations index
3
star
25

BrowserPlayButton

▶️ Adds a play button to the Anki Browser toolbar.
Python
3
star
26

rdricpp

🍔 Rikaitan Deinflector Reference Implementation in C++.
C++
3
star
27

twimm

Tool for watching twitch broadcasts in a desired language (and a bit more)
Shell
2
star
28

hunspell-ja

Hunspell morphology dictionary for Japanese used in GoldenDict.
1
star
29

autocopy

Automatically copy text from a card to the clipboard.
Python
1
star
30

anki-fast-note-type-editor

Python
1
star
31

btstrm

🫗 stream torrents without soy webtorrent (and with some features)
Python
1
star
32

nhk_1998_pronunciations_index

NHK 1998 pronunciations index
1
star
33

nhk_2016_pronunciations_index_mp3

NHK 2016 pronunciations index for AJT Japanese (mp3 audio files)
1
star
34

nhk_1998_pronunciations_index_mp3

NHK 1998 pronunciations index for AJT Japanese (mp3 audio files)
1
star
35

taas_pronunciations_index

TAAS pronunciations source for AJT Japanese (opus audio)
1
star