batch_anki_import tags

This commit is contained in:
Pawel Sarkowicz
2026-05-12 10:09:15 -04:00
parent 343568f32b
commit f46ff5d9b0
2 changed files with 48 additions and 13 deletions

View File

@@ -66,8 +66,8 @@ Most scripts assume:
### Usage: ### Usage:
```bash ```bash
./extract_anki_audio.py jp [--concat] [--outdir DIR] [--copy-only-new] ./audio_extractor.py jp [--concat] [--outdir DIR] [--copy-only-new]
./extract_anki_audio.py es [--concat] [--outdir DIR] [--copy-only-new] ./audio_extractor.py es [--concat] [--outdir DIR] [--copy-only-new]
``` ```
Outputs: Outputs:
@@ -86,11 +86,20 @@ Outputs:
### Usage ### Usage
```bash ```bash
./batch_anki_import.sh [jp|es] [--concat] [--outdir DIR] ./batch_anki_import.sh [jp|es] [--tags TAG1,TAG2,...]
``` ```
- Keeps all individual MP3s. | Option | Description |
- If `--concat` is passed, also writes one combined MP3 for the run. | -------------------------- | ------------------------------------------------------------------------------------------------ |
| `--tags TAG1,TAG2,...` | Comma-separated list of tags. `text-to-speech` is always included. Default: `AI-generated` |
### Tag behavior
- By default, cards are tagged with `text-to-speech` and `AI-generated`
- When `--tags` is specified, `text-to-speech` is always included, and `AI-generated` is replaced by the custom tags
- Examples:
- `./batch_anki_import.sh jp` → tags: `text-to-speech`, `AI-generated`
- `./batch_anki_import.sh jp --tags manual` → tags: `text-to-speech`, `manual`
- `./batch_anki_import.sh es --tags "youtube,media"` → tags: `text-to-speech`, `youtube`, `media`
### Requirements ### Requirements
- Anki + AnkiConnect - Anki + AnkiConnect
@@ -100,6 +109,9 @@ Outputs:
- Japanese: `~/Languages/Anki/sentences_jp.txt` - Japanese: `~/Languages/Anki/sentences_jp.txt`
- Spanish: `~/Languages/Anki/sentences_es.txt` - Spanish: `~/Languages/Anki/sentences_es.txt`
### Notes
- Audio files are generated in a temporary directory and cleaned up after import. No local audio files are retained.
## word-scraper ## word-scraper
Extract frequent words from Anki notes using **AnkiConnect** and **spaCy**. Extract frequent words from Anki notes using **AnkiConnect** and **spaCy**.

View File

@@ -4,29 +4,32 @@ prog="$(basename "$0")"
print_help() { print_help() {
cat <<EOF cat <<EOF
usage: $prog [-h] {es,jp} usage: $prog [-h] [--tags TAG1,TAG2,...] {es,jp}
positional arguments: positional arguments:
{es,jp} {es,jp}
options: options:
-h, --help show this help message and exit -h, --help show this help message and exit
--tags TAG1,TAG2,... comma-separated list of additional tags (default: AI-generated)
text-to-speech is always included
EOF EOF
} }
arg_error_missing_lang() { arg_error_missing_lang() {
echo "usage: $prog [-h] {es,jp}" >&2 echo "usage: $prog [-h] [--tags TAG1,TAG2,...] {es,jp}" >&2
echo "$prog: error: the following arguments are required: lang" >&2 echo "$prog: error: the following arguments are required: lang" >&2
exit 2 exit 2
} }
arg_error_unknown() { arg_error_unknown() {
echo "usage: $prog [-h] {es,jp}" >&2 echo "usage: $prog [-h] [--tags TAG1,TAG2,...] {es,jp}" >&2
echo "$prog: error: unrecognized arguments: $*" >&2 echo "$prog: error: unrecognized arguments: $*" >&2
exit 2 exit 2
} }
lang="" lang=""
custom_tags=""
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
@@ -34,6 +37,14 @@ while [[ $# -gt 0 ]]; do
print_help print_help
exit 0 exit 0
;; ;;
--tags)
if [[ -z "$2" || "$2" == -* ]]; then
echo "$prog: error: --tags requires an argument" >&2
exit 2
fi
custom_tags="$2"
shift 2
;;
jp|es) jp|es)
if [[ -n "$lang" ]]; then if [[ -n "$lang" ]]; then
arg_error_unknown "$1" arg_error_unknown "$1"
@@ -49,6 +60,20 @@ done
[[ -z "$lang" ]] && arg_error_missing_lang [[ -z "$lang" ]] && arg_error_missing_lang
# Build tags JSON array - text-to-speech is always included
TAGS='["text-to-speech"'
if [[ -n "$custom_tags" ]]; then
IFS=',' read -ra tag_array <<< "$custom_tags"
for tag in "${tag_array[@]}"; do
# Trim whitespace
tag="$(echo -e "$tag" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
TAGS+=", \"$tag\""
done
else
TAGS+=', "AI-generated"'
fi
TAGS+=']'
case "$lang" in case "$lang" in
jp) jp)
DECK_NAME="日本語" DECK_NAME="日本語"
@@ -66,8 +91,6 @@ case "$lang" in
;; ;;
esac esac
TAGS='["AI-generated", "text-to-speech"]'
count=0 count=0
# Use a temporary directory to handle processing # Use a temporary directory to handle processing