add bulk procesing
This commit is contained in:
@@ -12,7 +12,7 @@ from genanki import Deck, Model, Note, Package
|
||||
from pinyin_tone_converter.pinyin_tone_converter import PinyinToneConverter
|
||||
|
||||
# Local
|
||||
from .utility import DictionaryResult, ProcessFile, TranslationResult
|
||||
from .utility import DictionaryResult, ProcessFile, ProcessFolder, TranslationResult
|
||||
|
||||
# Constants
|
||||
|
||||
@@ -153,7 +153,6 @@ def output_anki_dictation(
|
||||
f"Deck for {final_file.name}, "
|
||||
"created in https://www.wolfang.info.ve/hskankicreator/",
|
||||
)
|
||||
package = Package(deck)
|
||||
audios = []
|
||||
for result in results:
|
||||
note = Note(
|
||||
@@ -166,6 +165,7 @@ def output_anki_dictation(
|
||||
)
|
||||
deck.add_note(note)
|
||||
audios.append(result.audio_path)
|
||||
package = Package(deck)
|
||||
package.media_files = audios
|
||||
package.write_to_file(final_file)
|
||||
return final_file
|
||||
@@ -236,3 +236,36 @@ def output_anki_phrase(
|
||||
package.media_files = audios
|
||||
package.write_to_file(final_file)
|
||||
return final_file
|
||||
|
||||
|
||||
def output_anki_package(
|
||||
process_folder: ProcessFolder, results: dict[ProcessFile, list[TranslationResult]]
|
||||
):
|
||||
final_file = process_file.output_name.with_suffix(".apkg")
|
||||
decks = []
|
||||
audios = []
|
||||
for process_file, results in results.items():
|
||||
deck_name = "::".join(
|
||||
ProcessFolder.input_folder.parts[:-1] + (ProcessFolder.output_name.stem,)
|
||||
)
|
||||
deck = Deck(
|
||||
random.randrange(1 << 30, 1 << 31),
|
||||
deck_name,
|
||||
f"Deck for {final_file.name}, "
|
||||
"created in https://www.wolfang.info.ve/hskankicreator/",
|
||||
)
|
||||
for result in results:
|
||||
note = Note(
|
||||
model=DICTATION_MODEL,
|
||||
fields=[
|
||||
result.translated,
|
||||
result.line,
|
||||
f"[sound:{result.audio_path}]",
|
||||
],
|
||||
)
|
||||
deck.add_note(note)
|
||||
audios.append(result.audio_path)
|
||||
decks.append(deck)
|
||||
package = Package(decks)
|
||||
package.media_files = audios
|
||||
package.write_to_file(final_file)
|
||||
|
||||
Reference in New Issue
Block a user