diff --git a/README.md b/README.md index 73f7c3a..3fc386b 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ Most scripts assume: ### Usage: ```bash -./extract_anki_audio.py jp [--concat] [--outdir DIR] [--copy-only-new] -./extract_anki_audio.py es [--concat] [--outdir DIR] [--copy-only-new] +./audio_extractor.py jp [--concat] [--outdir DIR] [--copy-only-new] +./audio_extractor.py es [--concat] [--outdir DIR] [--copy-only-new] ``` Outputs: @@ -86,11 +86,20 @@ Outputs: ### Usage ```bash -./batch_anki_import.sh [jp|es] [--concat] [--outdir DIR] +./batch_anki_import.sh [jp|es] [--tags TAG1,TAG2,...] ``` -- Keeps all individual MP3s. -- If `--concat` is passed, also writes one combined MP3 for the run. +| Option | Description | +| -------------------------- | ------------------------------------------------------------------------------------------------ | +| `--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 - Anki + AnkiConnect @@ -100,6 +109,9 @@ Outputs: - Japanese: `~/Languages/Anki/sentences_jp.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 Extract frequent words from Anki notes using **AnkiConnect** and **spaCy**. @@ -292,4 +304,4 @@ Example: # License This project is licensed under the MIT License. -See the [`LICENSE`](./LICENSE) file for details. +See the [`LICENSE`](./LICENSE) file for details. \ No newline at end of file diff --git a/batch_anki_import.sh b/batch_anki_import.sh index aa28ab9..7a9442c 100755 --- a/batch_anki_import.sh +++ b/batch_anki_import.sh @@ -4,29 +4,32 @@ prog="$(basename "$0")" print_help() { cat <&2 + echo "usage: $prog [-h] [--tags TAG1,TAG2,...] {es,jp}" >&2 echo "$prog: error: the following arguments are required: lang" >&2 exit 2 } 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 exit 2 } lang="" +custom_tags="" while [[ $# -gt 0 ]]; do case "$1" in @@ -34,6 +37,14 @@ while [[ $# -gt 0 ]]; do print_help 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) if [[ -n "$lang" ]]; then arg_error_unknown "$1" @@ -49,6 +60,20 @@ done [[ -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 jp) DECK_NAME="日本語" @@ -66,8 +91,6 @@ case "$lang" in ;; esac - -TAGS='["AI-generated", "text-to-speech"]' count=0 # Use a temporary directory to handle processing @@ -138,4 +161,4 @@ done <"$SENTENCE_FILE" # Cleanup temp directory rm -rf "$TEMP_DIR" -echo "🎉 Done! Added $count cards to deck \"$DECK_NAME\"." +echo "🎉 Done! Added $count cards to deck \"$DECK_NAME\"." \ No newline at end of file