Skip to content

Latest commit

 

History

History
333 lines (287 loc) · 11.2 KB

card-export.md

File metadata and controls

333 lines (287 loc) · 11.2 KB

Card Creation

Subtitle Selection

The card creation process can be started at any time by pressing a, which brings up a menu for selecting subtitles to include on the card. Once the sub selection menu is active, the selected subtitles are shown at the bottom right of the screen. Information on timing is at the bottom left, and a help menu listing all available key bindings is at the top left.

Pressing a again adds the current subtitle to the selection. By default all subtitles are added automatically. This behavior can be toggled with A, or disabled in the script config.

q and e can be used to set the timing of the exported audio clip manually to the start or end of the currently active subtitle. Q and E do the same but using the current playback time instead. s sets the screenshot time to the current frame. Pressing the timing keys again while a time is set resets the corresponding time if the keypress would have set it to the same value. For example, if the screenshot time is set to 15:00.000 and the current timestamp in the video is also 15:00.000, pressing s will unset the screenshot time.

If no times are set, the clip will begin at the start of the first selected subtitle and end at the end of the last one. The screenshot will be the frame that's visible when the export happens. Screenshots can be toggled with s in the global menu.

y resets the selection and times. p plays the audio that would be exported with the current selection/times. d ends the subtitle selection and begins target word selection. f exports the selection immediately without any target words. F does the same but opens the export menu first.

Single Subtitle Export

By pressing K, line selection is skipped and the target word selection is started immediately with the current subtitle. Ctrl+k skips the entirety of the card creation process and instantly exports a card of the active subtitle including an audio clip and screenshot. Ctrl+K opens the export menu first.

Target Word Selection

In this part of the export process you can select one or more target words. By default you are limited to one (in accordance with AJATT/MIA/Refold practices), but it's possible to increase this limit (or remove it entirely) in the script config.

Unneeded parts of the text are deletable using the bindings described in keys.md.

The word can be selected with the usual key combinations for selecting text: (Ctrl+)(+)/. and switch between subtitles and Alt+DEL removes the current one from the selection.

Once you have chosen some text, you can look up any dictionary entries that match it exactly using and any entries starting with it using +. If you have lookup transformations configured you can use those with Ctrl+. Any whitespace characters (according to Unicode properties, including zero width spaces (U+200B)) before or after the word are automatically removed before searching.

If the search has any results, a new menu will open that allows you to choose one of them with / and , or Ctrl+ to add multiple definitions without returning to the previous menu. / can be used to switch between dictionaries (in the current group, if more than one is configured).

After selecting a definition, the word will be shown at the bottom right of the screen. If you want, you can now add pronunciation audio from Forvo using a (see below).

Like during subtitle selection, you can preview the selection audio with p. Alt+ removes the newest selected word.

When you are ready to export the card, you can do so using f, or F if you want to open the export menu first.

Forvo Audio

If you hit a after selecting a target word, Immersive will load a list of pronunciations of that word from Forvo. You will then be able to choose one using /. To play the audio of a pronunciation press SPACE. If it isn't loaded yet it might take a moment before it starts playing. If you want to load all audio files automatically set forvo_preload_audio to yes in the script config. Once you have selected a pronunciation that you are happy with, confirm it using .

If your target language is not Japanese you have to change forvo_language in the script config. The language code can be found on the Forvo website, for example on this page at the right of:

日本 pronunciation in Japanese [ja]

Export Menu

The export menu allows exporting a card using Anki's 'Add' GUI (g), and adding the export to an existing note.

The candidates for adding are found using the following query: "deck:<target deck>" "note:<target note type>" is:new, so all new cards of the target note type from the target deck.

s exports by adding to the most recently added candidate. a allows selecting a note from a list of candidates first. You can pick a note with / and . If you want to change how notes are displayed, you can use the target config entry note_template:

Variable Type Description
note_template
type single The note type
id single The note ID
tags list The tags of the note
field_<field name> single Contents of the field <field name>

Exporting

Once you initiate the export, Immersive will first validate your Anki target config and only proceed if that is successful. After that, the audio clip and screenshot are encoded, as is the Forvo audio if there is any and it is configured to be.

Then the following template is applied to each field of the target note type, as configured by the field:... entries of the target config, as well as to all tags in the target's tags entry (any spaces in variable values are replaced by underscores in tags):

Variable Type Description
field:<field name>/tags
words list all target words
selections list all target words, but exactly as selected from subtitles
sentences list subtitles selected for export
definitions list target word definitions as exported by the dictionary
audio single audio clip as an Anki sound tag
image single screenshot as an Anki/HTML image tag
word_audio single pronunciation file as an Anki sound tag
audio_file single filename of the audio clip
image_file single filename of the screenshot
word_audio_file single filename of the pronunciation audio
path single path to the file mpv is currently playing (excluding the filename)
the full URL for URLs
filename single filename of the file mpv is currently playing
identical to path for URLs
series_id single series ID as explained here
series_title single series title as explained here
prev_content single previous content of the field when adding to an existing note
start single start time of the audio formatted as [HH:][MM:]SS
end single end time of the audio formatted as [HH:][MM:]SS
start_ms single start time of the audio formatted as [HH:][MM:]SS.mmm
end_ms single end time of the audio formatted as [HH:][MM:]SS.mmm
start_seconds single start time of the audio in seconds
end_seconds single end time of the audio in seconds
start_seconds_ms single start time of the audio in seconds and milliseconds
end_seconds_ms single end time of the audio in seconds and milliseconds

The card is exported with the resulting fields and tags.

Substitutions

The variables definitions and sentences can be filtered through substitutions before being exported. These are defined in the target config entries definition_substitutions and sentence_substitutions.

sentence_substitutions are applied when selecting a subtitle line, definition_substitutions as the definition is added to the note immediately before it is sent to Anki.

Both entries expect a multiline value, with each line representing a substitution, e.g. this is what the default value of sentence_substitutions would look like in a config file:

sentence_substitutions=[[
<(.-)
<%(.-%)
]]

Each line is split at the first <. Everything to the left of it becomes the replacement and everything to the right becomes the pattern. If you want to use a < in the replacement string, you can escape it as \<. Other common escapes like \n or \t work as well, in both the replacement and pattern.

The pattern is a Lua pattern, which means that the following characters need to be escaped by placing a % before them if you want to use them literally: ^$()%.[]*+-?.

All occurrences of the pattern are replaced by the replacement string, or deleted if the string is empty (i.e. < is the first character of the substitution definition). The patterns are applied one after the other in the order they are defined in.

The default value of sentence_substitutions contains the patterns (.-) and %(.-%) (both with an empty replacement), which delete character names and kanji readings from Japanese subtitles. If you want to disable them, simply put this line in the global section of immersive-targets.conf:

sentence_substitutions=