diff --git a/src/Command/CreateProductionCommand.php b/src/Command/CreateProductionCommand.php index 78835be..2c8cc4f 100644 --- a/src/Command/CreateProductionCommand.php +++ b/src/Command/CreateProductionCommand.php @@ -2,6 +2,7 @@ namespace App\Command; +use App\Entity\SentenceListeningNote; use App\Entity\SentenceNote; use App\Entity\Term; use App\Service\AnkiService; @@ -70,6 +71,11 @@ class CreateProductionCommand extends Command $allNotes = $this->ankiService->getNotes($allIds); printf(" OK (%d)\n", count($allNotes)); + printf('Getting all SentenceCards...'); + $allListeningIds = $this->ankiService->getAllSentenceListeningNoteIds(); + $allListeningNotes = $this->ankiService->getNotes($allListeningIds); + printf(" OK (%d)\n", count($allListeningNotes)); + printf('Indexing all terms...'); $knownTerms = []; $knownKanji = []; @@ -152,6 +158,16 @@ class CreateProductionCommand extends Command arsort($termCounts); + // Have into account the ones that have already been created. + // This will not only skip them but take into account the kanjis they + // have. + foreach ($allListeningNotes as $listeningNote) { + assert($listeningNote instanceof SentenceListeningNote); + + $termKanji = self::getOnlyKanji($listeningNote->getTerm()->getKanji()); + self::kanjiDiff($seenKanji, $termKanji); + } + foreach ($termCounts as $term => $count) { $termKanji = self::getOnlyKanji($term); diff --git a/src/Entity/SentenceListeningNote.php b/src/Entity/SentenceListeningNote.php new file mode 100644 index 0000000..f361a10 --- /dev/null +++ b/src/Entity/SentenceListeningNote.php @@ -0,0 +1,104 @@ +term; + } + public function setTerm(Term $terms): static + { + $this->term = $terms; + return $this; + } + + + // ------------------------------------------------------- Anki-related --- + + public static function fromAnki(array $noteInfo): static + { + $note = parent::fromAnki($noteInfo); + + if ($note->getModel() !== self::MODEL_NAME) { + throw new \Exception('Trying to parse wrong model'); + } + + $note->mediaInfo = self::parseMediaInfo($note->fields['Notes']); + + // Set VocabKanji field + $note->term = Term::fromNoteFields($note->fields)[0] ?? null; + if ($note->term === null) { + throw new \Exception("Couldn't get term for Listening card"); + } + + return $note; + } + + public function toAnki(): array + { + return $this->fields; + } + + + // ---------------------------------------------------- Derived methods --- + + public function isSentKanjiHighlighted(): bool + { + return str_contains( + $this->fields['SentKanji'], + self::HIGHLIGHT_ATTR_KANJI, + ); + } + + private static function parseMediaInfo(string $notes): ?array + { + $matches = null; + + // Parse the notes fields. It can be in the form of + // series-name_S01 EP07 (11h22m33s44ms) + // or + // movie-name EP (11h22m33s44ms) + if (1 !== preg_match( + '/(?[0-9A-Za-z\-_]+)(_S)?(?\d*) EP(?\d*) \((?