From 1cf671c61981442b76c575e944bc132f514cf7a5 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 8 Oct 2023 14:34:00 +0200 Subject: add anki search query filtering to bulk-audio --- bulk-audio/bulk-audio.py | 8 ++++++++ bulk-audio/readme.md | 1 + 2 files changed, 9 insertions(+) (limited to 'bulk-audio') diff --git a/bulk-audio/bulk-audio.py b/bulk-audio/bulk-audio.py index 1027b3e..1fa84bb 100755 --- a/bulk-audio/bulk-audio.py +++ b/bulk-audio/bulk-audio.py @@ -48,6 +48,7 @@ def parse_args(argv): parser.add_argument("-n", "--noaudio", help="only modify notes that have \"noaudio\" as AUDIO_FIELD value", action='store_true') parser.add_argument("-i", "--note-id", help="select specific note (specify multiple times to select multiple notes)", action='append', nargs=1, default=[]) parser.add_argument("-d", "--dry-run", help="print only, do not edit anything", action='store_true') + parser.add_argument("-q", "--query", help="filter notes by search query", default=None) return parser.parse_known_args(argv[1:]) def main(): @@ -65,6 +66,7 @@ def main(): sys.stdout = real_stdout if aqt.mw == None: print("Please close any open Anki windows before running this script!") + sys.stdout = trash_out exit(1) # load last open profile if no profile was specified on command line (option parsed by Anki) @@ -85,8 +87,14 @@ def main(): if options.noaudio: note_ids = [nid for nid in note_ids if col.get_note(nid)[options.audio_field] == "noaudio"] + # filter flagged notes + if options.query != None: + filtered_note_ids = col.find_notes(options.query) + note_ids = [nid for nid in note_ids if nid in filtered_note_ids] + if len(note_ids) == 0: print("-- No notes found! (check your filters or note type?) --") + sys.stdout = trash_out exit(1) edited_notes = 0 diff --git a/bulk-audio/readme.md b/bulk-audio/readme.md index 06e7542..37b70d4 100644 --- a/bulk-audio/readme.md +++ b/bulk-audio/readme.md @@ -28,4 +28,5 @@ template](../anki-card-template) by default. |`./bulk-audio.py`|Download audio for all notes with empty Audio field| |`./bulk-audio.py -nO`|Try to download audio again for notes with "noaudio" Audio field| |`./bulk-audio.py -C`|Clear all Audio fields| +|`./bulk-audio.py -q flag:1 -O -s lp101_alt`|Override audio of all notes with red flag with audio from JapanesePod101 (Alternate)| -- cgit v1.2.3